QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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;
41
52class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
53{
54 Q_OBJECT
55
56 public:
57
59 {
60 DefaultQgsSetting = -1,
64 LayerSelection
65 };
66 Q_ENUM( IdentifyMode )
67
68 enum Type
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 {
83 IdentifyResult() = default;
84
85 IdentifyResult( QgsMapLayer *layer, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes )
86 : mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
87
88 IdentifyResult( QgsMapLayer *layer, const QString &label, const QMap< QString, QString > &attributes, const QMap< QString, QString > &derivedAttributes )
89 : mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
90
91 IdentifyResult( QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes )
92 : mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
93
94 QgsMapLayer *mLayer = nullptr;
95 QString mLabel;
98 QMap< QString, QString > mAttributes;
99 QMap< QString, QString > mDerivedAttributes;
100 QMap< QString, QVariant > mParams;
101 };
102
105
106 ~QgsMapToolIdentify() override;
107
108 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
109 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
110 void canvasPressEvent( QgsMapMouseEvent *e ) override;
111 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
112 void activate() override;
113 void deactivate() override;
114
124 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
125
137 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
138
140 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
142 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
143
144
149 QgsIdentifyMenu *identifyMenu() { return mIdentifyMenu; }
150
156 static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
157
164 void fromElevationProfileLayerIdentificationToIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
165
166 public slots:
167 void formatChanged( QgsRasterLayer *layer );
168
169 signals:
170 void identifyProgress( int, int );
171 void identifyMessage( const QString & );
172 void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> & );
173
174 protected:
175
188 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
189
190 QgsIdentifyMenu *mIdentifyMenu = nullptr;
191
193 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
194
204 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
205
213 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
214
221 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
222
224 QMap< QString, QString > derivedAttributesForPoint( const QgsPoint &point );
225
238 void setCanvasPropertiesOverrides( double searchRadiusMapUnits );
239
245 void restoreCanvasPropertiesOverrides();
246
247 private:
248
249 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
250 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
251 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
252 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 );
253 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
254 bool identifyVectorTileLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorTileLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
255 bool identifyPointCloudLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
256
262 virtual Qgis::DistanceUnit displayDistanceUnits() const;
263
269 virtual Qgis::AreaUnit displayAreaUnits() const;
270
276 QString formatDistance( double distance ) const;
277
283 QString formatArea( double area ) const;
284
289 QString formatDistance( double distance, Qgis::DistanceUnit unit ) const;
290
295 QString formatArea( double area, Qgis::AreaUnit unit ) const;
296
297 QMap< QString, QString > featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
298
302 void closestVertexAttributes( const QgsAbstractGeometry &geometry, QgsVertexId vId, QgsMapLayer *layer, QMap< QString, QString > &derivedAttributes );
303
307 void closestPointAttributes( const QgsAbstractGeometry &geometry, const QgsPointXY &layerPoint, QMap< QString, QString > &derivedAttributes );
308
309 void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y ) const;
310
311 // Last geometry (point or polygon) in map CRS
312 QgsGeometry mLastGeometry;
313
314 double mLastMapUnitsPerPixel;
315
316 QgsRectangle mLastExtent;
317
318 int mCoordinatePrecision;
319
320 double mOverrideCanvasSearchRadius = -1;
321};
322
323Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolIdentify::LayerType )
324
325#endif
DistanceUnit
Units of distance.
Definition qgis.h:3496
AreaUnit
Units of area.
Definition qgis.h:3534
Abstract base class for all geometries.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:56
Container of fields for a vector layer.
Definition qgsfields.h:45
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:74
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Map tool for identifying features in layers.
QgsIdentifyMenu * identifyMenu()
Returns a pointer to the identify menu which will be used in layer selection mode this menu can also ...
void changedRasterResults(QList< QgsMapToolIdentify::IdentifyResult > &)
void identifyProgress(int, int)
void identifyMessage(const QString &)
Flags flags() const override
Returns the flags for the map tool.
Abstract base class for all map tools.
Definition qgsmaptool.h:71
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:116
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:59
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_SKIP
Definition qgis_sip.h:126
QList< QgsFeature > QgsFeatureList
Definition qgsfeature.h:920
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
QMap< QString, QString > mDerivedAttributes
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, QString > mAttributes
IdentifyResult(QgsMapLayer *layer, const QString &label, const QMap< QString, QString > &attributes, const QMap< QString, QString > &derivedAttributes)
IdentifyResult()=default
Constructor for IdentifyResult.
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:31