Skip to content

Commit

Permalink
Fixed some issues when changing map properties
Browse files Browse the repository at this point in the history
A lot of places were still relying on the mapChanged signal, but they
should use the MapChangeEvent since 2177fac.
  • Loading branch information
bjorn committed Nov 11, 2024
1 parent cc8b527 commit 116cf5f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/tiled/mapdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ class TILED_EDITOR_EXPORT MapDocument final : public Document
void mapObjectPicked(MapObject *object);

/**
* Emitted when the map size or its tile size changes.
* Emitted when the map size size changes.
*/
void mapChanged();
void mapResized();

void layerAdded(Layer *layer);
void layerAboutToBeRemoved(GroupLayer *parentLayer, int index);
Expand Down
8 changes: 6 additions & 2 deletions src/tiled/mapdocumentactionhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,12 @@ void MapDocumentActionHandler::setMapDocument(MapDocument *mapDocument)
this, &MapDocumentActionHandler::updateActions);
connect(mapDocument, &MapDocument::selectedObjectsChanged,
this, &MapDocumentActionHandler::updateActions);
connect(mapDocument, &MapDocument::mapChanged,
this, &MapDocumentActionHandler::updateActions);
connect(mapDocument, &MapDocument::changed,
this, [this] (const ChangeEvent &change) {
if (change.type == ChangeEvent::MapChanged)
if (static_cast<const MapChangeEvent&>(change).property == Map::InfiniteProperty)
updateActions();
});
}
}

Expand Down
22 changes: 21 additions & 1 deletion src/tiled/mapitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ MapItem::MapItem(const MapDocumentPtr &mapDocument, DisplayMode displayMode,
connect(prefs, &Preferences::backgroundFadeColorChanged, this, [this] (QColor color) { mDarkRectangle->setBrush(color); });

connect(mapDocument.data(), &Document::changed, this, &MapItem::documentChanged);
connect(mapDocument.data(), &MapDocument::mapChanged, this, &MapItem::mapChanged);
connect(mapDocument.data(), &MapDocument::regionChanged, this, &MapItem::repaintRegion);
connect(mapDocument.data(), &MapDocument::tileLayerChanged, this, &MapItem::tileLayerChanged);
connect(mapDocument.data(), &MapDocument::layerAdded, this, &MapItem::layerAdded);
Expand Down Expand Up @@ -391,6 +390,27 @@ void MapItem::documentChanged(const ChangeEvent &change)

break;
}
case ChangeEvent::MapChanged: {
auto &mapChange = static_cast<const MapChangeEvent&>(change);
switch (mapChange.property) {
case Map::TileSizeProperty:
case Map::InfiniteProperty:
case Map::HexSideLengthProperty:
case Map::StaggerAxisProperty:
case Map::StaggerIndexProperty:
case Map::ParallaxOriginProperty:
case Map::OrientationProperty:
mapChanged();
break;
case Map::RenderOrderProperty:
case Map::BackgroundColorProperty:
case Map::LayerDataFormatProperty:
case Map::CompressionLevelProperty:
case Map::ChunkSizeProperty:
break;
}
break;
}
case ChangeEvent::LayerChanged:
layerChanged(static_cast<const LayerChangeEvent&>(change));
break;
Expand Down
11 changes: 3 additions & 8 deletions src/tiled/objectselectionitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ ObjectSelectionItem::ObjectSelectionItem(MapDocument *mapDocument,
connect(mapDocument, &MapDocument::aboutToBeSelectedObjectsChanged,
this, &ObjectSelectionItem::aboutToBeSelectedObjectsChanged);

connect(mapDocument, &MapDocument::mapChanged,
this, &ObjectSelectionItem::mapChanged);

connect(mapDocument, &MapDocument::layerAdded,
this, &ObjectSelectionItem::layerAdded);

Expand Down Expand Up @@ -403,6 +400,9 @@ void ObjectSelectionItem::changeEvent(const ChangeEvent &event)
}
break;
}
case ChangeEvent::MapChanged:
updateItemPositions();
break;
case ChangeEvent::LayerChanged:
layerChanged(static_cast<const LayerChangeEvent&>(event));
break;
Expand Down Expand Up @@ -493,11 +493,6 @@ void ObjectSelectionItem::hoveredMapObjectChanged(MapObject *object,
}
}

