35 QDomElement rulesElem = elem.firstChildElement( QStringLiteral(
"rules" ) );
54 , mFilterExp( filterExp )
55 , mDescription( description )
56 , mElseRule( elseRule )
64 qDeleteAll( mChildren );
70 if ( mSymbol.get() == symbol )
73 mSymbol.reset( symbol );
79 for (
Rule *
c : mChildren )
82 l +=
c->descendants();
87void QgsRuleBased3DRenderer::Rule::initFilter()
89 if ( mElseRule || mFilterExp.compare( QLatin1String(
"ELSE" ), Qt::CaseInsensitive ) == 0 )
92 mFilter.reset(
nullptr );
94 else if ( !mFilterExp.isEmpty() )
100 mFilter.reset(
nullptr );
104void QgsRuleBased3DRenderer::Rule::updateElseRules()
107 for ( Rule *rule : std::as_const( mChildren ) )
109 if ( rule->isElse() )
117 mChildren.append( rule );
118 rule->mParent =
this;
124 mChildren.insert( i, rule );
125 rule->mParent =
this;
131 delete mChildren.at( i );
132 mChildren.removeAt( i );
140 if ( key == mRuleKey )
143 for (
Rule *rule : std::as_const( mChildren ) )
154 if ( key == mRuleKey )
157 for (
Rule *rule : std::as_const( mChildren ) )
169 Rule *newrule =
new Rule( symbol, mFilterExp, mDescription );
172 for (
Rule *rule : std::as_const( mChildren ) )
180 QDomElement elemSymbol = ruleElem.firstChildElement( QStringLiteral(
"symbol" ) );
181 if ( !elemSymbol.isNull() )
183 QString symbolType = elemSymbol.attribute( QStringLiteral(
"type" ) );
186 symbol->
readXml( elemSymbol, context );
189 QString filterExp = ruleElem.attribute( QStringLiteral(
"filter" ) );
190 QString description = ruleElem.attribute( QStringLiteral(
"description" ) );
191 QString ruleKey = ruleElem.attribute( QStringLiteral(
"key" ) );
192 Rule *rule =
new Rule( symbol, filterExp, description );
194 if ( !ruleKey.isEmpty() )
195 rule->mRuleKey = ruleKey;
197 rule->
setActive( ruleElem.attribute( QStringLiteral(
"active" ), QStringLiteral(
"1" ) ).toInt() );
199 QDomElement childRuleElem = ruleElem.firstChildElement( QStringLiteral(
"rule" ) );
200 while ( !childRuleElem.isNull() )
202 Rule *childRule = create( childRuleElem, context );
211 childRuleElem = childRuleElem.nextSiblingElement( QStringLiteral(
"rule" ) );
219 QDomElement ruleElem = doc.createElement( QStringLiteral(
"rule" ) );
223 QDomElement elemSymbol = doc.createElement( QStringLiteral(
"symbol" ) );
224 elemSymbol.setAttribute( QStringLiteral(
"type" ), mSymbol->type() );
225 mSymbol->writeXml( elemSymbol, context );
229 if ( !mFilterExp.isEmpty() )
230 ruleElem.setAttribute( QStringLiteral(
"filter" ), mFilterExp );
231 if ( !mDescription.isEmpty() )
232 ruleElem.setAttribute( QStringLiteral(
"description" ), mDescription );
234 ruleElem.setAttribute( QStringLiteral(
"active" ), 0 );
235 ruleElem.setAttribute( QStringLiteral(
"key" ), mRuleKey );
237 for ( RuleList::const_iterator it = mChildren.constBegin(); it != mChildren.constEnd(); ++it )
251 Q_ASSERT( !handlers.value(
this ) );
254 handlers[
this] = handler;
258 for (
Rule *rule : std::as_const( mChildren ) )
260 rule->createHandlers(
layer, handlers );
269 QgsFeature3DHandler *handler = handlers[
this];
270 if ( !handler->prepare( context, attributeNames, chunkOrigin ) )
272 handlers.remove(
this );
279 attributeNames.unite( mFilter->referencedColumns() );
284 for (
Rule *rule : std::as_const( mChildren ) )
286 rule->prepare( context, attributeNames, chunkOrigin, handlers );
292 if ( !isFilterOK( feature, context ) )
295 bool registered =
false;
298 if ( handlers.contains(
this ) && mIsActive )
300 handlers[
this]->processFeature( feature, context );
304 bool matchedAChild =
false;
307 for (
Rule *rule : std::as_const( mChildren ) )
310 if ( !rule->isElse() )
312 const RegisterResult res = rule->registerFeature( feature, context, handlers );
314 matchedAChild |= ( res == Registered || res == Inactive );
315 registered |= matchedAChild;
320 if ( !matchedAChild )
322 for (
Rule *rule : std::as_const( mElseRules ) )
324 const RegisterResult res = rule->registerFeature( feature, context, handlers );
325 matchedAChild |= ( res == Registered || res == Inactive );
326 registered |= res != Filtered;
330 if ( !mIsActive || ( matchedAChild && !registered ) )
332 else if ( registered )
341 if ( !mFilter || mElseRule )
346 return res.toInt() != 0;
372 Q_ASSERT( origDescendants.count() == clonedDescendants.count() );
373 for (
int i = 0; i < origDescendants.count(); ++i )
374 clonedDescendants[i]->setRuleKey( origDescendants[i]->ruleKey() );
393 constexpr double MINIMUM_VECTOR_Z_ESTIMATE = -100000;
394 constexpr double MAXIMUM_VECTOR_Z_ESTIMATE = 100000;
396 return new QgsRuleBasedChunkedEntity( map, vl, MINIMUM_VECTOR_Z_ESTIMATE, MAXIMUM_VECTOR_Z_ESTIMATE,
tilingSettings(), mRootRule );
401 QDomDocument doc = elem.ownerDocument();
405 QDomElement rulesElem = mRootRule->
save( doc, context );
406 rulesElem.setTagName( QStringLiteral(
"rules" ) );
407 elem.appendChild( rulesElem );
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsAbstract3DSymbol * createSymbol(const QString &type) const
Creates a new instance of a symbol of the specified type.
QgsFeature3DHandler * createHandlerForSymbol(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol, for the specified vector layer.
Base class for all renderers that may to participate in 3D view.
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads symbol configuration from the given DOM element.
virtual QgsAbstract3DSymbol * clone() const =0
Returns a new instance of the symbol with the same settings.
QgsVectorLayer3DTilingSettings tilingSettings() const
Returns tiling settings of the renderer.
void writeXmlBaseProperties(QDomElement &elem, const QgsReadWriteContext &context) const
Writes common properties of this object to DOM element.
void readXmlBaseProperties(const QDomElement &elem, const QgsReadWriteContext &context)
Reads common properties of this object from DOM element.
void copyBaseProperties(QgsAbstractVectorLayer3DRenderer *r) const
Copies common properties of this object to another object.
QgsVectorLayer * layer() const
Returns vector layer associated with the renderer.
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
The class is used as a container of context for various read/write operations on other objects.
void insertChild(int i, QgsRuleBased3DRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
const QgsRuleBased3DRenderer::Rule * findRuleByKey(const QString &key) const
Try to find a rule given its unique key.
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets new symbol (or nullptr). Deletes old symbol if any.
Rule(QgsAbstract3DSymbol *symbol, const QString &filterExp=QString(), const QString &description=QString(), bool elseRule=false)
takes ownership of symbol, symbol may be nullptr
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)
void prepare(const Qgs3DRenderContext &context, QSet< QString > &attributeNames, const QgsVector3D &chunkOrigin, RuleToHandlerMap &handlers) const
call prepare() on handlers and populate attributeNames
RegisterResult
The result of registering a rule.
RegisterResult registerFeature(QgsFeature &feature, Qgs3DRenderContext &context, RuleToHandlerMap &handlers) const
register individual features
QgsRuleBased3DRenderer::Rule * clone() const
clone this rule, return new instance
QgsRuleBased3DRenderer::RuleList descendants() const
Returns all children, grand-children, grand-grand-children, grand-gra... you get it.
void createHandlers(QgsVectorLayer *layer, RuleToHandlerMap &handlers) const
add handlers
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const
store labeling info to XML element
static QgsRuleBased3DRenderer::Rule * create(const QDomElement &ruleElem, const QgsReadWriteContext &context)
Create a rule from an XML definition.
void removeChildAt(int i)
delete child rule
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based renderer)
void appendChild(QgsRuleBased3DRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
QgsRuleBased3DRenderer * clone() const override
Returns a cloned instance.
QHash< const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler * > RuleToHandlerMap
Qt3DCore::QEntity * createEntity(Qgs3DMapSettings *map) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.
QgsRuleBased3DRenderer(QgsRuleBased3DRenderer::Rule *root)
Construct renderer with the given root rule (takes ownership)
QgsRuleBased3DRenderer::Rule * rootRule()
Returns pointer to the root rule.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
~QgsRuleBased3DRenderer() override
QList< QgsRuleBased3DRenderer::Rule * > RuleList
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Represents a vector layer which manages a vector based data sets.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c