QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
21 #include "qgs3drendererregistry.h"
23 #include "qgsabstract3dsymbol.h"
24 #include "qgsmaplayerref.h"
25 #include <QUuid>
26 
27 class Qgs3DRenderContext;
28 class 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 
82  Rule( const Rule &rh ) = delete;
84  Rule &operator=( const Rule &rh ) = delete;
85 
88  {
89  Filtered = 0,
91  Registered
92  };
93 
97  QgsAbstract3DSymbol *symbol() const { return mSymbol.get(); }
98 
103  QString filterExpression() const { return mFilterExp; }
104 
110  QString description() const { return mDescription; }
111 
117  bool active() const { return mIsActive; }
118 
124  bool isElse() const { return mElseRule; }
125 
127  QString ruleKey() const { return mRuleKey; }
128 
130  void setSymbol( QgsAbstract3DSymbol *symbol SIP_TRANSFER );
131 
137  void setFilterExpression( const QString &filterExp ) { mFilterExp = filterExp; initFilter(); }
138 
144  void setDescription( const QString &description ) { mDescription = description; }
145 
150  void setActive( bool state ) { mIsActive = state; }
151 
157  void setIsElse( bool iselse ) { mElseRule = iselse; }
158 
159  // TODO: needed?
161  void setRuleKey( const QString &key ) { mRuleKey = key; }
162 
163  // parent / child operations
164 
170  const QgsRuleBased3DRenderer::RuleList &children() const { return mChildren; }
171 
178 
184  QgsRuleBased3DRenderer::RuleList descendants() const;
185 
191  const QgsRuleBased3DRenderer::Rule *parent() const SIP_SKIP { return mParent; }
192 
198  QgsRuleBased3DRenderer::Rule *parent() { return mParent; }
199 
201  void appendChild( QgsRuleBased3DRenderer::Rule *rule SIP_TRANSFER );
202 
204  void insertChild( int i, QgsRuleBased3DRenderer::Rule *rule SIP_TRANSFER );
205 
207  void removeChildAt( int i );
208 
210  const QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) const;
211 
217  QgsRuleBased3DRenderer::Rule *findRuleByKey( const QString &key ) SIP_SKIP;
218 
221 
222  // load / save
223 
230  static QgsRuleBased3DRenderer::Rule *create( const QDomElement &ruleElem, const QgsReadWriteContext &context ) SIP_FACTORY;
231 
233  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) const;
234 
235  // evaluation
236 
241  void createHandlers( QgsVectorLayer *layer, RuleToHandlerMap &handlers ) const SIP_SKIP;
242 
247  void prepare( const Qgs3DRenderContext &context, QSet<QString> &attributeNames, RuleToHandlerMap &handlers ) const SIP_SKIP;
248 
253  RegisterResult registerFeature( QgsFeature &feature, Qgs3DRenderContext &context, RuleToHandlerMap &handlers ) const SIP_SKIP;
254 
255  private:
256 #ifdef SIP_RUN
257  Rule( const QgsRuleBased3DRenderer::Rule &rh );
258 #endif
259 
267  bool isFilterOK( QgsFeature &f, Qgs3DRenderContext &context ) const;
268 
272  void initFilter();
273 
277  void updateElseRules();
278 
279  private:
280  Rule *mParent = nullptr; // parent rule (nullptr only for root rule)
281  std::unique_ptr<QgsAbstract3DSymbol> mSymbol;
282  QString mFilterExp;
283  QString mDescription;
284  bool mElseRule = false;
285  RuleList mChildren;
286  RuleList mElseRules;
287  bool mIsActive = true; // whether it is enabled or not
288 
289  QString mRuleKey = QUuid::createUuid().toString(); // string used for unique identification of rule within labeling
290 
291  std::unique_ptr<QgsExpression> mFilter;
292  };
293 
294 
297  ~QgsRuleBased3DRenderer() override;
298 
300  QgsRuleBased3DRenderer::Rule *rootRule() { return mRootRule; }
302  const Rule *rootRule() const SIP_SKIP { return mRootRule; }
303 
304  QString type() const override { return "rulebased"; }
305  QgsRuleBased3DRenderer *clone() const override SIP_FACTORY;
306  Qt3DCore::QEntity *createEntity( const Qgs3DMapSettings &map ) const override SIP_SKIP;
307 
308  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
309  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
310 
311  private:
312  Rule *mRootRule = nullptr;
313 
314 };
315 
316 #endif // QGSRULEBASED3DRENDERER_H
QgsRuleBased3DRenderer::Rule::setFilterExpression
void setFilterExpression(const QString &filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
Definition: qgsrulebased3drenderer.h:137
QgsRuleBased3DRenderer::rootRule
QgsRuleBased3DRenderer::Rule * rootRule()
Returns pointer to the root rule.
Definition: qgsrulebased3drenderer.h:300
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
Qgs3DRendererAbstractMetadata::createRenderer
virtual QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:48
QgsRuleBased3DRenderer::Rule::ruleKey
QString ruleKey() const
Unique rule identifier (for identification of rule within labeling, used as provider ID)
Definition: qgsrulebased3drenderer.h:127
Qgs3DRendererAbstractMetadata
Base metadata class for 3D renderers.
Definition: qgs3drendererregistry.h:34
QgsRuleBased3DRenderer::Rule::setIsElse
void setIsElse(bool iselse)
Sets if this rule is an ELSE rule.
Definition: qgsrulebased3drenderer.h:157
QgsAbstractVectorLayer3DRenderer
Base class for 3D renderers that are based on vector layers.
Definition: qgsabstractvectorlayer3drenderer.h:77
QgsRuleBased3DRenderer::Rule::Inactive
@ Inactive
The rule is inactive.
Definition: qgsrulebased3drenderer.h:90
QgsRuleBased3DRenderer::Rule::symbol
QgsAbstract3DSymbol * symbol() const
Returns the labeling settings.
Definition: qgsrulebased3drenderer.h:97
qgsabstract3dsymbol.h
QgsRuleBased3DRenderer::RuleToHandlerMap
QHash< const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler * > RuleToHandlerMap
Definition: qgsrulebased3drenderer.h:67
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsAbstract3DSymbol
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
Definition: qgsabstract3dsymbol.h:46
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsRuleBased3DRenderer::Rule::setActive
void setActive(bool state)
Sets if this rule is active.
Definition: qgsrulebased3drenderer.h:150
QgsRuleBased3DRenderer::Rule::setRuleKey
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based renderer)
Definition: qgsrulebased3drenderer.h:161
qgsabstractvectorlayer3drenderer.h
QgsRuleBased3DRenderer::Rule::parent
const QgsRuleBased3DRenderer::Rule * parent() const
The parent rule.
Definition: qgsrulebased3drenderer.h:191
Qt3DCore
Definition: qgsabstract3drenderer.h:30
QgsRuleBased3DRenderer::Rule::parent
QgsRuleBased3DRenderer::Rule * parent()
The parent rule.
Definition: qgsrulebased3drenderer.h:198
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
QgsRuleBased3DRenderer::Rule::children
QgsRuleBased3DRenderer::RuleList & children()
Returns all children rules of this rule.
Definition: qgsrulebased3drenderer.h:177
QgsRuleBased3DRenderer::Rule::filterExpression
QString filterExpression() const
A filter that will check if this rule applies.
Definition: qgsrulebased3drenderer.h:103
qgs3drendererregistry.h
QgsRuleBased3DRenderer::RuleList
QList< QgsRuleBased3DRenderer::Rule * > RuleList
Definition: qgsrulebased3drenderer.h:65
QgsRuleBased3DRenderer::Rule::isElse
bool isElse() const
Check if this rule is an ELSE rule.
Definition: qgsrulebased3drenderer.h:124
QgsRuleBased3DRenderer::type
QString type() const override
Returns unique identifier of the renderer class (used to identify subclass)
Definition: qgsrulebased3drenderer.h:304
QgsRuleBased3DRenderer::Rule::setDescription
void setDescription(const QString &description)
Set a human readable description for this rule.
Definition: qgsrulebased3drenderer.h:144
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsRuleBased3DRenderer::Rule
A child rule for a QgsRuleBased3DRenderer.
Definition: qgsrulebased3drenderer.h:74
QgsRuleBased3DRenderer::Rule::description
QString description() const
A human readable description for this rule.
Definition: qgsrulebased3drenderer.h:110
QgsRuleBased3DRenderer::Rule::RegisterResult
RegisterResult
The result of registering a rule.
Definition: qgsrulebased3drenderer.h:87
QgsRuleBased3DRenderer
Rule-based 3D renderer.
Definition: qgsrulebased3drenderer.h:61
qgsmaplayerref.h
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsRuleBased3DRenderer::rootRule
const Rule * rootRule() const
Returns pointer to the root rule.
Definition: qgsrulebased3drenderer.h:302
QgsRuleBased3DRenderer::Rule::children
const QgsRuleBased3DRenderer::RuleList & children() const
Returns all children rules of this rule.
Definition: qgsrulebased3drenderer.h:170
QgsRuleBased3DRenderer::Rule::active
bool active() const
Returns if this rule is active.
Definition: qgsrulebased3drenderer.h:117
QgsRuleBased3DRendererMetadata
Metadata for rule-based 3D renderer to allow creation of its instances from XML.
Definition: qgsrulebased3drenderer.h:40