Skip to content

Commit

Permalink
Fixed positioning of map view when switching between maps in a world
Browse files Browse the repository at this point in the history
When the new map has not previously been open the "fit map in view"
logic kicked in, overriding the synchronization of the scale and
position for the current world.

Fixed by never doing "fit map in view" when a "forceCenterOn" call
happened.
  • Loading branch information
bjorn committed Jun 24, 2020
1 parent c129d49 commit 8376b44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/tiled/mapeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ void MapEditor::restoreDocumentState(MapDocument *mapDocument) const
mapView->zoomable()->setScale(scale);

const QPointF viewCenter = fromSettingsValue<QPointF>(fileState.value(QLatin1String("viewCenter")));
mapView->setInitialCenterPos(viewCenter);
mapView->forceCenterOn(viewCenter);

const int layerIndex = fileState.value(QLatin1String("selectedLayer")).toInt();
if (Layer *layer = layerAtGlobalIndex(mapDocument->map(), layerIndex))
Expand Down
8 changes: 8 additions & 0 deletions src/tiled/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ void MapView::setHandScrolling(bool handScrolling)
*/
void MapView::forceCenterOn(const QPointF &pos)
{
// Let's wait until the initial paint event before we position the view,
// otherwise layout changes may still affect the position.
if (!mViewInitialized) {
mInitialCenterPos = pos;
mHasInitialCenterPos = true;
return;
}

// This is only to make it update QGraphicsViewPrivate::lastCenterPoint,
// just in case this is important.
QGraphicsView::centerOn(pos);
Expand Down
9 changes: 0 additions & 9 deletions src/tiled/mapview.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class MapView : public QGraphicsView
MapView(QWidget *parent = nullptr, Mode mode = StaticContents);
~MapView() override;

void setInitialCenterPos(const QPointF &center);

void setScene(MapScene *scene);
MapScene *mapScene() const;

Expand Down Expand Up @@ -125,13 +123,6 @@ class MapView : public QGraphicsView
Zoomable *mZoomable;
};


inline void MapView::setInitialCenterPos(const QPointF &center)
{
mInitialCenterPos = center;
mHasInitialCenterPos = true;
}

} // namespace Tiled

Q_DECLARE_METATYPE(Tiled::MapView*)

0 comments on commit 8376b44

Please sign in to comment.