QGIS API Documentation  2.2.0-Valmiera
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmaptoolidentify.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptoolidentify.h - map tool for identifying features
3  ---------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPTOOLIDENTIFY_H
17 #define QGSMAPTOOLIDENTIFY_H
18 
19 
20 #include "qgsmaptool.h"
21 #include "qgspoint.h"
22 #include "qgsfeature.h"
23 #include "qgsfield.h"
24 #include "qgsdistancearea.h"
25 #include "qgsmaplayer.h"
26 
27 #include <QObject>
28 #include <QPointer>
29 
30 class QgsRasterLayer;
31 class QgsVectorLayer;
32 class QgsMapLayer;
33 class QgsMapCanvas;
34 class QgsHighlight;
35 
44 class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
45 {
46  Q_OBJECT
47 
48  public:
49 
51  {
52  DefaultQgsSetting = -1,
56  LayerSelection
57  };
58 
59  enum LayerType
60  {
61  AllLayers = -1,
63  RasterLayer
64  };
65 
67  {
69 
70  IdentifyResult( QgsMapLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
71  mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
72 
73  IdentifyResult( QgsMapLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes ):
74  mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
75 
76  IdentifyResult( QgsMapLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
77  mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
78 
80  QString mLabel;
83  QMap< QString, QString > mAttributes;
84  QMap< QString, QString > mDerivedAttributes;
85  QMap< QString, QVariant > mParams;
86  };
87 
89  QgsMapToolIdentify( QgsMapCanvas * canvas );
90 
91  virtual ~QgsMapToolIdentify();
92 
94  virtual void canvasMoveEvent( QMouseEvent * e );
95 
97  virtual void canvasPressEvent( QMouseEvent * e );
98 
100  virtual void canvasReleaseEvent( QMouseEvent * e );
101 
102  virtual void activate();
103 
104  virtual void deactivate();
105 
112  QList<IdentifyResult> identify( int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
113 
122  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
123 
124  protected:
126  void deleteRubberBands();
127 
128  public slots:
129  void formatChanged( QgsRasterLayer *layer );
130 
131  signals:
132  void identifyProgress( int, int );
133  void identifyMessage( QString );
134  void changedRasterResults( QList<IdentifyResult>& );
135 
136  private:
146  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
147 
149  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
150 
151  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
152  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
153 
155  virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
156 
158  virtual QGis::UnitType displayUnits();
159 
160  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer );
161 
162  // specific to layer selection mode
164  QMap< QgsMapLayer*, QList<IdentifyResult> > mLayerIdResults;
166  QList<QgsHighlight*> mRubberBands;
167 
168  // Last point in canvas CRS
170 
172 
174 
175  private slots:
177  void handleMenuHover();
178 };
179 
180 #endif