mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-29 00:03:59 -04:00
Fix updating map extent on resize
This commit is contained in:
parent
53c877963a
commit
45ffb262b7
@ -50,8 +50,7 @@ QgsLayoutItemMap::QgsLayoutItemMap( QgsLayout *layout )
|
|||||||
|
|
||||||
connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
|
connect( this, &QgsLayoutItem::sizePositionChanged, this, [ = ]
|
||||||
{
|
{
|
||||||
updateBoundingRect();
|
shapeChanged();
|
||||||
update();
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
# if 0
|
# if 0
|
||||||
@ -945,6 +944,29 @@ void QgsLayoutItemMap::painterJobFinished()
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsLayoutItemMap::shapeChanged()
|
||||||
|
{
|
||||||
|
// keep center as center
|
||||||
|
QgsPointXY oldCenter = mExtent.center();
|
||||||
|
|
||||||
|
double w = rect().width();
|
||||||
|
double h = rect().height();
|
||||||
|
|
||||||
|
// keep same width as before
|
||||||
|
double newWidth = mExtent.width();
|
||||||
|
// but scale height to match item's aspect ratio
|
||||||
|
double newHeight = newWidth * h / w;
|
||||||
|
|
||||||
|
mExtent = QgsRectangle::fromCenterAndSize( oldCenter, newWidth, newHeight );
|
||||||
|
|
||||||
|
//recalculate data defined scale and extents
|
||||||
|
refreshMapExtents();
|
||||||
|
updateBoundingRect();
|
||||||
|
invalidateCache();
|
||||||
|
emit changed();
|
||||||
|
emit extentChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsLayoutItemMap::connectUpdateSlot()
|
void QgsLayoutItemMap::connectUpdateSlot()
|
||||||
{
|
{
|
||||||
//connect signal from layer registry to update in case of new or deleted layers
|
//connect signal from layer registry to update in case of new or deleted layers
|
||||||
|
@ -507,6 +507,8 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
|
|||||||
|
|
||||||
void painterJobFinished();
|
void painterJobFinished();
|
||||||
|
|
||||||
|
void shapeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
@ -619,11 +621,6 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
|
|||||||
//! True if annotation items, rubber band, etc. from the main canvas should be displayed
|
//! True if annotation items, rubber band, etc. from the main canvas should be displayed
|
||||||
bool mDrawAnnotations = true;
|
bool mDrawAnnotations = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Adjusts an extent rectangle to match the provided item width and height, so that extent
|
|
||||||
* center of extent remains the same */
|
|
||||||
void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle &extent ) const;
|
|
||||||
|
|
||||||
//! True if map is being controlled by an atlas
|
//! True if map is being controlled by an atlas
|
||||||
bool mAtlasDriven = false;
|
bool mAtlasDriven = false;
|
||||||
//! Current atlas scaling mode
|
//! Current atlas scaling mode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user