QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsrulebased3drenderer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrulebased3drenderer.h
3 --------------------------------------
4 Date : January 2019
5 Copyright : (C) 2019 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
16#ifndef QGSRULEBASED3DRENDERER_H
17#define QGSRULEBASED3DRENDERER_H
18
19#include "qgis_3d.h"
20
23#include "qgsabstract3dsymbol.h"
24#include "qgsmaplayerref.h"
25#include <QUuid>
26
28class QgsFeature3DHandler;
29
30
41{
42 public:
44
46 QgsAbstract3DRenderer *createRenderer( QDomElement &elem, const QgsReadWriteContext &context ) override SIP_FACTORY;
47};
48
49
62{
63 public:
64 class Rule;
65 typedef QList<QgsRuleBased3DRenderer::Rule *> RuleList;
66 typedef QHash<const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler *> RuleToHandlerMap;
67
73 class _3D_EXPORT Rule
74 {
75 public:
77 Rule( QgsAbstract3DSymbol *symbol SIP_TRANSFER, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
78 ~Rule();
79
80 Rule( const Rule &rh ) = delete;
81 Rule &operator=( const Rule &rh ) = delete;
82
85 {
86 Filtered = 0,
88 Registered
89 };
90
94 QgsAbstract3DSymbol *symbol() const { return mSymbol.get(); }
95
100 QString filterExpression() const { return mFilterExp; }
101
107 QString description() const { return mDescription; }
108
114 bool active() const { return mIsActive; }
115
121 bool isElse() const { return mElseRule; }
122
124 QString ruleKey() const { return mRuleKey; }
125
127 void setSymbol( QgsAbstract3DSymbol *symbol SIP_TRANSFER );
128
134 void setFilterExpression( const QString &filterExp )
135 {
136 mFilterExp = filterExp;
137 initFilter();
138 }
139
145 void setDescription( const QString &description ) { mDescription = description; }
146
151 void setActive( bool state ) { mIsActive = state; }
152
158 void setIsElse( bool iselse ) { mElseRule = iselse; }
159
160 // TODO: needed?
162 void setRuleKey( const QString &key ) { mRuleKey = key; }
163
164 // parent / child operations
165
171 const QgsRuleBased3DRenderer::RuleList &children() const { return mChildren; }
172
179
185 QgsRuleBased3DRenderer::RuleList descendants() const;
186
192 const QgsRuleBased3DRenderer::Rule *parent() const SIP_SKIP { return mParent; }
193
200
202 void appendChild( QgsRuleBased3DRenderer::Rule *rule SIP_TRANSFER );
203
205 void insertChild( int i, QgsRuleBased3DRenderer::Rule *rule SIP_TRANSFER );
206
208 void removeChildAt( int i );
209
211 const QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) const;
212
218 QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) SIP_SKIP;
219
222
223 // load / save
224
231 static QgsRuleBased3DRenderer::Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context ) SIP_FACTORY;
232
234 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;
235
236 // evaluation
237
242 void createHandlers( QgsVectorLayer *layer, RuleToHandlerMap &handlers ) const SIP_SKIP;
243
248 void prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames, const QgsVector3D &chunkOrigin, RuleToHandlerMap &handlers ) const SIP_SKIP;
249
254 RegisterResult registerFeature( QgsFeature &feature, Qgs3DRenderContext &context, RuleToHandlerMap &handlers ) const SIP_SKIP;
255
256 private:
257#ifdef SIP_RUN
259#endif
260
268 bool isFilterOK( QgsFeature &f, Qgs3DRenderContext &context ) const;
269
273 void initFilter();
274
278 void updateElseRules();
279
280 private:
281 Rule *mParent = nullptr; // parent rule (nullptr only for root rule)
282 std::unique_ptr<QgsAbstract3DSymbol> mSymbol;
283 QString mFilterExp;
284 QString mDescription;
285 bool mElseRule = false;
286 RuleList mChildren;
287 RuleList mElseRules;
288 bool mIsActive = true; // whether it is enabled or not
289
290 QString mRuleKey = QUuid::createUuid().toString(); // string used for unique identification of rule within labeling
291
292 std::unique_ptr<QgsExpression> mFilter;
293 };
294
295
298 ~QgsRuleBased3DRenderer() override;
299
301 QgsRuleBased3DRenderer::Rule *rootRule() { return mRootRule; }
303 const Rule *rootRule() const SIP_SKIP { return mRootRule; }
304
305 QString type() const override { return "rulebased"; }
306 QgsRuleBased3DRenderer *clone() const override SIP_FACTORY;
307 Qt3DCore::QEntity *createEntity( Qgs3DMapSettings *map ) const override SIP_SKIP;
308
309 void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
310 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
311
312 private:
313 Rule *mRootRule = nullptr;
314};
315
316#endif // QGSRULEBASED3DRENDERER_H
Base metadata class for 3D renderers.
virtual QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
Base class for all renderers that may to participate in 3D view.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
The class is used as a container of context for various read/write operations on other objects.
Rule & operator=(const Rule &rh)=delete
bool isElse() const
Check if this rule is an ELSE rule.
QgsRuleBased3DRenderer::Rule * parent()
The parent rule.
const QgsRuleBased3DRenderer::RuleList & children() const
Returns all children rules of this rule.
void setDescription(const QString &description)
Set a human readable description for this rule.
Rule(const Rule &rh)=delete
const QgsRuleBased3DRenderer::Rule * parent() const
The parent rule.
void setFilterExpression(const QString &filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
void setActive(bool state)
Sets if this rule is active.
QString ruleKey() const
Unique rule identifier (for identification of rule within labeling, used as provider ID)
RegisterResult
The result of registering a rule.
bool active() const
Returns if this rule is active.
void setIsElse(bool iselse)
Sets if this rule is an ELSE rule.
QString filterExpression() const
A filter that will check if this rule applies.
QgsAbstract3DSymbol * symbol() const
Returns the labeling settings.
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based renderer)
QString description() const
A human readable description for this rule.
QgsRuleBased3DRenderer::RuleList & children()
Returns all children rules of this rule.
QHash< const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler * > RuleToHandlerMap
QgsRuleBased3DRenderer::Rule * rootRule()
Returns pointer to the root rule.
QString type() const override
Returns unique identifier of the renderer class (used to identify subclass)
QList< QgsRuleBased3DRenderer::Rule * > RuleList
const Rule * rootRule() const
Returns pointer to the root rule.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition qgsvector3d.h:31
Represents a vector layer which manages a vector based data sets.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_FACTORY
Definition qgis_sip.h:76