Skip to content
Permalink
Browse files

Allow storing QgsField and QgsFields in a QVariant

  • Loading branch information
nyalldawson committed May 5, 2015
1 parent ee17eb9 commit fba32f123dafb463ca61e3b165acbd36882874b9
Showing with 36 additions and 0 deletions.
  1. +4 −0 src/core/qgsfield.h
  2. +13 −0 tests/src/core/testqgsfield.cpp
  3. +19 −0 tests/src/core/testqgsfields.cpp
@@ -154,6 +154,8 @@ class CORE_EXPORT QgsField

}; // class QgsField

Q_DECLARE_METATYPE( QgsField );


/** \class QgsFields
* \ingroup core
@@ -270,4 +272,6 @@ class CORE_EXPORT QgsFields

};

Q_DECLARE_METATYPE( QgsFields );

#endif
@@ -35,6 +35,7 @@ class TestQgsField: public QObject
void assignment();
void gettersSetters(); //test getters and setters
void equality(); //test equality operators
void asVariant(); //test conversion to and from a QVariant
private:
};

@@ -147,5 +148,17 @@ void TestQgsField::equality()
field2.setPrecision( 2 );
}

void TestQgsField::asVariant()
{
QgsField original( "original", QVariant::Double, "double", 5, 2, "comment" );

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

QgsField fromVar = qvariant_cast<QgsField>( var );
QCOMPARE( fromVar, original );
}

QTEST_MAIN( TestQgsField )
#include "testqgsfield.moc"
@@ -34,6 +34,7 @@ class TestQgsFields: public QObject
void copy();// test cpy destruction (double delete)
void assignment();
void equality(); //test equality operators
void asVariant(); //test conversion to and from a QVariant
private:
};

@@ -125,5 +126,23 @@ void TestQgsFields::equality()
QVERIFY( fields1 != fields2 );
}

void TestQgsFields::asVariant()
{
QgsField field1;
field1.setName( "name" );
QgsField field2;
field2.setName( "name" );
QgsFields original;
original.append( field1 );
original.append( field2 );

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

QgsFields fromVar = qvariant_cast<QgsFields>( var );
QCOMPARE( fromVar, original );
}

QTEST_MAIN( TestQgsFields )
#include "testqgsfields.moc"

0 comments on commit fba32f1

Please sign in to comment.
You can’t perform that action at this time.