QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 {
50  return new QgsSimpleLineMaterialSettings();
51 }
52 
54 {
55  return new QgsSimpleLineMaterialSettings( *this );
56 }
57 
58 void QgsSimpleLineMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext & )
59 {
60  mAmbient = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) );
61 }
62 
63 void 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 
102 void 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 }
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:64
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
qgssymbollayerutils.h
QgsSimpleLineMaterialSettings::create
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsSimpleLineMaterialSettings.
Definition: qgssimplelinematerialsettings.cpp:48
QgsMaterialSettingsRenderingTechnique::InstancedPoints
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:69
QgsSimpleLineMaterialSettings::QgsSimpleLineMaterialSettings
QgsSimpleLineMaterialSettings()=default
Constructor for QgsSimpleLineMaterialSettings.
QgsSimpleLineMaterialSettings::supportsTechnique
static bool supportsTechnique(QgsMaterialSettingsRenderingTechnique technique)
Returns true if the specified technique is supported by the material.
Definition: qgssimplelinematerialsettings.cpp:30
QgsMaterialContext::selectionColor
QColor selectionColor() const
Returns the color for representing materials in a selected state.
Definition: qgsabstractmaterialsettings.h:87
QgsMaterialContext
Context settings for a material.
Definition: qgsabstractmaterialsettings.h:64
qgslinematerial_p.h
qgssimplelinematerialsettings.h
QgsAbstractMaterialSettings
Abstract base class for material settings.
Definition: qgsabstractmaterialsettings.h:114
QgsMaterialSettingsRenderingTechnique::Lines
@ Lines
Line based rendering, requires line data.
QgsSimpleLineMaterialSettings::clone
QgsSimpleLineMaterialSettings * clone() const override
Clones the material settings.
Definition: qgssimplelinematerialsettings.cpp:53
QgsSimpleLineMaterialSettings::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
Definition: qgssimplelinematerialsettings.cpp:58
QgsMaterialSettingsRenderingTechnique::Triangles
@ Triangles
Triangle based rendering (default)
QgsMaterialSettingsRenderingTechnique::TrianglesWithFixedTexture
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering)
QgsSimpleLineMaterialSettings::toExportParameters
QMap< QString, QString > toExportParameters() const override
Returns the parameters to be exported to .mtl file.
Definition: qgssimplelinematerialsettings.cpp:95
QgsMaterialSettingsRenderingTechnique
QgsMaterialSettingsRenderingTechnique
Material rendering techniques.
Definition: qgsabstractmaterialsettings.h:43
QgsSimpleLineMaterialSettings
Basic shading material used for rendering simple lines as solid line components.
Definition: qgssimplelinematerialsettings.h:36
QgsSimpleLineMaterialSettings::addParametersToEffect
void addParametersToEffect(Qt3DRender::QEffect *effect) const override
Adds parameters from the material to a destination effect.
Definition: qgssimplelinematerialsettings.cpp:102
QgsMaterialSettingsRenderingTechnique::TrianglesDataDefined
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
QgsMaterialSettingsRenderingTechnique::TrianglesFromModel
@ TrianglesFromModel
Triangle based rendering, using a model object source.
QgsSimpleLineMaterialSettings::writeXml
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
Definition: qgssimplelinematerialsettings.cpp:63
QgsMaterialSettingsRenderingTechnique::Points
@ Points
Point based rendering, requires point data.
QgsSimpleLineMaterialSettings::type
QString type() const override
Returns the unique type name for the material.
Definition: qgssimplelinematerialsettings.cpp:25
QgsSimpleLineMaterialSettings::toMaterial
Qt3DRender::QMaterial * toMaterial(QgsMaterialSettingsRenderingTechnique technique, const QgsMaterialContext &context) const override
Creates a new QMaterial object representing the material settings.
Definition: qgssimplelinematerialsettings.cpp:68
QgsMaterialContext::isSelected
bool isSelected() const
Returns true if the material should represent a selected state.
Definition: qgsabstractmaterialsettings.h:73