mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Allow storing QgsCoordinateReferenceSystem in QVariants
This commit is contained in:
parent
5718abd4e1
commit
d5f930adad
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user