1 /***************************************************************************
2 testqgsmaptoolzoom.cpp
3 --------------------------------------
4 Date : Sat Apr 28th 2012
5 Copyright : (C) 2012 by Nathan Woodrow
6 Email : woodrow.nathan at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 #include "qgstest.h"
16 #include <QObject>
17 #include <QString>
18 #include <QCoreApplication>
19 #include <QWidget>
20
21 #include "qgsmaptoolzoom.h"
22 #include "qgsapplication.h"
23 #include "qgsmapcanvas.h"
24 #include "qgslogger.h"
25 #include "qgsmapmouseevent.h"
26
27
28 class TestQgsMapToolZoom : public QObject
29 {
30 Q_OBJECT
31 public:
32 TestQgsMapToolZoom() = default;
33
34 private slots:
35 void initTestCase(); // will be called before the first testfunction is executed.
36 void cleanupTestCase(); // will be called after the last testfunction was executed.
37 void init(); // will be called before each testfunction is executed.
38 void cleanup(); // will be called after every testfunction.
39 void zeroDragArea();
40 private:
41 QgsMapCanvas *canvas = nullptr;
42 };
43
initTestCase()44 void TestQgsMapToolZoom::initTestCase()
45 {
46 QgsApplication::init();
47 QgsApplication::initQgis();
48 QgsApplication::showSettings();
49 }
50
cleanupTestCase()51 void TestQgsMapToolZoom::cleanupTestCase()
52 {
53 QgsApplication::exitQgis();
54 }
55
init()56 void TestQgsMapToolZoom::init()
57 {
58 canvas = new QgsMapCanvas();
59 }
60
cleanup()61 void TestQgsMapToolZoom::cleanup()
62 {
63 delete canvas;
64 }
65
66 /*
67 * Zero drag areas can happen on pen based computer when a mouse down,
68 * move, and up, all happened at the same spot due to the pen. In this case
69 * QGIS thinks it is in dragging mode but it's not really and fails to zoom in.
70 */
zeroDragArea()71 void TestQgsMapToolZoom::zeroDragArea()
72 {
73 const QPoint point = QPoint( 15, 15 );
74 QMouseEvent press( QEvent::MouseButtonPress, point,
75 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
76 QMouseEvent move( QEvent::MouseMove, point,
77 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
78 QMouseEvent releases( QEvent::MouseButtonRelease, point,
79 Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
80
81 QgsMapMouseEvent mapPress( nullptr, &press );
82 QgsMapMouseEvent mapMove( nullptr, &move );
83 QgsMapMouseEvent mapReleases( nullptr, &releases );
84
85 QgsMapToolZoom *tool = new QgsMapToolZoom( canvas, false );
86 // Just set some made up extent so that we can zoom.
87 canvas->setExtent( QgsRectangle( 0, 0, 20, 20 ) );
88
89 const QgsRectangle before = canvas->extent();
90 tool->canvasPressEvent( &mapPress );
91 tool->canvasMoveEvent( &mapMove );
92 tool->canvasReleaseEvent( &mapReleases );
93
94 const QgsRectangle after = canvas->extent();
95 // We don't really care if we zoom in or out here just that the extent did
96 // change we
97 QVERIFY2( before != after, "Extents didn't change" );
98 }
99
100 QGSTEST_MAIN( TestQgsMapToolZoom )
101 #include "testqgsmaptoolzoom.moc"
102
103
104
105
106