QGIS API Documentation 3.43.0-Master (c67cf405802)
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
43class CORE_EXPORT QgsMapHitTest
44{
45 public:
47 typedef QMap<QString, QString> LayerFilterExpression;
48
54 QgsMapHitTest( const QgsMapSettings &settings, const QgsGeometry &polygon = QgsGeometry(), const QgsMapHitTest::LayerFilterExpression &layerFilterExpression = QgsMapHitTest::LayerFilterExpression() );
55
57 QgsMapHitTest( const QgsMapSettings &settings, const QgsMapHitTest::LayerFilterExpression &layerFilterExpression );
58
65
67 void run();
68
76 QMap<QString, QSet<QString>> results() const SIP_SKIP;
77
79
86 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
88
95 bool symbolVisible( QgsSymbol *symbol, QgsVectorLayer *layer ) const;
96
103 bool legendKeyVisible( const QString &ruleKey, QgsVectorLayer *layer ) const;
104
105 private:
106
108 typedef QSet<QString> SymbolSet;
109
111 typedef QMap<QString, SymbolSet> HitTest;
112
126 void runHitTestFeatureSource( QgsAbstractFeatureSource *source,
127 const QString &layerId,
128 const QgsFields &fields,
129 const QgsFeatureRenderer *renderer,
130 SymbolSet &usedSymbols,
131 SymbolSet &usedSymbolsRuleKey,
132 QgsRenderContext &context,
133 QgsFeedback *feedback,
134 const QgsGeometry &visibleExtent );
135
137 HitTest mHitTest;
138
140 HitTest mHitTestRuleKey;
141
143
144 friend class QgsMapHitTestTask;
145};
146
147
154class CORE_EXPORT QgsMapHitTestTask : public QgsTask
155{
156 Q_OBJECT
157
158 public:
159
164
170 QMap<QString, QSet<QString>> results() const SIP_SKIP;
171
173
178 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
180
181 void cancel() override;
182
183 protected:
184
185 bool run() override;
186
187 private:
188
189 void prepare();
190
191 struct PreparedLayerData
192 {
193 std::unique_ptr< QgsAbstractFeatureSource > source;
194 QString layerId;
195 QgsFields fields;
196 std::unique_ptr< QgsFeatureRenderer > renderer;
197 QgsGeometry extent;
198 QgsCoordinateTransform transform;
199 std::unique_ptr< QgsExpressionContextScope > layerScope;
200 };
201
202 std::vector< PreparedLayerData > mPreparedData;
203
205
206 QMap<QString, QSet<QString>> mResults;
207
208 std::unique_ptr< QgsFeedback > mFeedback;
209};
210
211#endif // QGSMAPHITTEST_H
Base class that can be used for any class that is capable of returning features.
Handles coordinate transforms between two coordinate systems.
Handles 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.
Runs a hit test with given map settings.
QMap< QString, QString > LayerFilterExpression
Maps an expression string to a layer id.
Contains configuration for rendering maps.
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 dataset.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_PYNAME(name)
Definition qgis_sip.h:81