QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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#include "qgsreadwritecontext.h"
18
19#include <QDomDocument>
20
22{
23 bool out = true;
24 out &= this->mMode == rhs.mMode;
25 out &= this->mHorizontalPosition == rhs.mHorizontalPosition;
26 out &= this->mVerticalPosition == rhs.mVerticalPosition;
27 out &= this->mDefaultViewportSize == rhs.mDefaultViewportSize;
28 out &= this->mMaxViewportRatio == rhs.mMaxViewportRatio;
29 out &= this->mMinViewportRatio == rhs.mMinViewportRatio;
30 return out;
31}
32
34{
35 return !this->operator==( rhs );
36}
37
38void Qgs3DAxisSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
39{
40 QString sizeStr = element.attribute( QStringLiteral( "defaultViewportSize" ) );
41 if ( !sizeStr.isEmpty() )
42 mDefaultViewportSize = sizeStr.toInt();
43
44 sizeStr = element.attribute( QStringLiteral( "minViewportRatio" ) );
45 if ( !sizeStr.isEmpty() )
46 mMinViewportRatio = sizeStr.toDouble();
47
48 sizeStr = element.attribute( QStringLiteral( "maxViewportRatio" ) );
49 if ( !sizeStr.isEmpty() )
50 mMaxViewportRatio = sizeStr.toDouble();
51
52 const QString modeStr = element.attribute( QStringLiteral( "mode" ) );
53 if ( modeStr == QLatin1String( "Off" ) )
55 else if ( modeStr == QLatin1String( "Crs" ) )
57 else if ( modeStr == QLatin1String( "Cube" ) )
59
60 const QString horizontalStr = element.attribute( QStringLiteral( "horizontal" ) );
61 if ( horizontalStr == QLatin1String( "Left" ) )
62 mHorizontalPosition = Qt::AnchorPoint::AnchorLeft;
63 else if ( horizontalStr == QLatin1String( "Middle" ) )
64 mHorizontalPosition = Qt::AnchorPoint::AnchorHorizontalCenter;
65 else if ( horizontalStr == QLatin1String( "Right" ) )
66 mHorizontalPosition = Qt::AnchorPoint::AnchorRight;
67
68 const QString verticalStr = element.attribute( QStringLiteral( "vertical" ) );
69 if ( verticalStr == QLatin1String( "Top" ) )
70 mVerticalPosition = Qt::AnchorPoint::AnchorTop;
71 else if ( verticalStr == QLatin1String( "Middle" ) )
72 mVerticalPosition = Qt::AnchorPoint::AnchorVerticalCenter;
73 else if ( verticalStr == QLatin1String( "Bottom" ) )
74 mVerticalPosition = Qt::AnchorPoint::AnchorBottom;
75}
76
77void Qgs3DAxisSettings::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
78{
79 QString str;
80
81 str = QString::number( mDefaultViewportSize );
82 element.setAttribute( QStringLiteral( "defaultViewportSize" ), str );
83
84 str = QString::number( mMinViewportRatio );
85 element.setAttribute( QStringLiteral( "minViewportRatio" ), str );
86
87 str = QString::number( mMaxViewportRatio );
88 element.setAttribute( QStringLiteral( "maxViewportRatio" ), str );
89
90 switch ( mMode )
91 {
93 str = QLatin1String( "Crs" );
94 break;
96 str = QLatin1String( "Cube" );
97 break;
98
100 default:
101 str = QLatin1String( "Off" );
102 break;
103 }
104 element.setAttribute( QStringLiteral( "mode" ), str );
105
106 switch ( mHorizontalPosition )
107 {
108 case Qt::AnchorPoint::AnchorLeft:
109 str = QLatin1String( "Left" );
110 break;
111 case Qt::AnchorPoint::AnchorHorizontalCenter:
112 str = QLatin1String( "Middle" );
113 break;
114 case Qt::AnchorPoint::AnchorRight:
115 default:
116 str = QLatin1String( "End" );
117 break;
118 }
119 element.setAttribute( QStringLiteral( "horizontal" ), str );
120
121 switch ( mVerticalPosition )
122 {
123 case Qt::AnchorPoint::AnchorBottom:
124 str = QLatin1String( "Bottom" );
125 break;
126 case Qt::AnchorPoint::AnchorVerticalCenter:
127 str = QLatin1String( "Middle" );
128 break;
129 case Qt::AnchorPoint::AnchorTop:
130 default:
131 str = QLatin1String( "Top" );
132 break;
133 }
134 element.setAttribute( QStringLiteral( "vertical" ), str );
135}
136
138{
139 if ( ratio < mMaxViewportRatio )
140 {
141 mMinViewportRatio = std::clamp( ratio, 0.0, 1.0 );
142 }
143}
144
146{
147 if ( ratio > mMinViewportRatio )
148 {
149 mMaxViewportRatio = std::clamp( ratio, 0.0, 1.0 );
150 }
151}
Contains the configuration of a 3d axis.
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
@ Crs
Respect CRS directions.
@ Cube
Abstract cube mode.
bool operator!=(Qgs3DAxisSettings const &rhs) const
void setMinViewportRatio(double ratio)
Sets the minimal axis viewport ratio between 0-1.
bool operator==(Qgs3DAxisSettings const &rhs) const
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.