Skip to content

Commit

Permalink
Allow storing QgsProperty in QVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 9, 2017
1 parent 499a35d commit 3cd3e5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsproperty.sip
Expand Up @@ -137,6 +137,8 @@ class QgsProperty

bool convertToTransformer();

operator QVariant() const;

};


8 changes: 8 additions & 0 deletions src/core/qgsproperty.h
Expand Up @@ -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;
Expand All @@ -446,4 +452,6 @@ class CORE_EXPORT QgsProperty

};

Q_DECLARE_METATYPE( QgsProperty )

#endif // QGSPROPERTY_H
15 changes: 15 additions & 0 deletions tests/src/core/testqgsproperty.cpp
Expand Up @@ -92,6 +92,7 @@ class TestQgsProperty : public QObject
void propertyCollection(); //test for QgsPropertyCollection
void collectionStack(); //test for QgsPropertyCollectionStack
void curveTransform();
void asVariant();

private:

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3cd3e5d

Please sign in to comment.