Skip to content

Commit 4e64d72

Browse files
committedFeb 7, 2013
Merge remote branch '3nids/maptoolidentify_returnresults'
2 parents 863da7d + d97f05e commit 4e64d72

8 files changed

+99
-132
lines changed
 

‎python/gui/qgsmaptoolidentify.sip

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,26 @@ class QgsMapToolIdentify : QgsMapTool
2020
VectorLayer,
2121
RasterLayer,
2222
};
23-
24-
struct VectorResult
25-
{
26-
VectorResult();
27-
VectorResult(QgsVectorLayer* layer, QgsFeature feature, QMap< QString, QString > derivedAttributes);
28-
QgsVectorLayer* mLayer;
29-
QgsFeature mFeature;
30-
QMap< QString, QString > mDerivedAttributes;
31-
};
3223

33-
struct RasterResult
24+
25+
struct IdentifyResult
3426
{
35-
RasterResult();
36-
RasterResult( QgsRasterLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes );
37-
QgsRasterLayer* mLayer;
27+
IdentifyResult();
28+
29+
IdentifyResult( QgsMapLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes );
30+
31+
IdentifyResult( QgsMapLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes );
32+
33+
IdentifyResult( QgsMapLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes );
34+
35+
QgsMapLayer* mLayer;
3836
QString mLabel;
3937
QgsFields mFields;
4038
QgsFeature mFeature;
4139
QMap< QString, QString > mAttributes;
4240
QMap< QString, QString > mDerivedAttributes;
4341
};
4442

45-
struct IdentifyResults
46-
{
47-
IdentifyResults();
48-
IdentifyResults ( QList<QgsMapToolIdentify::VectorResult> vectorResults , QList<QgsMapToolIdentify::RasterResult> rasterResults);
49-
QList<QgsMapToolIdentify::VectorResult> mVectorResults;
50-
QList<QgsMapToolIdentify::RasterResult> mRasterResults;
51-
};
52-
5343
//! constructor
5444
QgsMapToolIdentify( QgsMapCanvas* canvas );
5545

@@ -73,8 +63,8 @@ class QgsMapToolIdentify : QgsMapTool
7363
@param y y coordinates of mouseEvent
7464
@param layerList Performs the identification within the given list of layers. Default value is an empty list, i.e. uses all the layers.
7565
@param mode Identification mode. Can use Qgis default settings or a defined mode. Default mode is DefaultQgsSetting.
76-
@return true if identification succeeded and a feature has been found, false otherwise.*/
77-
bool identify(int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting);
66+
@return a list of IdentifyResult*/
67+
QList<QgsMapToolIdentify::IdentifyResult> identify(int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting);
7868

7969
/** Performs the identification.
8070
To avoid beeing forced to specify IdentifyMode with a list of layers
@@ -83,11 +73,8 @@ class QgsMapToolIdentify : QgsMapTool
8373
@param y y coordinates of mouseEvent
8474
@param mode Identification mode. Can use Qgis default settings or a defined mode.
8575
@param layerType Only performs identification in a certain type of layers (raster, vector). Default value is AllLayers.
86-
@return true if identification succeeded and a feature has been found, false otherwise.*/
87-
bool identify(int x, int y, IdentifyMode mode, LayerType layerType = AllLayers);
88-
89-
/** Access to results */
90-
IdentifyResults &results();
76+
@return a list of IdentifyResult*/
77+
QList<QgsMapToolIdentify::IdentifyResult> identify(int x, int y, IdentifyMode mode, LayerType layerType = AllLayers);
9178

9279
signals:
9380
void identifyProgress( int, int );

‎src/app/qgsfeatureaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <QPair>
2424
#include <QAction>
2525

26-
class QgsIdentifyResults;
26+
class QgsIdentifyResultsDialog;
2727
class QgsVectorLayer;
2828
class QgsHighlight;
2929
class QgsAttributeDialog;

‎src/app/qgsidentifyresultsdialog.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,19 @@ QTreeWidgetItem *QgsIdentifyResultsDialog::layerItem( QObject *layer )
292292
return 0;
293293
}
294294

