17 #include <QDomElement>    26   if ( 
"unknown" == element.text() )
    41   QDomNode xminNode = element.namedItem( QStringLiteral( 
"xmin" ) );
    42   QDomNode yminNode = element.namedItem( QStringLiteral( 
"ymin" ) );
    43   QDomNode xmaxNode = element.namedItem( QStringLiteral( 
"xmax" ) );
    44   QDomNode ymaxNode = element.namedItem( QStringLiteral( 
"ymax" ) );
    46   QDomElement exElement = xminNode.toElement();
    47   double xmin = exElement.text().toDouble();
    50   exElement = yminNode.toElement();
    51   double ymin = exElement.text().toDouble();
    54   exElement = xmaxNode.toElement();
    55   double xmax = exElement.text().toDouble();
    58   exElement = ymaxNode.toElement();
    59   double ymax = exElement.text().toDouble();
    72     unitsString = QStringLiteral( 
"unknown" );
    74   QDomElement unitsNode = doc.createElement( QStringLiteral( 
"units" ) );
    75   unitsNode.appendChild( doc.createTextNode( unitsString ) );
    81   QDomElement xMin = doc.createElement( QStringLiteral( 
"xmin" ) );
    82   QDomElement yMin = doc.createElement( QStringLiteral( 
"ymin" ) );
    83   QDomElement xMax = doc.createElement( QStringLiteral( 
"xmax" ) );
    84   QDomElement yMax = doc.createElement( QStringLiteral( 
"ymax" ) );
    91   xMin.appendChild( xMinText );
    92   yMin.appendChild( yMinText );
    93   xMax.appendChild( xMaxText );
    94   yMax.appendChild( yMaxText );
    96   QDomElement extentNode = doc.createElement( QStringLiteral( 
"extent" ) );
    97   extentNode.appendChild( xMin );
    98   extentNode.appendChild( yMin );
    99   extentNode.appendChild( xMax );
   100   extentNode.appendChild( yMax );
   106   QDomElement element = doc.createElement( QStringLiteral( 
"Option" ) );
   107   switch ( value.type() )
   109     case QVariant::Invalid:
   111       element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"invalid" ) );
   117       QVariantMap map = value.toMap();
   119       for ( 
auto option = map.constBegin(); option != map.constEnd(); ++option )
   121         QDomElement optionElement = 
writeVariant( option.value(), doc );
   122         optionElement.setAttribute( QStringLiteral( 
"name" ), option.key() );
   123         element.appendChild( optionElement );
   124         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"Map" ) );
   131       QVariantList list = value.toList();
   133       const auto constList = list;
   134       for ( 
const QVariant &value : constList )
   137         element.appendChild( valueElement );
   138         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"List" ) );
   143     case QVariant::StringList:
   145       QStringList list = value.toStringList();
   147       const auto constList = list;
   148       for ( 
const QString &value : constList )
   151         element.appendChild( valueElement );
   152         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"StringList" ) );
   160     case QVariant::Double:
   161     case QVariant::LongLong:
   162     case QVariant::ULongLong:
   163     case QVariant::String:
   164       element.setAttribute( QStringLiteral( 
"type" ), QVariant::typeToName( value.type() ) );
   165       element.setAttribute( QStringLiteral( 
"value" ), value.toString() );
   169       element.setAttribute( QStringLiteral( 
"type" ), QVariant::typeToName( value.type() ) );
   170       element.setAttribute( QStringLiteral( 
"value" ), value.isNull() ? QString() : value.toString() );
   173     case QVariant::Color:
   174       element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"color" ) );
   175       element.setAttribute( QStringLiteral( 
"value" ), value.value< QColor >().isValid() ? 
QgsSymbolLayerUtils::encodeColor( value.value< QColor >() ) : QString() );
   178     case QVariant::UserType:
   182         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"QgsProperty" ) );
   184         element.appendChild( propertyElem );
   189         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"QgsCoordinateReferenceSystem" ) );
   196         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"QgsGeometry" ) );
   198         element.setAttribute( QStringLiteral( 
"value" ), geom.
asWkt() );
   205       Q_ASSERT_X( 
false, 
"QgsXmlUtils::writeVariant", QStringLiteral( 
"unsupported variant type %1" ).arg( QVariant::typeToName( value.type() ) ).toLocal8Bit() );
   214   QString type = element.attribute( QStringLiteral( 
"type" ) );
   216   if ( type == QLatin1String( 
"invalid" ) )
   220   else if ( type == QLatin1String( 
"int" ) )
   222     return element.attribute( QStringLiteral( 
"value" ) ).toInt();
   224   else if ( type == QLatin1String( 
"uint" ) )
   226     return element.attribute( QStringLiteral( 
"value" ) ).toUInt();
   228   else if ( type == QLatin1String( 
"qlonglong" ) )
   230     return element.attribute( QStringLiteral( 
"value" ) ).toLongLong();
   232   else if ( type == QLatin1String( 
"qulonglong" ) )
   234     return element.attribute( QStringLiteral( 
"value" ) ).toULongLong();
   236   else if ( type == QLatin1String( 
"double" ) )
   238     return element.attribute( QStringLiteral( 
"value" ) ).toDouble();
   240   else if ( type == QLatin1String( 
"QString" ) )
   242     return element.attribute( QStringLiteral( 
"value" ) );
   244   else if ( type == QLatin1String( 
"QChar" ) )
   246     const QString res = element.attribute( QStringLiteral( 
"value" ) );
   247     return res.isEmpty() ? QChar() : res.at( 0 );
   249   else if ( type == QLatin1String( 
"bool" ) )
   251     return element.attribute( QStringLiteral( 
"value" ) ) == QLatin1String( 
"true" );
   253   else if ( type == QLatin1String( 
"color" ) )
   255     return element.attribute( QStringLiteral( 
"value" ) ).isEmpty() ? QColor() : 
QgsSymbolLayerUtils::decodeColor( element.attribute( QStringLiteral( 
"value" ) ) );
   257   else if ( type == QLatin1String( 
"Map" ) )
   260     QDomNodeList options = element.childNodes();
   262     for ( 
int i = 0; i < options.count(); ++i )
   264       QDomElement elem = options.at( i ).toElement();
   265       if ( elem.tagName() == QLatin1String( 
"Option" ) )
   266         map.insert( elem.attribute( QStringLiteral( 
"name" ) ), 
readVariant( elem ) );
   270   else if ( type == QLatin1String( 
"List" ) )
   273     QDomNodeList values = element.childNodes();
   274     for ( 
int i = 0; i < values.count(); ++i )
   276       QDomElement elem = values.at( i ).toElement();
   281   else if ( type == QLatin1String( 
"StringList" ) )
   284     QDomNodeList values = element.childNodes();
   285     for ( 
int i = 0; i < values.count(); ++i )
   287       QDomElement elem = values.at( i ).toElement();
   292   else if ( type == QLatin1String( 
"QgsProperty" ) )
   294     const QDomNodeList values = element.childNodes();
   295     if ( values.isEmpty() )
   304   else if ( type == QLatin1String( 
"QgsCoordinateReferenceSystem" ) )
   310   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
 
static QString encodeColor(const QColor &color)
 
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. 
 
static QColor decodeColor(const QString &str)