QGIS API Documentation 3.29.0-Master (19d7edcfed)
qgssimplelinematerialsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssimplelinematerialsettings.cpp
3 --------------------------------------
4 Date : August 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#include "qgssymbollayerutils.h"
18#include "qgslinematerial_p.h"
19#include <Qt3DRender/QTexture>
20#include <Qt3DRender/QParameter>
21#include <Qt3DRender/QEffect>
22#include <QMap>
23
24
26{
27 return QStringLiteral( "simpleline" );
28}
29
31{
32 switch ( technique )
33 {
35 return true;
36
43 return false;
44 }
45 return false;
46}
47
49{
51}
52
54{
55 return new QgsSimpleLineMaterialSettings( *this );
56}
57
58void QgsSimpleLineMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext & )
59{
60 mAmbient = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) );
61}
62
63void QgsSimpleLineMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext & ) const
64{
65 elem.setAttribute( QStringLiteral( "ambient" ), QgsSymbolLayerUtils::encodeColor( mAmbient ) );
66}
67
69{
70 switch ( technique )
71 {
78 return nullptr;
79
81 {
82 QgsLineMaterial *mat = new QgsLineMaterial;
83 mat->setLineColor( mAmbient );
84 if ( context.isSelected() )
85 {
86 // update the material with selection colors
87 mat->setLineColor( context.selectionColor() );
88 }
89 return mat;
90 }
91 }
92 return nullptr;
93}
94
96{
97 QMap<QString, QString> parameters;
98 parameters[ QStringLiteral( "Ka" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
99 return parameters;
100}
101
102void QgsSimpleLineMaterialSettings::addParametersToEffect( Qt3DRender::QEffect *effect ) const
103{
104 Qt3DRender::QParameter *ambientParameter = new Qt3DRender::QParameter( QStringLiteral( "ka" ), QColor::fromRgbF( 0.05f, 0.05f, 0.05f, 1.0f ) );
105 ambientParameter->setValue( mAmbient );
106 effect->addParameter( ambientParameter );
107}
QColor selectionColor() const
Returns the color for representing materials in a selected state.
bool isSelected() const
Returns true if the material should represent a selected state.
The class is used as a container of context for various read/write operations on other objects.
void addParametersToEffect(Qt3DRender::QEffect *effect) const override
Adds parameters from the material to a destination effect.
QgsSimpleLineMaterialSettings * clone() const override
Clones the material settings.
Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QMaterial object representing the material settings.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsSimpleLineMaterialSettings.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
QgsSimpleLineMaterialSettings()=default
Constructor for QgsSimpleLineMaterialSettings.
QString type() const override
Returns the unique type name for the material.
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
static QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
QgsMaterialSettingsRenderingTechnique
Material rendering techniques 3.
@ Points
Point based rendering, requires point data.
@ Triangles
Triangle based rendering (default)
@ TrianglesFromModel
Triangle based rendering, using a model object source.
@ Lines
Line based rendering, requires line data.
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering)