21
21
#include < qgsmaprenderer.h>
22
22
#include < qgsmaplayerregistry.h>
23
23
#include < qgsrenderchecker.h>
24
+ #include < qgsvectordataprovider.h>
24
25
25
26
namespace QTest
26
27
{
@@ -47,6 +48,7 @@ class TestQgsMapCanvas : public QObject
47
48
void testMapRendererInteraction ();
48
49
void testPanByKeyboard ();
49
50
void testMagnification ();
51
+ void testMagnificationExtent ();
50
52
51
53
private:
52
54
QgsMapCanvas* mCanvas ;
@@ -251,5 +253,96 @@ void TestQgsMapCanvas::testMagnification()
251
253
QCOMPARE ( checker.compareImages ( " map_magnification" , 100 ), true );
252
254
}
253
255
256
+ void compareExtent ( const QgsRectangle &initialExtent,
257
+ const QgsRectangle &extent )
258
+ {
259
+ QVERIFY ( qgsDoubleNear ( initialExtent.xMinimum (), extent.xMinimum (), 0.00000000001 ) );
260
+ QVERIFY ( qgsDoubleNear ( initialExtent.xMaximum (), extent.xMaximum (), 0.00000000001 ) );
261
+ QVERIFY ( qgsDoubleNear ( initialExtent.yMinimum (), extent.yMinimum (), 0.00000000001 ) );
262
+ QVERIFY ( qgsDoubleNear ( initialExtent.yMaximum (), extent.yMaximum (), 0.00000000001 ) );
263
+ }
264
+
265
+ void TestQgsMapCanvas::testMagnificationExtent ()
266
+ {
267
+ // build vector layer
268
+ QString testDataDir = QString ( TEST_DATA_DIR ) + ' /' ;
269
+ QString myPointsFileName = testDataDir + " points.shp" ;
270
+ QFileInfo myPointFileInfo ( myPointsFileName );
271
+ QgsVectorLayer *layer = new QgsVectorLayer ( myPointFileInfo.filePath (),
272
+ myPointFileInfo.completeBaseName (), " ogr" );
273
+
274
+ // prepare map canvas
275
+ QList<QgsMapCanvasLayer> layers;
276
+ layers.append ( layer );
277
+ mCanvas ->setLayerSet ( layers );
278
+ QgsMapLayerRegistry::instance ()->addMapLayers ( QList<QgsMapLayer *>() << layer );
279
+
280
+ // zoomToFullExtent
281
+ mCanvas ->zoomToFullExtent ();
282
+ QgsRectangle initialExtent = mCanvas ->extent ();
283
+
284
+ mCanvas ->setMagnificationFactor ( 4.0 );
285
+ mCanvas ->setMagnificationFactor ( 1.0 );
286
+
287
+ compareExtent ( mCanvas ->extent (), initialExtent );
288
+
289
+ // setExtent with layer extent
290
+ mCanvas ->setExtent ( layer->extent () );
291
+ initialExtent = mCanvas ->extent ();
292
+
293
+ mCanvas ->setMagnificationFactor ( 4.0 );
294
+ mCanvas ->setMagnificationFactor ( 1.0 );
295
+
296
+ compareExtent ( mCanvas ->extent (), initialExtent );
297
+
298
+ // zoomToSelected
299
+ QgsFeature f1 ( layer->dataProvider ()->fields (), 1 );
300
+ QgsFeature f2 ( layer->dataProvider ()->fields (), 2 );
301
+ QgsFeatureIds ids;
302
+ ids << f1.id () << f2.id ();
303
+ layer->setSelectedFeatures ( ids );
304
+
305
+ mCanvas ->zoomToSelected ( layer );
306
+ initialExtent = mCanvas ->extent ();
307
+
308
+ mCanvas ->setMagnificationFactor ( 4.0 );
309
+ mCanvas ->setMagnificationFactor ( 1.0 );
310
+
311
+ compareExtent ( mCanvas ->extent (), initialExtent );
312
+
313
+ // zoomToFeatureIds
314
+ mCanvas ->zoomToFeatureIds ( layer, ids );
315
+ initialExtent = mCanvas ->extent ();
316
+
317
+ mCanvas ->setMagnificationFactor ( 4.0 );
318
+ mCanvas ->setMagnificationFactor ( 1.0 );
319
+
320
+ compareExtent ( mCanvas ->extent (), initialExtent );
321
+
322
+ // zoomIn / zoomOut
323
+ initialExtent = mCanvas ->extent ();
324
+ mCanvas ->zoomIn ();
325
+
326
+ mCanvas ->setMagnificationFactor ( 4.0 );
327
+ mCanvas ->zoomIn ();
328
+ mCanvas ->zoomOut ();
329
+ mCanvas ->setMagnificationFactor ( 1.0 );
330
+
331
+ mCanvas ->zoomOut ();
332
+
333
+ compareExtent ( mCanvas ->extent (), initialExtent );
334
+
335
+ // zoomScale
336
+ initialExtent = mCanvas ->extent ();
337
+ double scale = mCanvas ->scale ();
338
+ mCanvas ->zoomScale ( 6.052017 *10e7 );
339
+
340
+ mCanvas ->setMagnificationFactor ( 4.0 );
341
+ mCanvas ->setMagnificationFactor ( 1.0 );
342
+
343
+ mCanvas ->zoomScale ( scale );
344
+ compareExtent ( mCanvas ->extent (), initialExtent );
345
+ }
346
+
254
347
QTEST_MAIN ( TestQgsMapCanvas )
255
348
#include " testqgsmapcanvas.moc"
0 commit comments