Skip to content

Commit

Permalink
Require at least Qt 4.6
Browse files Browse the repository at this point in the history
Cleans up the code a bit. The Qt 4.6 release is now more than one year
old so maintaining compilation against 4.5 is no longer worth it.
  • Loading branch information
bjorn committed Feb 4, 2011
1 parent 4f2147d commit 3adf2fd
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 68 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ provide parts of the user interface.
COMPILING
-------------------------------------------------------------------------------

Make sure the Qt (>= 4.5) development libraries are installed:
Make sure the Qt (>= 4.6) development libraries are installed:

In Ubuntu/Debian: sudo apt-get install libqt4-dev
In Fedora: yum install qt-devel
Expand Down
45 changes: 13 additions & 32 deletions src/libtiled/mapreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ class MapReaderPrivate
QString errorString() const;

private:
bool readNextStartElement();
void readUnknownElement();
void skipCurrentElement();

Map *readMap();

Expand Down Expand Up @@ -126,7 +124,7 @@ Map *MapReaderPrivate::readMap(QIODevice *device, const QString &path)

xml.setDevice(device);

if (readNextStartElement() && xml.name() == "map") {
if (xml.readNextStartElement() && xml.name() == "map") {
map = readMap();
} else {
xml.raiseError(tr("Not a map file."));
Expand All @@ -145,7 +143,7 @@ Tileset *MapReaderPrivate::readTileset(QIODevice *device, const QString &path)

xml.setDevice(device);

if (readNextStartElement() && xml.name() == "tileset")
if (xml.readNextStartElement() && xml.name() == "tileset")
tileset = readTileset();
else
xml.raiseError(tr("Not a tileset file."));
Expand Down Expand Up @@ -179,27 +177,10 @@ bool MapReaderPrivate::openFile(QFile *file)
return true;
}

bool MapReaderPrivate::readNextStartElement()
{
while (xml.readNext() != QXmlStreamReader::Invalid) {
if (xml.isEndElement())
return false;
else if (xml.isStartElement())
return true;
}
return false;
}

void MapReaderPrivate::readUnknownElement()
{
qDebug() << "Unknown element (fixme):" << xml.name();
skipCurrentElement();
}

void MapReaderPrivate::skipCurrentElement()
{
while (readNextStartElement())
skipCurrentElement();
xml.skipCurrentElement();
}

static Map::Orientation orientationFromString(const QStringRef &string)
Expand Down Expand Up @@ -239,7 +220,7 @@ Map *MapReaderPrivate::readMap()

mMap = new Map(orientation, mapWidth, mapHeight, tileWidth, tileHeight);

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "properties")
mMap->mergeProperties(readProperties());
else if (xml.name() == "tileset")
Expand Down Expand Up @@ -295,7 +276,7 @@ Tileset *MapReaderPrivate::readTileset()
tileset = new Tileset(name, tileWidth, tileHeight,
tileSpacing, margin);

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "tile")
readTilesetTile(tileset);
else if (xml.name() == "image")
Expand All @@ -314,7 +295,7 @@ Tileset *MapReaderPrivate::readTileset()
.arg(absoluteSource, error));
}

skipCurrentElement();
xml.skipCurrentElement();
}

if (tileset && !mReadingExternalTileset)
Expand All @@ -337,7 +318,7 @@ void MapReaderPrivate::readTilesetTile(Tileset *tileset)

// TODO: Add support for individual tiles (then it needs to be added here)

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "properties") {
Tile *tile = tileset->tileAt(id);
tile->mergeProperties(readProperties());
Expand Down Expand Up @@ -367,7 +348,7 @@ void MapReaderPrivate::readTilesetImage(Tileset *tileset)
if (!tileset->loadFromImage(tilesetImage, source))
xml.raiseError(tr("Error loading tileset image:\n'%1'").arg(source));

skipCurrentElement();
xml.skipCurrentElement();
}

static void readLayerAttributes(Layer *layer,
Expand Down Expand Up @@ -400,7 +381,7 @@ TileLayer *MapReaderPrivate::readLayer()
TileLayer *tileLayer = new TileLayer(name, x, y, width, height);
readLayerAttributes(tileLayer, atts);

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "properties")
tileLayer->mergeProperties(readProperties());
else if (xml.name() == "data")
Expand Down Expand Up @@ -448,7 +429,7 @@ void MapReaderPrivate::readLayerData(TileLayer *tileLayer)
y++;
}

skipCurrentElement();
xml.skipCurrentElement();
} else {
readUnknownElement();
}
Expand Down Expand Up @@ -596,7 +577,7 @@ ObjectGroup *MapReaderPrivate::readObjectGroup()
if (!color.isEmpty())
objectGroup->setColor(color);

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "object")
objectGroup->addObject(readObject());
else if (xml.name() == "properties")
Expand Down Expand Up @@ -652,7 +633,7 @@ MapObject *MapReaderPrivate::readObject()
}
}

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "properties")
object->mergeProperties(readProperties());
else
Expand All @@ -668,7 +649,7 @@ Properties MapReaderPrivate::readProperties()

Properties properties;

