17 #include <QDomElement> 25 if (
"unknown" == element.text() )
40 QDomNode xminNode = element.namedItem( QStringLiteral(
"xmin" ) );
41 QDomNode yminNode = element.namedItem( QStringLiteral(
"ymin" ) );
42 QDomNode xmaxNode = element.namedItem( QStringLiteral(
"xmax" ) );
43 QDomNode ymaxNode = element.namedItem( QStringLiteral(
"ymax" ) );
45 QDomElement exElement = xminNode.toElement();
46 double xmin = exElement.text().toDouble();
49 exElement = yminNode.toElement();
50 double ymin = exElement.text().toDouble();
53 exElement = xmaxNode.toElement();
54 double xmax = exElement.text().toDouble();
57 exElement = ymaxNode.toElement();
58 double ymax = exElement.text().toDouble();
71 unitsString = QStringLiteral(
"unknown" );
73 QDomElement unitsNode = doc.createElement( QStringLiteral(
"units" ) );
74 unitsNode.appendChild( doc.createTextNode( unitsString ) );
80 QDomElement xMin = doc.createElement( QStringLiteral(
"xmin" ) );
81 QDomElement yMin = doc.createElement( QStringLiteral(
"ymin" ) );
82 QDomElement xMax = doc.createElement( QStringLiteral(
"xmax" ) );
83 QDomElement yMax = doc.createElement( QStringLiteral(
"ymax" ) );
90 xMin.appendChild( xMinText );
91 yMin.appendChild( yMinText );
92 xMax.appendChild( xMaxText );
93 yMax.appendChild( yMaxText );
95 QDomElement extentNode = doc.createElement( QStringLiteral(
"extent" ) );
96 extentNode.appendChild( xMin );
97 extentNode.appendChild( yMin );
98 extentNode.appendChild( xMax );
99 extentNode.appendChild( yMax );
105 QDomElement element = doc.createElement( QStringLiteral(
"Option" ) );
106 switch ( value.type() )
110 QVariantMap map = value.toMap();
112 for (
auto option = map.constBegin(); option != map.constEnd(); ++option )
114 QDomElement optionElement =
writeVariant( option.value(), doc );
115 optionElement.setAttribute( QStringLiteral(
"name" ), option.key() );
116 element.appendChild( optionElement );
117 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"Map" ) );
124 QVariantList list = value.toList();
126 Q_FOREACH (
const QVariant &value, list )
129 element.appendChild( valueElement );
130 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"List" ) );
135 case QVariant::StringList:
137 QStringList list = value.toStringList();
139 Q_FOREACH (
const QString &value, list )
142 element.appendChild( valueElement );
143 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"StringList" ) );
150 case QVariant::Double:
151 case QVariant::String:
152 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
153 element.setAttribute( QStringLiteral(
"value" ), value.toString() );
157 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"Unknown" ) );
158 element.setAttribute( QStringLiteral(
"value" ), value.toString() );
167 QString type = element.attribute( QStringLiteral(
"type" ) );
169 if ( type == QLatin1String(
"int" ) )
171 return element.attribute( QStringLiteral(
"value" ) ).toInt();
173 else if ( type == QLatin1String(
"double" ) )
175 return element.attribute( QStringLiteral(
"value" ) ).toDouble();
177 else if ( type == QLatin1String(
"QString" ) )
179 return element.attribute( QStringLiteral(
"value" ) );
181 else if ( type == QLatin1String(
"bool" ) )
183 return element.attribute( QStringLiteral(
"value" ) ) == QLatin1String(
"true" );
185 else if ( type == QLatin1String(
"Map" ) )
188 QDomNodeList options = element.childNodes();
190 for (
int i = 0; i < options.count(); ++i )
192 QDomElement elem = options.at( i ).toElement();
193 if ( elem.tagName() == QLatin1String(
"Option" ) )
194 map.insert( elem.attribute( QStringLiteral(
"name" ) ),
readVariant( elem ) );
198 else if ( type == QLatin1String(
"List" ) )
201 QDomNodeList values = element.childNodes();
202 for (
int i = 0; i < values.count(); ++i )
204 QDomElement elem = values.at( i ).toElement();
209 else if ( type == QLatin1String(
"StringList" ) )
212 QDomNodeList values = element.childNodes();
213 for (
int i = 0; i < values.count(); ++i )
215 QDomElement elem = values.at( i ).toElement();
A rectangle specified with double values.
void setXMaximum(double x)
Set the maximum x value.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
static QgsUnitTypes::DistanceUnit readMapUnits(const QDomElement &element)
Decodes a distance unit from a DOM element.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
void setYMinimum(double y)
Set the minimum y value.
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Degrees, for planar geographic CRS distance measurements.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
DistanceUnit
Units of distance.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
void setYMaximum(double y)
Set the maximum y value.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
static QgsRectangle readRectangle(const QDomElement &element)
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
void setXMinimum(double x)
Set the minimum x value.