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() )
108 case QVariant::Invalid:
110 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"invalid" ) );
116 QVariantMap map = value.toMap();
118 for (
auto option = map.constBegin(); option != map.constEnd(); ++option )
120 QDomElement optionElement =
writeVariant( option.value(), doc );
121 optionElement.setAttribute( QStringLiteral(
"name" ), option.key() );
122 element.appendChild( optionElement );
123 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"Map" ) );
130 QVariantList list = value.toList();
132 Q_FOREACH (
const QVariant &value, list )
135 element.appendChild( valueElement );
136 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"List" ) );
141 case QVariant::StringList:
143 QStringList list = value.toStringList();
145 Q_FOREACH (
const QString &value, list )
148 element.appendChild( valueElement );
149 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"StringList" ) );
156 case QVariant::Double:
157 case QVariant::String:
158 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
159 element.setAttribute( QStringLiteral(
"value" ), value.toString() );
162 case QVariant::UserType:
166 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProperty" ) );
168 element.appendChild( propertyElem );
173 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsCoordinateReferenceSystem" ) );
182 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", QStringLiteral(
"unsupported variant type %1" ).arg( QVariant::typeToName( value.type() ) ).toLocal8Bit() );
191 QString type = element.attribute( QStringLiteral(
"type" ) );
193 if ( type == QLatin1String(
"invalid" ) )
197 else if ( type == QLatin1String(
"int" ) )
199 return element.attribute( QStringLiteral(
"value" ) ).toInt();
201 else if ( type == QLatin1String(
"double" ) )
203 return element.attribute( QStringLiteral(
"value" ) ).toDouble();
205 else if ( type == QLatin1String(
"QString" ) )
207 return element.attribute( QStringLiteral(
"value" ) );
209 else if ( type == QLatin1String(
"bool" ) )
211 return element.attribute( QStringLiteral(
"value" ) ) == QLatin1String(
"true" );
213 else if ( type == QLatin1String(
"Map" ) )
216 QDomNodeList options = element.childNodes();
218 for (
int i = 0; i < options.count(); ++i )
220 QDomElement elem = options.at( i ).toElement();
221 if ( elem.tagName() == QLatin1String(
"Option" ) )
222 map.insert( elem.attribute( QStringLiteral(
"name" ) ),
readVariant( elem ) );
226 else if ( type == QLatin1String(
"List" ) )
229 QDomNodeList values = element.childNodes();
230 for (
int i = 0; i < values.count(); ++i )
232 QDomElement elem = values.at( i ).toElement();
237 else if ( type == QLatin1String(
"StringList" ) )
240 QDomNodeList values = element.childNodes();
241 for (
int i = 0; i < values.count(); ++i )
243 QDomElement elem = values.at( i ).toElement();
248 else if ( type == QLatin1String(
"QgsProperty" ) )
250 const QDomNodeList values = element.childNodes();
251 if ( values.isEmpty() )
260 else if ( type == QLatin1String(
"QgsCoordinateReferenceSystem" ) )
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.
const QgsCoordinateReferenceSystem & crs
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
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.
A store for object properties.
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.
This class represents a coordinate reference system (CRS).
double xMinimum() const
Returns the x minimum value (left side of rectangle).
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
double yMaximum() const
Returns the y maximum value (top side of rectangle).
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
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.