QGIS API Documentation  2.6.0-Brighton
 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 #include "qgsdistancearea.h"
20 #include "qgsfeature.h"
21 #include "qgsfield.h"
22 #include "qgsmaptool.h"
23 #include "qgsmaplayer.h"
24 #include "qgspoint.h"
25 
26 #include <QObject>
27 #include <QPointer>
28 
29 class QgsRasterLayer;
30 class QgsVectorLayer;
31 class QgsMapLayer;
32 class QgsMapCanvas;
33 class QgsHighlight;
34 class QgsIdentifyMenu;
35 
44 class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
45 {
46  Q_OBJECT
47  Q_FLAGS( LayerType )
48 
49  public:
50 
52  {
53  DefaultQgsSetting = -1,
57  LayerSelection
58  };
59 
60  enum Type
61  {
62  VectorLayer = 1,
63  RasterLayer = 2,
64  AllLayers = VectorLayer | RasterLayer
65  };
66  Q_DECLARE_FLAGS( LayerType, Type )
67 
69  {
71 
72  IdentifyResult( QgsMapLayer * layer, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
73  mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
74 
75  IdentifyResult( QgsMapLayer * layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes ):
76  mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
77 
78  IdentifyResult( QgsMapLayer * layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes ):
79  mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
80 
82  QString mLabel;
85  QMap< QString, QString > mAttributes;
86  QMap< QString, QString > mDerivedAttributes;
87  QMap< QString, QVariant > mParams;
88  };
89 
91  QgsMapToolIdentify( QgsMapCanvas * canvas );
92 
93  virtual ~QgsMapToolIdentify();
94 
96  virtual void canvasMoveEvent( QMouseEvent * e );
97 
99  virtual void canvasPressEvent( QMouseEvent * e );
100 
102  virtual void canvasReleaseEvent( QMouseEvent * e );
103 
104  virtual void activate();
105 
106  virtual void deactivate();
107 
114  QList<IdentifyResult> identify( int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
115 
124  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
125 
128  QgsIdentifyMenu* identifyMenu() {return mIdentifyMenu;}
129 
130  public slots:
131  void formatChanged( QgsRasterLayer *layer );
132 
133  signals:
134  void identifyProgress( int, int );
135  void identifyMessage( QString );
136  void changedRasterResults( QList<IdentifyResult>& );
137 
138  protected:
148  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
149 
151 
153  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
154 
155  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
156  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
157 
158  private:
159 
161  virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
162 
164  virtual QGis::UnitType displayUnits();
165 
166  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer );
167 
168  // Last point in canvas CRS
169  QgsPoint mLastPoint;
170 
171  double mLastMapUnitsPerPixel;
172 
173  QgsRectangle mLastExtent;
174 };
175 
176 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
177 
178 #endif