Skip to content

Commit 682524f

Browse files
3nidsNathanW2
authored andcommitted
MapToolIdentify moved to gui to make it accessible in python
put back convertMeasurement in gui as it is not app specific use display settings for specific app units
1 parent 0ebc058 commit 682524f

13 files changed

+562
-147
lines changed

python/gui/gui.sip

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
%Include qgsmaptip.sip
4040
%Include qgsmaptool.sip
4141
%Include qgsmaptoolemitpoint.sip
42+
%Include qgsmaptoolidentify.sip
4243
%Include qgsmaptoolpan.sip
4344
%Include qgsmaptooltouch.sip
4445
%Include qgsmaptoolzoom.sip

python/gui/qgsmaptool.sip

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <qgsmaptoolzoom.h>
77
#include <qgsmaptoolpan.h>
88
#include <qgsmaptoolemitpoint.h>
9+
#include <qgsmaptoolidentify.h>
910
%End
1011

1112
%Feature HAVE_TOUCH
@@ -23,6 +24,8 @@ class QgsMapTool : QObject
2324
sipClass = sipClass_QgsMapToolPan;
2425
else if (dynamic_cast<QgsMapToolEmitPoint*>(sipCpp) != NULL)
2526
sipClass = sipClass_QgsMapToolEmitPoint;
27+
else if (dynamic_cast<QgsMapToolIdentify*>(sipCpp) != NULL)
28+
sipClass = sipClass_QgsMapToolIdentify;
2629
else
2730
sipClass = NULL;
2831
%End

python/gui/qgsmaptoolidentify.sip

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
class QgsMapToolIdentify : QgsMapTool
3+
{
4+
%TypeHeaderCode
5+
#include <qgsmaptoolidentify.h>
6+
%End
7+
8+
public:
9+
enum IdentifyMode
10+
{
11+
DefaultQgsSetting=-1,
12+
ActiveLayer,
13+
TopDownStopAtFirst,
14+
TopDownAll,
15+
};
16+
17+
enum LayerType
18+
{
19+
AllLayers=-1,
20+
VectorLayer,
21+
RasterLayer,
22+
};
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+
};
32+
33+
struct RasterResult
34+
{
35+
RasterResult();
36+
RasterResult( QgsRasterLayer* layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes);
37+
QgsRasterLayer* mLayer;
38+
QString mLabel;
39+
QMap< QString, QString > mAttributes;
40+
QMap< QString, QString > mDerivedAttributes;
41+
};
42+
43+
struct IdentifyResults
44+
{
45+
IdentifyResults();
46+
IdentifyResults ( QList<QgsMapToolIdentify::VectorResult> vectorResults , QList<QgsMapToolIdentify::RasterResult> rasterResults);
47+
QList<QgsMapToolIdentify::VectorResult> mVectorResults;
48+
QList<QgsMapToolIdentify::RasterResult> mRasterResults;
49+
};
50+
51+
//! constructor
52+
QgsMapToolIdentify( QgsMapCanvas* canvas );
53+
54+
//! Overridden mouse move event
55+
virtual void canvasMoveEvent( QMouseEvent * e );
56+
57+
//! Overridden mouse press event
58+
virtual void canvasPressEvent( QMouseEvent * e );
59+
60+
//! Overridden mouse release event
61+
virtual void canvasReleaseEvent( QMouseEvent * e );
62+
63+
virtual void activate();
64+
65+
virtual void deactivate();
66+
67+
//QgsMapLayer::LayerType LayerType;
68+
69+
/** Performs the identification.
70+
@param x x coordinates of mouseEvent
71+
@param y y coordinates of mouseEvent
72+
@param layerList Performs the identification within the given list of layers. Default value is an empty list, i.e. uses all the layers.
73+
@param mode Identification mode. Can use Qgis default settings or a defined mode. Default mode is DefaultQgsSetting.
74+
@return true if identification succeeded and a feature has been found, false otherwise.*/
75+
bool identify(int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting);
76+
77+
/** Performs the identification.
78+
To avoid beeing forced to specify IdentifyMode with a list of layers
79+
this has been made private and two publics methods are offered
80+
@param x x coordinates of mouseEvent
81+
@param y y coordinates of mouseEvent
82+
@param mode Identification mode. Can use Qgis default settings or a defined mode.
83+
@param layerType Only performs identification in a certain type of layers (raster, vector). Default value is AllLayers.
84+
@return true if identification succeeded and a feature has been found, false otherwise.*/
85+
bool identify(int x, int y, IdentifyMode mode, LayerType layerType = AllLayers);
86+
87+
/** Access to results */
88+
IdentifyResults &results();
89+
90+
signals:
91+
void identifyProgress( int, int );
92+
void identifyMessage( QString );
93+
94+
private:
95+
/** Performs the identification.
96+
To avoid beeing forced to specify IdentifyMode with a list of layers
97+
this has been made private and two publics methods are offered
98+
@param x x coordinates of mouseEvent
99+
@param y y coordinates of mouseEvent
100+
@param mode Identification mode. Can use Qgis default settings or a defined mode.
101+
@param layerList Performs the identification within the given list of layers.
102+
@param layerType Only performs identification in a certain type of layers (raster, vector).
103+
@return true if identification succeeded and a feature has been found, false otherwise.*/
104+
bool identify(int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers);
105+
106+
bool identifyLayer( QgsMapLayer *layer, int x, int y, LayerType layerType = AllLayers );
107+
bool identifyRasterLayer( QgsRasterLayer *layer, int x, int y );
108+
bool identifyVectorLayer( QgsVectorLayer *layer, int x, int y );
109+
110+
//! Private helper
111+
virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
112+
113+
/** Transforms the measurements of derived attributes in the desired units*/
114+
virtual QGis::UnitType displayUnits();
115+
};

