Skip to content

Commit

Permalink
[composer] Correctly draw overview frame when map item CRS differs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 25, 2017
1 parent 83ac0e5 commit 345ce73
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/composer/qgscomposermapoverview.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgsmapsettings.h"
#include "qgspainting.h"
#include "qgscomposerutils.h"
#include "qgscsexception.h"

#include <QPainter>

Expand Down Expand Up @@ -82,6 +83,25 @@ void QgsComposerMapOverview::draw( QPainter *painter )

//get polygon for other overview frame map's extent (use visibleExtentPolygon as it accounts for map rotation)
QPolygonF otherExtent = overviewFrameMap->visibleExtentPolygon();
if ( overviewFrameMap->crs() !=
mComposerMap->crs() )
{
QgsGeometry g = QgsGeometry::fromQPolygonF( otherExtent );

// reproject extent
QgsCoordinateTransform ct( overviewFrameMap->crs(),
mComposerMap->crs() );
g = g.densifyByCount( 20 );
try
{
g.transform( ct );
}
catch ( QgsCsException & )
{
}

otherExtent = g.asQPolygonF();
}

//get current map's extent as a QPolygonF
QPolygonF thisExtent = mComposerMap->visibleExtentPolygon();
Expand Down
23 changes: 23 additions & 0 deletions tests/src/core/testqgscomposermapoverview.cpp
Expand Up @@ -50,6 +50,7 @@ class TestQgsComposerMapOverview : public QObject
void overviewMapBlending(); //test if blend modes with overview map frame works
void overviewMapInvert(); //test if invert of overview map frame works
void overviewMapCenter(); //test if centering of overview map frame works
void overviewReprojected(); //test that overview frame is reprojected

private:
QgsComposition *mComposition = nullptr;
Expand Down Expand Up @@ -217,5 +218,27 @@ void TestQgsComposerMapOverview::overviewMapCenter()
QVERIFY( testResult );
}

void TestQgsComposerMapOverview::overviewReprojected()
{
QgsComposerMap *overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
overviewMap->setFrameEnabled( true );
//overviewMap->setLayers( QList<QgsMapLayer *>() << mRasterLayer );
mComposition->addComposerMap( overviewMap );

mComposerMap->setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
overviewMap->setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 54030 ) );

mComposerMap->setNewExtent( QgsRectangle( 93, -64.245, 120.6, -45 ) );
overviewMap->setNewExtent( QgsRectangle( 4712502, -7620278, 10872777, -2531356 ) );
overviewMap->overview()->setFrameMap( mComposerMap->id() );

QgsCompositionChecker checker( QStringLiteral( "composermap_overview_reprojected" ), mComposition );
checker.setControlPathPrefix( QStringLiteral( "composer_mapoverview" ) );

bool testResult = checker.testComposition( mReport, 0, 0 );
mComposition->removeComposerItem( overviewMap );
QVERIFY( testResult );
}

QGSTEST_MAIN( TestQgsComposerMapOverview )
#include "testqgscomposermapoverview.moc"
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 345ce73

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 345ce73 Mar 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant.

Please sign in to comment.