24
24
#include " qgsmapcanvas.h"
25
25
#include " qgsunittypes.h"
26
26
#include " qgsmaptoolidentifyaction.h"
27
+ #include " qgisapp.h"
28
+ #include " qgsidentifymenu.h"
29
+ #include " qgsidentifyresultsdialog.h"
27
30
28
31
#include " cpl_conv.h"
29
32
@@ -46,9 +49,11 @@ class TestQgsMapToolIdentifyAction : public QObject
46
49
void identifyRasterFloat32 (); // test pixel identification and decimal precision
47
50
void identifyRasterFloat64 (); // test pixel identification and decimal precision
48
51
void identifyInvalidPolygons (); // test selecting invalid polygons
52
+ void clickxy (); // test if click_x and click_y variables are propagated
49
53
50
54
private:
51
55
QgsMapCanvas* canvas;
56
+ QgisApp *mQgisApp ;
52
57
53
58
QString testIdentifyRaster ( QgsRasterLayer* layer, double xGeoref, double yGeoref );
54
59
QList<QgsMapToolIdentify::IdentifyResult> testIdentifyVector ( QgsVectorLayer* layer, double xGeoref, double yGeoref );
@@ -91,6 +96,8 @@ void TestQgsMapToolIdentifyAction::initTestCase()
91
96
// enforce C locale because the tests expect it
92
97
// (decimal separators / thousand separators)
93
98
QLocale::setDefault ( QLocale::c () );
99
+
100
+ mQgisApp = new QgisApp ();
94
101
}
95
102
96
103
void TestQgsMapToolIdentifyAction::cleanupTestCase ()
@@ -108,6 +115,57 @@ void TestQgsMapToolIdentifyAction::cleanup()
108
115
delete canvas;
109
116
}
110
117
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
+
111
169
void TestQgsMapToolIdentifyAction::lengthCalculation ()
112
170
{
113
171
QSettings s;
0 commit comments