QGIS API Documentation  2.15.0-Master (972fc9f)
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  {
70  IdentifyResult() : mLayer( nullptr ) {}
71 
72  IdentifyResult( QgsMapLayer * layer, const QgsFeature& feature, const QMap< QString, QString >& derivedAttributes ):
73  mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
74 
75  IdentifyResult( QgsMapLayer * layer, const QString& label, const QMap< QString, QString >& attributes, const QMap< QString, QString >& derivedAttributes ):
76  mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
77 
78  IdentifyResult( QgsMapLayer * layer, const QString& label, const QgsFields& fields, const QgsFeature& feature, const QMap< QString, QString >& derivedAttributes ):
79  mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
80 
88  };
89 
91  QgsMapToolIdentify( QgsMapCanvas * canvas );
92 
93  virtual ~QgsMapToolIdentify();
94 
95  virtual Flags flags() const override { return QgsMapTool::AllowZoomRect; }
96 
98  virtual void canvasMoveEvent( QgsMapMouseEvent* e ) override;
99 
101  virtual void canvasPressEvent( QgsMapMouseEvent* e ) override;
102 
104  virtual void canvasReleaseEvent( QgsMapMouseEvent* e ) override;
105 
106  virtual void activate() override;
107 
108  virtual void deactivate() override;
109 
116  QList<IdentifyResult> identify( int x, int y, const QList<QgsMapLayer*>& layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
117 
126  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, const 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( const QString& );
138  void changedRasterResults( QList<IdentifyResult>& );
139 
140  protected:
150  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer*>& layerList, const LayerType& layerType = AllLayers );
151 
153 
155  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsPoint& point, const QgsRectangle& viewExtent, double mapUnitsPerPixel, const QgsMapToolIdentify::LayerType& layerType = AllLayers );
156 
157  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, const QgsRectangle& viewExtent, double mapUnitsPerPixel );
158  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, const QgsPoint& point );
159 
160  private:
161 
164  Q_DECL_DEPRECATED virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
165 
169  Q_DECL_DEPRECATED virtual QGis::UnitType displayUnits();
170 
175  virtual QGis::UnitType displayDistanceUnits() const;
176 
181  virtual QgsUnitTypes::AreaUnit displayAreaUnits() const;
182 
187  QString formatDistance( double distance ) const;
188 
193  QString formatArea( double area ) const;
194 
195  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPoint& layerPoint = QgsPoint() );
196 
199  void closestVertexAttributes( const QgsAbstractGeometryV2& geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString >& derivedAttributes );
200 
201  QString formatCoordinate( const QgsPoint& canvasPoint ) const;
202  QString formatXCoordinate( const QgsPoint& canvasPoint ) const;
203  QString formatYCoordinate( const QgsPoint& canvasPoint ) const;
204 
205  // Last point in canvas CRS
206  QgsPoint mLastPoint;
207 
208  double mLastMapUnitsPerPixel;
209 
210  QgsRectangle mLastExtent;
211 
212  int mCoordinatePrecision;
213 };
214 
215 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
216 
217 #endif
IdentifyResult(QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes)
IdentifyResult(QgsMapLayer *layer, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes)
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:145
QMap< QString, QString > mAttributes
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Abstract base class for all geometries.
Container of fields for a vector layer.
Definition: qgsfield.h:193
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
IdentifyResult(QgsMapLayer *layer, const QString &label, const QMap< QString, QString > &attributes, const QMap< QString, QString > &derivedAttributes)
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:155
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:83
QgsIdentifyMenu * mIdentifyMenu
Map tool for identifying features in layers.
Utility class for identifying a unique vertex within a geometry.
virtual Flags flags() const override
Returns the flags for the map tool.
A class for highlight features on the map.
Definition: qgshighlight.h:36
The QgsIdentifyMenu class builds a menu to be used with identify results (.
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:99
A class to represent a point.
Definition: qgspoint.h:117
Abstract base class for all map tools.
Definition: qgsmaptool.h:50
General purpose distance and area calculator.
QMap< QString, QVariant > mParams
UnitType
Map units that qgis supports.
Definition: qgis.h:159
QgsIdentifyMenu * identifyMenu()
return a pointer to the identify menu which will be used in layer selection mode this menu can also b...
Represents a vector layer which manages a vector based data sets.
AreaUnit
Units of area.
Definition: qgsunittypes.h:49
QMap< QString, QString > mDerivedAttributes
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:160