295-
void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer,
296-
const QgsFeature &f,
297-
const QMap<QString, QString> &derivedAttributes )
295+
void QgsIdentifyResultsDialog::addFeature( QgsMapToolIdentify::IdentifyResult result )
296+
{
297+
if ( result.mLayer->type() == QgsMapLayer::VectorLayer )
298+
{
299+
addFeature( qobject_cast<QgsVectorLayer *>( result.mLayer ), result.mFeature, result.mDerivedAttributes );
300+
}
301+
else if ( result.mLayer->type() == QgsMapLayer::RasterLayer )
302+
{
303+
addFeature( qobject_cast<QgsRasterLayer *>( result.mLayer ), result.mLabel, result.mAttributes, result.mDerivedAttributes, result.mFields, result.mFeature );
304+
}
305+
}
306+
307+
void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeature &f, const QMap<QString, QString> &derivedAttributes )
298308
{
299309
QTreeWidgetItem *layItem = layerItem( vlayer );
300310

‎src/app/qgsidentifyresultsdialog.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgsfeature.h"
2525
#include "qgsfeaturestore.h"
2626
#include "qgsfield.h"
27+
#include "qgsmaptoolidentify.h"
2728
#include "qgscoordinatereferencesystem.h"
2829

2930
#include <QWidget>
@@ -101,18 +102,21 @@ class QgsIdentifyResultsDialog: public QDialog, private Ui::QgsIdentifyResultsBa
101102
~QgsIdentifyResultsDialog();
102103

103104
/** Add add feature from vector layer */
104-
void addFeature( QgsVectorLayer *layer,
105+
void addFeature( QgsVectorLayer * layer,
105106
const QgsFeature &f,
106107
const QMap< QString, QString > &derivedAttributes );
107108

108109
/** Add add feature from other layer */
109-
void addFeature( QgsRasterLayer *layer,
110+
void addFeature( QgsRasterLayer * layer,
110111
QString label,
111112
const QMap< QString, QString > &attributes,
112113
const QMap< QString, QString > &derivedAttributes,
113114
const QgsFields &fields = QgsFields(),
114115
const QgsFeature &feature = QgsFeature() );
115116

117+
/** Add feature from identify results */
118+
void addFeature( QgsMapToolIdentify::IdentifyResult result );
119+
116120
/** map tool was deactivated */
117121
void deactivate();
118122

‎src/app/qgsmaptoolidentifyaction.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
#include <QStatusBar>
4242
#include <QVariant>
4343

44-
QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas* canvas )
44+
QgsMapToolIdentifyAction::QgsMapToolIdentifyAction( QgsMapCanvas * canvas )
4545
: QgsMapToolIdentify( canvas )
4646
{
4747
// set cursor
4848
QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
4949
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
5050

51-
connect( this, SIGNAL( changedRasterResults( QList<RasterResult>& ) ), this, SLOT( handleChangedRasterResults( QList<RasterResult>& ) ) );
51+
connect( this, SIGNAL( changedRasterResults( QList<IdentifyResult>& ) ), this, SLOT( handleChangedRasterResults( QList<IdentifyResult>& ) ) );
5252
}
5353

5454
QgsMapToolIdentifyAction::~QgsMapToolIdentifyAction()
@@ -93,23 +93,18 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
9393

9494
connect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
9595
connect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );
96-
bool res = QgsMapToolIdentify::identify( e->x(), e->y() );
96+
QList<IdentifyResult> results = QgsMapToolIdentify::identify( e->x(), e->y() );
9797
disconnect( this, SIGNAL( identifyProgress( int, int ) ), QgisApp::instance(), SLOT( showProgress( int, int ) ) );
9898
disconnect( this, SIGNAL( identifyMessage( QString ) ), QgisApp::instance(), SLOT( showStatusMessage( QString ) ) );
9999

100100

101-
QList<VectorResult>::const_iterator vresult;
102-
for ( vresult = results().mVectorResults.begin(); vresult != results().mVectorResults.end(); ++vresult )
101+
QList<IdentifyResult>::const_iterator result;
102+
for ( result = results.begin(); result != results.end(); ++result )
103103
{
104-
resultsDialog()->addFeature( vresult->mLayer, vresult->mFeature, vresult->mDerivedAttributes );
105-
}
106-
QList<RasterResult>::const_iterator rresult;
107-
for ( rresult = results().mRasterResults.begin(); rresult != results().mRasterResults.end(); ++rresult )
108-
{
109-
resultsDialog()->addFeature( rresult->mLayer, rresult->mLabel, rresult->mAttributes, rresult->mDerivedAttributes, rresult->mFields, rresult->mFeature );
104+
resultsDialog()->addFeature( *result );
110105
}
111106

112-
if ( res )
107+
if ( !results.isEmpty() )
113108
{
114109
resultsDialog()->show();
115110
}
@@ -129,14 +124,17 @@ void QgsMapToolIdentifyAction::canvasReleaseEvent( QMouseEvent *e )
129124
}
130125
}
131126

