QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsxmlutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsxmlutils.h
3 ---------------------
4 begin : December 2013
5 copyright : (C) 2013 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#ifndef QGSXMLUTILS_H
16#define QGSXMLUTILS_H
17
18class QDomDocument;
19
20class QgsRectangle;
21class QgsBox3D;
22
23#include <QDomElement>
24#include <QMetaEnum>
25
26#include "qgis_core.h"
27#include "qgis_sip.h"
28#include "qgis.h"
29
30
31
36class CORE_EXPORT QgsXmlUtils
37{
38 public:
39
40 /* reading */
41
48 static Qgis::DistanceUnit readMapUnits( const QDomElement &element );
49
50 static QgsRectangle readRectangle( const QDomElement &element );
51
58 static QgsBox3D readBox3D( const QDomElement &element );
59
60 /* writing */
61
69 static QDomElement writeMapUnits( Qgis::DistanceUnit units, QDomDocument &doc );
70
79 static QDomElement writeBox3D( const QgsBox3D &box, QDomDocument &doc, const QString &elementName = QStringLiteral( "extent3D" ) );
80
88 static QDomElement writeRectangle( const QgsRectangle &rect, QDomDocument &doc, const QString &elementName = QStringLiteral( "extent" ) );
89
102 static QDomElement writeVariant( const QVariant &value, QDomDocument &doc );
103
107 static QVariant readVariant( const QDomElement &element );
108
118 template<class T> static T readFlagAttribute( const QDomElement &element, const QString &attributeName, T defaultValue ) SIP_SKIP
119 {
120 T value = defaultValue;
121 // Get source categories
122 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
123 const QString sourceCategoriesStr( element.attribute( attributeName, metaEnum.valueToKeys( static_cast<int>( defaultValue ) ) ) );
124 if ( metaEnum.isValid() )
125 {
126 bool ok = false;
127 const int newValue = metaEnum.keysToValue( sourceCategoriesStr.toUtf8().constData(), &ok );
128 if ( ok )
129 value = static_cast<T>( newValue );
130 }
131 return value;
132 }
133};
134
135
136#endif // QGSXMLUTILS_H
DistanceUnit
Units of distance.
Definition qgis.h:4677
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
A rectangle specified with double values.
Assorted helper methods for reading and writing chunks of XML.
Definition qgsxmlutils.h:37
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
#define SIP_SKIP
Definition qgis_sip.h:126