QGIS API Documentation  3.23.0-Master (c716e02dd3)
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 
18 QgsPropertiesDefinition QgsAbstractMaterialSettings::sPropertyDefinitions;
19 
20 void 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 
27 void 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 void QgsAbstractMaterialSettings::applyDataDefinedToGeometry( Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes ) const
55 {
56  Q_UNUSED( geometry )
57  Q_UNUSED( vertexCount )
58  Q_UNUSED( dataDefinedBytes )
59 }
60 
61 void QgsAbstractMaterialSettings::initPropertyDefinitions() const
62 {
63  if ( !sPropertyDefinitions.isEmpty() )
64  return;
65 
66  const QString origin = QStringLiteral( "material3d" );
67 
68  sPropertyDefinitions = QgsPropertiesDefinition
69  {
70  { Diffuse, QgsPropertyDefinition( "diffuse", QObject::tr( "Diffuse" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
71  { Ambient, QgsPropertyDefinition( "ambient", QObject::tr( "Ambient" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
72  { Warm, QgsPropertyDefinition( "warm", QObject::tr( "Warm" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
73  { Cool, QgsPropertyDefinition( "cool", QObject::tr( "Cool" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
74  { Specular, QgsPropertyDefinition( "specular", QObject::tr( "Specular" ), QgsPropertyDefinition::ColorNoAlpha, origin ) }
75  };
76 }
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.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the material property collection, used for data defined overrides.
const QgsPropertiesDefinition & propertyDefinitions() const
Returns a reference to the material properties definition, used for data defined overrides.
virtual void applyDataDefinedToGeometry(Qt3DRender::QGeometry *geometry, int vertexCount, const QByteArray &dataDefinedBytes) const
Applies the data defined bytes, dataDefinedBytes, on the geometry by filling a specific vertex buffer...
@ Ambient
Ambient color (phong material)
@ Warm
Warm color (gooch material)
@ Cool
Cool color (gooch material)
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:47
@ ColorNoAlpha
Color with no alpha channel.
Definition: qgsproperty.h:65
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.