35using namespace Qt::StringLiterals;
44 renderer->
readXml( elem, context );
61 :
Qgs3DRendererCategory( other.mValue, other.mSymbol ? other.mSymbol->clone() : nullptr, other.mRender )
68 mValue = other.mValue;
69 mSymbol = other.mSymbol ? std::unique_ptr<QgsAbstract3DSymbol>( other.mSymbol->clone() ) :
nullptr;
70 mRender = other.mRender;
88 if ( mSymbol.get() !=
symbol )
101 : mAttributeName( attributeName )
114 if ( mSourceColorRamp )
140 std::unique_ptr<QgsAbstract3DSymbol> newSymbol( symbol->
clone() );
150 mAttributeName = attributeName;
155 return mSourceSymbol.get();
160 return mSourceSymbol.get();
165 mSourceSymbol.reset( symbol );
170 return mSourceColorRamp.get();
175 return mSourceColorRamp.get();
180 mSourceColorRamp.reset( ramp );
186 const double num =
static_cast<double>( mCategories.count() - 1 );
206 if ( catIndex < 0 || catIndex >= mCategories.size() )
211 mCategories[catIndex].setValue( value );
217 if ( catIndex < 0 || catIndex >= mCategories.size() )
222 mCategories[catIndex].setSymbol( symbol );
228 if ( catIndex < 0 || catIndex >= mCategories.size() )
233 mCategories[catIndex].setRenderState( render );
239 mCategories.append( category );
244 if ( catIndex < 0 || catIndex >= mCategories.size() )
249 mCategories.removeAt( catIndex );
260 if ( from < 0 || from >= mCategories.size() || to < 0 || to >= mCategories.size() )
265 mCategories.move( from, to );
272 bool less = qgsVariantLessThan( cat1.value(), cat2.value() );
273 return ( order == Qt::AscendingOrder ) ? less : !less;
279 QDomDocument doc = elem.ownerDocument();
283 elem.setAttribute( u
"attribute"_s, mAttributeName );
286 if ( !mCategories.isEmpty() )
288 QDomElement catsElem = doc.createElement( u
"categories"_s );
291 QDomElement catElem = doc.createElement( u
"category"_s );
293 catElem.appendChild( valueElem );
294 catElem.setAttribute( u
"render"_s, category.renderState() ? 1 : 0 );
296 QDomElement symbolElem = doc.createElement( u
"symbol"_s );
297 symbolElem.setAttribute( u
"type"_s, category.symbol()->type() );
298 category.symbol()->writeXml( symbolElem, context );
299 catElem.appendChild( symbolElem );
301 catsElem.appendChild( catElem );
303 elem.appendChild( catsElem );
309 QDomElement sourceSymbolElem = doc.createElement( u
"source-symbol"_s );
310 sourceSymbolElem.setAttribute( u
"type"_s, mSourceSymbol->type() );
311 mSourceSymbol->writeXml( sourceSymbolElem, context );
312 elem.appendChild( sourceSymbolElem );
316 if ( mSourceColorRamp )
319 elem.appendChild( colorRampElem );
327 mAttributeName = elem.attribute( u
"attribute"_s );
330 QDomElement catsElem = elem.firstChildElement( u
"categories"_s );
331 if ( !catsElem.isNull() )
333 QDomElement catElem = catsElem.firstChildElement();
334 while ( !catElem.isNull() )
336 if ( catElem.tagName() ==
"category"_L1 )
339 const bool render =
static_cast<bool>( catElem.attribute( u
"render"_s, u
"0"_s ).toInt() );
342 QDomElement symbolElem = catElem.firstChildElement( u
"symbol"_s );
343 if ( !symbolElem.isNull() )
345 QString symbolType = symbolElem.attribute( u
"type"_s );
349 symbol->
readXml( symbolElem, context );
355 catElem = catElem.nextSiblingElement();
360 QDomElement sourceSymbolElem = elem.firstChildElement( u
"source-symbol"_s );
361 if ( !sourceSymbolElem.isNull() )
363 QString symbolType = sourceSymbolElem.attribute( u
"type"_s );
373 QDomElement sourceColorRampElem = elem.firstChildElement( u
"colorramp"_s );
374 if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( u
"name"_s ) ==
"[source]"_L1 )
383 QVariantList vals = values;
387 if (
layer && !attributeName.isNull() )
390 for (
const QVariant &value : vals )
394 std::unique_ptr<QgsAbstract3DSymbol> newSymbol( symbol->
clone() );
401 std::unique_ptr<QgsAbstract3DSymbol> newSymbol( symbol->
clone() );
Represents an individual category (class) from a QgsCategorized3DRenderer.
Qgs3DRendererCategory()=default
const QVariant value() const
Returns the value corresponding to this category.
void setRenderState(bool render)
Sets whether the category is currently enabled and should be rendered.
void setValue(const QVariant &value)
Sets the value corresponding to this category.
Qgs3DRendererCategory & operator=(const Qgs3DRendererCategory &other)
void setSymbol(QgsAbstract3DSymbol *symbol)
Sets the symbol which will be used to render this category.
QgsAbstract3DSymbol * symbol() const
Returns the symbol which will be used to render this category.
QgsAbstract3DSymbol * createSymbol(const QString &type) const
Creates a new instance of a symbol of the specified type.
static bool copyVectorSymbolMaterial(const QgsAbstract3DSymbol *fromSymbol, QgsAbstract3DSymbol *toSymbol)
Copies the material properties of a vector 3D symbol from one symbol to another.
static bool setVectorSymbolBaseColor(QgsAbstract3DSymbol *symbol, const QColor &baseColor)
Sets the base color of the material settings associated with a 3D vector symbol.
static constexpr double MINIMUM_VECTOR_Z_ESTIMATE
static constexpr double MAXIMUM_VECTOR_Z_ESTIMATE
Base class for all renderers that participate in 3D views.
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
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.
bool updateCategorySymbol(int catIndex, QgsAbstract3DSymbol *symbol)
Changes the symbol for the category with the specified index.
QgsAbstract3DSymbol * sourceSymbol()
Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol b...
bool updateCategoryValue(int catIndex, const QVariant &value)
Changes the value for the category with the specified index.
static Qgs3DCategoryList createCategories(const QVariantList &values, const QgsAbstract3DSymbol *symbol, QgsVectorLayer *layer=nullptr, const QString &attributeName=QString())
Create categories for a list of values.
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.
void updateColorRamp(QgsColorRamp *ramp)
Update the color ramp used and all symbols colors.
QgsCategorized3DRenderer(const QString &attributeName=QString(), const Qgs3DCategoryList &categories=Qgs3DCategoryList())
Construct renderer with the given categories.
QgsColorRamp * sourceColorRamp()
Returns the source color ramp, from which each categories' color is derived.
void addCategory(const Qgs3DRendererCategory &category)
Adds a new category to the renderer.
void setSourceSymbol(QgsAbstract3DSymbol *symbol)
Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbo...
void deleteAllCategories()
Deletes all existing categories from the renderer.
const Qgs3DCategoryList & categories() const
Returns a list of all categories recognized by the renderer.
void setClassAttribute(QString attributeName)
Sets the class attribute for the renderer, which is the field name or expression string from the laye...
Qt3DCore::QEntity * createEntity(Qgs3DMapSettings *mapSettings) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.
void setSourceColorRamp(QgsColorRamp *ramp)
Sets the source color ramp.
bool moveCategory(int from, int to)
Moves an existing category at index position from to index position to.
void sortByValue(Qt::SortOrder order=Qt::AscendingOrder)
Sorts the existing categories by their value.
bool updateCategoryRenderState(int catIndex, bool render)
Changes the render state for the category with the specified index.
QgsCategorized3DRenderer * clone() const override
Returns a cloned instance.
void updateSymbols(QgsAbstract3DSymbol *symbol)
Update all the symbols but leave categories and colors.
bool deleteCategory(int catIndex)
Deletes the category with the specified index from the renderer.
Abstract base class for color ramps.
Container of fields for a vector layer.
A color ramp consisting of random colors, constrained within component ranges.
virtual void setTotalColorCount(int colorCount)
Sets the desired total number of unique colors for the resultant ramp.
A container for the context for various read/write operations on objects.
static void sortVariantList(QList< QVariant > &list, Qt::SortOrder order)
Sorts the passed list in requested order.
static std::unique_ptr< QgsColorRamp > loadColorRamp(QDomElement &element)
Creates a color ramp from the settings encoded in an XML element.
static QDomElement saveColorRamp(const QString &name, const QgsColorRamp *ramp, QDomDocument &doc)
Encodes a color ramp's settings to an XML element.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
QList< Qgs3DRendererCategory > Qgs3DCategoryList