QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
20#include "qgsapplication.h"
22#include "qgsunittypes.h"
23
24#include <QString>
25#include <QThread>
26
27using namespace Qt::StringLiterals;
28
29//
30// QgsTiledSceneRenderContext
31//
32
34 : mRenderContext( context )
35 , mFeedback( feedback )
36{
37
38}
39
41{
42 return mTextureImage;
43}
44
46{
47 mTextureImage = image;
48}
49
50void QgsTiledSceneRenderContext::setTextureCoordinates( float textureX1, float textureY1, float textureX2, float textureY2, float textureX3, float textureY3 )
51{
52 mTextureCoordinates[0] = textureX1;
53 mTextureCoordinates[1] = textureY1;
54 mTextureCoordinates[2] = textureX2;
55 mTextureCoordinates[3] = textureY2;
56 mTextureCoordinates[4] = textureX3;
57 mTextureCoordinates[5] = textureY3;
58}
59
60void QgsTiledSceneRenderContext::textureCoordinates( float &textureX1, float &textureY1, float &textureX2, float &textureY2, float &textureX3, float &textureY3 ) const
61{
62 textureX1 = mTextureCoordinates[0];
63 textureY1 = mTextureCoordinates[1];
64 textureX2 = mTextureCoordinates[2];
65 textureY2 = mTextureCoordinates[3];
66 textureX3 = mTextureCoordinates[4];
67 textureY3 = mTextureCoordinates[5];
68}
69
70//
71// QgsTiledSceneRenderer
72//
73
78
80{
81 if ( element.isNull() )
82 return nullptr;
83
84 // load renderer
85 const QString rendererType = element.attribute( u"type"_s );
86
88 if ( !m )
89 return nullptr;
90
91 std::unique_ptr< QgsTiledSceneRenderer > r( m->createRenderer( element, context ) );
92 return r.release();
93}
94
96{
97#ifdef QGISDEBUG
98 if ( !mThread )
99 {
100 mThread = QThread::currentThread();
101 }
102 else
103 {
104 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsTiledSceneRenderer::startRender", "startRender called in a different thread - use a cloned renderer instead" );
105 }
106#endif
107}
108
110{
111#ifdef QGISDEBUG
112 Q_ASSERT_X( mThread == QThread::currentThread(), "QgsTiledSceneRenderer::stopRender", "stopRender called in a different thread - use a cloned renderer instead" );
113#endif
114}
115
117{
118 return mMaximumScreenError;
119}
120
122{
123 mMaximumScreenError = error;
124}
125
127{
128 return mMaximumScreenErrorUnit;
129}
130
132{
133 mMaximumScreenErrorUnit = unit;
134}
135
136QList<QgsLayerTreeModelLegendNode *> QgsTiledSceneRenderer::createLegendNodes( QgsLayerTreeLayer * )
137{
138 return QList<QgsLayerTreeModelLegendNode *>();
139}
140
142{
143 return QStringList();
144}
145
147{
148 destination->setMaximumScreenError( mMaximumScreenError );
149 destination->setMaximumScreenErrorUnit( mMaximumScreenErrorUnit );
150 destination->setTileBorderRenderingEnabled( mTileBorderRendering );
151}
152
154{
155 mMaximumScreenError = element.attribute( u"maximumScreenError"_s, u"3"_s ).toDouble();
156 mMaximumScreenErrorUnit = QgsUnitTypes::decodeRenderUnit( element.attribute( u"maximumScreenErrorUnit"_s, u"MM"_s ) );
157 mTileBorderRendering = element.attribute( u"tileBorderRendering"_s, u"0"_s ).toInt();
158}
159
160void QgsTiledSceneRenderer::saveCommonProperties( QDomElement &element, const QgsReadWriteContext & ) const
161{
162 element.setAttribute( u"maximumScreenError"_s, qgsDoubleToString( mMaximumScreenError ) );
163 element.setAttribute( u"maximumScreenErrorUnit"_s, QgsUnitTypes::encodeUnit( mMaximumScreenErrorUnit ) );
164 element.setAttribute( u"tileBorderRendering"_s, mTileBorderRendering ? 1 : 0 );
165}
@ RendersLines
Renderer can render line primitives.
Definition qgis.h:5994
@ RendersTriangles
Renderer can render triangle primitives.
Definition qgis.h:5993
RenderUnit
Rendering size units.
Definition qgis.h:5279
QFlags< TiledSceneRendererFlag > TiledSceneRendererFlags
Flags which control how tiled scene 2D renderers behave.
Definition qgis.h:6003
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.
A container for the context for various read/write operations on 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.
QgsFeedback * feedback() const
Returns the feedback object used to cancel rendering.
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.
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.
QgsTiledSceneRenderer()=default
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:6841