QGIS API Documentation  2.4.0-Chugiak
 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  void layerDestroyed();
131 
132  signals:
133  void identifyProgress( int, int );
134  void identifyMessage( QString );
135  void changedRasterResults( QList<IdentifyResult>& );
136 
137  private:
147  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
148 
150  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
151 
152  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
153  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
154 
156  virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
157 
159  virtual QGis::UnitType displayUnits();
160 
161  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer );
162 
163  // specific to layer selection mode
165  QMap< QgsMapLayer*, QList<IdentifyResult> > mLayerIdResults;
167  QList<QgsHighlight*> mRubberBands;
168 
169  // Last point in canvas CRS
171 
173 
175 
176  private slots:
178  void handleMenuHover();
179 };
180 
181 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
QMap< QString, QString > mAttributes
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
virtual void canvasMoveEvent(QMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:134
Container of fields for a vector layer.
Definition: qgsfield.h:161
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
virtual void canvasPressEvent(QMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:144
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:77
Map tool for identifying features in layers.
QList< QgsHighlight * > mRubberBands
rubber bands for layer select mode
A class for highlight features on the map.
Definition: qgshighlight.h:36
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:91
A class to represent a point geometry.
Definition: qgspoint.h:63
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
General purpose distance and area calculator.
QMap< QgsMapLayer *, QList< IdentifyResult > > mLayerIdResults
layer id map for layer select mode
virtual void canvasReleaseEvent(QMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:149
QMap< QString, QVariant > mParams
IdentifyResult(QgsMapLayer *layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes)
UnitType
Map units that qgis supports.
Definition: qgis.h:229
IdentifyResult(QgsMapLayer *layer, QgsFeature feature, QMap< QString, QString > derivedAttributes)
IdentifyResult(QgsMapLayer *layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes)
Represents a vector layer which manages a vector based data sets.
QMap< QString, QString > mDerivedAttributes