|
| 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