void ObjectSelectionItem::mapChanged()
{
updateItemPositions();
}

static void collectObjects(const GroupLayer &groupLayer, QList<MapObject*> &objects, bool onlyVisibleLayers = false)
{
for (Layer *layer : groupLayer) {
Expand Down
1 change: 0 additions & 1 deletion src/tiled/objectselectionitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class ObjectSelectionItem : public QGraphicsObject
void selectedObjectsChanged();
void aboutToBeSelectedObjectsChanged();
void hoveredMapObjectChanged(MapObject *object, MapObject *previous);
void mapChanged();
void layerAdded(Layer *layer);
void layerAboutToBeRemoved(GroupLayer *parentLayer, int index);
void layerChanged(const LayerChangeEvent &event);
Expand Down
14 changes: 7 additions & 7 deletions src/tiled/objectselectiontool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include <QUndoStack>

#include <cmath>
#include <float.h>

using namespace Tiled;

Expand Down Expand Up @@ -335,8 +334,10 @@ ObjectSelectionTool::ObjectSelectionTool(QObject *parent)
else
mSelectContained->setChecked(true);

connect(mSelectIntersected, &QAction::triggered, [this] { setSelectionMode(Qt::IntersectsItemShape); });
connect(mSelectContained, &QAction::triggered, [this] { setSelectionMode(Qt::ContainsItemShape); });
connect(mSelectIntersected, &QAction::triggered,
this, [this] { setSelectionMode(Qt::IntersectsItemShape); });
connect(mSelectContained, &QAction::triggered,
this, [this] { setSelectionMode(Qt::ContainsItemShape); });

for (int i = 0; i < CornerAnchorCount; ++i)
mRotateHandles[i] = new RotateHandle(static_cast<AnchorPosition>(i));
Expand Down Expand Up @@ -366,8 +367,6 @@ void ObjectSelectionTool::activate(MapScene *scene)

updateHandlesAndOrigin();

connect(mapDocument(), &MapDocument::mapChanged,
this, &ObjectSelectionTool::updateHandlesAndOrigin);
connect(mapDocument(), &MapDocument::selectedObjectsChanged,
this, &ObjectSelectionTool::updateHandlesAndOrigin);
connect(mapDocument(), &MapDocument::tilesetTilePositioningChanged,
Expand All @@ -390,8 +389,6 @@ void ObjectSelectionTool::deactivate(MapScene *scene)
for (ResizeHandle *handle : mResizeHandles)
scene->removeItem(handle);

disconnect(mapDocument(), &MapDocument::mapChanged,
this, &ObjectSelectionTool::updateHandlesAndOrigin);
disconnect(mapDocument(), &MapDocument::selectedObjectsChanged,
this, &ObjectSelectionTool::updateHandlesAndOrigin);
disconnect(mapDocument(), &MapDocument::tilesetTilePositioningChanged,
Expand Down Expand Up @@ -779,6 +776,9 @@ void ObjectSelectionTool::changeEvent(const ChangeEvent &event)
return;

switch (event.type) {
case ChangeEvent::MapChanged:
updateHandlesAndOrigin();
break;
case ChangeEvent::LayerChanged:
if (static_cast<const LayerChangeEvent&>(event).properties & LayerChangeEvent::PositionProperties)
updateHandlesAndOrigin();
Expand Down
2 changes: 1 addition & 1 deletion src/tiled/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ class MapSizeProperty : public SizeProperty
parent)
, mMapDocument(mapDocument)
{
connect(mMapDocument, &MapDocument::mapChanged,
connect(mMapDocument, &MapDocument::mapResized,
this, &Property::valueChanged);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tiled/resizemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void ResizeMap::swapSize()
map->setHeight(mSize.height());
mSize = oldSize;

emit mMapDocument->mapChanged();
emit mMapDocument->mapResized();
}

} // namespace Tiled

0 comments on commit 116cf5f

Please sign in to comment.