132-
void QgsMapToolIdentifyAction::handleChangedRasterResults( QList<RasterResult>& rasterResults )
127+
void QgsMapToolIdentifyAction::handleChangedRasterResults( QList<IdentifyResult> &results )
133128
{
134129
// Add new result after raster format change
135-
QgsDebugMsg( QString( "%1 raster results" ).arg( rasterResults.size() ) );
136-
QList<RasterResult>::const_iterator rresult;
137-
for ( rresult = rasterResults.begin(); rresult != rasterResults.end(); ++rresult )
130+
QgsDebugMsg( QString( "%1 raster results" ).arg( results.size() ) );
131+
QList<IdentifyResult>::const_iterator rresult;
132+
for ( rresult = results.begin(); rresult != results.end(); ++rresult )
138133
{
139-
resultsDialog()->addFeature( rresult->mLayer, rresult->mLabel, rresult->mAttributes, rresult->mDerivedAttributes, rresult->mFields, rresult->mFeature );
134+
if ( rresult->mLayer->type() == QgsMapLayer::RasterLayer )
135+
{
136+
resultsDialog()->addFeature( qobject_cast<QgsRasterLayer *>( rresult->mLayer ), rresult->mLabel, rresult->mAttributes, rresult->mDerivedAttributes, rresult->mFields, rresult->mFeature );
137+
}
140138
}
141139
}
142140

‎src/app/qgsmaptoolidentifyaction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class QgsMapToolIdentifyAction : public QgsMapToolIdentify
4646
Q_OBJECT
4747

4848
public:
49-
QgsMapToolIdentifyAction( QgsMapCanvas* canvas );
49+
QgsMapToolIdentifyAction( QgsMapCanvas * canvas );
5050

5151
~QgsMapToolIdentifyAction();
5252

@@ -65,7 +65,7 @@ class QgsMapToolIdentifyAction : public QgsMapToolIdentify
6565

6666
public slots:
6767
void handleCopyToClipboard( QgsFeatureStore & );
68-
void handleChangedRasterResults( QList<RasterResult>& rasterResults );
68+
void handleChangedRasterResults( QList<IdentifyResult>& results );
6969

7070
signals:
7171
void identifyProgress( int, int );

‎src/gui/qgsmaptoolidentify.cpp

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,50 +53,44 @@ QgsMapToolIdentify::~QgsMapToolIdentify()
5353
{
5454
}
5555

56-
void QgsMapToolIdentify::canvasMoveEvent( QMouseEvent *e )
56+
void QgsMapToolIdentify::canvasMoveEvent( QMouseEvent * e )
5757
{
5858
Q_UNUSED( e );
5959
}
6060

61-
void QgsMapToolIdentify::canvasPressEvent( QMouseEvent *e )
61+
void QgsMapToolIdentify::canvasPressEvent( QMouseEvent * e )
6262
{
6363
Q_UNUSED( e );
6464
}
6565

66-
void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent *e )
66+
void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
6767
{
6868
Q_UNUSED( e );
6969
}
7070

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 )
7272
{
7373
return identify( x, y, mode, layerList, AllLayers );
7474
}
7575

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 )
7777
{
7878
return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
7979
}
8080

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 )
8282
{
83+
QList<IdentifyResult> results;
84+
8385
mLastPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( x, y );
8486
mLastExtent = mCanvas->extent();
8587
mLastMapUnitsPerPixel = mCanvas->mapUnitsPerPixel();
86-
return identify( mLastPoint, mLastExtent, mLastMapUnitsPerPixel, mode, layerList, layerType );
87-
}
8888

