QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgstiledscenerenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledscenerenderer.cpp
3 --------------------
4 begin : August 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "qgsunittypes.h"
20#include "qgsapplication.h"
22
23#include <QThread>
24
25//
26// QgsTiledSceneRenderContext
27//
28
30 : mRenderContext( context )
31 , mFeedback( feedback )
32{
33
34}
35
37{
38 return mTextureImage;
39}
40
42{
43 mTextureImage = image;
44}
45
46void QgsTiledSceneRenderContext::setTextureCoordinates( float textureX1, float textureY1, float textureX2, float textureY2, float textureX3, float textureY3 )
47{
48 mTextureCoordinates[0] = textureX1;
49 mTextureCoordinates[1] = textureY1;
50 mTextureCoordinates[2] = textureX2;
51 mTextureCoordinates[3] = textureY2;
52 mTextureCoordinates[4] = textureX3;
53 mTextureCoordinates[5] = textureY3;
54}
55
56void QgsTiledSceneRenderContext::textureCoordinates( float &textureX1, float &textureY1, float &textureX2, float &textureY2, float &textureX3, float &textureY3 ) const
57{
58 textureX1 = mTextureCoordinates[0];
59 textureY1 = mTextureCoordinates[1];
60 textureX2 = mTextureCoordinates[2];
61 textureY2 = mTextureCoordinates[3];
62 textureX3 = mTextureCoordinates[4];
63 textureY3 = mTextureCoordinates[5];
64}
65
66//
67// QgsTiledSceneRenderer
68//
69
74
76{
77 if ( element.isNull() )
78 return nullptr;
79
80 // load renderer
81 const QString rendererType = element.attribute( QStringLiteral( "type" ) );
82
84 if ( !m )
85 return nullptr;
86
87 std::unique_ptr< QgsTiledSceneRenderer > r( m->createRenderer( element, context ) );
88 return r.release();
89}
90
92{
93#ifdef QGISDEBUG
94 if ( !mThread )
95 {
96 mThread = QThread::currentThread();
97 }
98 else
99 {
100 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsTiledSceneRenderer::startRender", "startRender called in a different thread - use a cloned renderer instead" );
101 }
102#endif
103}
104
106{
107#ifdef QGISDEBUG
108 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsTiledSceneRenderer::stopRender", "stopRender called in a different thread - use a cloned renderer instead" );
109#endif
110}
111
113{
114 return mMaximumScreenError;
115}
116
118{
119 mMaximumScreenError = error;
120}
121
123{
124 return mMaximumScreenErrorUnit;
125}
126
128{
129 mMaximumScreenErrorUnit = unit;
130}
131
132QList<QgsLayerTreeModelLegendNode *> QgsTiledSceneRenderer::createLegendNodes( QgsLayerTreeLayer * )
133{
134 return QList<QgsLayerTreeModelLegendNode *>();
135}
136
138{
139 return QStringList();
140}
141
143{
144 destination->setMaximumScreenError( mMaximumScreenError );
145 destination->setMaximumScreenErrorUnit( mMaximumScreenErrorUnit );
146 destination->setTileBorderRenderingEnabled( mTileBorderRendering );
147}
148
150{
151 mMaximumScreenError = element.attribute( QStringLiteral( "maximumScreenError" ), QStringLiteral( "3" ) ).toDouble();
152 mMaximumScreenErrorUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( QStringLiteral( "maximumScreenErrorUnit" ), QStringLiteral( "MM" ) ) );
153 mTileBorderRendering = element.attribute( QStringLiteral( "tileBorderRendering" ), QStringLiteral( "0" ) ).toInt();
154}
155
156void QgsTiledSceneRenderer::saveCommonProperties( QDomElement &element, const QgsReadWriteContext & ) const
157{
158 element.setAttribute( QStringLiteral( "maximumScreenError" ), qgsDoubleToString( mMaximumScreenError ) );
159 element.setAttribute( QStringLiteral( "maximumScreenErrorUnit" ), QgsUnitTypes::encodeUnit( mMaximumScreenErrorUnit ) );
160 element.setAttribute( QStringLiteral( "tileBorderRendering" ), mTileBorderRendering ? 1 : 0 );
161}
@ RendersLines
Renderer can render line primitives.
@ RendersTriangles
Renderer can render triangle primitives.
RenderUnit
Rendering size units.
Definition qgis.h:4839
QFlags< TiledSceneRendererFlag > TiledSceneRendererFlags
Flags which control how tiled scene 2D renderers behave.
Definition qgis.h:5303
static QgsTiledSceneRendererRegistry * tiledSceneRendererRegistry()
Returns the application's tiled scene renderer registry, used for managing tiled scene layer 2D rende...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Layer tree node points to a map layer.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
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.
void setTextureImage(const QImage &image)
Sets the current texture image.
void setTextureCoordinates(float textureX1, float textureY1, float textureX2, float textureY2, float textureX3, float textureY3)
Sets the current texture coordinates.
QImage textureImage() const
Returns the current texture image.
QgsTiledSceneRenderContext(QgsRenderContext &context, QgsFeedback *feedback=nullptr)
Constructor for QgsTiledSceneRenderContext.
Stores metadata about one tiled scene renderer class.
virtual QgsTiledSceneRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
QgsTiledSceneRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Abstract base class for 2d tiled scene renderers.
void setTileBorderRenderingEnabled(bool enabled)
Sets whether to render the borders of tiles.
virtual QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer)
Creates a set of legend nodes representing the renderer.
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.
void setMaximumScreenErrorUnit(Qgis::RenderUnit unit)
Sets the unit for the maximum screen error allowed when rendering the tiled scene.
Qgis::RenderUnit maximumScreenErrorUnit() const
Returns the unit for the maximum screen error allowed when rendering the tiled scene.
static QgsTiledSceneRenderer * load(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer from an XML element.
double maximumScreenError() const
Returns the maximum screen error allowed when rendering the tiled scene.
void setMaximumScreenError(double error)
Sets the maximum screen error allowed when rendering the tiled scene.
virtual void startRender(QgsTiledSceneRenderContext &context)
Must be called when a new render cycle is started.
void restoreCommonProperties(const QDomElement &element, const QgsReadWriteContext &context)
Restores common renderer properties (such as screen error) from the specified DOM element.
virtual Qgis::TiledSceneRendererFlags flags() const
Returns flags which control how the renderer behaves.
virtual QStringList legendRuleKeys() const
Returns a list of all rule keys for legend nodes created by the renderer.
void copyCommonProperties(QgsTiledSceneRenderer *destination) const
Copies common tiled scene renderer properties (such as screen error) to the destination renderer.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:5834