QGIS API Documentation 3.29.0-Master (ade4f0cf0f)
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;
21
22#include <QDomElement>
23#include <QMetaEnum>
24
25#include "qgis_core.h"
26#include "qgis_sip.h"
27#include "qgsunittypes.h"
28
29
30
35class CORE_EXPORT QgsXmlUtils
36{
37 public:
38
39 /* reading */
40
47 static QgsUnitTypes::DistanceUnit readMapUnits( const QDomElement &element );
48
49 static QgsRectangle readRectangle( const QDomElement &element );
50
51 /* writing */
52
60 static QDomElement writeMapUnits( QgsUnitTypes::DistanceUnit units, QDomDocument &doc );
61
69 static QDomElement writeRectangle( const QgsRectangle &rect, QDomDocument &doc, const QString &elementName = QStringLiteral( "extent" ) );
70
83 static QDomElement writeVariant( const QVariant &value, QDomDocument &doc );
84
88 static QVariant readVariant( const QDomElement &element );
89
99 template<class T> static T readFlagAttribute( const QDomElement &element, const QString &attributeName, T defaultValue ) SIP_SKIP
100 {
101 T value = defaultValue;
102 // Get source categories
103 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
104 const QString sourceCategoriesStr( element.attribute( attributeName, metaEnum.valueToKeys( static_cast<int>( defaultValue ) ) ) );
105 if ( metaEnum.isValid() )
106 {
107 bool ok = false;
108 const int newValue = metaEnum.keysToValue( sourceCategoriesStr.toUtf8().constData(), &ok );
109 if ( ok )
110 value = static_cast<T>( newValue );
111 }
112 return value;
113 }
114};
115
116
117#endif // QGSXMLUTILS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:42
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
Assorted helper methods for reading and writing chunks of XML.
Definition: qgsxmlutils.h:36
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
Definition: qgsxmlutils.h:99
#define SIP_SKIP
Definition: qgis_sip.h:126