Skip to content

Commit 45ffb26

Browse files
committedNov 7, 2017
Fix updating map extent on resize
1 parent 53c8779 commit 45ffb26

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed
 

‎src/core/layout/qgslayoutitemmap.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ QgsLayoutItemMap::QgsLayoutItemMap( QgsLayout *layout )
5050

5151
connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
5252
{
53-
updateBoundingRect();
54-
update();
53+
shapeChanged();
5554
} );
5655

5756
# if 0
@@ -945,6 +944,29 @@ void QgsLayoutItemMap::painterJobFinished()
945944
update();
946945
}
947946

947+
void QgsLayoutItemMap::shapeChanged()
948+
{
949+
// keep center as center
950+
QgsPointXY oldCenter = mExtent.center();
951+
952+
double w = rect().width();
953+
double h = rect().height();
954+
955+
// keep same width as before
956+
double newWidth = mExtent.width();
957+
// but scale height to match item's aspect ratio
958+
double newHeight = newWidth * h / w;
959+
960+
mExtent = QgsRectangle::fromCenterAndSize( oldCenter, newWidth, newHeight );
961+
962+
//recalculate data defined scale and extents
963+
refreshMapExtents();
964+
updateBoundingRect();
965+
invalidateCache();
966+
emit changed();
967+
emit extentChanged();
968+
}
969+
948970
void QgsLayoutItemMap::connectUpdateSlot()
949971
{
950972
//connect signal from layer registry to update in case of new or deleted layers

‎src/core/layout/qgslayoutitemmap.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,8 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
507507

508508
void painterJobFinished();
509509

510+
void shapeChanged();
511+
510512
private:
511513

512514

@@ -619,11 +621,6 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
619621
//! True if annotation items, rubber band, etc. from the main canvas should be displayed
620622
bool mDrawAnnotations = true;
621623

622-
/**
623-
* Adjusts an extent rectangle to match the provided item width and height, so that extent
624-
* center of extent remains the same */
625-
void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle &extent ) const;
626-
627624
//! True if map is being controlled by an atlas
628625
bool mAtlasDriven = false;
629626
//! Current atlas scaling mode

0 commit comments

Comments
 (0)
Please sign in to comment.