mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
parent
4030390acc
commit
c94eefb6df
@ -540,7 +540,7 @@ bool QgsLayoutItemMap::writePropertiesToElement( QDomElement &mapElem, QDomDocum
|
||||
}
|
||||
|
||||
// follow map theme
|
||||
mapElem.setAttribute( QStringLiteral( "followPreset" ), mFollowVisibilityPreset ? "true" : "false" );
|
||||
mapElem.setAttribute( QStringLiteral( "followPreset" ), mFollowVisibilityPreset ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
|
||||
mapElem.setAttribute( QStringLiteral( "followPresetName" ), mFollowVisibilityPresetName );
|
||||
|
||||
//map rotation
|
||||
@ -1960,9 +1960,10 @@ void QgsLayoutItemMap::updateAtlasFeature()
|
||||
}
|
||||
newExtent = QgsRectangle( xa1, ya1, xa2, ya2 );
|
||||
|
||||
if ( mAtlasMargin > 0.0 )
|
||||
const double evaluatedAtlasMargin = atlasMargin();
|
||||
if ( evaluatedAtlasMargin > 0.0 )
|
||||
{
|
||||
newExtent.scale( 1 + mAtlasMargin );
|
||||
newExtent.scale( 1 + evaluatedAtlasMargin );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -626,6 +626,51 @@ class TestQgsLayoutAtlas(unittest.TestCase):
|
||||
|
||||
QgsProject.instance().removeMapLayer(polygonLayer)
|
||||
|
||||
def test_datadefined_margin(self):
|
||||
polygonLayer = QgsVectorLayer('Polygon?field=margin:int', 'test_polygon', 'memory')
|
||||
poly = QgsFeature(polygonLayer.fields())
|
||||
poly.setAttributes([0])
|
||||
poly.setGeometry(QgsGeometry.fromWkt('Polygon((30 30, 40 30, 40 40, 30 40, 30 30))'))
|
||||
polygonLayer.dataProvider().addFeatures([poly])
|
||||
poly = QgsFeature(polygonLayer.fields())
|
||||
poly.setAttributes([10])
|
||||
poly.setGeometry(QgsGeometry.fromWkt('Polygon((10 10, 20 10, 20 20, 10 20, 10 10))'))
|
||||
polygonLayer.dataProvider().addFeatures([poly])
|
||||
poly = QgsFeature(polygonLayer.fields())
|
||||
poly.setAttributes([20])
|
||||
poly.setGeometry(QgsGeometry.fromWkt('Polygon((50 50, 60 50, 60 60, 50 60, 50 50))'))
|
||||
polygonLayer.dataProvider().addFeatures([poly])
|
||||
QgsProject.instance().addMapLayer(polygonLayer)
|
||||
|
||||
layout = QgsPrintLayout(QgsProject.instance())
|
||||
map = QgsLayoutItemMap(layout)
|
||||
map.setCrs(polygonLayer.crs())
|
||||
map.attemptSetSceneRect(QRectF(20, 20, 130, 130))
|
||||
map.setFrameEnabled(True)
|
||||
map.setLayers([polygonLayer])
|
||||
map.setExtent(QgsRectangle(0, 0, 100, 50))
|
||||
layout.addLayoutItem(map)
|
||||
|
||||
atlas = layout.atlas()
|
||||
atlas.setCoverageLayer(polygonLayer)
|
||||
atlas.setEnabled(True)
|
||||
|
||||
map.setAtlasDriven(True)
|
||||
map.setAtlasScalingMode(QgsLayoutItemMap.Auto)
|
||||
map.setAtlasMargin(77.0)
|
||||
map.dataDefinedProperties().setProperty(QgsLayoutObject.MapAtlasMargin, QgsProperty.fromExpression('margin/2'))
|
||||
|
||||
atlas.beginRender()
|
||||
atlas.first()
|
||||
|
||||
self.assertEqual(map.extent(), QgsRectangle(25, 30, 45, 40))
|
||||
self.assertTrue(atlas.next())
|
||||
self.assertEqual(map.extent(), QgsRectangle(4.5, 9.75, 25.5, 20.25))
|
||||
self.assertTrue(atlas.next())
|
||||
self.assertEqual(map.extent(), QgsRectangle(44, 49.5, 66, 60.5))
|
||||
|
||||
QgsProject.instance().removeMapLayer(polygonLayer)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user