17 #include <QDomElement> 
   28   if ( 
"unknown" == element.text() )
 
   43   const QDomNode xminNode = element.namedItem( QStringLiteral( 
"xmin" ) );
 
   44   const QDomNode yminNode = element.namedItem( QStringLiteral( 
"ymin" ) );
 
   45   const QDomNode xmaxNode = element.namedItem( QStringLiteral( 
"xmax" ) );
 
   46   const QDomNode ymaxNode = element.namedItem( QStringLiteral( 
"ymax" ) );
 
   48   QDomElement exElement = xminNode.toElement();
 
   49   const double xmin = exElement.text().toDouble();
 
   52   exElement = yminNode.toElement();
 
   53   const double ymin = exElement.text().toDouble();
 
   56   exElement = xmaxNode.toElement();
 
   57   const double xmax = exElement.text().toDouble();
 
   60   exElement = ymaxNode.toElement();
 
   61   const 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       const 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       const QVariantList list = value.toList();
 
  135       const auto constList = list;
 
  136       for ( 
const QVariant &value : constList )
 
  138         const QDomElement valueElement = 
writeVariant( value, doc );
 
  139         element.appendChild( valueElement );
 
  140         element.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"List" ) );
 
  145     case QVariant::StringList:
 
  147       const QStringList list = value.toStringList();
 
  149       const auto constList = list;
 
  150       for ( 
const QString &value : constList )
 
  152         const QDomElement valueElement = 
writeVariant( value, doc );
 
  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   const 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     const QDomNodeList options = element.childNodes();
 
  313     for ( 
int i = 0; i < options.count(); ++i )
 
  315       const 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     const QDomNodeList values = element.childNodes();
 
  325     for ( 
int i = 0; i < values.count(); ++i )
 
  327       const QDomElement elem = values.at( i ).toElement();
 
  332   else if ( type == QLatin1String( 
"StringList" ) )
 
  335     const QDomNodeList values = element.childNodes();
 
  336     for ( 
int i = 0; i < values.count(); ++i )
 
  338       const 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 );