QGIS API Documentation  2.99.0-Master (6a61179)
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 "qgsfeature.h"
20 #include "qgsfields.h"
21 #include "qgsmaptool.h"
22 #include "qgspoint.h"
23 #include "qgsunittypes.h"
24 
25 #include <QObject>
26 #include <QPointer>
27 
28 class QgsRasterLayer;
29 class QgsVectorLayer;
30 class QgsMapLayer;
31 class QgsMapCanvas;
32 class QgsHighlight;
33 class QgsIdentifyMenu;
34 class QgsDistanceArea;
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 
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 
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, 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:
141 
151  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer*>& layerList, LayerType layerType = AllLayers );
152 
154 
156  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsPoint& point, const QgsRectangle& viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers );
157 
158  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, const QgsRectangle& viewExtent, double mapUnitsPerPixel );
159  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, const QgsPoint& point );
160 
161  private:
162 
167  virtual QgsUnitTypes::DistanceUnit displayDistanceUnits() const;
168 
173  virtual QgsUnitTypes::AreaUnit displayAreaUnits() const;
174 
179  QString formatDistance( double distance ) const;
180 
185  QString formatArea( double area ) const;
186 
187  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPoint& layerPoint = QgsPoint() );
188 
191  void closestVertexAttributes( const QgsAbstractGeometry& geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString >& derivedAttributes );
192 
193  QString formatCoordinate( const QgsPoint& canvasPoint ) const;
194  QString formatXCoordinate( const QgsPoint& canvasPoint ) const;
195  QString formatYCoordinate( const QgsPoint& canvasPoint ) const;
196 
197  // Last point in canvas CRS
198  QgsPoint mLastPoint;
199 
200  double mLastMapUnitsPerPixel;
201 
202  QgsRectangle mLastExtent;
203 
204  int mCoordinatePrecision;
205 };
206 
207 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
208 
209 #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:144
QMap< QString, QString > mAttributes
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
Allow zooming by rectangle (by holding shift and dragging) while the tool is active.
Definition: qgsmaptool.h:65
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Container of fields for a vector layer.
Definition: qgsfields.h:36
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:135
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:106
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:154
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:82
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:35
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:98
Abstract base class for all geometries.
A class to represent a point.
Definition: qgspoint.h:111
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
Abstract base class for all map tools.
Definition: qgsmaptool.h:50
General purpose distance and area calculator.
QMap< QString, QVariant > mParams
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:64
QMap< QString, QString > mDerivedAttributes
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:159