QGIS API Documentation  2.13.0-Master
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 
96  virtual void canvasMoveEvent( QgsMapMouseEvent* e ) override;
97 
99  virtual void canvasPressEvent( QgsMapMouseEvent* e ) override;
100 
102  virtual void canvasReleaseEvent( QgsMapMouseEvent* e ) override;
103 
104  virtual void activate() override;
105 
106  virtual void deactivate() override;
107 
114  QList<IdentifyResult> identify( int x, int y, const QList<QgsMapLayer*>& layerList = QList<QgsMapLayer*>(), IdentifyMode mode = DefaultQgsSetting );
115 
124  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, const LayerType& layerType = AllLayers );
125 
128  QgsIdentifyMenu* identifyMenu() {return mIdentifyMenu;}
129 
130  public slots:
131  void formatChanged( QgsRasterLayer *layer );
132 
133  signals:
134  void identifyProgress( int, int );
135  void identifyMessage( const QString& );
136  void changedRasterResults( QList<IdentifyResult>& );
137 
138  protected:
148  QList<IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer*>& layerList, const LayerType& layerType = AllLayers );
149 
151 
153  bool identifyLayer( QList<IdentifyResult> *results, QgsMapLayer *layer, const QgsPoint& point, const QgsRectangle& viewExtent, double mapUnitsPerPixel, const QgsMapToolIdentify::LayerType& layerType = AllLayers );
154 
155  bool identifyRasterLayer( QList<IdentifyResult> *results, QgsRasterLayer *layer, QgsPoint point, const QgsRectangle& viewExtent, double mapUnitsPerPixel );
156  bool identifyVectorLayer( QList<IdentifyResult> *results, QgsVectorLayer *layer, const QgsPoint& point );
157 
158  private:
159 
161  virtual void convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea );
162 
164  virtual QGis::UnitType displayUnits();
165 
166  QMap< QString, QString > featureDerivedAttributes( QgsFeature *feature, QgsMapLayer *layer, const QgsPoint& layerPoint = QgsPoint() );
167 
170  void closestVertexAttributes( const QgsAbstractGeometryV2& geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString >& derivedAttributes );
171 
172  // Last point in canvas CRS
173  QgsPoint mLastPoint;
174 
175  double mLastMapUnitsPerPixel;
176 
177  QgsRectangle mLastExtent;
178 };
179 
180 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
181 
182 #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:189
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:105
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.
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:65
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:155
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.
QMap< QString, QString > mDerivedAttributes
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:160