src/app/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ SET(QGIS_APP_SRCS
3838
qgsfieldcalculator.cpp
3939
qgsfieldsproperties.cpp
4040
qgsgraduatedsymboldialog.cpp
41-
qgsidentifyresults.cpp
41+
qgsidentifyresultsdialog.cpp
4242
qgsfeatureaction.cpp
4343
qgslabeldialog.cpp
4444
qgslabelpropertydialog.cpp
@@ -62,7 +62,7 @@ SET(QGIS_APP_SRCS
6262
qgsmaptoolhtmlannotation.cpp
6363
qgsmaptoolpinlabels.cpp
6464
qgsmaptoolshowhidelabels.cpp
65-
qgsmaptoolidentify.cpp
65+
qgsmaptoolidentifyaction.cpp
6666
qgsmaptoollabel.cpp
6767
qgsmaptoolmeasureangle.cpp
6868
qgsmaptoolmovefeature.cpp
@@ -203,7 +203,7 @@ SET (QGIS_APP_MOC_HDRS
203203
qgsformannotationdialog.h
204204
qgshtmlannotationdialog.h
205205
qgsgraduatedsymboldialog.h
206-
qgsidentifyresults.h
206+
qgsidentifyresultsdialog.h
207207
qgslabeldialog.h
208208
qgslabelengineconfigdialog.h
209209
qgslabelinggui.h
@@ -222,7 +222,7 @@ SET (QGIS_APP_MOC_HDRS
222222
qgsmaptoolfeatureaction.h
223223
qgsmaptoolpinlabels.h
224224
qgsmaptoolshowhidelabels.h
225-
qgsmaptoolidentify.h
225+
qgsmaptoolidentifyaction.h
226226
qgsmaptoolmeasureangle.h
227227
qgsmaptoolmovefeature.h
228228
qgsmaptoolmovelabel.h

src/app/qgisapp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
#include "qgsmaptoolfeatureaction.h"
225225
#include "qgsmaptoolformannotation.h"
226226
#include "qgsmaptoolhtmlannotation.h"
227-
#include "qgsmaptoolidentify.h"
227+
#include "qgsmaptoolidentifyaction.h"
228228
#include "qgsmaptoolmeasureangle.h"
229229
#include "qgsmaptoolmovefeature.h"
230230
#include "qgsmaptoolrotatefeature.h"
@@ -1861,7 +1861,7 @@ void QgisApp::createCanvasTools()
18611861
mMapTools.mTouch = new QgsMapToolTouch( mMapCanvas );
18621862
mMapTools.mTouch->setAction( mActionTouch );
18631863
#endif
1864-
mMapTools.mIdentify = new QgsMapToolIdentify( mMapCanvas );
1864+
mMapTools.mIdentify = new QgsMapToolIdentifyAction( mMapCanvas );
18651865
mMapTools.mIdentify->setAction( mActionIdentify );
18661866
mMapTools.mFeatureAction = new QgsMapToolFeatureAction( mMapCanvas );
18671867
mMapTools.mFeatureAction->setAction( mActionFeatureAction );

src/app/qgsfeatureaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "qgsfeatureaction.h"
1919
#include "qgsvectorlayer.h"
2020
#include "qgsvectordataprovider.h"
21-
#include "qgsidentifyresults.h"
21+
#include "qgsidentifyresultsdialog.h"
2222
#include "qgsattributedialog.h"
2323
#include "qgslogger.h"
2424

0 commit comments

Comments
 (0)