QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgs3daxissettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgs3daxissettings.cpp
3 --------------------------------------
4 Date : April 2022
5 copyright : (C) 2021 B. De Mezzo
6 email : benoit dot de dot mezzo at oslandia 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
16#include "qgs3daxissettings.h"
17
18#include <QDomDocument>
19
20#include "qgsreadwritecontext.h"
21#include "qgssymbollayerutils.h"
22
24 : mMode( other.mMode )
25 , mHorizontalPosition( other.mHorizontalPosition )
26 , mVerticalPosition( other.mVerticalPosition )
27{
28
29}
30
32{
33 this->mMode = rhs.mMode;
34 this->mHorizontalPosition = rhs.mHorizontalPosition;
35 this->mVerticalPosition = rhs.mVerticalPosition;
36 return *this;
37}
38
40{
41 bool out = true;
42 out &= this->mMode == rhs.mMode;
43 out &= this->mHorizontalPosition == rhs.mHorizontalPosition;
44 out &= this->mVerticalPosition == rhs.mVerticalPosition;
45 return out;
46}
47
49{
50 return ! this->operator==( rhs );
51}
52
53void Qgs3DAxisSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
54{
55 QString sizeStr = element.attribute( QStringLiteral( "defaultViewportSize" ) );
56 if ( !sizeStr.isEmpty() )
57 mDefaultViewportSize = sizeStr.toInt();
58
59 sizeStr = element.attribute( QStringLiteral( "minViewportRatio" ) );
60 if ( !sizeStr.isEmpty() )
61 mMinViewportRatio = sizeStr.toInt();
62
63 sizeStr = element.attribute( QStringLiteral( "maxViewportRatio" ) );
64 if ( !sizeStr.isEmpty() )
65 mMaxViewportRatio = sizeStr.toInt();
66
67 const QString modeStr = element.attribute( QStringLiteral( "mode" ) );
68 if ( modeStr == QLatin1String( "Off" ) )
70 else if ( modeStr == QLatin1String( "Crs" ) )
72 else if ( modeStr == QLatin1String( "Cube" ) )
74
75 const QString horizontalStr = element.attribute( QStringLiteral( "horizontal" ) );
76 if ( horizontalStr == QLatin1String( "Left" ) )
77 mHorizontalPosition = Qt::AnchorPoint::AnchorLeft;
78 else if ( horizontalStr == QLatin1String( "Middle" ) )
79 mHorizontalPosition = Qt::AnchorPoint::AnchorHorizontalCenter;
80 else if ( horizontalStr == QLatin1String( "Right" ) )
81 mHorizontalPosition = Qt::AnchorPoint::AnchorRight;
82
83 const QString verticalStr = element.attribute( QStringLiteral( "vertical" ) );
84 if ( verticalStr == QLatin1String( "Top" ) )
85 mVerticalPosition = Qt::AnchorPoint::AnchorTop;
86 else if ( verticalStr == QLatin1String( "Middle" ) )
87 mVerticalPosition = Qt::AnchorPoint::AnchorVerticalCenter;
88 else if ( verticalStr == QLatin1String( "Bottom" ) )
89 mVerticalPosition = Qt::AnchorPoint::AnchorBottom;
90}
91
92void Qgs3DAxisSettings::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
93{
94 QString str;
95
96 str = QString::number( mDefaultViewportSize );
97 element.setAttribute( QStringLiteral( "defaultViewportSize" ), str );
98
99 str = QString::number( mMinViewportRatio );
100 element.setAttribute( QStringLiteral( "minViewportRatio" ), str );
101
102 str = QString::number( mMaxViewportRatio );
103 element.setAttribute( QStringLiteral( "maxViewportRatio" ), str );
104
105 switch ( mMode )
106 {
108 str = QLatin1String( "Crs" );
109 break;
111 str = QLatin1String( "Cube" );
112 break;
113
115 default:
116 str = QLatin1String( "Off" );
117 break;
118 }
119 element.setAttribute( QStringLiteral( "mode" ), str );
120
121 switch ( mHorizontalPosition )
122 {
123 case Qt::AnchorPoint::AnchorLeft:
124 str = QLatin1String( "Left" );
125 break;
126 case Qt::AnchorPoint::AnchorHorizontalCenter:
127 str = QLatin1String( "Middle" );
128 break;
129 case Qt::AnchorPoint::AnchorRight:
130 default:
131 str = QLatin1String( "End" );
132 break;
133 }
134 element.setAttribute( QStringLiteral( "horizontal" ), str );
135
136 switch ( mVerticalPosition )
137 {
138 case Qt::AnchorPoint::AnchorBottom:
139 str = QLatin1String( "Bottom" );
140 break;
141 case Qt::AnchorPoint::AnchorVerticalCenter:
142 str = QLatin1String( "Middle" );
143 break;
144 case Qt::AnchorPoint::AnchorTop:
145 default:
146 str = QLatin1String( "Top" );
147 break;
148 }
149 element.setAttribute( QStringLiteral( "vertical" ), str );
150
151}
152
154{
155 if ( ratio < mMaxViewportRatio )
156 {
157 mMinViewportRatio = std::clamp( ratio, 0.0, 1.0 );
158 }
159}
160
162{
163 if ( ratio > mMinViewportRatio )
164 {
165 mMaxViewportRatio = std::clamp( ratio, 0.0, 1.0 );
166 }
167}
Contains the configuration of a 3d axis.
Qgs3DAxisSettings()=default
default constructor
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Qgs3DAxisSettings & operator=(Qgs3DAxisSettings const &rhs)
delete assignment operator
@ Crs
Respect CRS directions.
@ Cube
Abstract cube mode.
bool operator!=(Qgs3DAxisSettings const &rhs) const
Returns true if objects are not equal.
void setMinViewportRatio(double ratio)
Sets the minimal axis viewport ratio between 0-1.
bool operator==(Qgs3DAxisSettings const &rhs) const
Returns true if both objects are equal.
void setMaxViewportRatio(double ratio)
Sets the maximal axis viewport ratio between 0-1.
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
The class is used as a container of context for various read/write operations on other objects.
#define str(x)
Definition: qgis.cpp:37