13
13
* *
14
14
***************************************************************************/
15
15
16
+ #include " qgsapplication.h"
16
17
#include " qgscursors.h"
17
18
#include " qgsdistancearea.h"
18
19
#include " qgsfeature.h"
19
20
#include " qgsfield.h"
20
21
#include " qgsgeometry.h"
22
+ #include " qgshighlight.h"
21
23
#include " qgslogger.h"
22
24
#include " qgsidentifyresultsdialog.h"
23
25
#include " qgsmapcanvas.h"
@@ -57,6 +59,7 @@ QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
57
59
{
58
60
mResultsDialog ->done ( 0 );
59
61
}
62
+ deleteRubberBands ();
60
63
}
61
64
62
65
QgsIdentifyResultsDialog *QgsMapToolIdentifyAction::resultsDialog ()
@@ -90,10 +93,26 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
90
93
}
91
94
92
95
resultsDialog ()->clear ();
93
-
94
96
connect ( this , SIGNAL ( identifyProgress ( int , int ) ), QgisApp::instance (), SLOT ( showProgress ( int , int ) ) );
95
97
connect ( this , SIGNAL ( identifyMessage ( QString ) ), QgisApp::instance (), SLOT ( showStatusMessage ( QString ) ) );
96
- QList<IdentifyResult> results = QgsMapToolIdentify::identify ( e->x (), e->y () );
98
+
99
+ QList<IdentifyResult> results;
100
+ QSettings settings;
101
+ IdentifyMode mode = static_cast <IdentifyMode>( settings.value ( " /Map/identifyMode" , 0 ).toInt () );
102
+ if ( mode == LayerSelection )
103
+ {
104
+ fillLayerIdResults ( e->x (), e->y () ); // get id results from all layers into mLayerIdResults
105
+ QMenu layerSelectionMenu;
106
+ fillLayerSelectionMenu ( layerSelectionMenu ); // fill selection menu with entries from mLayerIdResults
107
+ execLayerSelectionMenu ( layerSelectionMenu, e->globalPos (), results );
108
+ mLayerIdResults .clear ();
109
+ deleteRubberBands ();
110
+ }
111
+ else
112
+ {
113
+ results = QgsMapToolIdentify::identify ( e->x (), e->y () );
114
+ }
115
+
97
116
disconnect ( this , SIGNAL ( identifyProgress ( int , int ) ), QgisApp::instance (), SLOT ( showProgress ( int , int ) ) );
98
117
disconnect ( this , SIGNAL ( identifyMessage ( QString ) ), QgisApp::instance (), SLOT ( showStatusMessage ( QString ) ) );
99
118
@@ -148,6 +167,7 @@ void QgsMapToolIdentifyAction::deactivate()
148
167
{
149
168
resultsDialog ()->deactivate ();
150
169
QgsMapTool::deactivate ();
170
+ deleteRubberBands ();
151
171
}
152
172
153
173
QGis::UnitType QgsMapToolIdentifyAction::displayUnits ()
@@ -163,3 +183,113 @@ void QgsMapToolIdentifyAction::handleCopyToClipboard( QgsFeatureStore & featureS
163
183
emit copyToClipboard ( featureStore );
164
184
}
165
185
186
+ void QgsMapToolIdentifyAction::handleMenuHover ()
187
+ {
188
+ if ( !mCanvas )
189
+ {
190
+ return ;
191
+ }
192
+
193
+ deleteRubberBands ();
194
+ QAction* senderAction = qobject_cast<QAction*>( sender () );
195
+ if ( senderAction )
196
+ {
197
+ QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( senderAction->data ().toString () ) );
198
+ if ( vl )
199
+ {
200
+ QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator lIt = mLayerIdResults .find ( vl );
201
+ if ( lIt != mLayerIdResults .constEnd () )
202
+ {
203
+ const QList<IdentifyResult>& idList = lIt.value ();
204
+ QList<IdentifyResult>::const_iterator idListIt = idList.constBegin ();
205
+ for ( ; idListIt != idList.constEnd (); ++idListIt )
206
+ {
207
+ QgsHighlight* hl = new QgsHighlight ( mCanvas , idListIt->mFeature .geometry (), vl );
208
+ hl->setColor ( QColor ( 255 , 0 , 0 ) );
209
+ hl->setWidth ( 2 );
210
+ mRubberBands .append ( hl );
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ void QgsMapToolIdentifyAction::deleteRubberBands ()
218
+ {
219
+ QList<QgsHighlight*>::const_iterator it = mRubberBands .constBegin ();
220
+ for ( ; it != mRubberBands .constEnd (); ++it )
221
+ {
222
+ delete *it;
223
+ }
224
+ mRubberBands .clear ();
225
+ }
226
+
227
+ void QgsMapToolIdentifyAction::fillLayerIdResults ( int x, int y )
228
+ {
229
+ mLayerIdResults .clear ();
230
+ if ( !mCanvas )
231
+ {
232
+ return ;
233
+ }
234
+
235
+ QList<QgsMapLayer*> canvasLayers = mCanvas ->layers ();
236
+ QList<QgsMapLayer*>::iterator it = canvasLayers.begin ();
237
+ for ( ; it != canvasLayers.end (); ++it )
238
+ {
239
+ QList<IdentifyResult> idResult = QgsMapToolIdentify::identify ( x, y, QList<QgsMapLayer*>() << *it );
240
+ if ( !idResult.isEmpty () )
241
+ {
242
+ mLayerIdResults .insert ( *it, idResult );
243
+ }
244
+ }
245
+ }
246
+
247
+ void QgsMapToolIdentifyAction::fillLayerSelectionMenu ( QMenu& menu )
248
+ {
249
+ QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator resultIt = mLayerIdResults .constBegin ();
250
+ for ( ; resultIt != mLayerIdResults .constEnd (); ++resultIt )
251
+ {
252
+ QAction* action = new QAction ( resultIt.key ()->name (), 0 );
253
+ action->setData ( resultIt.key ()->id () );
254
+ // add point/line/polygon icon
255
+ QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( resultIt.key () );
256
+ if ( vl )
257
+ {
258
+ switch ( vl->geometryType () )
259
+ {
260
+ case QGis::Point:
261
+ action->setIcon ( QgsApplication::getThemeIcon ( " /mIconPointLayer.png" ) );
262
+ break ;
263
+ case QGis::Line:
264
+ action->setIcon ( QgsApplication::getThemeIcon ( " /mIconLineLayer.png" ) );
265
+ break ;
266
+ case QGis::Polygon:
267
+ action->setIcon ( QgsApplication::getThemeIcon ( " /mIconPolygonLayer.png" ) );
268
+ break ;
269
+ default :
270
+ break ;
271
+ }
272
+ }
273
+ else if ( resultIt.key ()->type () == QgsMapLayer::RasterLayer )
274
+ {
275
+ action->setIcon ( QgsApplication::getThemeIcon ( " /mIconRaster.png" ) );
276
+ }
277
+ QObject::connect ( action, SIGNAL ( hovered () ), this , SLOT ( handleMenuHover () ) );
278
+ menu.addAction ( action );
279
+ }
280
+ }
281
+
282
+ void QgsMapToolIdentifyAction::execLayerSelectionMenu ( QMenu& menu, const QPoint& pos, QList<IdentifyResult>& resultList )
283
+ {
284
+ QAction* selectedAction = menu.exec ( QPoint ( pos.x () + 5 , pos.y () + 5 ) );
285
+ if ( selectedAction )
286
+ {
287
+ QgsMapLayer* selectedLayer = QgsMapLayerRegistry::instance ()->mapLayer ( selectedAction->data ().toString () );
288
+ QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator sIt = mLayerIdResults .find ( selectedLayer );
289
+ if ( sIt != mLayerIdResults .constEnd () )
290
+ {
291
+ resultList = sIt .value ();
292
+ }
293
+ }
294
+ }
295
+
0 commit comments