QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsannotationlayer3drenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsannotationlayer3drenderer.cpp
3 --------------------------------------
4 Date : January 2020
5 Copyright : (C) 2020 by Martin Dobias
6 Email : wonder dot sk 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
18#include "qgis.h"
19#include "qgsannotationlayer.h"
21#include "qgsstyle.h"
22
23//
24// QgsAnnotationLayer3DRendererMetadata
25//
26
31
33{
34 auto r = std::make_unique< QgsAnnotationLayer3DRenderer >();
35 r->readXml( elem, context );
36 return r.release();
37}
38
39
40//
41// QgsAnnotationLayer3DRenderer
42//
43
45{
47 mTextFormat.setNamedStyle( QStringLiteral( "Bold" ) );
48 mTextFormat.setSize( 20 );
49}
50
55
57{
58 return qobject_cast<QgsAnnotationLayer *>( mLayerRef.layer );
59}
60
62{
63 mLayerRef.resolve( &project );
64}
65
67{
68 return mShowCalloutLines;
69}
70
72{
73 mShowCalloutLines = show;
74}
75
77{
78 mCalloutLineColor = color;
79}
80
82{
83 return mCalloutLineColor;
84}
85
87{
88 mCalloutLineWidth = width;
89}
90
92{
93 return mCalloutLineWidth;
94}
95
97{
98 return mTextFormat;
99}
100
102{
103 mTextFormat = format;
104}
105
107{
108 return "annotation";
109}
110
112{
113 auto r = std::make_unique< QgsAnnotationLayer3DRenderer >();
114 r->mLayerRef = mLayerRef;
115 r->mAltClamping = mAltClamping;
116 r->mZOffset = mZOffset;
117 r->mShowCalloutLines = mShowCalloutLines;
118 r->mCalloutLineColor = mCalloutLineColor;
119 r->mCalloutLineWidth = mCalloutLineWidth;
120 r->mTextFormat = mTextFormat;
121 return r.release();
122}
123
125{
127
128 if ( !l )
129 return nullptr;
130
131 // For some cases we start with a maximal z range because we can't know this upfront, as it potentially involves terrain heights.
132 // This range will be refined after populating the nodes to the actual z range of the generated chunks nodes.
133 // Assuming the vertical height is in meter, then it's extremely unlikely that a real vertical
134 // height will exceed this amount!
135 constexpr double MINIMUM_ANNOTATION_Z_ESTIMATE = -100000;
136 constexpr double MAXIMUM_ANNOTATION_Z_ESTIMATE = 100000;
137
138 double minimumZ = MINIMUM_ANNOTATION_Z_ESTIMATE;
139 double maximumZ = MAXIMUM_ANNOTATION_Z_ESTIMATE;
140 switch ( mAltClamping )
141 {
143 // special case where we DO know the exact z range upfront!
144 minimumZ = mZOffset;
145 maximumZ = mZOffset;
146 break;
147
150 break;
151 }
152
153 return new QgsAnnotationLayerChunkedEntity( map, l, mAltClamping, mZOffset, mShowCalloutLines, mCalloutLineColor, mCalloutLineWidth, mTextFormat, minimumZ, maximumZ );
154}
155
156void QgsAnnotationLayer3DRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
157{
158 QDomDocument doc = elem.ownerDocument();
159
160 elem.setAttribute( QStringLiteral( "layer" ), mLayerRef.layerId );
161 elem.setAttribute( QStringLiteral( "clamping" ), qgsEnumValueToKey( mAltClamping ) );
162 elem.setAttribute( QStringLiteral( "offset" ), mZOffset );
163 if ( mShowCalloutLines )
164 elem.setAttribute( QStringLiteral( "callouts" ), QStringLiteral( "1" ) );
165
166 if ( mTextFormat.isValid() )
167 {
168 elem.appendChild( mTextFormat.writeXml( doc, context ) );
169 }
170}
171
172void QgsAnnotationLayer3DRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
173{
174 mLayerRef = QgsMapLayerRef( elem.attribute( QStringLiteral( "layer" ) ) );
175 mAltClamping = qgsEnumKeyToValue( elem.attribute( QStringLiteral( "clamping" ) ), Qgis::AltitudeClamping::Relative );
176 mZOffset = elem.attribute( QStringLiteral( "offset" ), QString::number( DEFAULT_Z_OFFSET ) ).toDouble();
177 mShowCalloutLines = elem.attribute( QStringLiteral( "callouts" ), QStringLiteral( "0" ) ).toInt();
178 if ( !elem.firstChildElement( QStringLiteral( "text-style" ) ).isNull() )
179 {
180 mTextFormat = QgsTextFormat();
181 mTextFormat.readXml( elem.firstChildElement( QStringLiteral( "text-style" ) ), context );
182 }
183}
@ Relative
Elevation is relative to terrain height (final elevation = terrain elevation + feature elevation).
Definition qgis.h:3984
@ Terrain
Elevation is clamped to terrain (final elevation = terrain elevation).
Definition qgis.h:3985
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
Definition qgis.h:3983
Definition of the world.
Qgs3DRendererAbstractMetadata(const QString &type)
Constructor of the base class.
Base class for all renderers that participate in 3D views.
QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context) override
Creates an instance of a 3D renderer based on a DOM element with renderer configuration.
QString type() const override
Returns unique identifier of the renderer class (used to identify subclass).
Qt3DCore::QEntity * createEntity(Qgs3DMapSettings *map) const override
Returns a 3D entity that will be used to show renderer's data in 3D scene.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
QColor calloutLineColor() const
Returns the callout line color.
void setCalloutLineColor(const QColor &color)
Sets the callout line color.
void setShowCalloutLines(bool show)
Sets whether callout lines are shown, vertically joining the annotations to the terrain.
QgsTextFormat textFormat() const
Returns the text format to use for rendering text annotations in 3D.
void resolveReferences(const QgsProject &project) override
Resolves references to other objects - second phase of loading - after readXml().
double calloutLineWidth() const
Returns the callout line width.
QgsAnnotationLayer * layer() const
Returns the annotation layer associated with the renderer.
bool showCalloutLines() const
Returns true if callout lines are shown, vertically joining the annotations to the terrain.
void setCalloutLineWidth(double width)
Sets the callout line width.
void setLayer(QgsAnnotationLayer *layer)
Sets the annotation layer associated with the renderer.
void setTextFormat(const QgsTextFormat &format)
Sets the text format to use for rendering text annotations in 3D.
QgsAnnotationLayer3DRenderer * clone() const override
Returns a cloned instance.
Represents a map layer containing a set of georeferenced annotations, e.g.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
A container for the context for various read/write operations on objects.
QgsTextFormat defaultTextFormat(QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling) const
Returns the default text format to use for new text based objects in the specified context.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the default application-wide style.
Definition qgsstyle.cpp:147
Container for all settings relating to text rendering.
void setNamedStyle(const QString &style)
Sets the named style for the font used for rendering text.
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:6817
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6798
_LayerRef< QgsMapLayer > QgsMapLayerRef