Skip to content

Commit bba09a1

Browse files
committed
Add fix for bad zoom using pen PCs; Add tests
1 parent 8f186be commit bba09a1

File tree

3 files changed

+135
-17
lines changed

3 files changed

+135
-17
lines changed

src/gui/qgsmaptoolzoom.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ void QgsMapToolZoom::canvasReleaseEvent( QMouseEvent * e )
7575
if ( e->button() != Qt::LeftButton )
7676
return;
7777

78+
// We are not really dragging in this case. This is sometimes caused by
79+
// a pen based computer reporting a press, move, and release, all the
80+
// one point.
81+
if ( mDragging && ( mZoomRect.topLeft() == mZoomRect.bottomRight() ) )
82+
{
83+
mDragging = false;
84+
delete mRubberBand;
85+
mRubberBand = 0;
86+
}
87+
7888
if ( mDragging )
7989
{
8090
mDragging = false;

tests/src/gui/CMakeLists.txt

+32-17
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,39 @@ ENDIF (APPLE)
7575
# ADD_TEST(qgis_quickprinttest ${CMAKE_INSTALL_PREFIX}/bin/qgis_quickprinttest)
7676
#ENDIF (APPLE)
7777
78+
MACRO (ADD_QGIS_TEST testname testsrc)
79+
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
80+
SET(qgis_${testname}_MOC_CPPS ${testsrc})
81+
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
82+
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
83+
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
84+
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
85+
TARGET_LINK_LIBRARIES(qgis_${testname}
86+
${QT_QTXML_LIBRARY}
87+
${QT_QTCORE_LIBRARY}
88+
${QT_QTSVG_LIBRARY}
89+
${QT_QTTEST_LIBRARY}
90+
${QT_QTNETWORK_LIBRARY}
91+
${QT_QTWEBKIT_LIBRARY}
92+
${QT_QTMAIN_LIBRARY}
93+
${PROJ_LIBRARY}
94+
${GEOS_LIBRARY}
95+
${GDAL_LIBRARY}
96+
qgis_core
97+
qgis_gui)
98+
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
99+
#SET_TARGET_PROPERTIES(qgis_${testname} PROPERTIES
100+
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
101+
# INSTALL_RPATH_USE_LINK_PATH true )
102+
ENDMACRO (ADD_QGIS_TEST)
78103
79-
# a simple app for testing GUI of renderers
80-
81-
SET(rendererv2gui_SRCS testrendererv2gui.cpp)
82-
SET(rendererv2gui_HDRS testrendererv2gui.h)
104+
ADD_QGIS_TEST(zoomtest testqgsmaptoolzoom.cpp)
83105
84-
QT4_WRAP_CPP(rendererv2gui_MOC_SRCS ${rendererv2gui_HDRS})
106+
# a simple app for testing GUI of renderers
107+
# These tests are old and are never run so removed for now.
108+
#SET(rendererv2gui_SRCS testrendererv2gui.cpp)
109+
#SET(rendererv2gui_HDRS testrendererv2gui.h)
110+
#QT4_WRAP_CPP(rendererv2gui_MOC_SRCS ${rendererv2gui_HDRS})
111+
#ADD_EXECUTABLE(qgis_rendererv2gui ${rendererv2gui_SRCS} ${rendererv2gui_MOC_SRCS})
85112
86-
ADD_EXECUTABLE(qgis_rendererv2gui ${rendererv2gui_SRCS} ${rendererv2gui_MOC_SRCS})
87113
88-
TARGET_LINK_LIBRARIES(qgis_rendererv2gui
89-
qgis_core
90-
qgis_gui
91-
${QT_QTCORE_LIBRARY}
92-
${QT_QTNETWORK_LIBRARY}
93-
${QT_QTSVG_LIBRARY}
94-
${QT_QTXML_LIBRARY}
95-
${QT_QTWEBKIT_LIBRARY}
96-
${QT_QTMAIN_LIBRARY}
97-
#${QT_QTTEST_LIBRARY}
98-
)

tests/src/gui/testqgsmaptoolzoom.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 <QtTest>
16+
#include <QObject>
17+
#include <QString>
18+
#include <QObject>
19+
#include <QCoreApplication>
20+
#include <QWidget>
21+
#include <QMouseEvent>
22+
23+
#include <qgsmaptoolzoom.h>
24+
#include <qgsapplication.h>
25+
#include <qgsmapcanvas.h>
26+
#include <qgslogger.h>
27+
28+
class TestQgsMapToolZoom: public QObject
29+
{
30+
Q_OBJECT;
31+
private slots:
32+
void initTestCase(); // will be called before the first testfunction is executed.
33+
void cleanupTestCase(); // will be called after the last testfunction was executed.
34+
void init(); // will be called before each testfunction is executed.
35+
void cleanup(); // will be called after every testfunction.
36+
void zeroDragArea();
37+
private:
38+
QgsMapCanvas* canvas;
39+
};
40+
41+
void TestQgsMapToolZoom::initTestCase()
42+
{
43+
QString qgisPath = QCoreApplication::applicationDirPath();
44+
QgsApplication::setPrefixPath( INSTALL_PREFIX, true );
45+
QgsApplication::showSettings();
46+
}
47+
48+
void TestQgsMapToolZoom::cleanupTestCase() {};
49+
50+
void TestQgsMapToolZoom::init()
51+
{
52+
canvas = new QgsMapCanvas();
53+
}
54+
55+
void TestQgsMapToolZoom::cleanup()
56+
{
57+
delete canvas;
58+
}
59+
60+
/** Zero drag areas can happen on pen based computer when a mouse down,
61+
* move, and up, all happened at the same spot due to the pen. In this case
62+
* QGIS thinks it is in dragging mode but it's not really and fails to zoom in.
63+
**/
64+
void TestQgsMapToolZoom::zeroDragArea()
65+
{
66+
QPoint point = QPoint( 15, 15 );
67+
QMouseEvent *press = new QMouseEvent( QEvent::MouseButtonPress, point ,
68+
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
69+
QMouseEvent *move = new QMouseEvent( QEvent::MouseMove, point,
70+
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
71+
QMouseEvent *releases = new QMouseEvent( QEvent::MouseButtonRelease, point,
72+
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
73+
74+
QgsMapToolZoom* tool = new QgsMapToolZoom( canvas, false );
75+
// Just set some made up extent so that we can zoom.
76+
canvas->setExtent( QgsRectangle( 0, 0, 20, 20 ) );
77+
78+
QgsRectangle before = canvas->extent();
79+
tool->canvasPressEvent( press );
80+
tool->canvasMoveEvent( move );
81+
tool->canvasReleaseEvent( releases );
82+
QgsRectangle after = canvas->extent();
83+
// We don't really care if we zoom in or out here just that the extent did
84+
// change we
85+
QVERIFY2( before != after, "Extents didn't change" );
86+
}
87+
88+
QTEST_MAIN( TestQgsMapToolZoom )
89+
#include "moc_testqgsmaptoolzoom.cxx"
90+
91+
92+
93+

0 commit comments

Comments
 (0)