QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsabstractmaterialsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractmaterialsettings.cpp
3 --------------------------------------
4 Date : July 2020
5 Copyright : (C) 2020 by Nyall Dawson
6 Email : nyall dot dawson 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
17
18QgsPropertiesDefinition QgsAbstractMaterialSettings::sPropertyDefinitions;
19
20void QgsAbstractMaterialSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
21{
22 const QDomElement elemDataDefinedProperties = element.firstChildElement( QStringLiteral( "data-defined-properties" ) );
23 if ( !elemDataDefinedProperties.isNull() )
24 mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
25}
26
27void QgsAbstractMaterialSettings::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
28{
29 QDomElement elemDataDefinedProperties = element.ownerDocument().createElement( QStringLiteral( "data-defined-properties" ) );
30 mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
31 element.appendChild( elemDataDefinedProperties );
32}
33
35{
36 mDataDefinedProperties = collection;
37}
38
40
42{
43 if ( sPropertyDefinitions.isEmpty() )
44 initPropertyDefinitions();
45 return sPropertyDefinitions;
46}
47
49{
50 Q_UNUSED( expressionContext )
51 return QByteArray();
52}
53
54#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
55void QgsAbstractMaterialSettings::applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const
56#else
57void QgsAbstractMaterialSettings::applyDataDefinedToGeometry( Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const
58#endif
59{
60 Q_UNUSED( geometry )
61 Q_UNUSED( vertexCount )
62 Q_UNUSED( dataDefinedBytes )
63}
64
65void QgsAbstractMaterialSettings::initPropertyDefinitions() const
66{
67 if ( !sPropertyDefinitions.isEmpty() )
68 return;
69
70 const QString origin = QStringLiteral( "material3d" );
71
72 sPropertyDefinitions = QgsPropertiesDefinition
73 {
74 { static_cast< int >( Property::Diffuse ), QgsPropertyDefinition( "diffuse", QObject::tr( "Diffuse" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
75 { static_cast< int >( Property::Ambient ), QgsPropertyDefinition( "ambient", QObject::tr( "Ambient" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
76 { static_cast< int >( Property::Warm ), QgsPropertyDefinition( "warm", QObject::tr( "Warm" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
77 { static_cast< int >( Property::Cool ), QgsPropertyDefinition( "cool", QObject::tr( "Cool" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
78 { static_cast< int >( Property::Specular ), QgsPropertyDefinition( "specular", QObject::tr( "Specular" ), QgsPropertyDefinition::ColorNoAlpha, origin ) }
79 };
80}
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual QByteArray dataDefinedVertexColorsAsByte(const QgsExpressionContext &expressionContext) const
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
@ Warm
Warm color (gooch material)
@ Cool
Cool color (gooch material)
@ Ambient
Ambient color (phong material)
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the material property collection, used for data defined overrides.
virtual void applyDataDefinedToGeometry(Qt3DCore::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes) const
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
const QgsPropertiesDefinition & propertyDefinitions() const
Returns a reference to the material properties definition, used for data defined overrides.
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition for a property.
Definition: qgsproperty.h:45
@ ColorNoAlpha
Color with no alpha channel.
Definition: qgsproperty.h:63
The class is used as a container of context for various read/write operations on other objects.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.