QGIS API Documentation  3.23.0-Master (eb871beae0)
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
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:56
The class is used as a container of context for various read/write operations on other objects.
bool isElse() const
Check if this rule is an ELSE rule.
QgsRuleBased3DRenderer::RuleList & children()
Returns all children rules of this rule.
QgsAbstract3DSymbol * symbol() const
Returns the labeling settings.
void setDescription(const QString &description)
Set a human readable description for this rule.
Rule(const Rule &rh)=delete
Rules cannot be copied.
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.
Rule & operator=(const Rule &rh)=delete
Rules cannot be copied.
const QgsRuleBased3DRenderer::Rule * parent() const
The parent rule.
void setIsElse(bool iselse)
Sets 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.
QString filterExpression() const
A filter that will check if this rule applies.
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::Rule * rootRule()
Returns pointer to the root rule.
QHash< const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler * > RuleToHandlerMap
QString type() const override
Returns unique identifier of the renderer class (used to identify subclass)
const Rule * rootRule() const
Returns pointer to the root rule.
QList< QgsRuleBased3DRenderer::Rule * > RuleList
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