33 return QStringLiteral(
"wireframe" );
38 std::unique_ptr< QgsTiledSceneWireframeRenderer > res = std::make_unique< QgsTiledSceneWireframeRenderer >();
40 res->setFillSymbol( mFillSymbol->clone() );
41 res->setLineSymbol( mLineSymbol->clone() );
42 res->setUseTextureColors( mUseTextureColors );
51 std::unique_ptr< QgsTiledSceneWireframeRenderer > r = std::make_unique< QgsTiledSceneWireframeRenderer >();
53 const QDomElement fillSymbolElem = element.firstChildElement( QStringLiteral(
"fillSymbol" ) );
54 if ( !fillSymbolElem.isNull() )
56 const QDomElement symbolElem = fillSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
57 std::unique_ptr< QgsFillSymbol >
fillSymbol( QgsSymbolLayerUtils::loadSymbol<QgsFillSymbol>( symbolElem, context ) );
63 const QDomElement lineSymbolElem = element.firstChildElement( QStringLiteral(
"lineSymbol" ) );
64 if ( !lineSymbolElem.isNull() )
66 const QDomElement symbolElem = lineSymbolElem.firstChildElement( QStringLiteral(
"symbol" ) );
67 std::unique_ptr< QgsLineSymbol >
lineSymbol( QgsSymbolLayerUtils::loadSymbol<QgsLineSymbol>( symbolElem, context ) );
73 r->setUseTextureColors( element.attribute( QStringLiteral(
"useTextureColors" ), QStringLiteral(
"0" ) ).toInt() );
75 r->restoreCommonProperties( element, context );
81 QVariantMap properties;
82 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"white" ) );
83 properties.insert( QStringLiteral(
"style" ), QStringLiteral(
"solid" ) );
84 properties.insert( QStringLiteral(
"style_border" ), QStringLiteral(
"solid" ) );
85 properties.insert( QStringLiteral(
"color_border" ), QStringLiteral(
"black" ) );
86 properties.insert( QStringLiteral(
"width_border" ), QStringLiteral(
"0.3" ) );
87 properties.insert( QStringLiteral(
"joinstyle" ), QStringLiteral(
"miter" ) );
94 return mFillSymbol.get();
99 mFillSymbol.reset( symbol );
104 QVariantMap properties;
105 properties.insert( QStringLiteral(
"color" ), QStringLiteral(
"red" ) );
112 return mLineSymbol.get();
117 mLineSymbol.reset( symbol );
122 return mUseTextureColors;
127 mUseTextureColors = newUseTextureColors;
132 QDomElement rendererElem = doc.createElement( QStringLiteral(
"renderer" ) );
134 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"wireframe" ) );
135 rendererElem.setAttribute( QStringLiteral(
"useTextureColors" ), mUseTextureColors ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
138 QDomElement fillSymbolElem = doc.createElement( QStringLiteral(
"fillSymbol" ) );
143 fillSymbolElem.appendChild( symbolElement );
144 rendererElem.appendChild( fillSymbolElem );
147 QDomElement lineSymbolElem = doc.createElement( QStringLiteral(
"lineSymbol" ) );
152 lineSymbolElem.appendChild( symbolElement );
153 rendererElem.appendChild( lineSymbolElem );
162 if ( mUseTextureColors )
164 std::unique_ptr< QgsFillSymbol > s( mFillSymbol->clone() );
166 if ( !textureImage.isNull() )
174 context.
textureCoordinates( textureX1, textureY1, textureX2, textureY2, textureX3, textureY3 );
176 const QColor centerColor( textureImage.pixelColor(
177 static_cast<int>( ( ( textureX1 + textureX2 + textureX3 ) / 3 ) * ( textureImage.width() - 1 ) ),
178 static_cast< int >( ( ( textureY1 + textureY2 + textureY3 ) / 3 ) * ( textureImage.height() - 1 ) ) )
180 s->setColor( centerColor );
183 s->renderPolygon( triangle,
nullptr,
nullptr, context.
renderContext() );
188 mFillSymbol->renderPolygon( triangle,
nullptr,
nullptr, context.
renderContext() );
194 mLineSymbol->renderPolyline( line,
nullptr, context.
renderContext() );
201 if ( !mUseTextureColors )
209 if ( !mUseTextureColors )
222 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 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 QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
The class is used as a container of context for various read/write operations on other objects.
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.
Abstract base class for 2d tiled scene renderers.
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.
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.
~QgsTiledSceneWireframeRenderer()
void startRender(QgsTiledSceneRenderContext &context) override
Must be called when a new render cycle is started.
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.
static QgsLineSymbol * createDefaultLineSymbol()
Returns a copy of the default line symbol used to render lines in the wireframe.
void renderLine(QgsTiledSceneRenderContext &context, const QPolygonF &line) override
Renders a line.
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.
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.
static QgsFillSymbol * createDefaultFillSymbol()
Returns a copy of the default fill symbol used to render triangles in the wireframe.