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 const auto constList = list;
133 for (
const QVariant &value : constList )
136 element.appendChild( valueElement );
137 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"List" ) );
142 case QVariant::StringList:
144 QStringList list = value.toStringList();
146 const auto constList = list;
147 for (
const QString &value : constList )
150 element.appendChild( valueElement );
151 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"StringList" ) );
159 case QVariant::Double:
160 case QVariant::LongLong:
161 case QVariant::ULongLong:
162 case QVariant::String:
163 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
164 element.setAttribute( QStringLiteral(
"value" ), value.toString() );
167 case QVariant::UserType:
171 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProperty" ) );
173 element.appendChild( propertyElem );
178 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsCoordinateReferenceSystem" ) );
185 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsGeometry" ) );
187 element.setAttribute( QStringLiteral(
"value" ), geom.
asWkt() );
194 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", QStringLiteral(
"unsupported variant type %1" ).arg( QVariant::typeToName( value.type() ) ).toLocal8Bit() );
203 QString type = element.attribute( QStringLiteral(
"type" ) );
205 if ( type == QLatin1String(
"invalid" ) )
209 else if ( type == QLatin1String(
"int" ) )
211 return element.attribute( QStringLiteral(
"value" ) ).toInt();
213 else if ( type == QLatin1String(
"uint" ) )
215 return element.attribute( QStringLiteral(
"value" ) ).toUInt();
217 else if ( type == QLatin1String(
"qlonglong" ) )
219 return element.attribute( QStringLiteral(
"value" ) ).toLongLong();
221 else if ( type == QLatin1String(
"qulonglong" ) )
223 return element.attribute( QStringLiteral(
"value" ) ).toULongLong();
225 else if ( type == QLatin1String(
"double" ) )
227 return element.attribute( QStringLiteral(
"value" ) ).toDouble();
229 else if ( type == QLatin1String(
"QString" ) )
231 return element.attribute( QStringLiteral(
"value" ) );
233 else if ( type == QLatin1String(
"bool" ) )
235 return element.attribute( QStringLiteral(
"value" ) ) == QLatin1String(
"true" );
237 else if ( type == QLatin1String(
"Map" ) )
240 QDomNodeList options = element.childNodes();
242 for (
int i = 0; i < options.count(); ++i )
244 QDomElement elem = options.at( i ).toElement();
245 if ( elem.tagName() == QLatin1String(
"Option" ) )
246 map.insert( elem.attribute( QStringLiteral(
"name" ) ),
readVariant( elem ) );
250 else if ( type == QLatin1String(
"List" ) )
253 QDomNodeList values = element.childNodes();
254 for (
int i = 0; i < values.count(); ++i )
256 QDomElement elem = values.at( i ).toElement();
261 else if ( type == QLatin1String(
"StringList" ) )
264 QDomNodeList values = element.childNodes();
265 for (
int i = 0; i < values.count(); ++i )
267 QDomElement elem = values.at( i ).toElement();
272 else if ( type == QLatin1String(
"QgsProperty" ) )
274 const QDomNodeList values = element.childNodes();
275 if ( values.isEmpty() )
284 else if ( type == QLatin1String(
"QgsCoordinateReferenceSystem" ) )
290 else if ( type == QLatin1String(
"QgsGeometry" ) )
A rectangle specified with double values.
void setXMaximum(double x)
Set the maximum x value.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
A geometry is the spatial representation of a feature.
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).
QString asWkt(int precision=17) const
Exports the geometry to WKT.
DistanceUnit
Units of distance.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
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.