QGIS API Documentation 4.1.0-Master (3fcefe620d1)
Loading...
Searching...
No Matches
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#include <QString>
19
20using namespace Qt::StringLiterals;
21
22QgsPropertiesDefinition QgsAbstractMaterialSettings::sPropertyDefinitions;
23
24void QgsAbstractMaterialSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
25{
26 const QDomElement elemDataDefinedProperties = element.firstChildElement( u"data-defined-properties"_s );
27 if ( !elemDataDefinedProperties.isNull() )
28 mDataDefinedProperties.readXml( elemDataDefinedProperties, propertyDefinitions() );
29}
30
31void QgsAbstractMaterialSettings::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
32{
33 QDomElement elemDataDefinedProperties = element.ownerDocument().createElement( u"data-defined-properties"_s );
34 mDataDefinedProperties.writeXml( elemDataDefinedProperties, propertyDefinitions() );
35 element.appendChild( elemDataDefinedProperties );
36 element.setAttribute( u"type"_s, type() );
37}
38
40{
41 return false;
42}
43
45{
46 return false;
47}
48
49QSet<QgsAbstractMaterialSettings::Property> QgsAbstractMaterialSettings::supportedProperties() const
50{
51 return {};
52}
53
55{
56 mDataDefinedProperties = collection;
57}
58
60{
61 return mDataDefinedProperties;
62}
63
65{
66 if ( sPropertyDefinitions.isEmpty() )
67 initPropertyDefinitions();
68 return sPropertyDefinitions;
69}
70
71void QgsAbstractMaterialSettings::initPropertyDefinitions() const
72{
73 if ( !sPropertyDefinitions.isEmpty() )
74 return;
75
76 const QString origin = u"material3d"_s;
77
78 sPropertyDefinitions = QgsPropertiesDefinition {
79 { static_cast<int>( Property::Diffuse ), QgsPropertyDefinition( "diffuse", QObject::tr( "Diffuse" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
80 { static_cast<int>( Property::Ambient ), QgsPropertyDefinition( "ambient", QObject::tr( "Ambient" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
81 { static_cast<int>( Property::Warm ), QgsPropertyDefinition( "warm", QObject::tr( "Warm" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
82 { static_cast<int>( Property::Cool ), QgsPropertyDefinition( "cool", QObject::tr( "Cool" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
83 { static_cast<int>( Property::Specular ), QgsPropertyDefinition( "specular", QObject::tr( "Specular" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
84 { static_cast<int>( Property::BaseColor ), QgsPropertyDefinition( "baseColor", QObject::tr( "Base color" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
85 { static_cast<int>( Property::EmissionColor ), QgsPropertyDefinition( "emissionColor", QObject::tr( "Emission color" ), QgsPropertyDefinition::ColorNoAlpha, origin ) },
86 { static_cast<int>( Property::TextureScale ), QgsPropertyDefinition( "textureScale", QObject::tr( "Texture scale" ), QgsPropertyDefinition::DoublePositive, origin ) },
87 { static_cast<int>( Property::TextureRotation ), QgsPropertyDefinition( "textureRotation", QObject::tr( "Texture rotation" ), QgsPropertyDefinition::Double, origin ) },
88 { static_cast<int>( Property::TextureOffset ), QgsPropertyDefinition( "textureOffset", QObject::tr( "Texture offset" ), QgsPropertyDefinition::Offset, origin ) }
89
90 };
91}
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
virtual QSet< QgsAbstractMaterialSettings::Property > supportedProperties() const
Returns the set of data-defined properties supported by this material.
virtual bool requiresTangents() const
Returns true if the material requires tangents generated during triangulation.
@ BaseColor
Base color (metal-rough material).
@ EmissionColor
Emission color (metal-rough material).
virtual QString type() const =0
Returns the unique type name for the material.
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.
QgsPropertyCollection dataDefinedProperties() const
Returns the symbol material property collection, used for data defined overrides.
virtual bool requiresTextureCoordinates() const
Returns true if the material requires texture coordinates to be generated during triangulation.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
Definition for a property.
Definition qgsproperty.h:47
@ Double
Double value (including negative values).
Definition qgsproperty.h:56
@ ColorNoAlpha
Color with no alpha channel.
Definition qgsproperty.h:64
@ DoublePositive
Positive double value (including 0).
Definition qgsproperty.h:57
A container for the context for various read/write operations on objects.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.