|
| 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 | +}; |
0 commit comments