QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
115  QList<IdentifyResult> identify( int x, int y, QList<QgsMapLayer*> layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
116 
126  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
127 
130  QgsIdentifyMenu* identifyMenu() {return mIdentifyMenu;}
131 
132  public slots:
133  void formatChanged( QgsRasterLayer *layer );
134 
135  signals:
136  void identifyProgress( int, int );
137  void identifyMessage( QString );
138  void changedRasterResults( QList<IdentifyResult>& );
139 
140  protected:
151  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, QList<QgsMapLayer*> layerList, LayerType layerType = AllLayers );
152 
154 
156  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel, LayerType layerType = AllLayers );
157 
158  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, QgsRectangle viewExtent, double mapUnitsPerPixel );
159  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, QgsPoint point );
160 
161  private:
162 
164  virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
165 
167  virtual QGis::UnitType displayUnits();
168 
169  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer );
170 
171  // Last point in canvas CRS
172  QgsPoint mLastPoint;
173 
174  double mLastMapUnitsPerPixel;
175 
176  QgsRectangle mLastExtent;
177 };
178 
179 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
180 
181 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
Definition: qgsmaptoolidentify.h:56
QMap< QString, QString > mAttributes
Definition: qgsmaptoolidentify.h:85
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
Definition: qgsrasterlayer.h:169
UnitType
Map units that qgis supports.
Definition: qgis.h:229
virtual void canvasMoveEvent(QMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:138
QgsFields mFields
Definition: qgsmaptoolidentify.h:83
Type
Definition: qgsmaptoolidentify.h:60
Container of fields for a vector layer.
Definition: qgsfield.h:163
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:148
QgsFeature mFeature
Definition: qgsmaptoolidentify.h:84
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
QgsIdentifyMenu * mIdentifyMenu
Definition: qgsmaptoolidentify.h:153
QString mLabel
Definition: qgsmaptoolidentify.h:82
Map tool for identifying features in layers.
Definition: qgsmaptoolidentify.h:44
IdentifyMode
Definition: qgsmaptoolidentify.h:51
A class for highlight features on the map.
Definition: qgshighlight.h:36
The QgsIdentifyMenu class builds a menu to be used with identify results (.
Definition: qgsidentifymenu.h:32
Definition: qgsmaptoolidentify.h:54
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:93
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.
Definition: qgsdistancearea.h:34
IdentifyResult()
Definition: qgsmaptoolidentify.h:70
virtual void canvasReleaseEvent(QMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:153
QMap< QString, QVariant > mParams
Definition: qgsmaptoolidentify.h:87
Definition: qgsmaptoolidentify.h:55
IdentifyResult(QgsMapLayer *layer, QString label, QgsFields fields, QgsFeature feature, QMap< QString, QString > derivedAttributes)
Definition: qgsmaptoolidentify.h:78
QgsIdentifyMenu * identifyMenu()
return a pointer to the identify menu which will be used in layer selection mode this menu can also b...
Definition: qgsmaptoolidentify.h:130
QgsMapLayer * mLayer
Definition: qgsmaptoolidentify.h:81
IdentifyResult(QgsMapLayer *layer, QgsFeature feature, QMap< QString, QString > derivedAttributes)
Definition: qgsmaptoolidentify.h:72
IdentifyResult(QgsMapLayer *layer, QString label, QMap< QString, QString > attributes, QMap< QString, QString > derivedAttributes)
Definition: qgsmaptoolidentify.h:75
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
Definition: qgsmaptoolidentify.h:68
QMap< QString, QString > mDerivedAttributes
Definition: qgsmaptoolidentify.h:86