QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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:
58
60 {
61 DefaultQgsSetting = -1,
65 LayerSelection
66 };
67 Q_ENUM( IdentifyMode )
68
69 enum Type SIP_ENUM_BASETYPE( IntFlag )
70 {
71 VectorLayer = 1,
72 RasterLayer = 2,
73 MeshLayer = 4,
74 VectorTileLayer = 8,
75 PointCloudLayer = 16,
76 AllLayers = VectorLayer | RasterLayer | MeshLayer | VectorTileLayer | PointCloudLayer
77 };
78 Q_DECLARE_FLAGS( LayerType, Type )
79 Q_FLAG( LayerType )
80
82 {
83
84 IdentifyResult() = default;
85
86 IdentifyResult( QgsMapLayer *layer, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes )
87 : mLayer( layer ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
88
89 IdentifyResult( QgsMapLayer *layer, const QString &label, const QMap< QString, QString > &attributes, const QMap< QString, QString > &derivedAttributes )
90 : mLayer( layer ), mLabel( label ), mAttributes( attributes ), mDerivedAttributes( derivedAttributes ) {}
91
92 IdentifyResult( QgsMapLayer *layer, const QString &label, const QgsFields &fields, const QgsFeature &feature, const QMap< QString, QString > &derivedAttributes )
93 : mLayer( layer ), mLabel( label ), mFields( fields ), mFeature( feature ), mDerivedAttributes( derivedAttributes ) {}
94
95 QgsMapLayer *mLayer = nullptr;
96 QString mLabel;
99 QMap< QString, QString > mAttributes;
100 QMap< QString, QString > mDerivedAttributes;
101 QMap< QString, QVariant > mParams;
102 };
103
106
107 ~QgsMapToolIdentify() override;
108
109 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
110 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
111 void canvasPressEvent( QgsMapMouseEvent *e ) override;
112 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
113 void activate() override;
114 void deactivate() override;
115
125 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, const QList<QgsMapLayer *> &layerList = QList<QgsMapLayer *>(), IdentifyMode mode = DefaultQgsSetting, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
126
138 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
139
141 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
143 QList<QgsMapToolIdentify::IdentifyResult> identify( const QgsGeometry &geometry, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
144
145
150 QgsIdentifyMenu *identifyMenu() { return mIdentifyMenu; }
151
157 static void fromPointCloudIdentificationToIdentifyResults( QgsPointCloudLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
158
165 void fromElevationProfileLayerIdentificationToIdentifyResults( QgsMapLayer *layer, const QVector<QVariantMap> &identified, QList<QgsMapToolIdentify::IdentifyResult> &results ) SIP_SKIP;
166
167 public slots:
168 void formatChanged( QgsRasterLayer *layer );
169
170 signals:
171
178 void identifyProgress( int processed, int total );
179
185 void identifyMessage( const QString &message );
186
190 void changedRasterResults( QList<QgsMapToolIdentify::IdentifyResult> &results );
191
192 protected:
193
206 QList<QgsMapToolIdentify::IdentifyResult> identify( int x, int y, IdentifyMode mode, const QList<QgsMapLayer *> &layerList, LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
207
208 QgsIdentifyMenu *mIdentifyMenu = nullptr;
209
211 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsPointXY &point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
212
222 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, QgsPointXY point, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
223
231 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
232
239 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsPointXY &point, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
240
242 QMap< QString, QString > derivedAttributesForPoint( const QgsPoint &point );
243
256 void setCanvasPropertiesOverrides( double searchRadiusMapUnits );
257
263 void restoreCanvasPropertiesOverrides();
264
265 private:
266
267 bool identifyLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMapLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, QgsMapToolIdentify::LayerType layerType = AllLayers, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
268 bool identifyRasterLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsRasterLayer *layer, const QgsGeometry &geometry, const QgsRectangle &viewExtent, double mapUnitsPerPixel, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
269 bool identifyVectorLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
270 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 );
271 bool identifyMeshLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsMeshLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
272 bool identifyVectorTileLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsVectorTileLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
273 bool identifyPointCloudLayer( QList<QgsMapToolIdentify::IdentifyResult> *results, QgsPointCloudLayer *layer, const QgsGeometry &geometry, const QgsIdentifyContext &identifyContext = QgsIdentifyContext() );
274
279 virtual Qgis::DistanceUnit displayDistanceUnits() const;
280
285 virtual Qgis::AreaUnit displayAreaUnits() const;
286
291 QString formatDistance( double distance ) const;
292
297 QString formatArea( double area ) const;
298
303 QString formatDistance( double distance, Qgis::DistanceUnit unit ) const;
304
309 QString formatArea( double area, Qgis::AreaUnit unit ) const;
310
311 QMap< QString, QString > featureDerivedAttributes( const QgsFeature &feature, QgsMapLayer *layer, const QgsPointXY &layerPoint = QgsPointXY() );
312
316 void closestVertexAttributes( const QgsCoordinateTransform layerToMapTransform,
317 const QgsCoordinateReferenceSystem &layerVertCrs,
318 const QgsCoordinateReferenceSystem &mapVertCrs,
319 const QgsAbstractGeometry &geometry, QgsVertexId vId,
320 bool showTransformedZ, QMap< QString, QString > &derivedAttributes );
321
325 void closestPointAttributes( const QgsCoordinateTransform layerToMapTransform,
326 const QgsCoordinateReferenceSystem &layerVertCrs,
327 const QgsCoordinateReferenceSystem &mapVertCrs,
328 const QgsAbstractGeometry &geometry, const QgsPointXY &layerPoint, bool showTransformedZ, QMap< QString, QString > &derivedAttributes );
329
330 static void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y, const QgsCoordinateReferenceSystem &mapCrs, int coordinatePrecision );
331 void formatCoordinate( const QgsPointXY &canvasPoint, QString &x, QString &y ) const;
332
333 // Last geometry (point or polygon) in map CRS
334 QgsGeometry mLastGeometry;
335
336 double mLastMapUnitsPerPixel;
337
338 QgsRectangle mLastExtent;
339
340 int mCoordinatePrecision;
341
342 double mOverrideCanvasSearchRadius = -1;
343};
344
346
347#endif
DistanceUnit
Units of distance.
Definition qgis.h:4669
AreaUnit
Units of area.
Definition qgis.h:4746
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:116
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:113
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_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 > 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)
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30