QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
38 QDomElement rulesElem = elem.firstChildElement( QStringLiteral(
"rules" ) );
57 , mFilterExp( filterExp )
58 , mDescription( description )
59 , mElseRule( elseRule )
67 qDeleteAll( mChildren );
73 if ( mSymbol.get() == symbol )
76 mSymbol.reset( symbol );
82 for (
Rule *
c : mChildren )
85 l +=
c->descendants();
90 void QgsRuleBased3DRenderer::Rule::initFilter()
92 if ( mElseRule || mFilterExp.compare( QLatin1String(
"ELSE" ), Qt::CaseInsensitive ) == 0 )
95 mFilter.reset(
nullptr );
97 else if ( !mFilterExp.isEmpty() )
103 mFilter.reset(
nullptr );
107 void QgsRuleBased3DRenderer::Rule::updateElseRules()
110 for ( Rule *rule : qgis::as_const( mChildren ) )
112 if ( rule->isElse() )
120 mChildren.append( rule );
121 rule->mParent =
this;
127 mChildren.insert( i, rule );
128 rule->mParent =
this;
134 delete mChildren.at( i );
135 mChildren.removeAt( i );
143 if ( key == mRuleKey )
146 for (
Rule *rule : qgis::as_const( mChildren ) )
157 if ( key == mRuleKey )
160 for (
Rule *rule : qgis::as_const( mChildren ) )
172 Rule *newrule =
new Rule( symbol, mFilterExp, mDescription );
175 for (
Rule *rule : qgis::as_const( mChildren ) )
183 QDomElement elemSymbol = ruleElem.firstChildElement( QStringLiteral(
"symbol" ) );
184 if ( !elemSymbol.isNull() )
186 QString symbolType = elemSymbol.attribute( QStringLiteral(
"type" ) );
189 symbol->
readXml( elemSymbol, context );
192 QString filterExp = ruleElem.attribute( QStringLiteral(
"filter" ) );
193 QString description = ruleElem.attribute( QStringLiteral(
"description" ) );
194 QString ruleKey = ruleElem.attribute( QStringLiteral(
"key" ) );
195 Rule *rule =
new Rule( symbol, filterExp, description );
197 if ( !ruleKey.isEmpty() )
198 rule->mRuleKey = ruleKey;
200 rule->
setActive( ruleElem.attribute( QStringLiteral(
"active" ), QStringLiteral(
"1" ) ).toInt() );
202 QDomElement childRuleElem = ruleElem.firstChildElement( QStringLiteral(
"rule" ) );
203 while ( !childRuleElem.isNull() )
205 Rule *childRule = create( childRuleElem, context );
214 childRuleElem = childRuleElem.nextSiblingElement( QStringLiteral(
"rule" ) );
222 QDomElement ruleElem = doc.createElement( QStringLiteral(
"rule" ) );
226 QDomElement elemSymbol = doc.createElement( QStringLiteral(
"symbol" ) );
227 elemSymbol.setAttribute( QStringLiteral(
"type" ), mSymbol->type() );
228 mSymbol->writeXml( elemSymbol, context );
229 ruleElem.appendChild( elemSymbol );
232 if ( !mFilterExp.isEmpty() )
233 ruleElem.setAttribute( QStringLiteral(
"filter" ), mFilterExp );
234 if ( !mDescription.isEmpty() )
235 ruleElem.setAttribute( QStringLiteral(
"description" ), mDescription );
237 ruleElem.setAttribute( QStringLiteral(
"active" ), 0 );
238 ruleElem.setAttribute( QStringLiteral(
"key" ), mRuleKey );
240 for ( RuleList::const_iterator it = mChildren.constBegin(); it != mChildren.constEnd(); ++it )
254 Q_ASSERT( !handlers.value(
this ) );
257 handlers[
this] = handler;
261 for (
Rule *rule : qgis::as_const( mChildren ) )
263 rule->createHandlers(
layer, handlers );
272 QgsFeature3DHandler *handler = handlers[
this];
273 if ( !handler->prepare( context, attributeNames ) )
275 handlers.remove(
this );
282 attributeNames.unite( mFilter->referencedColumns() );
283 mFilter->prepare( &context.expressionContext() );
287 for (
Rule *rule : qgis::as_const( mChildren ) )
289 rule->prepare( context, attributeNames, handlers );
295 if ( !isFilterOK( feature, context ) )
298 bool registered =
false;
301 if ( handlers.contains(
this ) && mIsActive )
303 handlers[
this]->processFeature( feature, context );
307 bool willRegisterSomething =
false;
310 for (
Rule *rule : qgis::as_const( mChildren ) )
313 if ( !rule->isElse() )
315 RegisterResult res = rule->registerFeature( feature, context, handlers );
317 willRegisterSomething |= ( res == Registered || res == Inactive );
318 registered |= willRegisterSomething;
323 if ( !willRegisterSomething )
325 for (
Rule *rule : qgis::as_const( mElseRules ) )
327 registered |= rule->registerFeature( feature, context, handlers ) != Filtered;
333 else if ( registered )
340 bool QgsRuleBased3DRenderer::Rule::isFilterOK(
QgsFeature &f, Qgs3DRenderContext &context )
const
342 if ( ! mFilter || mElseRule )
345 context.expressionContext().setFeature( f );
346 QVariant res = mFilter->evaluate( &context.expressionContext() );
347 return res.toInt() != 0;
373 Q_ASSERT( origDescendants.count() == clonedDescendants.count() );
374 for (
int i = 0; i < origDescendants.count(); ++i )
375 clonedDescendants[i]->setRuleKey( origDescendants[i]->ruleKey() );
392 return new QgsRuleBasedChunkedEntity( vl, zMin, zMax,
tilingSettings(), mRootRule, map );
397 QDomDocument doc = elem.ownerDocument();
401 QDomElement rulesElem = mRootRule->
save( doc, context );
402 rulesElem.setTagName( QStringLiteral(
"rules" ) );
403 elem.appendChild( rulesElem );
static QgsRuleBased3DRenderer::Rule * create(const QDomElement &ruleElem, const QgsReadWriteContext &context)
Create a rule from an XML definition.
void createHandlers(QgsVectorLayer *layer, RuleToHandlerMap &handlers) const
add handlers
QgsRuleBased3DRenderer::Rule * clone() const
clone this rule, return new instance
QgsRuleBased3DRenderer::Rule * rootRule()
Returns pointer to the root rule.
const QgsRuleBased3DRenderer::Rule * findRuleByKey(const QString &key) const
Try to find a rule given its unique key.
QgsRuleBased3DRenderer::RuleList descendants() const
Returns all children, grand-children, grand-grand-children, grand-gra...
The class is used as a container of context for various read/write operations on other objects.
QgsAbstract3DSymbol * createSymbol(const QString &type) const
Creates a new instance of a symbol of the specified type.
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets new symbol (or nullptr). Deletes old symbol if any.
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.
QString ruleKey() const
Unique rule identifier (for identification of rule within labeling, used as provider ID)
~QgsRuleBased3DRenderer() override
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
QgsRuleBased3DRenderer * clone() const override
Returns a cloned instance.
void prepare(const Qgs3DRenderContext &context, QSet< QString > &attributeNames, RuleToHandlerMap &handlers) const
call prepare() on handlers and populate attributeNames
void removeChildAt(int i)
delete child rule
void appendChild(QgsRuleBased3DRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
void copyBaseProperties(QgsAbstractVectorLayer3DRenderer *r) const
Copies common properties of this object to another object.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const
store labeling info to XML element
QHash< const QgsRuleBased3DRenderer::Rule *, QgsFeature3DHandler * > RuleToHandlerMap
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
void insertChild(int i, QgsRuleBased3DRenderer::Rule *rule)
add child rule, take ownership, sets this as parent
void readXmlBaseProperties(const QDomElement &elem, const QgsReadWriteContext &context)
Reads common properties of this object from DOM element.
3 Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
QgsVectorLayer3DTilingSettings tilingSettings() const
Returns tiling settings of the renderer.
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.
QgsVectorLayer * layer() const
Returns vector layer associated with the renderer.
void setRuleKey(const QString &key)
Override the assigned rule key (should be used just internally by rule-based renderer)
virtual QgsAbstract3DSymbol * clone() const =0
Returns a new instance of the symbol with the same settings.
3 Definition of the world
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
void writeXmlBaseProperties(QDomElement &elem, const QgsReadWriteContext &context) const
Writes common properties of this object to DOM element.
QList< QgsRuleBased3DRenderer::Rule * > RuleList
static void estimateVectorLayerZRange(QgsVectorLayer *layer, double &zMin, double &zMax)
Try to estimate range of Z values used in the given vector layer and store that in zMin and zMax.
RegisterResult registerFeature(QgsFeature &feature, Qgs3DRenderContext &context, RuleToHandlerMap &handlers) const
register individual features
QgsRuleBased3DRenderer(QgsRuleBased3DRenderer::Rule *root)
Construct renderer with the given root rule (takes ownership)
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
Represents a vector layer which manages a vector based data sets.
RegisterResult
The result of registering a rule.
3 Rule-based 3D renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsFeature3DHandler * createHandlerForSymbol(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol, for the specified vector layer.
Class for parsing and evaluation of expressions (formerly called "search strings").
Qt3DCore::QEntity * createEntity(const Qgs3DMapSettings &map) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.