Skip to content
Permalink
Browse files
Allow storing QgsCoordinateReferenceSystem in QVariants
  • Loading branch information
nyalldawson committed Apr 5, 2017
1 parent 5718abd commit d5f930adad1854c0f485cba6900b2381f2d7d1b2
Showing with 22 additions and 0 deletions.
  1. +1 −0 python/core/qgscoordinatereferencesystem.sip
  2. +7 −0 src/core/qgscoordinatereferencesystem.h
  3. +14 −0 tests/src/core/testqgscoordinatereferencesystem.cpp
@@ -183,6 +183,7 @@ class QgsCoordinateReferenceSystem
// TODO QGIS 3: remove type and always use EPSG code
QgsCoordinateReferenceSystem( const long id, CrsType type = PostgisCrsId );

operator QVariant() const;
static QList< long > validSrsIds();

// static creators
@@ -236,6 +236,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
//! Assignment operator
QgsCoordinateReferenceSystem &operator=( const QgsCoordinateReferenceSystem &srs );

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

/**
* Returns a list of all valid SRS IDs present in the CRS database. Any of the
* returned values can be safely passed to fromSrsId() to create a new, valid
@@ -713,6 +719,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
friend class TestQgsCoordinateReferenceSystem;
};

Q_DECLARE_METATYPE( QgsCoordinateReferenceSystem )

//! Output stream operator
inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateReferenceSystem &r )
@@ -74,6 +74,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void hasAxisInverted();
void createFromProj4Invalid();
void validSrsIds();
void asVariant();

private:
void debugPrint( QgsCoordinateReferenceSystem &crs );
@@ -743,5 +744,18 @@ void TestQgsCoordinateReferenceSystem::validSrsIds()
}
}

void TestQgsCoordinateReferenceSystem::asVariant()
{
QgsCoordinateReferenceSystem original;
original.createFromSrid( 3112 );

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

QgsCoordinateReferenceSystem fromVar = qvariant_cast<QgsCoordinateReferenceSystem>( var );
QCOMPARE( fromVar.authid(), original.authid() );
}

QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
#include "testqgscoordinatereferencesystem.moc"

0 comments on commit d5f930a

Please sign in to comment.