QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsAbstractMaterialSettings::propertyDefinitions
const QgsPropertiesDefinition & propertyDefinitions() const
Returns a reference to the material properties definition, used for data defined overrides.
Definition: qgsabstractmaterialsettings.cpp:41
QgsAbstractMaterialSettings::setDataDefinedProperties
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the material property collection, used for data defined overrides.
Definition: qgsabstractmaterialsettings.cpp:34
QgsAbstractMaterialSettings::applyDataDefinedToGeometry
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...
Definition: qgsabstractmaterialsettings.cpp:54
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsAbstractPropertyCollection::readXml
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Definition: qgspropertycollection.cpp:108
QgsAbstractMaterialSettings::Specular
@ Specular
Specular color.
Definition: qgsabstractmaterialsettings.h:195
QgsAbstractMaterialSettings::Warm
@ Warm
Warm color (gooch material)
Definition: qgsabstractmaterialsettings.h:193
QgsAbstractMaterialSettings::Cool
@ Cool
Cool color (gooch material)
Definition: qgsabstractmaterialsettings.h:194
QgsAbstractMaterialSettings::dataDefinedVertexColorsAsByte
virtual QByteArray dataDefinedVertexColorsAsByte(const QgsExpressionContext &expressionContext) const
Returns byte array corresponding to the data defined colors depending of the expressionContext,...
Definition: qgsabstractmaterialsettings.cpp:48
qgsabstractmaterialsettings.h
QgsAbstractMaterialSettings::Diffuse
@ Diffuse
Diffuse color.
Definition: qgsabstractmaterialsettings.h:191
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsAbstractMaterialSettings::Ambient
@ Ambient
Ambient color (phong material)
Definition: qgsabstractmaterialsettings.h:192
QgsPropertyDefinition
Definition for a property.
Definition: qgsproperty.h:46
QgsAbstractMaterialSettings::dataDefinedProperties
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
Definition: qgsabstractmaterialsettings.cpp:39
QgsAbstractMaterialSettings::writeXml
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
Definition: qgsabstractmaterialsettings.cpp:27
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsAbstractMaterialSettings::readXml
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
Definition: qgsabstractmaterialsettings.cpp:20
QgsPropertyDefinition::ColorNoAlpha
@ ColorNoAlpha
Color with no alpha channel.
Definition: qgsproperty.h:65
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99