Allow storing QgsProperty in QVariant

This commit is contained in:
Nyall Dawson 2017-05-09 12:22:30 +10:00
parent 499a35d0c8
commit 3cd3e5d378
3 changed files with 25 additions and 0 deletions

View File

@ -137,6 +137,8 @@ class QgsProperty
bool convertToTransformer();
operator QVariant() const;
};

View File

@ -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

View File

@ -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