Skip to content

Commit 4e64d72

Browse files
committed
Merge remote branch '3nids/maptoolidentify_returnresults'
2 parents 863da7d + d97f05e commit 4e64d72

8 files changed

+99
-132
lines changed

python/gui/qgsmaptoolidentify.sip

+15-28
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

+1-1
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

+13-3
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

+6-2
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

+15-17
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

+2-2
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 );

0 commit comments

Comments
 (0)