26using namespace Qt::StringLiterals;
38 return u
"wireframe"_s;
43 auto res = std::make_unique< QgsTiledSceneWireframeRenderer >();
45 res->setFillSymbol( mFillSymbol->clone() );
46 res->setLineSymbol( mLineSymbol->clone() );
47 res->setUseTextureColors( mUseTextureColors );
56 auto r = std::make_unique< QgsTiledSceneWireframeRenderer >();
58 const QDomElement fillSymbolElem = element.firstChildElement( u
"fillSymbol"_s );
59 if ( !fillSymbolElem.isNull() )
61 const QDomElement symbolElem = fillSymbolElem.firstChildElement( u
"symbol"_s );
68 const QDomElement lineSymbolElem = element.firstChildElement( u
"lineSymbol"_s );
69 if ( !lineSymbolElem.isNull() )
71 const QDomElement symbolElem = lineSymbolElem.firstChildElement( u
"symbol"_s );
78 r->setUseTextureColors( element.attribute( u
"useTextureColors"_s, u
"0"_s ).toInt() );
80 r->restoreCommonProperties( element, context );
86 QVariantMap properties;
87 properties.insert( u
"color"_s, u
"white"_s );
88 properties.insert( u
"style"_s, u
"solid"_s );
89 properties.insert( u
"style_border"_s, u
"solid"_s );
90 properties.insert( u
"color_border"_s, u
"black"_s );
91 properties.insert( u
"width_border"_s, u
"0.3"_s );
92 properties.insert( u
"joinstyle"_s, u
"miter"_s );
99 return mFillSymbol.get();
104 mFillSymbol.reset( symbol );
109 QVariantMap properties;
110 properties.insert( u
"color"_s, u
"red"_s );
117 return mLineSymbol.get();
122 mLineSymbol.reset( symbol );
127 return mUseTextureColors;
132 mUseTextureColors = newUseTextureColors;
137 QDomElement rendererElem = doc.createElement( u
"renderer"_s );
139 rendererElem.setAttribute( u
"type"_s, u
"wireframe"_s );
140 rendererElem.setAttribute( u
"useTextureColors"_s, mUseTextureColors ? u
"1"_s : u
"0"_s );
143 QDomElement fillSymbolElem = doc.createElement( u
"fillSymbol"_s );
148 fillSymbolElem.appendChild( symbolElement );
149 rendererElem.appendChild( fillSymbolElem );
152 QDomElement lineSymbolElem = doc.createElement( u
"lineSymbol"_s );
157 lineSymbolElem.appendChild( symbolElement );
158 rendererElem.appendChild( lineSymbolElem );
167 if ( mUseTextureColors )
169 std::unique_ptr< QgsFillSymbol > s( mFillSymbol->clone() );
171 if ( !textureImage.isNull() )
179 context.
textureCoordinates( textureX1, textureY1, textureX2, textureY2, textureX3, textureY3 );
181 const QColor centerColor( textureImage.pixelColor(
182 static_cast<int>( ( ( textureX1 + textureX2 + textureX3 ) / 3 ) * ( textureImage.width() - 1 ) ),
183 static_cast< int >( ( ( textureY1 + textureY2 + textureY3 ) / 3 ) * ( textureImage.height() - 1 ) ) )
185 s->setColor( centerColor );
188 s->renderPolygon( triangle,
nullptr,
nullptr, context.
renderContext() );
193 mFillSymbol->renderPolygon( triangle,
nullptr,
nullptr, context.
renderContext() );
199 mLineSymbol->renderPolyline( line,
nullptr, context.
renderContext() );
206 if ( !mUseTextureColors )
214 if ( !mUseTextureColors )
227 if ( mUseTextureColors )
@ RendersLines
Renderer can render line primitives.
@ RequiresTextures
Renderer requires textures.
@ RendersTriangles
Renderer can render triangle primitives.
QFlags< TiledSceneRendererFlag > TiledSceneRendererFlags
Flags which control how tiled scene 2D renderers behave.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
static std::unique_ptr< QgsFillSymbol > createSimple(const QVariantMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties.
A line symbol type, for rendering LineString and MultiLineString geometries.
static std::unique_ptr< QgsLineSymbol > createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
A container for the context for various read/write operations on objects.
static std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
Encapsulates the render context for a 2D tiled scene rendering operation.
void textureCoordinates(float &textureX1, float &textureY1, float &textureX2, float &textureY2, float &textureX3, float &textureY3) const
Returns the current texture coordinates.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
QImage textureImage() const
Returns the current texture image.
void saveCommonProperties(QDomElement &element, const QgsReadWriteContext &context) const
Saves common renderer properties (such as point size and screen error) to the specified DOM element.
virtual void stopRender(QgsTiledSceneRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsTiledSceneRenderer()=default
virtual void startRender(QgsTiledSceneRenderContext &context)
Must be called when a new render cycle is started.
void copyCommonProperties(QgsTiledSceneRenderer *destination) const
Copies common tiled scene renderer properties (such as screen error) to the destination renderer.
Qgis::TiledSceneRendererFlags flags() const override
Returns flags which control how the renderer behaves.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Saves the renderer configuration to an XML element.
void startRender(QgsTiledSceneRenderContext &context) override
Must be called when a new render cycle is started.
~QgsTiledSceneWireframeRenderer() override
QString type() const override
Returns the identifier of the renderer type.
void renderTriangle(QgsTiledSceneRenderContext &context, const QPolygonF &triangle) override
Renders a triangle.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the fill symbol used to render triangles in the wireframe.
void renderLine(QgsTiledSceneRenderContext &context, const QPolygonF &line) override
Renders a line.
static std::unique_ptr< QgsLineSymbol > createDefaultLineSymbol()
Returns a copy of the default line symbol used to render lines in the wireframe.
void stopRender(QgsTiledSceneRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
static QgsTiledSceneRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a textured renderer from an XML element.
void setLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol used to render lines in the wireframe.
static std::unique_ptr< QgsFillSymbol > createDefaultFillSymbol()
Returns a copy of the default fill symbol used to render triangles in the wireframe.
QgsTiledSceneWireframeRenderer()
Constructor for QgsTiledSceneWireframeRenderer.
QgsFillSymbol * fillSymbol() const
Returns the fill symbol used to render triangles in the wireframe.
QgsLineSymbol * lineSymbol() const
Returns the line symbol used to render lines in the wireframe.
void setUseTextureColors(bool enabled)
Sets whether representative colors from the textures should be used to recolor the symbols used to re...
bool useTextureColors() const
Returns true if representative colors from the textures will be used to recolor the symbols used to r...
QgsTiledSceneRenderer * clone() const override
Create a deep copy of this renderer.