Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 637ec81

Browse files
committedJun 4, 2019
Fix inverted polygon is distorted when map is rotated
Fixes #26381
1 parent a97de95 commit 637ec81

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed
 

‎src/core/symbology/qgsinvertedpolygonrenderer.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,23 @@ void QgsInvertedPolygonRenderer::startRender( QgsRenderContext &context, const Q
111111
// We compute coordinates of the extent which will serve as exterior ring
112112
// for the final polygon
113113
// It must be computed in the destination CRS if reprojection is enabled.
114-
const QgsMapToPixel &mtp( context.mapToPixel() );
115114

116115
if ( !context.painter() )
117116
{
118117
return;
119118
}
120119

121120
// convert viewport to dest CRS
122-
QRect e( context.painter()->viewport() );
123121
// add some space to hide borders and tend to infinity
124-
e.adjust( -e.width() * 5, -e.height() * 5, e.width() * 5, e.height() * 5 );
122+
const double buffer = std::max( context.mapExtent().width(), context.mapExtent().height() ) * 0.1;
123+
const QRectF outer = context.mapExtent().buffered( buffer ).toRectF();
125124
QgsPolylineXY exteriorRing;
126-
exteriorRing << mtp.toMapCoordinates( e.topLeft() );
127-
exteriorRing << mtp.toMapCoordinates( e.topRight() );
128-
exteriorRing << mtp.toMapCoordinates( e.bottomRight() );
129-
exteriorRing << mtp.toMapCoordinates( e.bottomLeft() );
130-
exteriorRing << mtp.toMapCoordinates( e.topLeft() );
125+
exteriorRing.reserve( 5 );
126+
exteriorRing << outer.topLeft();
127+
exteriorRing << outer.topRight();
128+
exteriorRing << outer.bottomRight();
129+
exteriorRing << outer.bottomLeft();
130+
exteriorRing << outer.topLeft();
131131

132132
// copy the rendering context
133133
mContext = context;
@@ -142,8 +142,7 @@ void QgsInvertedPolygonRenderer::startRender( QgsRenderContext &context, const Q
142142
// disable projection
143143
mContext.setCoordinateTransform( QgsCoordinateTransform() );
144144
// recompute extent so that polygon clipping is correct
145-
QRect v( context.painter()->viewport() );
146-
mContext.setExtent( QgsRectangle( mtp.toMapCoordinates( v.topLeft() ), mtp.toMapCoordinates( v.bottomRight() ) ) );
145+
mContext.setExtent( context.mapExtent() );
147146
// do we have to recompute the MapToPixel ?
148147
}
149148

‎tests/src/core/testqgsinvertedpolygonrenderer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TestQgsInvertedPolygon : public QObject
5555
void preprocess();
5656
void projectionTest();
5757
void curvedPolygons();
58+
void rotationTest();
5859

5960
private:
6061
bool mTestHasError = false ;
@@ -154,7 +155,6 @@ void TestQgsInvertedPolygon::projectionTest()
154155
mMapSettings.setDestinationCrs( mpPolysLayer->crs() );
155156
}
156157

157-
// This test relies on GDAL support of curved polygons
158158
void TestQgsInvertedPolygon::curvedPolygons()
159159
{
160160
QString myCurvedPolysFileName = mTestDataDir + "curved_polys.gpkg";
@@ -170,6 +170,16 @@ void TestQgsInvertedPolygon::curvedPolygons()
170170
mMapSettings.setLayers( QList< QgsMapLayer * >() << mpPolysLayer );
171171
}
172172

173+
void TestQgsInvertedPolygon::rotationTest()
174+
{
175+
mReport += QLatin1String( "<h2>Inverted polygon renderer, rotation test</h2>\n" );
176+
mMapSettings.setRotation( 45 );
177+
QVERIFY( setQml( mpPolysLayer, "inverted_polys_single.qml" ) );
178+
QVERIFY( imageCheck( "inverted_polys_rotation" ) );
179+
mMapSettings.setRotation( 0 );
180+
}
181+
182+
173183
//
174184
// Private helper functions not called directly by CTest
175185
//

0 commit comments

Comments
 (0)
Please sign in to comment.