while (readNextStartElement()) {
while (xml.readNextStartElement()) {
if (xml.name() == "property")
readProperty(&properties);
else
Expand Down
2 changes: 0 additions & 2 deletions src/tiled/brushitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ BrushItem::BrushItem():
mMapDocument(0),
mTileLayer(0)
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
#endif
}

void BrushItem::setMapDocument(MapDocument *mapDocument)
Expand Down
4 changes: 0 additions & 4 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
QUndoGroup *undoGroup = mDocumentManager->undoGroup();
QAction *undoAction = undoGroup->createUndoAction(this, tr("Undo"));
QAction *redoAction = undoGroup->createRedoAction(this, tr("Redo"));
#if QT_VERSION >= 0x040600
mUi->mainToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
mUi->actionNew->setPriority(QAction::LowPriority);
redoAction->setPriority(QAction::LowPriority);
#endif
redoAction->setIcon(redoIcon);
undoAction->setIcon(undoIcon);
redoAction->setIconText(tr("Redo"));
Expand All @@ -153,9 +151,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
mUi->actionSave->setShortcuts(QKeySequence::Save);
mUi->actionSaveAs->setShortcuts(QKeySequence::SaveAs);
mUi->actionClose->setShortcuts(QKeySequence::Close);
#if QT_VERSION >= 0x040600
mUi->actionQuit->setShortcuts(QKeySequence::Quit);
#endif
mUi->actionCut->setShortcuts(QKeySequence::Cut);
mUi->actionCopy->setShortcuts(QKeySequence::Copy);
mUi->actionPaste->setShortcuts(QKeySequence::Paste);
Expand Down
11 changes: 0 additions & 11 deletions src/tiled/mapobjectitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ ResizeHandle::ResizeHandle(MapObjectItem *mapObjectItem)
{
setCursor(Qt::SizeFDiagCursor);
setFlag(QGraphicsItem::ItemIsMovable);
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemSendsGeometryChanges);
#endif
}

QRectF ResizeHandle::boundingRect() const
Expand Down Expand Up @@ -229,16 +227,7 @@ QRectF MapObjectItem::boundingRect() const
QPainterPath MapObjectItem::shape() const
{
QPainterPath path = mMapDocument->renderer()->shape(mObject);
#if QT_VERSION >= 0x040600
path.translate(-pos());
#else
const QPointF p = pos();
const int elementCount = path.elementCount();
for (int i = 0; i < elementCount; i++) {
const QPainterPath::Element &element = path.elementAt(i);
path.setElementPositionAt(i, element.x - p.x(), element.y - p.y());
}
#endif
return path;
}

Expand Down
2 changes: 0 additions & 2 deletions src/tiled/objectgroupitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ using namespace Tiled::Internal;
ObjectGroupItem::ObjectGroupItem(ObjectGroup *objectGroup):
mObjectGroup(objectGroup)
{
#if QT_VERSION >= 0x040600
// Since we don't do any painting, we can spare us the call to paint()
setFlag(QGraphicsItem::ItemHasNoContents);
#endif

const Map *map = objectGroup->map();
setPos(objectGroup->x() * map->tileWidth(),
Expand Down
2 changes: 0 additions & 2 deletions src/tiled/tilelayeritem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ TileLayerItem::TileLayerItem(TileLayer *layer, MapRenderer *renderer)
: mLayer(layer)
, mRenderer(renderer)
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
#endif

syncWithTileLayer();
setOpacity(mLayer->opacity());
Expand Down
2 changes: 0 additions & 2 deletions src/tiled/tileselectionitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ using namespace Tiled::Internal;
TileSelectionItem::TileSelectionItem(MapDocument *mapDocument)
: mMapDocument(mapDocument)
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
#endif

connect(mMapDocument, SIGNAL(tileSelectionChanged(QRegion,QRegion)),
this, SLOT(selectionChanged(QRegion,QRegion)));
Expand Down
2 changes: 0 additions & 2 deletions src/tiled/tileselectionitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class TileSelectionItem : public QObject,
public QGraphicsItem
{
Q_OBJECT
#if QT_VERSION >= 0x040600
Q_INTERFACES(QGraphicsItem)
#endif

public:
/**
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ QString writableImageFormatsFilter();
* This is a templated method which is used on instances of QAction, QMenu,
* QToolButton, etc.
*
* Does nothing for Qt < 4.6 or when the platform is not Linux.
* Does nothing when the platform is not Linux.
*/
template <class T>
void setThemeIcon(T *t, const char *name)
{
#if QT_VERSION >= 0x040600 && defined(Q_OS_LINUX)
#ifdef Q_OS_LINUX
QIcon themeIcon = QIcon::fromTheme(QLatin1String(name));
if (!themeIcon.isNull())
t->setIcon(themeIcon);
Expand Down
6 changes: 0 additions & 6 deletions src/tmxviewer/tmxviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ class TileLayerItem : public QGraphicsItem
, mTileLayer(tileLayer)
, mRenderer(renderer)
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption);
#endif
}

QRectF boundingRect() const
Expand Down Expand Up @@ -116,9 +114,7 @@ class ObjectGroupItem : public QGraphicsItem
QGraphicsItem *parent = 0)
: QGraphicsItem(parent)
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemHasNoContents);
#endif

// Create a child item for each object
foreach (MapObject *object, objectGroup->objects())
Expand All @@ -138,9 +134,7 @@ class MapItem : public QGraphicsItem
MapItem(Map *map, MapRenderer *renderer, QGraphicsItem *parent = 0)
: QGraphicsItem(parent)
{
#if QT_VERSION >= 0x040600
setFlag(QGraphicsItem::ItemHasNoContents);
#endif

// Create a child item for each layer
foreach (Layer *layer, map->layers()) {
Expand Down
4 changes: 2 additions & 2 deletions tiled.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
isEmpty(QT_VERSION) {
error("QT_VERSION not defined. Tiled does not work with Qt 3.")
}
contains(QT_VERSION, ^4\\.[0-4]\\..*) {
contains(QT_VERSION, ^4\\.[0-5]\\..*) {
message("Cannot build Tiled with Qt version $$QT_VERSION")
error("Use at least Qt 4.5")
error("Use at least Qt 4.6")
}

TEMPLATE = subdirs
Expand Down

0 comments on commit 3adf2fd

Please sign in to comment.