mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04: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
|
// TODO QGIS 3: remove type and always use EPSG code
|
||||||
QgsCoordinateReferenceSystem( const long id, CrsType type = PostgisCrsId );
|
QgsCoordinateReferenceSystem( const long id, CrsType type = PostgisCrsId );
|
||||||
|
|
||||||
|
operator QVariant() const;
|
||||||
static QList< long > validSrsIds();
|
static QList< long > validSrsIds();
|
||||||
|
|
||||||
// static creators
|
// static creators
|
||||||
|
@ -236,6 +236,12 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
|
|||||||
//! Assignment operator
|
//! Assignment operator
|
||||||
QgsCoordinateReferenceSystem &operator=( const QgsCoordinateReferenceSystem &srs );
|
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
|
* 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
|
* returned values can be safely passed to fromSrsId() to create a new, valid
|
||||||
@ -713,6 +719,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
|
|||||||
friend class TestQgsCoordinateReferenceSystem;
|
friend class TestQgsCoordinateReferenceSystem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QgsCoordinateReferenceSystem )
|
||||||
|
|
||||||
//! Output stream operator
|
//! Output stream operator
|
||||||
inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateReferenceSystem &r )
|
inline std::ostream &operator << ( std::ostream &os, const QgsCoordinateReferenceSystem &r )
|
||||||
|
@ -74,6 +74,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
|
|||||||
void hasAxisInverted();
|
void hasAxisInverted();
|
||||||
void createFromProj4Invalid();
|
void createFromProj4Invalid();
|
||||||
void validSrsIds();
|
void validSrsIds();
|
||||||
|
void asVariant();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void debugPrint( QgsCoordinateReferenceSystem &crs );
|
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 )
|
QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
|
||||||
#include "testqgscoordinatereferencesystem.moc"
|
#include "testqgscoordinatereferencesystem.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user