17 #include <QDomElement>
28 if (
"unknown" == element.text() )
43 QDomNode xminNode = element.namedItem( QStringLiteral(
"xmin" ) );
44 QDomNode yminNode = element.namedItem( QStringLiteral(
"ymin" ) );
45 QDomNode xmaxNode = element.namedItem( QStringLiteral(
"xmax" ) );
46 QDomNode ymaxNode = element.namedItem( QStringLiteral(
"ymax" ) );
48 QDomElement exElement = xminNode.toElement();
49 double xmin = exElement.text().toDouble();
52 exElement = yminNode.toElement();
53 double ymin = exElement.text().toDouble();
56 exElement = xmaxNode.toElement();
57 double xmax = exElement.text().toDouble();
60 exElement = ymaxNode.toElement();
61 double ymax = exElement.text().toDouble();
74 unitsString = QStringLiteral(
"unknown" );
76 QDomElement unitsNode = doc.createElement( QStringLiteral(
"units" ) );
77 unitsNode.appendChild( doc.createTextNode( unitsString ) );
83 QDomElement xMin = doc.createElement( QStringLiteral(
"xmin" ) );
84 QDomElement yMin = doc.createElement( QStringLiteral(
"ymin" ) );
85 QDomElement xMax = doc.createElement( QStringLiteral(
"xmax" ) );
86 QDomElement yMax = doc.createElement( QStringLiteral(
"ymax" ) );
93 xMin.appendChild( xMinText );
94 yMin.appendChild( yMinText );
95 xMax.appendChild( xMaxText );
96 yMax.appendChild( yMaxText );
98 QDomElement extentNode = doc.createElement( elementName );
99 extentNode.appendChild( xMin );
100 extentNode.appendChild( yMin );
101 extentNode.appendChild( xMax );
102 extentNode.appendChild( yMax );
108 QDomElement element = doc.createElement( QStringLiteral(
"Option" ) );
109 switch ( value.type() )
111 case QVariant::Invalid:
113 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"invalid" ) );
119 QVariantMap map = value.toMap();
121 for (
auto option = map.constBegin(); option != map.constEnd(); ++option )
123 QDomElement optionElement =
writeVariant( option.value(), doc );
124 optionElement.setAttribute( QStringLiteral(
"name" ), option.key() );
125 element.appendChild( optionElement );
126 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"Map" ) );
133 QVariantList list = value.toList();
135 const auto constList = list;
136 for (
const QVariant &value : constList )
139 element.appendChild( valueElement );
140 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"List" ) );
145 case QVariant::StringList:
147 QStringList list = value.toStringList();
149 const auto constList = list;
150 for (
const QString &value : constList )
153 element.appendChild( valueElement );
154 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"StringList" ) );
162 case QVariant::Double:
163 case QVariant::LongLong:
164 case QVariant::ULongLong:
165 case QVariant::String:
166 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
167 element.setAttribute( QStringLiteral(
"value" ), value.toString() );
171 element.setAttribute( QStringLiteral(
"type" ), QVariant::typeToName( value.type() ) );
172 element.setAttribute( QStringLiteral(
"value" ), value.isNull() ? QString() : value.toString() );
175 case QVariant::Color:
176 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"color" ) );
177 element.setAttribute( QStringLiteral(
"value" ), value.value< QColor >().isValid() ?
QgsSymbolLayerUtils::encodeColor( value.value< QColor >() ) : QString() );
180 case QVariant::DateTime:
181 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"datetime" ) );
182 element.setAttribute( QStringLiteral(
"value" ), value.value< QDateTime >().isValid() ? value.toDateTime().toString( Qt::ISODate ) : QString() );
186 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"date" ) );
187 element.setAttribute( QStringLiteral(
"value" ), value.value< QDate >().isValid() ? value.toDate().toString( Qt::ISODate ) : QString() );
191 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"time" ) );
192 element.setAttribute( QStringLiteral(
"value" ), value.value< QTime >().isValid() ? value.toTime().toString( Qt::ISODate ) : QString() );
195 case QVariant::UserType:
199 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProperty" ) );
201 element.appendChild( propertyElem );
206 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsCoordinateReferenceSystem" ) );
213 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsGeometry" ) );
215 element.setAttribute( QStringLiteral(
"value" ), geom.
asWkt() );
221 element.appendChild( valueElement );
222 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProcessingOutputLayerDefinition" ) );
228 element.appendChild( valueElement );
229 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsProcessingFeatureSourceDefinition" ) );
235 element.appendChild( valueElement );
236 element.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"QgsRemappingSinkDefinition" ) );
239 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", QStringLiteral(
"unsupported user variant type %1" ).arg(
QMetaType::typeName( value.userType() ) ).toLocal8Bit() );
244 Q_ASSERT_X(
false,
"QgsXmlUtils::writeVariant", QStringLiteral(
"unsupported variant type %1" ).arg( QVariant::typeToName( value.type() ) ).toLocal8Bit() );
253 QString type = element.attribute( QStringLiteral(
"type" ) );
255 if ( type == QLatin1String(
"invalid" ) )
259 else if ( type == QLatin1String(
"int" ) )
261 return element.attribute( QStringLiteral(
"value" ) ).toInt();
263 else if ( type == QLatin1String(
"uint" ) )
265 return element.attribute( QStringLiteral(
"value" ) ).toUInt();
267 else if ( type == QLatin1String(
"qlonglong" ) )
269 return element.attribute( QStringLiteral(
"value" ) ).toLongLong();
271 else if ( type == QLatin1String(
"qulonglong" ) )
273 return element.attribute( QStringLiteral(
"value" ) ).toULongLong();
275 else if ( type == QLatin1String(
"double" ) )
277 return element.attribute( QStringLiteral(
"value" ) ).toDouble();
279 else if ( type == QLatin1String(
"QString" ) )
281 return element.attribute( QStringLiteral(
"value" ) );
283 else if ( type == QLatin1String(
"QChar" ) )
285 const QString res = element.attribute( QStringLiteral(
"value" ) );
286 return res.isEmpty() ? QChar() : res.at( 0 );
288 else if ( type == QLatin1String(
"bool" ) )
290 return element.attribute( QStringLiteral(
"value" ) ) == QLatin1String(
"true" );
292 else if ( type == QLatin1String(
"color" ) )
294 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QColor() :
QgsSymbolLayerUtils::decodeColor( element.attribute( QStringLiteral(
"value" ) ) );
296 else if ( type == QLatin1String(
"datetime" ) )
298 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QDateTime() : QDateTime::fromString( element.attribute( QStringLiteral(
"value" ) ), Qt::ISODate );
300 else if ( type == QLatin1String(
"date" ) )
302 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QDate() : QDate::fromString( element.attribute( QStringLiteral(
"value" ) ), Qt::ISODate );
304 else if ( type == QLatin1String(
"time" ) )
306 return element.attribute( QStringLiteral(
"value" ) ).isEmpty() ? QTime() : QTime::fromString( element.attribute( QStringLiteral(
"value" ) ), Qt::ISODate );
308 else if ( type == QLatin1String(
"Map" ) )
311 QDomNodeList options = element.childNodes();
313 for (
int i = 0; i < options.count(); ++i )
315 QDomElement elem = options.at( i ).toElement();
316 if ( elem.tagName() == QLatin1String(
"Option" ) )
317 map.insert( elem.attribute( QStringLiteral(
"name" ) ),
readVariant( elem ) );
321 else if ( type == QLatin1String(
"List" ) )
324 QDomNodeList values = element.childNodes();
325 for (
int i = 0; i < values.count(); ++i )
327 QDomElement elem = values.at( i ).toElement();
332 else if ( type == QLatin1String(
"StringList" ) )
335 QDomNodeList values = element.childNodes();
336 for (
int i = 0; i < values.count(); ++i )
338 QDomElement elem = values.at( i ).toElement();
343 else if ( type == QLatin1String(
"QgsProperty" ) )
345 const QDomNodeList values = element.childNodes();
346 if ( values.isEmpty() )
355 else if ( type == QLatin1String(
"QgsCoordinateReferenceSystem" ) )
361 else if ( type == QLatin1String(
"QgsGeometry" ) )
365 else if ( type == QLatin1String(
"QgsProcessingOutputLayerDefinition" ) )
368 const QDomNodeList values = element.childNodes();
369 if ( values.isEmpty() )
377 else if ( type == QLatin1String(
"QgsProcessingFeatureSourceDefinition" ) )
380 const QDomNodeList values = element.childNodes();
381 if ( values.isEmpty() )
389 else if ( type == QLatin1String(
"QgsRemappingSinkDefinition" ) )
392 const QDomNodeList values = element.childNodes();
393 if ( values.isEmpty() )
397 return QVariant::fromValue( res );
This class represents a coordinate reference system (CRS).
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 yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
void setYMinimum(double y) SIP_HOLDGIL
Set the minimum y value.
void setXMaximum(double x) SIP_HOLDGIL
Set the maximum x value.
void setXMinimum(double x) SIP_HOLDGIL
Set the minimum x value.
void setYMaximum(double y) SIP_HOLDGIL
Set the maximum y 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 QColor decodeColor(const QString &str)
static QString encodeColor(const QColor &color)
DistanceUnit
Units of distance.
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
@ DistanceUnknownUnit
Unknown distance unit.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
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 QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
static QgsUnitTypes::DistanceUnit readMapUnits(const QDomElement &element)
Decodes a distance unit from a DOM element.
static QgsRectangle readRectangle(const QDomElement &element)
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
const QgsCoordinateReferenceSystem & crs