QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
53 void Qgs3DAxisSettings::readXml( const QDomElement &element, const QgsReadWriteContext & )
54 {
55  const QString modeStr = element.attribute( QStringLiteral( "mode" ) );
56  if ( modeStr == QLatin1String( "Off" ) )
57  mMode = Qgs3DAxis::Mode::Off;
58  else if ( modeStr == QLatin1String( "Crs" ) )
59  mMode = Qgs3DAxis::Mode::Crs;
60  else if ( modeStr == QLatin1String( "Cube" ) )
61  mMode = Qgs3DAxis::Mode::Cube;
62 
63  const QString horizontalStr = element.attribute( QStringLiteral( "horizontal" ) );
64  if ( horizontalStr == QLatin1String( "Left" ) )
65  mHorizontalPosition = Qt::AnchorPoint::AnchorLeft;
66  else if ( horizontalStr == QLatin1String( "Middle" ) )
67  mHorizontalPosition = Qt::AnchorPoint::AnchorHorizontalCenter;
68  else if ( horizontalStr == QLatin1String( "Right" ) )
69  mHorizontalPosition = Qt::AnchorPoint::AnchorRight;
70 
71  const QString verticalStr = element.attribute( QStringLiteral( "vertical" ) );
72  if ( verticalStr == QLatin1String( "Top" ) )
73  mVerticalPosition = Qt::AnchorPoint::AnchorTop;
74  else if ( verticalStr == QLatin1String( "Middle" ) )
75  mVerticalPosition = Qt::AnchorPoint::AnchorVerticalCenter;
76  else if ( verticalStr == QLatin1String( "Bottom" ) )
77  mVerticalPosition = Qt::AnchorPoint::AnchorBottom;
78 }
79 
80 void Qgs3DAxisSettings::writeXml( QDomElement &element, const QgsReadWriteContext & ) const
81 {
82  QString str;
83  switch ( mMode )
84  {
86  str = QLatin1String( "Crs" );
87  break;
89  str = QLatin1String( "Cube" );
90  break;
91 
93  default:
94  str = QLatin1String( "Off" );
95  break;
96  }
97  element.setAttribute( QStringLiteral( "mode" ), str );
98 
99  switch ( mHorizontalPosition )
100  {
101  case Qt::AnchorPoint::AnchorLeft:
102  str = QLatin1String( "Left" );
103  break;
104  case Qt::AnchorPoint::AnchorHorizontalCenter:
105  str = QLatin1String( "Middle" );
106  break;
107  case Qt::AnchorPoint::AnchorRight:
108  default:
109  str = QLatin1String( "End" );
110  break;
111  }
112  element.setAttribute( QStringLiteral( "horizontal" ), str );
113 
114  switch ( mVerticalPosition )
115  {
116  case Qt::AnchorPoint::AnchorBottom:
117  str = QLatin1String( "Bottom" );
118  break;
119  case Qt::AnchorPoint::AnchorVerticalCenter:
120  str = QLatin1String( "Middle" );
121  break;
122  case Qt::AnchorPoint::AnchorTop:
123  default:
124  str = QLatin1String( "Top" );
125  break;
126  }
127  element.setAttribute( QStringLiteral( "vertical" ), str );
128 
129 }
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
Qgs3DAxisSettings::operator=
Qgs3DAxisSettings & operator=(Qgs3DAxisSettings const &rhs)
delete assignment operator
Definition: qgs3daxissettings.cpp:31
Qgs3DAxisSettings::readXml
void readXml(const QDomElement &element, const QgsReadWriteContext &context)
Reads settings from a DOM element.
Definition: qgs3daxissettings.cpp:53
qgsreadwritecontext.h
qgssymbollayerutils.h
Qgs3DAxis::Mode::Cube
@ Cube
Abstract cube mode.
Qgs3DAxisSettings
Contains the configuration of a 3d axis.
Definition: qgs3daxissettings.h:35
Qgs3DAxisSettings::operator==
bool operator==(Qgs3DAxisSettings const &rhs) const
Returns true if both objects are equal.
Definition: qgs3daxissettings.cpp:39
Qgs3DAxisSettings::operator!=
bool operator!=(Qgs3DAxisSettings const &rhs) const
Returns true if objects are not equal.
Definition: qgs3daxissettings.cpp:48
Qgs3DAxisSettings::writeXml
void writeXml(QDomElement &element, const QgsReadWriteContext &context) const
Writes settings to a DOM element.
Definition: qgs3daxissettings.cpp:80
Qgs3DAxis::Mode::Crs
@ Crs
Respect CRS directions.
str
#define str(x)
Definition: qgis.cpp:37
qgs3daxissettings.h
Qgs3DAxis::Mode::Off
@ Off
Hide 3d axis.
Qgs3DAxisSettings::Qgs3DAxisSettings
Qgs3DAxisSettings()=default
default constructor