Skip to content
Permalink
Browse files
Merge pull request #133 from NathanW2/zoombug
[TEST]Add fix for bad zoom using pen PCs; Add tests
  • Loading branch information
timlinux committed Apr 30, 2012
2 parents 69ef4de + bba09a1 commit adb83901589ef9620715d5135de473018b1d3694
Showing with 135 additions and 17 deletions.
  1. +10 −0 src/gui/qgsmaptoolzoom.cpp
  2. +32 −17 tests/src/gui/CMakeLists.txt
  3. +93 −0 tests/src/gui/testqgsmaptoolzoom.cpp
@@ -75,6 +75,16 @@ void QgsMapToolZoom::canvasReleaseEvent( QMouseEvent * e )
if ( e->button() != Qt::LeftButton )
return;

// We are not really dragging in this case. This is sometimes caused by
// a pen based computer reporting a press, move, and release, all the
// one point.
if ( mDragging && ( mZoomRect.topLeft() == mZoomRect.bottomRight() ) )
{
mDragging = false;
delete mRubberBand;
mRubberBand = 0;
}

if ( mDragging )
{
mDragging = false;
@@ -75,24 +75,39 @@ ENDIF (APPLE)
# ADD_TEST(qgis_quickprinttest ${CMAKE_INSTALL_PREFIX}/bin/qgis_quickprinttest)
#ENDIF (APPLE)

MACRO (ADD_QGIS_TEST testname testsrc)
SET(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
SET(qgis_${testname}_MOC_CPPS ${testsrc})
QT4_WRAP_CPP(qgis_${testname}_MOC_SRCS ${qgis_${testname}_MOC_CPPS})
ADD_CUSTOM_TARGET(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
ADD_EXECUTABLE(qgis_${testname} ${qgis_${testname}_SRCS})
ADD_DEPENDENCIES(qgis_${testname} qgis_${testname}moc)
TARGET_LINK_LIBRARIES(qgis_${testname}
${QT_QTXML_LIBRARY}
${QT_QTCORE_LIBRARY}
${QT_QTSVG_LIBRARY}
${QT_QTTEST_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${QT_QTWEBKIT_LIBRARY}
${QT_QTMAIN_LIBRARY}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
qgis_core
qgis_gui)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
#SET_TARGET_PROPERTIES(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
ENDMACRO (ADD_QGIS_TEST)

# a simple app for testing GUI of renderers

SET(rendererv2gui_SRCS testrendererv2gui.cpp)
SET(rendererv2gui_HDRS testrendererv2gui.h)
ADD_QGIS_TEST(zoomtest testqgsmaptoolzoom.cpp)

QT4_WRAP_CPP(rendererv2gui_MOC_SRCS ${rendererv2gui_HDRS})
# a simple app for testing GUI of renderers
# These tests are old and are never run so removed for now.
#SET(rendererv2gui_SRCS testrendererv2gui.cpp)
#SET(rendererv2gui_HDRS testrendererv2gui.h)
#QT4_WRAP_CPP(rendererv2gui_MOC_SRCS ${rendererv2gui_HDRS})
#ADD_EXECUTABLE(qgis_rendererv2gui ${rendererv2gui_SRCS} ${rendererv2gui_MOC_SRCS})

ADD_EXECUTABLE(qgis_rendererv2gui ${rendererv2gui_SRCS} ${rendererv2gui_MOC_SRCS})

TARGET_LINK_LIBRARIES(qgis_rendererv2gui
qgis_core
qgis_gui
${QT_QTCORE_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${QT_QTSVG_LIBRARY}
${QT_QTXML_LIBRARY}
${QT_QTWEBKIT_LIBRARY}
${QT_QTMAIN_LIBRARY}
#${QT_QTTEST_LIBRARY}
)
@@ -0,0 +1,93 @@
/***************************************************************************
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 <QtTest>
#include <QObject>
#include <QString>
#include <QObject>
#include <QCoreApplication>
#include <QWidget>
#include <QMouseEvent>

#include <qgsmaptoolzoom.h>
#include <qgsapplication.h>
#include <qgsmapcanvas.h>
#include <qgslogger.h>

class TestQgsMapToolZoom: 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 init(); // will be called before each testfunction is executed.
void cleanup(); // will be called after every testfunction.
void zeroDragArea();
private:
QgsMapCanvas* canvas;
};

void TestQgsMapToolZoom::initTestCase()
{
QString qgisPath = QCoreApplication::applicationDirPath();
QgsApplication::setPrefixPath( INSTALL_PREFIX, true );
QgsApplication::showSettings();
}

void TestQgsMapToolZoom::cleanupTestCase() {};

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()
{
QPoint point = QPoint( 15, 15 );
QMouseEvent *press = new QMouseEvent( QEvent::MouseButtonPress, point ,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent *move = new QMouseEvent( QEvent::MouseMove, point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QMouseEvent *releases = new QMouseEvent( QEvent::MouseButtonRelease, point,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );

QgsMapToolZoom* tool = new QgsMapToolZoom( canvas, false );
// Just set some made up extent so that we can zoom.
canvas->setExtent( QgsRectangle( 0, 0, 20, 20 ) );

QgsRectangle before = canvas->extent();
tool->canvasPressEvent( press );
tool->canvasMoveEvent( move );
tool->canvasReleaseEvent( releases );
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" );
}

QTEST_MAIN( TestQgsMapToolZoom )
#include "moc_testqgsmaptoolzoom.cxx"




0 comments on commit adb8390

Please sign in to comment.