Skip to content
Permalink
Browse files

Sync works now between QgsMapRenderer and QgsMapCanvas

  • Loading branch information
wonder-sk committed Dec 6, 2013
1 parent bf7dd52 commit 0d2fbbe2cb9bde4fdad1cba32fc5869388063cdc
Showing with 102 additions and 8 deletions.
  1. +9 −8 src/gui/qgsmapcanvas.cpp
  2. +1 −0 tests/src/gui/CMakeLists.txt
  3. +92 −0 tests/src/gui/testqgsmapcanvas.cpp
@@ -105,9 +105,7 @@ QgsMapCanvasRendererSync::QgsMapCanvasRendererSync( QgsMapCanvas* canvas, QgsMap

void QgsMapCanvasRendererSync::onExtentC2R()
{
mRenderer->blockSignals( true );
mRenderer->setExtent( mCanvas->mapSettings().extent() );
mRenderer->blockSignals( false );
}

void QgsMapCanvasRendererSync::onExtentR2C()
@@ -117,9 +115,7 @@ void QgsMapCanvasRendererSync::onExtentR2C()

void QgsMapCanvasRendererSync::onMapUnitsC2R()
{
mRenderer->blockSignals( true );
mRenderer->setMapUnits( mCanvas->mapSettings().mapUnits() );
mRenderer->blockSignals( false );
}

void QgsMapCanvasRendererSync::onMapUnitsR2C()
@@ -129,9 +125,7 @@ void QgsMapCanvasRendererSync::onMapUnitsR2C()

void QgsMapCanvasRendererSync::onCrsTransformC2R()
{
mRenderer->blockSignals( true );
mRenderer->setProjectionsEnabled( mCanvas->mapSettings().hasCrsTransformEnabled() );
mRenderer->blockSignals( false );
}

void QgsMapCanvasRendererSync::onCrsTransformR2C()
@@ -141,9 +135,7 @@ void QgsMapCanvasRendererSync::onCrsTransformR2C()

void QgsMapCanvasRendererSync::onDestCrsC2R()
{
mRenderer->blockSignals( true );
mRenderer->setDestinationCrs( mCanvas->mapSettings().destinationCrs() );
mRenderer->blockSignals( false );
}

void QgsMapCanvasRendererSync::onDestCrsR2C()
@@ -461,6 +453,9 @@ void QgsMapCanvas::setCrsTransformEnabled(bool enabled)

void QgsMapCanvas::setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
{
if ( mSettings.destinationCrs() == crs )
return;

if ( mSettings.hasCrsTransformEnabled() )
{
// try to reproject current extent to the new one
@@ -734,6 +729,9 @@ void QgsMapCanvas::setExtent( QgsRectangle const & r )
{
QgsRectangle current = extent();

if ( r == current )
return;

if ( r.isEmpty() )
{
QgsDebugMsg( "Empty extent - keeping old extent with new center!" );
@@ -1425,6 +1423,9 @@ double QgsMapCanvas::mapUnitsPerPixel() const

void QgsMapCanvas::setMapUnits( QGis::UnitType u )
{
if ( mSettings.mapUnits() == u )
return;

QgsDebugMsg( "Setting map units to " + QString::number( static_cast<int>( u ) ) );
mSettings.setMapUnits( u );

@@ -122,4 +122,5 @@ ADD_QGIS_TEST(projectionissues testprojectionissues.cpp)
ADD_QGIS_TEST(scalecombobox testqgsscalecombobox.cpp)
ADD_QGIS_TEST(dualviewtest testqgsdualview.cpp )
ADD_QGIS_TEST(rubberbandtest testqgsrubberband.cpp )
ADD_QGIS_TEST(mapcanvastest testqgsmapcanvas.cpp )

@@ -0,0 +1,92 @@

#include <QtTest>

#include <qgsapplication.h>
#include <qgsmapcanvas.h>
#include <qgsmaprenderer.h>

class TestQgsMapCanvas : public QObject
{
Q_OBJECT
private slots:
void initTestCase(); // will be called before the first testfunction is executed.
void cleanupTestCase(); // will be called after the last testfunction was executed.

void testMapRendererInteraction();

private:
QgsMapCanvas* mCanvas;
};



void TestQgsMapCanvas::initTestCase()
{
QgsApplication::init(); // init paths for CRS lookup

mCanvas = new QgsMapCanvas();
}

void TestQgsMapCanvas::cleanupTestCase()
{
}

void TestQgsMapCanvas::testMapRendererInteraction()
{
QgsMapRenderer* mr = mCanvas->mapRenderer();

// CRS transforms

QSignalSpy spy0( mCanvas, SIGNAL(hasCrsTransformEnabledChanged(bool)) );
mr->setProjectionsEnabled( true );
QCOMPARE( mr->hasCrsTransformEnabled(), true );
QCOMPARE( mCanvas->hasCrsTransformEnabled(), true );
QCOMPARE( spy0.count(), 1 );

QSignalSpy spy1( mr, SIGNAL(hasCrsTransformEnabled(bool)) );
mCanvas->setCrsTransformEnabled( false );
QCOMPARE( mr->hasCrsTransformEnabled(), false );
QCOMPARE( mCanvas->hasCrsTransformEnabled(), false );
QCOMPARE( spy1.count(), 1 );

// Extent

QSignalSpy spy2( mCanvas, SIGNAL(extentsChanged()) );
QgsRectangle r1( 10, 10, 20, 20 );
mr->setExtent( r1 );
QgsRectangle r2 = mr->extent();
QCOMPARE( mCanvas->extent(), r2 );
QCOMPARE( spy2.count(), 1 );

QgsRectangle r3( 100, 100, 200, 200 );
QSignalSpy spy3( mr, SIGNAL(extentsChanged()) );
mCanvas->setExtent( r3 );
QgsRectangle r4 = mCanvas->extent();
QCOMPARE( mr->extent(), r4 );
QCOMPARE( spy3.count(), 1 );

// Destination CRS

QgsCoordinateReferenceSystem crs1("EPSG:27700");
QCOMPARE( crs1.isValid(), true );
QSignalSpy spy4( mCanvas, SIGNAL(destinationCrsChanged()) );
mr->setDestinationCrs( crs1 );
qDebug(" crs %s vs %s", mCanvas->mapSettings().destinationCrs().authid().toAscii().data(), crs1.authid().toAscii().data() );
QCOMPARE( mCanvas->mapSettings().destinationCrs(), crs1 );
QCOMPARE( mr->destinationCrs(), crs1 );
QCOMPARE( spy4.count(), 1 );

QgsCoordinateReferenceSystem crs2("EPSG:4326");
QCOMPARE( crs2.isValid(), true );
QSignalSpy spy5( mr, SIGNAL(destinationSrsChanged()) );
mCanvas->setDestinationCrs( crs2 );
QCOMPARE( mCanvas->mapSettings().destinationCrs(), crs2 );
QCOMPARE( mr->destinationCrs(), crs2 );
QCOMPARE( spy5.count(), 1 );

// TODO: set map units
}


QTEST_MAIN( TestQgsMapCanvas )
#include "moc_testqgsmapcanvas.cxx"

0 comments on commit 0d2fbbe

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