89-
bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType )
90-
{
91-
bool res = false;
9289
if ( !mCanvas || mCanvas->isDrawing() )
9390
{
94-
return res;
91+
return results;
9592
}
9693

97-
mResultData.mVectorResults.clear();
98-
mResultData.mRasterResults.clear();
99-
10094
if ( mode == DefaultQgsSetting )
10195
{
10296
QSettings settings;
@@ -110,12 +104,12 @@ bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, doub
110104
if ( !layer )
111105
{
112106
emit identifyMessage( tr( "No active layer. To identify features, you must choose an active layer." ) );
113-
return res;
107+
return results;
114108
}
115109

116110
QApplication::setOverrideCursor( Qt::WaitCursor );
117111

118-
res = identifyLayer( layer, point, viewExtent, mapUnitsPerPixel, layerType );
112+
identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
119113
}
120114
else
121115
{
@@ -145,9 +139,8 @@ bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, doub
145139
if ( noIdentifyLayerIdList.contains( layer->id() ) )
146140
continue;
147141

148-
if ( identifyLayer( layer, point, viewExtent, mapUnitsPerPixel, layerType ) )
142+
if ( identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
149143
{
150-
res = true;
151144
if ( mode == TopDownStopAtFirst )
152145
break;
153146
}
@@ -159,7 +152,7 @@ bool QgsMapToolIdentify::identify( QgsPoint point, QgsRectangle viewExtent, doub
159152

160153
QApplication::restoreOverrideCursor();
161154

162-
return res;
155+
return results;
163156
}
164157

165158
void QgsMapToolIdentify::activate()
@@ -172,25 +165,24 @@ void QgsMapToolIdentify::deactivate()
172165
QgsMapTool::deactivate();
173166
}
174167

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 )
176169
{
177170
if ( layer->type() == QgsMapLayer::RasterLayer && ( layerType == AllLayers || layerType == RasterLayer ) )
178171
{
179-
return identifyRasterLayer( qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel, mResultData.mRasterResults );
172+
return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
180173
}
181174
else if ( layer->type() == QgsMapLayer::VectorLayer && ( layerType == AllLayers || layerType == VectorLayer ) )
182175
{
183-
return identifyVectorLayer( qobject_cast<QgsVectorLayer *>( layer ), point );
176+
return identifyVectorLayer( results, qobject_cast<QgsVectorLayer *>( layer ), point );
184177
}
185178
else
186179
{
187180
return false;
188181
}
189182
}
190183

191-
bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, QgsPoint point )
184+
bool QgsMapToolIdentify::identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point )
192185
{
193-
QgsDebugMsg( "point = " + point.toString() );
194186
if ( !layer )
195187
return false;
196188

@@ -210,7 +202,6 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, QgsPoint po
210202
QSettings settings;
211203
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
212204

213-
214205
if ( identifyValue <= 0.0 )
215206
identifyValue = QGis::DEFAULT_IDENTIFY_RADIUS;
216207

@@ -271,7 +262,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QgsVectorLayer *layer, QgsPoint po
271262

272263
derivedAttributes.insert( tr( "feature id" ), fid < 0 ? tr( "new feature" ) : FID_TO_STRING( fid ) );
273264

274-
mResultData.mVectorResults.append( VectorResult( layer, *f_it, derivedAttributes ) );
265+
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
275266
}
276267

277268
if ( renderer && renderer->capabilities() & QgsFeatureRendererV2::ScaleDependent )
@@ -348,7 +339,7 @@ QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes( QgsFeatur
348339
return derivedAttributes;
349340
}
350341

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 )
352343
{
353344
QgsDebugMsg( "point = " + point.toString() );
354345
if ( !layer ) return false;
@@ -442,7 +433,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, QgsPoint po
442433
attributes.insert( dprovider->generateBandName( bandNo ), valueString );
443434
}
444435
QString label = layer->name();
445-
rasterResults.append( RasterResult( layer, label, attributes, derivedAttributes ) );
436+
results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
446437
}
447438
else if ( format == QgsRasterDataProvider::IdentifyFormatFeature )
448439
{
@@ -476,7 +467,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, QgsPoint po
476467
QMap< QString, QString > derAttributes = derivedAttributes;
477468
derAttributes.unite( featureDerivedAttributes( &feature, layer ) );
478469

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 ) );
480471
}
481472
}
482473
}
@@ -491,7 +482,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, QgsPoint po
491482
attributes.insert( "", value );
492483

493484
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 ) );
495486
}
496487
}
497488

@@ -515,16 +506,13 @@ QGis::UnitType QgsMapToolIdentify::displayUnits()
515506
return mCanvas->mapUnits();
516507
}
517508

518-
QgsMapToolIdentify::IdentifyResults &QgsMapToolIdentify::results()
519-
{
520-
return mResultData;
521-
}
522-
523509
void QgsMapToolIdentify::formatChanged( QgsRasterLayer *layer )
524510
{
525511
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+
}
529517
}
530518

