@@ -636,24 +636,26 @@ bool QgsProperty::valueAsBool( const QgsExpressionContext &context, bool default
636
636
return val.toBool ();
637
637
}
638
638
639
- bool QgsProperty::writeXml ( QDomElement &propertyElem, QDomDocument &doc ) const
639
+ QVariant QgsProperty::toVariant ( ) const
640
640
{
641
- propertyElem.setAttribute ( " active" , d->active ? " 1" : " 0" );
642
- propertyElem.setAttribute ( " type" , d->type );
641
+ QVariantMap propertyMap;
642
+
643
+ propertyMap.insert ( QStringLiteral ( " active" ), d->active );
644
+ propertyMap.insert ( QStringLiteral ( " type" ), d->type );
643
645
644
646
switch ( d->type )
645
647
{
646
648
case StaticProperty:
647
- propertyElem. setAttribute ( " valType" , d->staticValue .typeName () );
648
- propertyElem. setAttribute ( " val" , d->staticValue .toString () );
649
+ // propertyMap.insert( QStringLiteral( "valType" ) , d->staticValue.typeName() );
650
+ propertyMap. insert ( QStringLiteral ( " val" ) , d->staticValue .toString () );
649
651
break ;
650
652
651
653
case FieldBasedProperty:
652
- propertyElem. setAttribute ( " field" , d->fieldName );
654
+ propertyMap. insert ( QStringLiteral ( " field" ) , d->fieldName );
653
655
break ;
654
656
655
657
case ExpressionBasedProperty:
656
- propertyElem. setAttribute ( " expression" , d->expressionString );
658
+ propertyMap. insert ( QStringLiteral ( " expression" ) , d->expressionString );
657
659
break ;
658
660
659
661
case InvalidProperty:
@@ -662,36 +664,39 @@ bool QgsProperty::writeXml( QDomElement &propertyElem, QDomDocument &doc ) const
662
664
663
665
if ( d->transformer )
664
666
{
665
- QDomElement transformerElem = doc.createElement ( " transformer" );
666
- transformerElem.setAttribute ( " t" , static_cast < int >( d->transformer ->transformerType () ) );
667
- if ( d->transformer ->writeXml ( transformerElem, doc ) )
668
- propertyElem.appendChild ( transformerElem );
667
+ QVariantMap transformer;
668
+ transformer.insert ( QStringLiteral ( " t" ), d->transformer ->transformerType () );
669
+ transformer.insert ( QStringLiteral ( " d" ), d->transformer ->toVariant () );
670
+
671
+ propertyMap.insert ( QStringLiteral ( " transformer" ), transformer );
669
672
}
670
673
671
- return true ;
674
+ return propertyMap ;
672
675
}
673
676
674
- bool QgsProperty::readXml ( const QDomElement &propertyElem, const QDomDocument &doc )
677
+ bool QgsProperty::loadVariant ( const QVariant &property )
675
678
{
679
+ QVariantMap propertyMap = property.toMap ();
680
+
676
681
d.detach ();
677
- d->active = static_cast < bool >( propertyElem. attribute ( " active" , " 1 " ).toInt () );
678
- d->type = static_cast < Type >( propertyElem. attribute ( " type" , " 0 " ).toInt () );
682
+ d->active = propertyMap. value ( QStringLiteral ( " active" ) ).toBool ( );
683
+ d->type = static_cast < Type >( propertyMap. value ( QStringLiteral ( " type" ), InvalidProperty ).toInt () );
679
684
680
685
switch ( d->type )
681
686
{
682
687
case StaticProperty:
683
- d->staticValue = QVariant ( propertyElem. attribute ( " val" , " " ) );
684
- d->staticValue .convert ( QVariant::nameToType ( propertyElem.attribute ( " valType" , " QString" ).toLocal8Bit ().constData () ) );
688
+ d->staticValue = propertyMap. value ( QStringLiteral ( " val" ) );
689
+ // d->staticValue.convert( QVariant::nameToType( propertyElem.attribute( "valType", "QString" ).toLocal8Bit().constData() ) );
685
690
break ;
686
691
687
692
case FieldBasedProperty:
688
- d->fieldName = propertyElem. attribute ( " field" );
693
+ d->fieldName = propertyMap. value ( QStringLiteral ( " field" ) ). toString ( );
689
694
if ( d->fieldName .isEmpty () )
690
695
d->active = false ;
691
696
break ;
692
697
693
698
case ExpressionBasedProperty:
694
- d->expressionString = propertyElem. attribute ( " expression" );
699
+ d->expressionString = propertyMap. value ( QStringLiteral ( " expression" ) ). toString ( );
695
700
if ( d->expressionString .isEmpty () )
696
701
d->active = false ;
697
702
@@ -709,15 +714,20 @@ bool QgsProperty::readXml( const QDomElement &propertyElem, const QDomDocument &
709
714
if ( d->transformer )
710
715
delete d->transformer ;
711
716
d->transformer = nullptr ;
712
- QDomNodeList transformerNodeList = propertyElem.elementsByTagName ( " transformer" );
713
- if ( !transformerNodeList.isEmpty () )
717
+
718
+
719
+ QVariant transform = propertyMap.value ( QStringLiteral ( " transformer" ) );
720
+
721
+ if ( transform.isValid () )
714
722
{
715
- QDomElement transformerElem = transformerNodeList.at ( 0 ).toElement ();
716
- QgsPropertyTransformer::Type type = static_cast < QgsPropertyTransformer::Type >( transformerElem.attribute ( " t" , " 0" ).toInt () );
723
+ QVariantMap transformerMap = transform.toMap ();
724
+
725
+ QgsPropertyTransformer::Type type = static_cast < QgsPropertyTransformer::Type >( transformerMap.value ( QStringLiteral ( " t" ), QgsPropertyTransformer::GenericNumericTransformer ).toInt () );
717
726
std::unique_ptr< QgsPropertyTransformer > transformer ( QgsPropertyTransformer::create ( type ) );
727
+
718
728
if ( transformer )
719
729
{
720
- if ( transformer->readXml ( transformerElem, doc ) )
730
+ if ( transformer->loadVariant ( transformerMap. value ( QStringLiteral ( " d " ) ) ) )
721
731
d->transformer = transformer.release ();
722
732
}
723
733
}
0 commit comments