@@ -53,50 +53,44 @@ QgsMapToolIdentify::~QgsMapToolIdentify()
53
53
{
54
54
}
55
55
56
- void QgsMapToolIdentify::canvasMoveEvent ( QMouseEvent *e )
56
+ void QgsMapToolIdentify::canvasMoveEvent ( QMouseEvent * e )
57
57
{
58
58
Q_UNUSED ( e );
59
59
}
60
60
61
- void QgsMapToolIdentify::canvasPressEvent ( QMouseEvent *e )
61
+ void QgsMapToolIdentify::canvasPressEvent ( QMouseEvent * e )
62
62
{
63
63
Q_UNUSED ( e );
64
64
}
65
65
66
- void QgsMapToolIdentify::canvasReleaseEvent ( QMouseEvent *e )
66
+ void QgsMapToolIdentify::canvasReleaseEvent ( QMouseEvent * e )
67
67
{
68
68
Q_UNUSED ( e );
69
69
}
70
70
71
- bool QgsMapToolIdentify::identify ( int x, int y, QList<QgsMapLayer *> layerList, IdentifyMode mode )
71
+ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify ( int x, int y, QList<QgsMapLayer *> layerList, IdentifyMode mode )
72
72
{
73
73
return identify ( x, y, mode, layerList, AllLayers );
74
74
}
75
75
76
- bool QgsMapToolIdentify::identify ( int x, int y, IdentifyMode mode, LayerType layerType )
76
+ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify ( int x, int y, IdentifyMode mode, LayerType layerType )
77
77
{
78
78
return identify ( x, y, mode, QList<QgsMapLayer*>(), layerType );
79
79
}
80
80
81
- bool QgsMapToolIdentify::identify ( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType )
81
+ QList<QgsMapToolIdentify::IdentifyResult> QgsMapToolIdentify::identify ( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType )
82
82
{
83
+ QList<IdentifyResult> results;
84
+
83
85
mLastPoint = mCanvas ->getCoordinateTransform ()->toMapCoordinates ( x, y );
84
86
mLastExtent = mCanvas ->extent ();
85
87
mLastMapUnitsPerPixel = mCanvas ->mapUnitsPerPixel ();
86
- return identify ( mLastPoint , mLastExtent , mLastMapUnitsPerPixel , mode, layerList, layerType );
87
- }
88
88
89
- bool QgsMapToolIdentify::identify ( QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType )
90
- {
91
- bool res = false ;
92
89
if ( !mCanvas || mCanvas ->isDrawing () )
93
90
{
94
- return res ;
91
+ return results ;
95
92
}
96
93
97
- mResultData .mVectorResults .clear ();
98
- mResultData .mRasterResults .clear ();
99
-
100
94
if ( mode == DefaultQgsSetting )
101
95
{
102
96
QSettings settings;
@@ -110,12 +104,12 @@ bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, doub
110
104
if ( !layer )
111
105
{
112
106
emit identifyMessage ( tr ( " No active layer. To identify features, you must choose an active layer." ) );
113
- return res ;
107
+ return results ;
114
108
}
115
109
116
110
QApplication::setOverrideCursor ( Qt::WaitCursor );
117
111
118
- res = identifyLayer ( layer, point, viewExtent, mapUnitsPerPixel , layerType );
112
+ identifyLayer ( &results, layer, mLastPoint , mLastExtent , mLastMapUnitsPerPixel , layerType );
119
113
}
120
114
else
121
115
{
@@ -145,9 +139,8 @@ bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, doub
145
139
if ( noIdentifyLayerIdList.contains ( layer->id () ) )
146
140
continue ;
147
141
148
- if ( identifyLayer ( layer, point, viewExtent, mapUnitsPerPixel , layerType ) )
142
+ if ( identifyLayer ( &results, layer, mLastPoint , mLastExtent , mLastMapUnitsPerPixel , layerType ) )
149
143
{
150
- res = true ;
151
144
if ( mode == TopDownStopAtFirst )
152
145
break ;
153
146
}
@@ -159,7 +152,7 @@ bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, doub
159
152
160
153
QApplication::restoreOverrideCursor ();
161
154
162
- return res ;
155
+ return results ;
163
156
}
164
157
165
158
void QgsMapToolIdentify::activate ()
@@ -172,25 +165,24 @@ void QgsMapToolIdentify::deactivate()
172
165
QgsMapTool::deactivate ();
173
166
}
174
167
175
- bool QgsMapToolIdentify::identifyLayer ( QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType )
168
+ bool QgsMapToolIdentify::identifyLayer ( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType )
176
169
{
177
170
if ( layer->type () == QgsMapLayer::RasterLayer && ( layerType == AllLayers || layerType == RasterLayer ) )
178
171
{
179
- return identifyRasterLayer ( qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel, mResultData . mRasterResults );
172
+ return identifyRasterLayer ( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
180
173
}
181
174
else if ( layer->type () == QgsMapLayer::VectorLayer && ( layerType == AllLayers || layerType == VectorLayer ) )
182
175
{
183
- return identifyVectorLayer ( qobject_cast<QgsVectorLayer *>( layer ), point );
176
+ return identifyVectorLayer ( results, qobject_cast<QgsVectorLayer *>( layer ), point );
184
177
}
185
178
else
186
179
{
187
180
return false ;
188
181
}
189
182
}
190
183
191
- bool QgsMapToolIdentify::identifyVectorLayer ( QgsVectorLayer *layer, QgsPoint point )
184
+ bool QgsMapToolIdentify::identifyVectorLayer ( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point )
192
185
{
193
- QgsDebugMsg ( " point = " + point.toString () );
194
186
if ( !layer )
195
187
return false ;
196
188
@@ -210,7 +202,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, QgsPoint po
210
202
QSettings settings;
211
203
double identifyValue = settings.value ( " /Map/identifyRadius" , QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble ();
212
204
213
-
214
205
if ( identifyValue <= 0.0 )
215
206
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
216
207
@@ -271,7 +262,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, QgsPoint po
271
262
272
263
derivedAttributes.insert ( tr ( " feature id" ), fid < 0 ? tr ( " new feature" ) : FID_TO_STRING ( fid ) );
273
264
274
- mResultData . mVectorResults . append ( VectorResult ( layer, *f_it, derivedAttributes ) );
265
+ results-> append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ) , *f_it, derivedAttributes ) );
275
266
}
276
267
277
268
if ( renderer && renderer->capabilities () & QgsFeatureRendererV2::ScaleDependent )
@@ -348,7 +339,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
348
339
return derivedAttributes;
349
340
}
350
341
351
- bool QgsMapToolIdentify::identifyRasterLayer ( QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, QList<RasterResult>& rasterResults )
342
+ bool QgsMapToolIdentify::identifyRasterLayer ( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel )
352
343
{
353
344
QgsDebugMsg ( " point = " + point.toString () );
354
345
if ( !layer ) return false ;
@@ -442,7 +433,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, QgsPoint po
442
433
attributes.insert ( dprovider->generateBandName ( bandNo ), valueString );
443
434
}
444
435
QString label = layer->name ();
445
- rasterResults. append ( RasterResult ( layer, label, attributes, derivedAttributes ) );
436
+ results-> append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ) , label, attributes, derivedAttributes ) );
446
437
}
447
438
else if ( format == QgsRasterDataProvider::IdentifyFormatFeature )
448
439
{
@@ -476,7 +467,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, QgsPoint po
476
467
QMap< QString, QString > derAttributes = derivedAttributes;
477
468
derAttributes.unite ( featureDerivedAttributes ( &feature, layer ) );
478
469
479
- rasterResults. append ( RasterResult ( layer, labels.join ( " / " ), featureStore.fields (), feature, derAttributes ) );
470
+ results-> append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ) , labels.join ( " / " ), featureStore.fields (), feature, derAttributes ) );
480
471
}
481
472
}
482
473
}
@@ -491,7 +482,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, QgsPoint po
491
482
attributes.insert ( " " , value );
492
483
493
484
QString label = layer->subLayers ().value ( bandNo );
494
- rasterResults. append ( RasterResult ( layer, label, attributes, derivedAttributes ) );
485
+ results-> append ( IdentifyResult ( qobject_cast<QgsMapLayer *>( layer ) , label, attributes, derivedAttributes ) );
495
486
}
496
487
}
497
488
@@ -515,16 +506,13 @@ QGis::UnitType QgsMapToolIdentify::displayUnits()
515
506
return mCanvas ->mapUnits ();
516
507
}
517
508
518
- QgsMapToolIdentify::IdentifyResults &QgsMapToolIdentify::results ()
519
- {
520
- return mResultData ;
521
- }
522
-
523
509
void QgsMapToolIdentify::formatChanged ( QgsRasterLayer *layer )
524
510
{
525
511
QgsDebugMsg ( " Entered" );
526
- QList<RasterResult> rasterResults;
527
- identifyRasterLayer ( layer, mLastPoint , mLastExtent , mLastMapUnitsPerPixel , rasterResults );
528
- emit changedRasterResults ( rasterResults );
512
+ QList<IdentifyResult> results;
513
+ if ( identifyRasterLayer ( &results, layer, mLastPoint , mLastExtent , mLastMapUnitsPerPixel ) )
514
+ {
515
+ emit changedRasterResults ( results );
516
+ }
529
517
}
530
518
0 commit comments