27using namespace Qt::StringLiterals;
31 if (
"unknown" == element.text() )
46 const double xmin = element.attribute( u
"xmin"_s ).toDouble();
49 const double ymin = element.attribute( u
"ymin"_s ).toDouble();
52 const double zmin = element.attribute( u
"zmin"_s ).toDouble();
55 const double xmax = element.attribute( u
"xmax"_s ).toDouble();
58 const double ymax = element.attribute( u
"ymax"_s ).toDouble();
61 const double zmax = element.attribute( u
"zmax"_s ).toDouble();
71 const QDomNode xminNode = element.namedItem( u
"xmin"_s );
72 const QDomNode yminNode = element.namedItem( u
"ymin"_s );
73 const QDomNode xmaxNode = element.namedItem( u
"xmax"_s );
74 const QDomNode ymaxNode = element.namedItem( u
"ymax"_s );
76 QDomElement exElement = xminNode.toElement();
77 const double xmin = exElement.text().toDouble();
80 exElement = yminNode.toElement();
81 const double ymin = exElement.text().toDouble();
84 exElement = xmaxNode.toElement();
85 const double xmax = exElement.text().toDouble();
88 exElement = ymaxNode.toElement();
89 const double ymax = exElement.text().toDouble();
102 unitsString = u
"unknown"_s;
104 QDomElement unitsNode = doc.createElement( u
"units"_s );
105 unitsNode.appendChild( doc.createTextNode( unitsString ) );
111 QDomElement elemExtent3D = doc.createElement( elementName );
112 elemExtent3D.setAttribute( u
"xMin"_s, box.
xMinimum() );
113 elemExtent3D.setAttribute( u
"yMin"_s, box.
yMinimum() );
114 elemExtent3D.setAttribute( u
"zMin"_s, box.
zMinimum() );
115 elemExtent3D.setAttribute( u
"xMax"_s, box.
xMaximum() );
116 elemExtent3D.setAttribute( u
"yMax"_s, box.
yMaximum() );
117 elemExtent3D.setAttribute( u
"zMax"_s, box.
zMaximum() );
124 QDomElement xMin = doc.createElement( u
"xmin"_s );
125 QDomElement yMin = doc.createElement( u
"ymin"_s );
126 QDomElement xMax = doc.createElement( u
"xmax"_s );
127 QDomElement yMax = doc.createElement( u
"ymax"_s );
134 xMin.appendChild( xMinText );
135 yMin.appendChild( yMinText );
136 xMax.appendChild( xMaxText );
137 yMax.appendChild( yMaxText );
139 QDomElement extentNode = doc.createElement( elementName );
140 extentNode.appendChild( xMin );
141 extentNode.appendChild( yMin );
142 extentNode.appendChild( xMax );
143 extentNode.appendChild( yMax );
149 QDomElement element = doc.createElement( u
"Option"_s );
150 switch ( value.userType() )
152 case QMetaType::Type::UnknownType:
154 element.setAttribute( u
"type"_s, u
"invalid"_s );
158 case QMetaType::Type::QVariantMap:
160 const QVariantMap map = value.toMap();
162 for (
auto option = map.constBegin(); option != map.constEnd(); ++option )
164 QDomElement optionElement =
writeVariant( option.value(), doc );
165 optionElement.setAttribute( u
"name"_s, option.key() );
166 element.appendChild( optionElement );
167 element.setAttribute( u
"type"_s, u
"Map"_s );
172 case QMetaType::Type::QVariantList:
174 const QVariantList list = value.toList();
176 const auto constList = list;
177 for (
const QVariant &value : constList )
179 const QDomElement valueElement =
writeVariant( value, doc );
180 element.appendChild( valueElement );
181 element.setAttribute( u
"type"_s, u
"List"_s );
186 case QMetaType::Type::QStringList:
188 const QStringList list = value.toStringList();
190 const auto constList = list;
191 for (
const QString &value : constList )
193 const QDomElement valueElement =
writeVariant( value, doc );
194 element.appendChild( valueElement );
195 element.setAttribute( u
"type"_s, u
"StringList"_s );
200 case QMetaType::Type::QRect:
202 element.setAttribute( u
"type"_s,
"QRect" );
204 const QRect rect = value.toRect();
205 element.setAttribute( u
"x"_s, rect.x() );
206 element.setAttribute( u
"y"_s, rect.y() );
207 element.setAttribute( u
"width"_s, rect.width() );
208 element.setAttribute( u
"height"_s, rect.height() );
212 case QMetaType::Type::Int:
213 case QMetaType::Type::UInt:
214 case QMetaType::Type::Bool:
215 case QMetaType::Type::Double:
216 case QMetaType::Type::LongLong:
217 case QMetaType::Type::ULongLong:
218 case QMetaType::Type::QString:
219 element.setAttribute( u
"type"_s, QVariant::typeToName(
static_cast<QMetaType::Type
>( value.userType() ) ) );
220 element.setAttribute( u
"value"_s, value.toString() );
223 case QMetaType::Type::QChar:
224 element.setAttribute( u
"type"_s, QVariant::typeToName(
static_cast<QMetaType::Type
>( value.userType() ) ) );
228 case QMetaType::Type::QColor:
229 element.setAttribute( u
"type"_s, u
"color"_s );
230 element.setAttribute( u
"value"_s, value.value< QColor >().isValid() ?
QgsColorUtils::colorToString( value.value< QColor >() ) : QString() );
233 case QMetaType::Type::QDateTime:
234 element.setAttribute( u
"type"_s, u
"datetime"_s );
235 element.setAttribute( u
"value"_s, value.value< QDateTime >().isValid() ? value.toDateTime().toString( Qt::ISODate ) : QString() );
238 case QMetaType::Type::QDate:
239 element.setAttribute( u
"type"_s, u
"date"_s );
240 element.setAttribute( u
"value"_s, value.value< QDate >().isValid() ? value.toDate().toString( Qt::ISODate ) : QString() );
243 case QMetaType::Type::QTime:
244 element.setAttribute( u
"type"_s, u
"time"_s );
245 element.setAttribute( u
"value"_s, value.value< QTime >().isValid() ? value.toTime().toString( Qt::ISODate ) : QString() );
250 if ( value.userType() == qMetaTypeId<QgsProperty>() )
252 element.setAttribute( u
"type"_s, u
"QgsProperty"_s );
254 element.appendChild( propertyElem );
257 else if ( value.userType() == qMetaTypeId<QgsCoordinateReferenceSystem>() )
259 element.setAttribute( u
"type"_s, u
"QgsCoordinateReferenceSystem"_s );
264 else if ( value.userType() == qMetaTypeId< QgsGeometry>() )
266 element.setAttribute( u
"type"_s, u
"QgsGeometry"_s );
268 element.setAttribute( u
"value"_s, geom.
asWkt() );
271 else if ( value.userType() == qMetaTypeId<QgsProcessingOutputLayerDefinition>() )
274 element.appendChild( valueElement );
275 element.setAttribute( u
"type"_s, u
"QgsProcessingOutputLayerDefinition"_s );
278 else if ( value.userType() == qMetaTypeId<QgsProcessingFeatureSourceDefinition>() )
281 element.appendChild( valueElement );
282 element.setAttribute( u
"type"_s, u
"QgsProcessingFeatureSourceDefinition"_s );
285 else if ( value.userType() == qMetaTypeId<QgsRemappingSinkDefinition>() )
288 element.appendChild( valueElement );
289 element.setAttribute( u
"type"_s, u
"QgsRemappingSinkDefinition"_s );
294 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", u
"unsupported %1variant type %2"_s
295 .arg( value.userType() >= QMetaType::Type::User ?
"user " : QString() ).arg( value.metaType().name() ).toLocal8Bit() );
305 const QString type = element.attribute( u
"type"_s );
307 if ( type ==
"invalid"_L1 )
311 else if ( type ==
"int"_L1 )
313 return element.attribute( u
"value"_s ).toInt();
315 else if ( type ==
"uint"_L1 )
317 return element.attribute( u
"value"_s ).toUInt();
319 else if ( type ==
"qlonglong"_L1 )
321 return element.attribute( u
"value"_s ).toLongLong();
323 else if ( type ==
"qulonglong"_L1 )
325 return element.attribute( u
"value"_s ).toULongLong();
327 else if ( type ==
"double"_L1 )
329 return element.attribute( u
"value"_s ).toDouble();
331 else if ( type ==
"QString"_L1 )
333 const QString res = element.attribute( u
"value"_s );
334 return res.isEmpty() ? QVariant() : res;
336 else if ( type ==
"QChar"_L1 )
338 const QString res = element.attribute( u
"value"_s );
339 return res.isEmpty() ? QVariant() : res.at( 0 );
341 else if ( type ==
"bool"_L1 )
343 return element.attribute( u
"value"_s ) ==
"true"_L1;
345 else if ( type ==
"color"_L1 )
349 else if ( type ==
"datetime"_L1 )
351 return element.attribute( u
"value"_s ).isEmpty() ? QVariant() : QDateTime::fromString( element.attribute( u
"value"_s ), Qt::ISODate );
353 else if ( type ==
"date"_L1 )
355 return element.attribute( u
"value"_s ).isEmpty() ? QVariant() : QDate::fromString( element.attribute( u
"value"_s ), Qt::ISODate );
357 else if ( type ==
"time"_L1 )
359 return element.attribute( u
"value"_s ).isEmpty() ? QVariant() : QTime::fromString( element.attribute( u
"value"_s ), Qt::ISODate );
361 else if ( type ==
"Map"_L1 )
364 const QDomNodeList options = element.childNodes();
366 for (
int i = 0; i < options.count(); ++i )
368 const QDomElement elem = options.at( i ).toElement();
369 if ( elem.tagName() ==
"Option"_L1 )
370 map.insert( elem.attribute( u
"name"_s ),
readVariant( elem ) );
374 else if ( type ==
"List"_L1 )
377 const QDomNodeList values = element.childNodes();
378 for (
int i = 0; i < values.count(); ++i )
380 const QDomElement elem = values.at( i ).toElement();
385 else if ( type ==
"StringList"_L1 )
388 const QDomNodeList values = element.childNodes();
389 for (
int i = 0; i < values.count(); ++i )
391 const QDomElement elem = values.at( i ).toElement();
396 else if ( type ==
"QRect"_L1 )
398 const int x = element.attribute(
"x" ).toInt();
399 const int y = element.attribute(
"y" ).toInt();
400 const int width = element.attribute(
"width" ).toInt();
401 const int height = element.attribute(
"height" ).toInt();
403 return QRect( x, y, width, height );
405 else if ( type ==
"QgsProperty"_L1 )
407 const QDomNodeList values = element.childNodes();
408 if ( values.isEmpty() )
417 else if ( type ==
"QgsCoordinateReferenceSystem"_L1 )
421 return crs.
isValid() ? crs : QVariant();
423 else if ( type ==
"QgsGeometry"_L1 )
426 return !g.
isNull() ? g : QVariant();
428 else if ( type ==
"QgsProcessingOutputLayerDefinition"_L1 )
431 const QDomNodeList values = element.childNodes();
432 if ( values.isEmpty() )
440 else if ( type ==
"QgsProcessingFeatureSourceDefinition"_L1 )
443 const QDomNodeList values = element.childNodes();
444 if ( values.isEmpty() )
452 else if ( type ==
"QgsRemappingSinkDefinition"_L1 )
455 const QDomNodeList values = element.childNodes();
456 if ( values.isEmpty() )
460 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.
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 Q_INVOKABLE QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
Q_INVOKABLE 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.
void setYMinimum(double y)
Set the minimum y value.
void setXMinimum(double x)
Set the minimum x value.
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 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 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 QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=u"extent"_s)
Encodes a rectangle to a DOM element.
static QgsRectangle readRectangle(const QDomElement &element)
static QDomElement writeBox3D(const QgsBox3D &box, QDomDocument &doc, const QString &elementName=u"extent3D"_s)
Encodes a 3D box to a DOM 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.