QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
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
96 bool symbolVisible( QgsSymbol *symbol, QgsVectorLayer *layer ) const;
97
105 bool legendKeyVisible( const QString &ruleKey, QgsVectorLayer *layer ) const;
106
107 private:
108
110 typedef QSet<QString> SymbolSet;
111
113 typedef QMap<QString, SymbolSet> HitTest;
114
128 void runHitTestFeatureSource( QgsAbstractFeatureSource *source,
129 const QString &layerId,
130 const QgsFields &fields,
131 const QgsFeatureRenderer *renderer,
132 SymbolSet &usedSymbols,
133 SymbolSet &usedSymbolsRuleKey,
134 QgsRenderContext &context,
135 QgsFeedback *feedback,
136 const QgsGeometry &visibleExtent );
137
139 HitTest mHitTest;
140
142 HitTest mHitTestRuleKey;
143
145
146 friend class QgsMapHitTestTask;
147};
148
149
156class CORE_EXPORT QgsMapHitTestTask : public QgsTask
157{
158 Q_OBJECT
159
160 public:
161
166
172 QMap<QString, QSet<QString>> results() const SIP_SKIP;
173
175
180 QMap<QString, QList<QString>> resultsPy() const SIP_PYNAME( results );
182
183 void cancel() override;
184
185 protected:
186
187 bool run() override;
188
189 private:
190
191 void prepare();
192
193 struct PreparedLayerData
194 {
195 std::unique_ptr< QgsAbstractFeatureSource > source;
196 QString layerId;
197 QgsFields fields;
198 std::unique_ptr< QgsFeatureRenderer > renderer;
199 QgsGeometry extent;
200 QgsCoordinateTransform transform;
201 std::unique_ptr< QgsExpressionContextScope > layerScope;
202 };
203
204 std::vector< PreparedLayerData > mPreparedData;
205
207
208 QMap<QString, QSet<QString>> mResults;
209
210 std::unique_ptr< QgsFeedback > mFeedback;
211};
212
213#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").
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.
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:94
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