Skip to content
Permalink
Browse files

[composer] Ensure that QgsComposerMap::mapPolygon returns a closed

polygon, fixes rare crash when using map overviews (fix #11305)
  • Loading branch information
nyalldawson committed Oct 8, 2014
1 parent fbc5f06 commit 6bb045bdbbceab330e4cf5818e3cfc588fa1cb49
@@ -1925,6 +1925,8 @@ void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) c
poly << QPointF( extent.xMaximum(), extent.yMaximum() );
poly << QPointF( extent.xMaximum(), extent.yMinimum() );
poly << QPointF( extent.xMinimum(), extent.yMinimum() );
//ensure polygon is closed by readding first point
poly << QPointF( poly.at( 0 ) );
return;
}

@@ -1955,6 +1957,9 @@ void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) c
dy = rotationPoint.y() - extent.yMinimum();
QgsComposerUtils::rotate( mEvaluatedMapRotation, dx, dy );
poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );

//ensure polygon is closed by readding first point
poly << QPointF( poly.at( 0 ) );
}

QPolygonF QgsComposerMap::visibleExtentPolygon() const
@@ -108,6 +108,8 @@ void QgsComposerMapOverview::draw( QPainter *painter )

//workaround QT Bug #21329
thisRectPoly.pop_back();
thisExtent.pop_back();

//create transform from map coordinates to painter coordinates
QTransform::quadToQuad( thisExtent, thisRectPoly, mapTransform );
QPolygonF intersectPolygon;
@@ -170,6 +170,9 @@ void TestQgsComposerMap::mapPolygonVertices()
QVERIFY( fabs( visibleExtent[3].x() - 781662.375 ) < 0.001 );
QVERIFY( fabs( visibleExtent[3].y() - 3339523.125 ) < 0.001 );

//polygon should be closed
QVERIFY( visibleExtent.isClosed() );

//now test with rotated map
mComposerMap->setMapRotation( 10 );
visibleExtent = mComposerMap->visibleExtentPolygon();
@@ -184,6 +187,9 @@ void TestQgsComposerMap::mapPolygonVertices()
QVERIFY( fabs( visibleExtent[3].x() - 782243.868114 ) < 0.001 );
QVERIFY( fabs( visibleExtent[3].y() - 3338576.62829 ) < 0.001 );

//polygon should be closed
QVERIFY( visibleExtent.isClosed() );

mComposerMap->setMapRotation( 0 );

}

0 comments on commit 6bb045b

Please sign in to comment.
You can’t perform that action at this time.