QGIS API Documentation  2.99.0-Master (75367e4)
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 #include "qgis_gui.h"
28 
29 class QgsRasterLayer;
30 class QgsVectorLayer;
31 class QgsMapLayer;
32 class QgsMapCanvas;
33 class QgsHighlight;
34 class QgsIdentifyMenu;
35 class QgsDistanceArea;
36 
45 class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
46 {
47  Q_OBJECT
48  Q_FLAGS( LayerType )
49 
50  public:
51 
53  {
54  DefaultQgsSetting = -1,
58  LayerSelection
59  };
60 
61  enum Type
62  {
63  VectorLayer = 1,
64  RasterLayer = 2,
65  AllLayers = VectorLayer | RasterLayer
66  };
67  Q_DECLARE_FLAGS( LayerType, Type )
68 
70  {
71  IdentifyResult() : mLayer( nullptr ) {}
72 
73  IdentifyResult( QgsMapLayer * layer, const QgsFeature& feature, const QMap< QString, QString >& derivedAttributes ):
74  mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
75 
76  IdentifyResult( QgsMapLayer * layer, const QString& label, const QMap< QString, QString >& attributes, const QMap< QString, QString >& derivedAttributes ):
77  mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
78 
79  IdentifyResult( QgsMapLayer * layer, const QString& label, const QgsFields& fields, const QgsFeature& feature, const QMap< QString, QString >& derivedAttributes ):
80  mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
81 
82  QgsMapLayer* mLayer = nullptr;
83  QString mLabel;
86  QMap< QString, QString > mAttributes;
87  QMap< QString, QString > mDerivedAttributes;
88  QMap< QString, QVariant > mParams;
89  };
90 
92  QgsMapToolIdentify( QgsMapCanvas * canvas );
93 
94  virtual ~QgsMapToolIdentify();
95 
96  virtual Flags flags() const override { return QgsMapTool::AllowZoomRect; }
97  virtual void canvasMoveEvent( QgsMapMouseEvent* e ) override;
98  virtual void canvasPressEvent( QgsMapMouseEvent* e ) override;
99  virtual void canvasReleaseEvent( QgsMapMouseEvent* e ) override;
100  virtual void activate() override;
101  virtual void deactivate() override;
102 
109  QList<IdentifyResult> identify( int x, int y, const QList<QgsMapLayer*>& layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
110 
119  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers );
120 
123  QgsIdentifyMenu* identifyMenu() {return mIdentifyMenu;}
124 
125  public slots:
126  void formatChanged( QgsRasterLayer *layer );
127 
128  signals:
129  void identifyProgress( int, int );
130  void identifyMessage( const QString& );
131  void changedRasterResults( QList<IdentifyResult>& );
132 
133  protected:
134 
144  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer*>& layerList, LayerType layerType = AllLayers );
145 
146  QgsIdentifyMenu* mIdentifyMenu = nullptr;
147 
149  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsPoint& point, const QgsRectangle& viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers );
150 
151  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, const QgsRectangle& viewExtent, double mapUnitsPerPixel );
152  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, const QgsPoint& point );
153 
154  private:
155 
160  virtual QgsUnitTypes::DistanceUnit displayDistanceUnits() const;
161 
166  virtual QgsUnitTypes::AreaUnit displayAreaUnits() const;
167 
172  QString formatDistance( double distance ) const;
173 
178  QString formatArea( double area ) const;
179 
180  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPoint& layerPoint = QgsPoint() );
181 
184  void closestVertexAttributes( const QgsAbstractGeometry& geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString >& derivedAttributes );
185 
186  QString formatCoordinate( const QgsPoint& canvasPoint ) const;
187  QString formatXCoordinate( const QgsPoint& canvasPoint ) const;
188  QString formatYCoordinate( const QgsPoint& canvasPoint ) const;
189 
190  // Last point in canvas CRS
191  QgsPoint mLastPoint;
192 
193  double mLastMapUnitsPerPixel;
194 
195  QgsRectangle mLastExtent;
196 
197  int mCoordinatePrecision;
198 };
199 
200 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
201 
202 #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:36
Base class for all map layer types.
Definition: qgsmaplayer.h:52
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:64
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:39
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:136
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
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
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:98
Abstract base class for all geometries.
A class to represent a point.
Definition: qgspoint.h:143
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:43
Abstract base class for all map tools.
Definition: qgsmaptool.h:49
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:65
QMap< QString, QString > mDerivedAttributes
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:159