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