Skip to content

Commit

Permalink
[composer] Ensure that QgsComposerMap::mapPolygon returns a closed
Browse files Browse the repository at this point in the history
polygon, fixes rare crash when using map overviews (fix #11305)
  • Loading branch information
nyalldawson committed Oct 8, 2014
1 parent fbc5f06 commit 6bb045b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposermap.cpp 100644 → 100755
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposermapoverview.cpp
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgscomposermap.cpp 100644 → 100755
Expand Up @@ -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();
Expand All @@ -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 );

}
Expand Down

0 comments on commit 6bb045b

Please sign in to comment.