QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
65 class Rule;
66 typedef QList<QgsRuleBased3DRenderer::Rule *> RuleList;
67 typedef QHash<const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler *> RuleToHandlerMap;
68
74 class _3D_EXPORT Rule
75 {
76 public:
78 Rule( QgsAbstract3DSymbol *symbol SIP_TRANSFER, const QString &filterExp = QString(), const QString &description = QString(), bool elseRule = false );
79 ~Rule();
80
81 Rule( const Rule &rh ) = delete;
82 Rule &operator=( const Rule &rh ) = delete;
83
86 {
87 Filtered = 0,
89 Registered
90 };
91
95 QgsAbstract3DSymbol *symbol() const { return mSymbol.get(); }
96
101 QString filterExpression() const { return mFilterExp; }
102
108 QString description() const { return mDescription; }
109
115 bool active() const { return mIsActive; }
116
122 bool isElse() const { return mElseRule; }
123
125 QString ruleKey() const { return mRuleKey; }
126
128 void setSymbol( QgsAbstract3DSymbol *symbol SIP_TRANSFER );
129
135 void setFilterExpression( const QString &filterExp ) { mFilterExp = filterExp; initFilter(); }
136
142 void setDescription( const QString &description ) { mDescription = description; }
143
148 void setActive( bool state ) { mIsActive = state; }
149
155 void setIsElse( bool iselse ) { mElseRule = iselse; }
156
157 // TODO: needed?
159 void setRuleKey( const QString &key ) { mRuleKey = key; }
160
161 // parent / child operations
162
168 const QgsRuleBased3DRenderer::RuleList &children() const { return mChildren; }
169
176
182 QgsRuleBased3DRenderer::RuleList descendants() const;
183
189 const QgsRuleBased3DRenderer::Rule *parent() const SIP_SKIP { return mParent; }
190
197
199 void appendChild( QgsRuleBased3DRenderer::Rule *rule SIP_TRANSFER );
200
202 void insertChild( int i, QgsRuleBased3DRenderer::Rule *rule SIP_TRANSFER );
203
205 void removeChildAt( int i );
206
208 const QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) const;
209
215 QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) SIP_SKIP;
216
219
220 // load / save
221
228 static QgsRuleBased3DRenderer::Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context ) SIP_FACTORY;
229
231 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;
232
233 // evaluation
234
239 void createHandlers( QgsVectorLayer *layer, RuleToHandlerMap &handlers ) const SIP_SKIP;
240
245 void prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames, const QgsVector3D &chunkOrigin, RuleToHandlerMap &handlers ) const SIP_SKIP;
246
251 RegisterResult registerFeature( QgsFeature &feature, Qgs3DRenderContext &context, RuleToHandlerMap &handlers ) const SIP_SKIP;
252
253 private:
254#ifdef SIP_RUN
256#endif
257
265 bool isFilterOK( QgsFeature &f, Qgs3DRenderContext &context ) const;
266
270 void initFilter();
271
275 void updateElseRules();
276
277 private:
278 Rule *mParent = nullptr; // parent rule (nullptr only for root rule)
279 std::unique_ptr<QgsAbstract3DSymbol> mSymbol;
280 QString mFilterExp;
281 QString mDescription;
282 bool mElseRule = false;
283 RuleList mChildren;
284 RuleList mElseRules;
285 bool mIsActive = true; // whether it is enabled or not
286
287 QString mRuleKey = QUuid::createUuid().toString(); // string used for unique identification of rule within labeling
288
289 std::unique_ptr<QgsExpression> mFilter;
290 };
291
292
295 ~QgsRuleBased3DRenderer() override;
296
298 QgsRuleBased3DRenderer::Rule *rootRule() { return mRootRule; }
300 const Rule *rootRule() const SIP_SKIP { return mRootRule; }
301
302 QString type() const override { return "rulebased"; }
303 QgsRuleBased3DRenderer *clone() const override SIP_FACTORY;
304 Qt3DCore::QEntity *createEntity( Qgs3DMapSettings *map ) const override SIP_SKIP;
305
306 void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
307 void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
308
309 private:
310 Rule *mRootRule = nullptr;
311
312};
313
314#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