28 if (
"unknown" == element.text() )
43 const double xmin = element.attribute( QStringLiteral(
"xmin" ) ).toDouble();
46 const double ymin = element.attribute( QStringLiteral(
"ymin" ) ).toDouble();
49 const double zmin = element.attribute( QStringLiteral(
"zmin" ) ).toDouble();
52 const double xmax = element.attribute( QStringLiteral(
"xmax" ) ).toDouble();
55 const double ymax = element.attribute( QStringLiteral(
"ymax" ) ).toDouble();
58 const double zmax = element.attribute( QStringLiteral(
"zmax" ) ).toDouble();
68 const QDomNode xminNode = element.namedItem( QStringLiteral(
"xmin" ) );
69 const QDomNode yminNode = element.namedItem( QStringLiteral(
"ymin" ) );
70 const QDomNode xmaxNode = element.namedItem( QStringLiteral(
"xmax" ) );
71 const QDomNode ymaxNode = element.namedItem( QStringLiteral(
"ymax" ) );
73 QDomElement exElement = xminNode.toElement();
74 const double xmin = exElement.text().toDouble();
77 exElement = yminNode.toElement();
78 const double ymin = exElement.text().toDouble();
81 exElement = xmaxNode.toElement();
82 const double xmax = exElement.text().toDouble();
85 exElement = ymaxNode.toElement();
86 const double ymax = exElement.text().toDouble();
99 unitsString = QStringLiteral(
"unknown" );
101 QDomElement unitsNode = doc.createElement( QStringLiteral(
"units" ) );
102 unitsNode.appendChild( doc.createTextNode( unitsString ) );
108 QDomElement elemExtent3D = doc.createElement( elementName );
109 elemExtent3D.setAttribute( QStringLiteral(
"xMin" ), box.
xMinimum() );
110 elemExtent3D.setAttribute( QStringLiteral(
"yMin" ), box.
yMinimum() );
111 elemExtent3D.setAttribute( QStringLiteral(
"zMin" ), box.
zMinimum() );
112 elemExtent3D.setAttribute( QStringLiteral(
"xMax" ), box.
xMaximum() );
113 elemExtent3D.setAttribute( QStringLiteral(
"yMax" ), box.
yMaximum() );
114 elemExtent3D.setAttribute( QStringLiteral(
"zMax" ), box.
zMaximum() );
121 QDomElement xMin = doc.createElement( QStringLiteral(
"xmin" ) );
122 QDomElement yMin = doc.createElement( QStringLiteral(
"ymin" ) );
123 QDomElement xMax = doc.createElement( QStringLiteral(
"xmax" ) );
124 QDomElement yMax = doc.createElement( QStringLiteral(
"ymax" ) );
131 xMin.appendChild( xMinText );
132 yMin.appendChild( yMinText );
133 xMax.appendChild( xMaxText );
134 yMax.appendChild( yMaxText );
136 QDomElement extentNode = doc.createElement( elementName );
137 extentNode.appendChild( xMin );
138 extentNode.appendChild( yMin );
139 extentNode.appendChild( xMax );
140 extentNode.appendChild( yMax );
146 QDomElement element = doc.createElement( QStringLiteral(
"Option" ) );
147 switch ( value.type() )
149 case QVariant::Invalid:
151 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"invalid" ) );
157 const QVariantMap map = value.toMap();
159 for (
auto option = map.constBegin(); option != map.constEnd(); ++option )
161 QDomElement optionElement =
writeVariant( option.value(), doc );
162 optionElement.setAttribute( QStringLiteral(
"name" ), option.key() );
163 element.appendChild( optionElement );
164 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"Map" ) );
171 const QVariantList list = value.toList();
173 const auto constList = list;
174 for (
const QVariant &value : constList )
176 const QDomElement valueElement =
writeVariant( value, doc );
177 element.appendChild( valueElement );
178 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"List" ) );
183 case QVariant::StringList:
185 const QStringList list = value.toStringList();
187 const auto constList = list;
188 for (
const QString &value : constList )
190 const QDomElement valueElement =
writeVariant( value, doc );
191 element.appendChild( valueElement );
192 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"StringList" ) );
200 case QVariant::Double:
201 case QVariant::LongLong:
202 case QVariant::ULongLong:
203 case QVariant::String:
204 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
205 element.setAttribute( QStringLiteral(
"value" ), value.toString() );
209 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
210 element.setAttribute( QStringLiteral(
"value" ),
QgsVariantUtils::isNull( value ) ? QString() : QString( value.toChar() ) );
213 case QVariant::Color:
214 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"color" ) );
215 element.setAttribute( QStringLiteral(
"value" ), value.value< QColor >().isValid() ?
QgsColorUtils::colorToString( value.value< QColor >() ) : QString() );
218 case QVariant::DateTime:
219 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"datetime" ) );
220 element.setAttribute( QStringLiteral(
"value" ), value.value< QDateTime >().isValid() ? value.toDateTime().toString( Qt::ISODate ) : QString() );
224 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"date" ) );
225 element.setAttribute( QStringLiteral(
"value" ), value.value< QDate >().isValid() ? value.toDate().toString( Qt::ISODate ) : QString() );
229 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"time" ) );
230 element.setAttribute( QStringLiteral(
"value" ), value.value< QTime >().isValid() ? value.toTime().toString( Qt::ISODate ) : QString() );
233 case QVariant::UserType:
235 if ( value.userType() == QMetaType::type(
"QgsProperty" ) )
237 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProperty" ) );
239 element.appendChild( propertyElem );
242 else if ( value.userType() == QMetaType::type(
"QgsCoordinateReferenceSystem" ) )
244 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsCoordinateReferenceSystem" ) );
249 else if ( value.userType() == QMetaType::type(
"QgsGeometry" ) )
251 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsGeometry" ) );
253 element.setAttribute( QStringLiteral(
"value" ), geom.
asWkt() );
256 else if ( value.userType() == QMetaType::type(
"QgsProcessingOutputLayerDefinition" ) )
259 element.appendChild( valueElement );
260 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProcessingOutputLayerDefinition" ) );
263 else if ( value.userType() == QMetaType::type(
"QgsProcessingFeatureSourceDefinition" ) )
266 element.appendChild( valueElement );
267 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProcessingFeatureSourceDefinition" ) );
270 else if ( value.userType() == QMetaType::type(
"QgsRemappingSinkDefinition" ) )
273 element.appendChild( valueElement );
274 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsRemappingSinkDefinition" ) );
277 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", QStringLiteral(
"unsupported user variant type %1" ).arg( QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
282 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", QStringLiteral(
"unsupported variant type %1" ).arg( QVariant::typeToName( value.type() ) ).toLocal8Bit() );
291 const QString type = element.attribute( QStringLiteral(
"type" ) );
293 if ( type == QLatin1String(
"invalid" ) )
297 else if ( type == QLatin1String(
"int" ) )
299 return element.attribute( QStringLiteral(
"value" ) ).toInt();
301 else if ( type == QLatin1String(
"uint" ) )
303 return element.attribute( QStringLiteral(
"value" ) ).toUInt();
305 else if ( type == QLatin1String(
"qlonglong" ) )
307 return element.attribute( QStringLiteral(
"value" ) ).toLongLong();
309 else if ( type == QLatin1String(
"qulonglong" ) )
311 return element.attribute( QStringLiteral(
"value" ) ).toULongLong();
313 else if ( type == QLatin1String(
"double" ) )
315 return element.attribute( QStringLiteral(
"value" ) ).toDouble();
317 else if ( type == QLatin1String(
"QString" ) )
319 const QString res = element.attribute( QStringLiteral(
"value" ) );
320 return res.isEmpty() ? QVariant() : res;
322 else if ( type == QLatin1String(
"QChar" ) )
324 const QString res = element.attribute( QStringLiteral(
"value" ) );
325 return res.isEmpty() ? QVariant() : res.at( 0 );
327 else if ( type == QLatin1String(
"bool" ) )
329 return element.attribute( QStringLiteral(
"value" ) ) == QLatin1String(
"true" );
331 else if ( type == QLatin1String(
"color" ) )
333 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QVariant() :
QgsColorUtils::colorFromString( element.attribute( QStringLiteral(
"value" ) ) );
335 else if ( type == QLatin1String(
"datetime" ) )
337 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QVariant() : QDateTime::fromString( element.attribute( QStringLiteral(
"value" ) ), Qt::ISODate );
339 else if ( type == QLatin1String(
"date" ) )
341 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QVariant() : QDate::fromString( element.attribute( QStringLiteral(
"value" ) ), Qt::ISODate );
343 else if ( type == QLatin1String(
"time" ) )
345 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QVariant() : QTime::fromString( element.attribute( QStringLiteral(
"value" ) ), Qt::ISODate );
347 else if ( type == QLatin1String(
"Map" ) )
350 const QDomNodeList options = element.childNodes();
352 for (
int i = 0; i < options.count(); ++i )
354 const QDomElement elem = options.at( i ).toElement();
355 if ( elem.tagName() == QLatin1String(
"Option" ) )
356 map.insert( elem.attribute( QStringLiteral(
"name" ) ),
readVariant( elem ) );
360 else if ( type == QLatin1String(
"List" ) )
363 const QDomNodeList values = element.childNodes();
364 for (
int i = 0; i < values.count(); ++i )
366 const QDomElement elem = values.at( i ).toElement();
371 else if ( type == QLatin1String(
"StringList" ) )
374 const QDomNodeList values = element.childNodes();
375 for (
int i = 0; i < values.count(); ++i )
377 const QDomElement elem = values.at( i ).toElement();
382 else if ( type == QLatin1String(
"QgsProperty" ) )
384 const QDomNodeList values = element.childNodes();
385 if ( values.isEmpty() )
394 else if ( type == QLatin1String(
"QgsCoordinateReferenceSystem" ) )
400 else if ( type == QLatin1String(
"QgsGeometry" ) )
403 return !g.
isNull() ? g : QVariant();
405 else if ( type == QLatin1String(
"QgsProcessingOutputLayerDefinition" ) )
408 const QDomNodeList values = element.childNodes();
409 if ( values.isEmpty() )
417 else if ( type == QLatin1String(
"QgsProcessingFeatureSourceDefinition" ) )
420 const QDomNodeList values = element.childNodes();
421 if ( values.isEmpty() )
429 else if ( type == QLatin1String(
"QgsRemappingSinkDefinition" ) )
432 const QDomNodeList values = element.childNodes();
433 if ( values.isEmpty() )
437 return QVariant::fromValue( res );
DistanceUnit
Units of distance.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
A 3-dimensional box composed of x, y, z coordinates.
double yMaximum() const
Returns the maximum y value.
void setZMinimum(double z)
Sets the minimum z value.
void setYMaximum(double y)
Sets the maximum y value.
void setZMaximum(double z)
Sets the maximum z value.
double xMinimum() const
Returns the minimum x value.
double zMaximum() const
Returns the maximum z value.
double xMaximum() const
Returns the maximum x value.
void setXMaximum(double x)
Sets the maximum x value.
void setYMinimum(double y)
Sets the minimum y value.
double zMinimum() const
Returns the minimum z value.
double yMinimum() const
Returns the minimum y value.
void setXMinimum(double x)
Sets the minimum x value.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
A geometry is the spatial representation of a feature.
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
QString asWkt(int precision=17) const
Exports the geometry to WKT.
Encapsulates settings relating to a feature source input to a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this source definition from a QVariantMap, wrapped in a QVariant.
QVariant toVariant() const
Saves this source definition to a QVariantMap, wrapped in a QVariant.
Encapsulates settings relating to a feature sink or output raster layer for a processing algorithm.
bool loadVariant(const QVariantMap &map)
Loads this output layer definition from a QVariantMap, wrapped in a QVariant.
QVariant toVariant() const
Saves this output layer definition to a QVariantMap, wrapped in a QVariant.
A store for object properties.
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
A rectangle specified with double values.
double xMinimum() const
Returns the x minimum value (left side of rectangle).
void setYMinimum(double y)
Set the minimum y value.
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
void setXMinimum(double x)
Set the minimum x value.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
double yMaximum() const
Returns the y maximum value (top side of rectangle).
void setYMaximum(double y)
Set the maximum y value.
void setXMaximum(double x)
Set the maximum x value.
Defines the parameters used to remap features when creating a QgsRemappingProxyFeatureSink.
QVariant toVariant() const
Saves this remapping definition to a QVariantMap, wrapped in a QVariant.
bool loadVariant(const QVariantMap &map)
Loads this remapping definition from a QVariantMap, wrapped in a QVariant.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE Qgis::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static QDomElement writeBox3D(const QgsBox3D &box, QDomDocument &doc, const QString &elementName=QStringLiteral("extent3D"))
Encodes a 3D box to a DOM element.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QgsBox3D readBox3D(const QDomElement &element)
Decodes a DOM element to a 3D box.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
static Qgis::DistanceUnit readMapUnits(const QDomElement &element)
Decodes a distance unit from a DOM element.
static QgsRectangle readRectangle(const QDomElement &element)
static QDomElement writeMapUnits(Qgis::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
const QgsCoordinateReferenceSystem & crs