QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
18 class QDomDocument;
19 
20 class QgsRectangle;
21 
22 #include <QDomElement>
23 
24 #include "qgis_core.h"
25 #include "qgis.h"
26 #include "qgsunittypes.h"
27 
28 
29 
34 class CORE_EXPORT QgsXmlUtils
35 {
36  public:
37 
38  /* reading */
39 
46  static QgsUnitTypes::DistanceUnit readMapUnits( const QDomElement &element );
47 
48  static QgsRectangle readRectangle( const QDomElement &element );
49 
50  /* writing */
51 
59  static QDomElement writeMapUnits( QgsUnitTypes::DistanceUnit units, QDomDocument &doc );
60 
61  static QDomElement writeRectangle( const QgsRectangle &rect, QDomDocument &doc );
62 
75  static QDomElement writeVariant( const QVariant &value, QDomDocument &doc );
76 
80  static QVariant readVariant( const QDomElement &element );
81 
91  template<class T> static T readFlagAttribute( const QDomElement &element, const QString &attributeName, T defaultValue ) SIP_SKIP
92  {
93  T value = defaultValue;
94  // Get source categories
95  QMetaEnum metaEnum = QMetaEnum::fromType<T>();
96  QString sourceCategoriesStr( element.attribute( attributeName, metaEnum.valueToKeys( static_cast<int>( defaultValue ) ) ) );
97  if ( metaEnum.isValid() )
98  {
99  bool ok = false;
100  int newValue = metaEnum.keysToValue( sourceCategoriesStr.toUtf8().constData(), &ok );
101  if ( ok )
102  value = static_cast<T>( newValue );
103  }
104  return value;
105  }
106 };
107 
108 
109 #endif // QGSXMLUTILS_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Assorted helper methods for reading and writing chunks of XML.
Definition: qgsxmlutils.h:34
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
Definition: qgsxmlutils.h:91
#define SIP_SKIP
Definition: qgis_sip.h:119
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:53