‎src/gui/qgsmaptoolidentify.h

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
class QgsRasterLayer;
3131
class QgsVectorLayer;
32+
class QgsMapLayer;
3233
class QgsMapCanvas;
3334

3435
/**
@@ -60,45 +61,29 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
6061
RasterLayer
6162
};
6263

63-
struct VectorResult
64+
struct IdentifyResult
6465
{
65-
VectorResult() {}
66-
VectorResult( QgsVectorLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
66+
IdentifyResult() {}
67+
68+
IdentifyResult( QgsMapLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
6769
mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
68-
QgsVectorLayer* mLayer;
69-
QgsFeature mFeature;
70-
QMap< QString, QString > mDerivedAttributes;
71-
};
7270

73-
struct RasterResult
74-
{
75-
RasterResult() {}
76-
RasterResult( QgsRasterLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes ):
71+
IdentifyResult( QgsMapLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes ):
7772
mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
7873

79-
RasterResult( QgsRasterLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
74+
IdentifyResult( QgsMapLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
8075
mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
81-
QgsRasterLayer* mLayer;
76+
77+
QgsMapLayer* mLayer;
8278
QString mLabel;
8379
QgsFields mFields;
8480
QgsFeature mFeature;
8581
QMap< QString, QString > mAttributes;
8682
QMap< QString, QString > mDerivedAttributes;
8783
};
8884

89-
struct IdentifyResults
90-
{
91-
IdentifyResults() {}
92-
IdentifyResults( QList<VectorResult> vectorResults , QList<RasterResult> rasterResults ) :
93-
mVectorResults( vectorResults ),
94-
mRasterResults( rasterResults )
95-
{}
96-
QList<VectorResult> mVectorResults;
97-
QList<RasterResult> mRasterResults;
98-
};
99-
10085
//! constructor
101-
QgsMapToolIdentify( QgsMapCanvas* canvas );
86+
QgsMapToolIdentify( QgsMapCanvas * canvas );
10287

10388
virtual ~QgsMapToolIdentify();
10489

@@ -120,8 +105,8 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
120105
@param y y coordinates of mouseEvent
121106
@param layerList Performs the identification within the given list of layers. Default value is an empty list, i.e. uses all the layers.
122107
@param mode Identification mode. Can use Qgis default settings or a defined mode. Default mode is DefaultQgsSetting.
123-
@return true if identification succeeded and a feature has been found, false otherwise.*/
124-
bool identify( int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
108+
@return a list of IdentifyResult*/
109+
QList<IdentifyResult> identify( int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
125110

126111
/** Performs the identification.
127112
To avoid beeing forced to specify IdentifyMode with a list of layers
@@ -130,19 +115,16 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
130115
@param y y coordinates of mouseEvent
131116
@param mode Identification mode. Can use Qgis default settings or a defined mode.
132117
@param layerType Only performs identification in a certain type of layers (raster, vector). Default value is AllLayers.
133-
@return true if identification succeeded and a feature has been found, false otherwise.*/
134-
bool identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
135-
136-
/** Access to results */
137-
IdentifyResults &results();
118+
@return a list of IdentifyResult*/
119+
QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
138120

139121
public slots:
140122
void formatChanged( QgsRasterLayer *layer );
141123

142124
signals:
143125
void identifyProgress( int, int );
144126
void identifyMessage( QString );
145-
void changedRasterResults( QList<RasterResult>& );
127+
void changedRasterResults( QList<IdentifyResult>& );
146128

147129
private:
148130
/** Performs the identification.
@@ -154,13 +136,13 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
154136
@param layerList Performs the identification within the given list of layers.
155137
@param layerType Only performs identification in a certain type of layers (raster, vector).
156138
@return true if identification succeeded and a feature has been found, false otherwise.*/
157-
bool identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
139+
QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
158140

159-
bool identify( QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
141+
/** call the right method depending on layer type */
142+
bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
160143

161-
bool identifyLayer( QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
162-
bool identifyRasterLayer( QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, QList<RasterResult>& rasterResults );
163-
bool identifyVectorLayer( QgsVectorLayer *layer, QgsPoint point );
144+
bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
145+
bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
164146

165147
//! Private helper
166148
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
@@ -170,8 +152,6 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
170152

171153
QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer );
172154

173-
IdentifyResults mResultData;
174-
175155
// Last point in canvas CRS
176156
QgsPoint mLastPoint;
177157

0 commit comments

Comments
 (0)
Please sign in to comment.