QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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"
21#include "qgsmapsettings.h"
22#include "qgsgeometry.h"
23#include "qgstaskmanager.h"
25
26#include <QSet>
27
29class QgsSymbol;
30class QgsVectorLayer;
31class QgsExpression;
35
42class CORE_EXPORT QgsMapHitTest
43{
44 public:
46 typedef QMap<QString, QString> LayerFilterExpression;
47
53 QgsMapHitTest( const QgsMapSettings &settings, const QgsGeometry &polygon = QgsGeometry(), const QgsMapHitTest::LayerFilterExpression &layerFilterExpression = QgsMapHitTest::LayerFilterExpression() );
54
56 QgsMapHitTest( const QgsMapSettings &settings, const QgsMapHitTest::LayerFilterExpression &layerFilterExpression );
57
64
66 void run();
67
75 QMap<QString, QSet<QString>> results() const SIP_SKIP;
76
78
85 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
87
94 bool symbolVisible( QgsSymbol *symbol, QgsVectorLayer *layer ) const;
95
102 bool legendKeyVisible( const QString &ruleKey, QgsVectorLayer *layer ) const;
103
104 private:
105
107 typedef QSet<QString> SymbolSet;
108
110 typedef QMap<QString, SymbolSet> HitTest;
111
125 void runHitTestFeatureSource( QgsAbstractFeatureSource *source,
126 const QString &layerId,
127 const QgsFields &fields,
128 const QgsFeatureRenderer *renderer,
129 SymbolSet &usedSymbols,
130 SymbolSet &usedSymbolsRuleKey,
131 QgsRenderContext &context,
132 QgsFeedback *feedback,
133 const QgsGeometry &visibleExtent );
134
136 HitTest mHitTest;
137
139 HitTest mHitTestRuleKey;
140
142
143 friend class QgsMapHitTestTask;
144};
145
146
153class CORE_EXPORT QgsMapHitTestTask : public QgsTask
154{
155 Q_OBJECT
156
157 public:
158
163
169 QMap<QString, QSet<QString>> results() const SIP_SKIP;
170
172
177 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
179
180 void cancel() override;
181
182 protected:
183
184 bool run() override;
185
186 private:
187
188 void prepare();
189
190 struct PreparedLayerData
191 {
192 std::unique_ptr< QgsAbstractFeatureSource > source;
193 QString layerId;
194 QgsFields fields;
195 std::unique_ptr< QgsFeatureRenderer > renderer;
196 QgsGeometry extent;
197 QgsCoordinateTransform transform;
198 std::unique_ptr< QgsExpressionContextScope > layerScope;
199 };
200
201 std::vector< PreparedLayerData > mPreparedData;
202
204
205 QMap<QString, QSet<QString>> mResults;
206
207 std::unique_ptr< QgsFeedback > mFeedback;
208};
209
210#endif // QGSMAPHITTEST_H
Base class that can be used for any class that is capable of returning features.
Class for doing transforms between two map coordinate systems.
Class for parsing and evaluation of expressions (formerly called "search strings").
Abstract base class for all 2D vector feature renderers.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
Contains settings relating to filtering the contents of QgsLayerTreeModel and views.
Executes a QgsMapHitTest in a background thread.
Class that runs a hit test with given map settings.
QMap< QString, QString > LayerFilterExpression
Maps an expression string to a layer id.
The QgsMapSettings class contains configuration for rendering of the map.
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
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