Skip to content
Permalink
Browse files
Allow storing QgsProperty in QVariant
  • Loading branch information
nyalldawson committed May 9, 2017
1 parent 499a35d commit 3cd3e5d37834f8cd99cd98cb68a58126ba9064a0
Showing with 25 additions and 0 deletions.
  1. +2 −0 python/core/qgsproperty.sip
  2. +8 −0 src/core/qgsproperty.h
  3. +15 −0 tests/src/core/testqgsproperty.cpp
@@ -137,6 +137,8 @@ class QgsProperty

bool convertToTransformer();

operator QVariant() const;

};


@@ -434,6 +434,12 @@ class CORE_EXPORT QgsProperty
*/
bool convertToTransformer();

//! Allows direct construction of QVariants from properties.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

private:

mutable QExplicitlySharedDataPointer<QgsPropertyPrivate> d;
@@ -446,4 +452,6 @@ class CORE_EXPORT QgsProperty

};

Q_DECLARE_METATYPE( QgsProperty )

#endif // QGSPROPERTY_H
@@ -92,6 +92,7 @@ class TestQgsProperty : public QObject
void propertyCollection(); //test for QgsPropertyCollection
void collectionStack(); //test for QgsPropertyCollectionStack
void curveTransform();
void asVariant();

private:

@@ -1764,6 +1765,20 @@ void TestQgsProperty::curveTransform()
QGSCOMPARENEAR( dest2.y( 0.5 ), 0.1, 0.638672 );
}

void TestQgsProperty::asVariant()
{
QgsProperty original = QgsProperty::fromField( QStringLiteral( "field1" ), true );

//convert to and from a QVariant
QVariant var = QVariant::fromValue( original );
QVERIFY( var.isValid() );

QgsProperty fromVar = qvariant_cast<QgsProperty>( var );
QCOMPARE( fromVar.propertyType(), QgsProperty::FieldBasedProperty );
QVERIFY( fromVar.isActive() );
QCOMPARE( fromVar.field(), QStringLiteral( "field1" ) );
}

void TestQgsProperty::checkCurveResult( const QList<QgsPoint> &controlPoints, const QVector<double> &x, const QVector<double> &y )
{
// build transform

0 comments on commit 3cd3e5d

Please sign in to comment.