Skip to content

Commit 35459c4

Browse files
committedNov 20, 2017
Add some tests
1 parent c969295 commit 35459c4

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,8 @@ QgisApp::QgisApp()
11901190
mLayerTreeView = new QgsLayerTreeView( this );
11911191
mUndoWidget = new QgsUndoWidget( nullptr, mMapCanvas );
11921192
mInfoBar = new QgsMessageBar( centralWidget() );
1193+
mPanelMenu = new QMenu( this );
1194+
mProgressBar = new QProgressBar( this );
11931195
// More tests may need more members to be initialized
11941196
}
11951197

‎src/app/qgsmaptoolidentifyaction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class APP_EXPORT QgsMapToolIdentifyAction : public QgsMapToolIdentify
8383
virtual QGis::UnitType displayDistanceUnits() const override;
8484
virtual QgsUnitTypes::AreaUnit displayAreaUnits() const override;
8585
void setClickContextScope( const QgsPoint &point );
86+
87+
friend class TestQgsMapToolIdentifyAction;
8688
};
8789

8890
#endif

‎tests/src/app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
2323
)
2424
INCLUDE_DIRECTORIES(SYSTEM
2525
${QT_INCLUDE_DIR}
26+
${QWT_INCLUDE_DIR}
2627
${GDAL_INCLUDE_DIR}
2728
${PROJ_INCLUDE_DIR}
2829
${GEOS_INCLUDE_DIR}

‎tests/src/app/testqgsmaptoolidentifyaction.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include "qgsmapcanvas.h"
2525
#include "qgsunittypes.h"
2626
#include "qgsmaptoolidentifyaction.h"
27+
#include "qgisapp.h"
28+
#include "qgsidentifymenu.h"
29+
#include "qgsidentifyresultsdialog.h"
2730

2831
#include "cpl_conv.h"
2932

@@ -46,9 +49,11 @@ class TestQgsMapToolIdentifyAction : public QObject
4649
void identifyRasterFloat32(); // test pixel identification and decimal precision
4750
void identifyRasterFloat64(); // test pixel identification and decimal precision
4851
void identifyInvalidPolygons(); // test selecting invalid polygons
52+
void clickxy(); // test if click_x and click_y variables are propagated
4953

5054
private:
5155
QgsMapCanvas* canvas;
56+
QgisApp *mQgisApp;
5257

5358
QString testIdentifyRaster( QgsRasterLayer* layer, double xGeoref, double yGeoref );
5459
QList<QgsMapToolIdentify::IdentifyResult> testIdentifyVector( QgsVectorLayer* layer, double xGeoref, double yGeoref );
@@ -91,6 +96,8 @@ void TestQgsMapToolIdentifyAction::initTestCase()
9196
// enforce C locale because the tests expect it
9297
// (decimal separators / thousand separators)
9398
QLocale::setDefault( QLocale::c() );
99+
100+
mQgisApp = new QgisApp();
94101
}
95102

96103
void TestQgsMapToolIdentifyAction::cleanupTestCase()
@@ -108,6 +115,57 @@ void TestQgsMapToolIdentifyAction::cleanup()
108115
delete canvas;
109116
}
110117

118+
void TestQgsMapToolIdentifyAction::clickxy()
119+
{
120+
int clickxOk = 2484588;
121+
int clickyOk = 2425722;
122+
123+
// create temp layer
124+
QScopedPointer<QgsVectorLayer> tempLayer( new QgsVectorLayer( QString( "Point?crs=epsg:3111" ), QString( "vl" ), QString( "memory" ) ) );
125+
QVERIFY( tempLayer->isValid() );
126+
127+
// add feature
128+
QgsFeature f1( tempLayer->dataProvider()->fields(), 1 );
129+
QgsPoint wordPoint( clickxOk, clickyOk );
130+
QgsGeometry *geom = QgsGeometry::fromPoint( wordPoint ) ;
131+
f1.setGeometry( geom );
132+
tempLayer->dataProvider()->addFeatures( QgsFeatureList() << f1 );
133+
134+
// prepare canvas
135+
QgsCoordinateReferenceSystem srs( 3111, QgsCoordinateReferenceSystem::EpsgCrsId );
136+
canvas->setDestinationCrs( srs );
137+
canvas->setCurrentLayer( tempLayer.data() );
138+
139+
// init map tool identify action
140+
QScopedPointer<QgsMapToolIdentifyAction> identifyAction( new QgsMapToolIdentifyAction( canvas ) );
141+
142+
// simulate a click on the canvas
143+
QgsPoint mapPoint = canvas->getCoordinateTransform()->transform( 2484588, 2425722 );
144+
QPoint point = QPoint( mapPoint.x(), mapPoint.y() );
145+
QMouseEvent releases( QEvent::MouseButtonRelease, point,
146+
Qt::RightButton, Qt::LeftButton, Qt::NoModifier );
147+
QgsMapMouseEvent mapReleases( 0, &releases );
148+
149+
identifyAction->canvasReleaseEvent( &mapReleases );
150+
151+
// test QgsIdentifyMenu expression context scope
152+
bool ok;
153+
QgsIdentifyMenu *menu = identifyAction->identifyMenu();
154+
int clickx = menu->expressionContextScope().variable( "click_x" ).toString().toInt( &ok, 10 );
155+
QCOMPARE( clickx, clickxOk );
156+
157+
int clicky = menu->expressionContextScope().variable( "click_y" ).toString().toInt( &ok, 10 );
158+
QCOMPARE( clicky, clickyOk );
159+
160+
// test QgsIdentifyResultsDialog expression context scope
161+
QgsIdentifyResultsDialog *dlg = identifyAction->resultsDialog();
162+
clickx = dlg->expressionContextScope().variable( "click_x" ).toString().toInt( &ok, 10 );
163+
QCOMPARE( clickx, clickxOk );
164+
165+
clicky = dlg->expressionContextScope().variable( "click_y" ).toString().toInt( &ok, 10 );
166+
QCOMPARE( clicky, clickyOk );
167+
}
168+
111169
void TestQgsMapToolIdentifyAction::lengthCalculation()
112170
{
113171
QSettings s;

0 commit comments

Comments
 (0)
Please sign in to comment.