QGIS API Documentation 3.31.0-Master (d2b117a3c8)
qgsmaphittest.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaphittest.h
3 ---------------------
4 begin : September 2014
5 copyright : (C) 2014 by Martin Dobias
6 email : wonder dot 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#ifndef QGSMAPHITTEST_H
16#define QGSMAPHITTEST_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgsmapsettings.h"
21#include "qgsgeometry.h"
22#include "qgstaskmanager.h"
24
25#include <QSet>
26
28class QgsSymbol;
29class QgsVectorLayer;
30class QgsExpression;
33
41class CORE_EXPORT QgsMapHitTest
42{
43 public:
45 typedef QMap<QString, QString> LayerFilterExpression;
46
52 QgsMapHitTest( const QgsMapSettings &settings, const QgsGeometry &polygon = QgsGeometry(), const QgsMapHitTest::LayerFilterExpression &layerFilterExpression = QgsMapHitTest::LayerFilterExpression() );
53
55 QgsMapHitTest( const QgsMapSettings &settings, const QgsMapHitTest::LayerFilterExpression &layerFilterExpression );
56
58 void run();
59
67 QMap<QString, QSet<QString>> results() const SIP_SKIP;
68
70
77 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
79
87 bool symbolVisible( QgsSymbol *symbol, QgsVectorLayer *layer ) const;
88
96 bool legendKeyVisible( const QString &ruleKey, QgsVectorLayer *layer ) const;
97
98 private:
99
101 typedef QSet<QString> SymbolSet;
102
104 typedef QMap<QString, SymbolSet> HitTest;
105
119 void runHitTestFeatureSource( QgsAbstractFeatureSource *source,
120 const QString &layerId,
122 const QgsFields &fields,
123 const QgsFeatureRenderer *renderer,
124 SymbolSet &usedSymbols,
125 SymbolSet &usedSymbolsRuleKey,
126 QgsRenderContext &context,
127 QgsFeedback *feedback );
128
130 QgsMapSettings mSettings;
131
133 HitTest mHitTest;
134
136 HitTest mHitTestRuleKey;
137
139 QgsMapHitTest::LayerFilterExpression mLayerFilterExpression;
140
142 QgsGeometry mPolygon;
143
145 bool mOnlyExpressions;
146
147 friend class QgsMapHitTestTask;
148};
149
150
157class CORE_EXPORT QgsMapHitTestTask : public QgsTask
158{
159 Q_OBJECT
160
161 public:
162
170 QgsMapHitTestTask( const QgsMapSettings &settings, const QgsGeometry &polygon = QgsGeometry(), const QgsMapHitTest::LayerFilterExpression &layerFilterExpression = QgsMapHitTest::LayerFilterExpression() );
171
178 QgsMapHitTestTask( const QgsMapSettings &settings, const QgsMapHitTest::LayerFilterExpression &layerFilterExpression );
179
185 QMap<QString, QSet<QString>> results() const SIP_SKIP;
186
188
193 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
195
196 void cancel() override;
197
198 protected:
199
200 bool run() override;
201
202 private:
203
204 void prepare();
205
206 struct PreparedLayerData
207 {
208 std::unique_ptr< QgsAbstractFeatureSource > source;
209 QString layerId;
211 QgsFields fields;
212 std::unique_ptr< QgsFeatureRenderer > renderer;
213 QgsRectangle extent;
214 QgsCoordinateTransform transform;
215 std::unique_ptr< QgsExpressionContextScope > layerScope;
216 };
217
218 std::vector< PreparedLayerData > mPreparedData;
219
220 QgsMapSettings mSettings;
221 QgsMapHitTest::LayerFilterExpression mLayerFilterExpression;
222 QgsGeometry mPolygon;
223 bool mOnlyExpressions = false;
224 QMap<QString, QSet<QString>> mResults;
225
226 std::unique_ptr< QgsFeedback > mFeedback;
227};
228
229#endif // QGSMAPHITTEST_H
Base class that can be used for any class that is capable of returning features.
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Class for parsing and evaluation of expressions (formerly called "search strings").
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
Container of fields for a vector layer.
Definition: qgsfields.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Executes a QgsMapHitTest in a background thread.
Class that runs a hit test with given map settings.
Definition: qgsmaphittest.h:42
QMap< QString, QString > LayerFilterExpression
Maps an expression string to a layer id.
Definition: qgsmaphittest.h:45
The QgsMapSettings class contains configuration for rendering of the map.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
Abstract base class for long running background tasks.
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_PYNAME(name)
Definition: qgis_sip.h:81
const QgsCoordinateReferenceSystem & crs