QGIS API Documentation 3.41.0-Master (d2aaa9c6e02)
Loading...
Searching...
No Matches
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 "qgsidentifycontext.h"
22#include "qgsmaptool.h"
23#include "qgspointxy.h"
24
25#include <QObject>
26#include <QPointer>
27#include "qgis_gui.h"
28
29class QgsRasterLayer;
30class QgsVectorLayer;
32class QgsMapLayer;
33class QgsMapCanvas;
34class QgsMeshLayer;
35class QgsHighlight;
36class QgsIdentifyMenu;
42
53class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
54{
55 Q_OBJECT
56
57 public:
59 {
60 DefaultQgsSetting = -1,
64 LayerSelection
65 };
66 Q_ENUM( IdentifyMode )
67
68 enum Type SIP_ENUM_BASETYPE( IntFlag )
69 {
70 VectorLayer = 1,
71 RasterLayer = 2,
72 MeshLayer = 4,
73 VectorTileLayer = 8,
74 PointCloudLayer = 16,
75 AllLayers = VectorLayer | RasterLayer | MeshLayer | VectorTileLayer | PointCloudLayer
76 };
77 Q_DECLARE_FLAGS( LayerType, Type )
78 Q_FLAG( LayerType )
79
81 {
82 IdentifyResult() = default;
83
84 IdentifyResult( QgsMapLayer *layer, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
85 : mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
86
87 IdentifyResult( QgsMapLayer *layer, const QString &label, const QMap<QString, QString> &attributes, const QMap<QString, QString> &derivedAttributes )
88 : mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
89
90 IdentifyResult( QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap<QString, QString> &derivedAttributes )
91 : mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
92
93 QgsMapLayer *mLayer = nullptr;
94 QString mLabel;
97 QMap<QString, QString> mAttributes;
98 QMap<QString, QString> mDerivedAttributes;
99 QMap<QString, QVariant> mParams;
100 };
101
103 {
105 double searchRadiusMapUnits = -1;
107 bool skip3DLayers = false;
108 };
109
112
113 ~QgsMapToolIdentify() override;
114
115 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
116 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
117 void canvasPressEvent( QgsMapMouseEvent *e ) override;
118 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
119 void activate() override;
120 void deactivate() override;
121
131 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
132
144 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
145
147 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
149 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
150
151
156 QgsIdentifyMenu *identifyMenu() { return mIdentifyMenu; }
157
163 static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
164
171 void fromElevationProfileLayerIdentificationToIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
172
173 public slots:
174 void formatChanged( QgsRasterLayer *layer );
175
176 signals:
177
184 void identifyProgress( int processed, int total );
185
191 void identifyMessage( const QString &message );
192
196 void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
197
198 protected:
211 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
212
213 QgsIdentifyMenu *mIdentifyMenu = nullptr;
214
216 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
217
227 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
228
236 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
237
244 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
245
247 QMap<QString, QString> derivedAttributesForPoint( const QgsPoint &point );
248
263 Q_DECL_DEPRECATED void setCanvasPropertiesOverrides( double searchRadiusMapUnits ) SIP_DEPRECATED;
264
271 Q_DECL_DEPRECATED void restoreCanvasPropertiesOverrides() SIP_DEPRECATED;
272
285 void setPropertiesOverrides( IdentifyProperties overrides );
286
292 void restorePropertiesOverrides();
293
294 private:
295 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
296 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
297 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
298 int identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsFeatureList &features, QgsFeatureRenderer *renderer, const QMap<QString, QString> &commonDerivedAttributes, const std::function<QMap<QString, QString>( const QgsFeature & )> &derivedAttributes, QgsRenderContext &context );
299 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
300 bool identifyVectorTileLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorTileLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
301 bool identifyPointCloudLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
302
307 virtual Qgis::DistanceUnit displayDistanceUnits() const;
308
313 virtual Qgis::AreaUnit displayAreaUnits() const;
314
319 QString formatDistance( double distance ) const;
320
325 QString formatArea( double area ) const;
326
331 QString formatDistance( double distance, Qgis::DistanceUnit unit ) const;
332
337 QString formatArea( double area, Qgis::AreaUnit unit ) const;
338
339 QMap<QString, QString> featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
340
344 void closestVertexAttributes( const QgsCoordinateTransform layerToMapTransform, const QgsCoordinateReferenceSystem &layerVertCrs, const QgsCoordinateReferenceSystem &mapVertCrs, const QgsAbstractGeometry &geometry, QgsVertexId vId, bool showTransformedZ, QMap<QString, QString> &derivedAttributes );
345
349 void closestPointAttributes( const QgsCoordinateTransform layerToMapTransform, const QgsCoordinateReferenceSystem &layerVertCrs, const QgsCoordinateReferenceSystem &mapVertCrs, const QgsAbstractGeometry &geometry, const QgsPointXY &layerPoint, bool showTransformedZ, QMap<QString, QString> &derivedAttributes );
350
351 static void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y, const QgsCoordinateReferenceSystem &mapCrs, int coordinatePrecision );
352 void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y ) const;
353
354 // Last geometry (point or polygon) in map CRS
355 QgsGeometry mLastGeometry;
356
357 double mLastMapUnitsPerPixel;
358
359 QgsRectangle mLastExtent;
360
361 int mCoordinatePrecision;
362
363 IdentifyProperties mPropertiesOverrides;
364};
365
367
368#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
Abstract base class for all geometries.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Abstract base class for all 2D vector feature renderers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
A class for highlight features on the map.
Identify contexts are used to encapsulate the settings to be used to perform an identify action.
The QgsIdentifyMenu class builds a menu to be used with identify results (.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:76
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Map tool for identifying features in layers.
QFlags< Type > LayerType
QgsIdentifyMenu * identifyMenu()
Returns a pointer to the identify menu which will be used in layer selection mode this menu can also ...
void identifyMessage(const QString &message)
Emitted when the identify operation needs to show a user-facing message.
void changedRasterResults(QList< QgsMapToolIdentify::IdentifyResult > &results)
Emitted when the format of raster results is changed and need to be updated in user-facing displays.
Flags flags() const override
Returns the flags for the map tool.
void identifyProgress(int processed, int total)
Emitted when the identify action progresses.
Abstract base class for all map tools.
Definition qgsmaptool.h:71
QFlags< Flag > Flags
Definition qgsmaptool.h:114
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
@ AllowZoomRect
Allow zooming by rectangle (by holding shift and dragging) while the tool is active.
Definition qgsmaptool.h:111
virtual void activate()
called when set as currently active map tool
virtual void deactivate()
called when map tool is being deactivated
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Point cloud layer specific subclass of QgsMapLayerElevationProperties.
Represents a map layer supporting display of point clouds.
A class to represent a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Represents a raster layer.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Represents a vector layer which manages a vector based data sets.
Implements a map layer that is dedicated to rendering of vector tiles.
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
QList< QgsFeature > QgsFeatureList
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
QMap< QString, QString > mAttributes
IdentifyResult(QgsMapLayer *layer, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes)
IdentifyResult(QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes)
QMap< QString, QVariant > mParams
QMap< QString, QString > mDerivedAttributes
IdentifyResult(QgsMapLayer *layer, const QString &label, const QMap< QString, QString > &attributes, const QMap< QString, QString > &derivedAttributes)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30