Skip to content
Permalink
Browse files
Promote CRS format enum to enum class, move to Qgis
  • Loading branch information
nyalldawson committed Jan 11, 2022
1 parent e692969 commit 6e7e8d3d7d74cd516900197609b75db725d2b74a
@@ -1200,3 +1200,14 @@
Qgis.HistoryProviderBackend.baseClass = Qgis
Qgis.HistoryProviderBackends.baseClass = Qgis
HistoryProviderBackends = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsCoordinateReferenceSystem.Format = Qgis.CrsDefinitionFormat
# monkey patching scoped based enum
QgsCoordinateReferenceSystem.FormatWkt = Qgis.CrsDefinitionFormat.Wkt
QgsCoordinateReferenceSystem.FormatWkt.is_monkey_patched = True
QgsCoordinateReferenceSystem.FormatWkt.__doc__ = "WKT format (always recommended over proj string format)"
QgsCoordinateReferenceSystem.FormatProj = Qgis.CrsDefinitionFormat.Proj
QgsCoordinateReferenceSystem.FormatProj.is_monkey_patched = True
QgsCoordinateReferenceSystem.FormatProj.__doc__ = "Proj string format"
Qgis.CrsDefinitionFormat.__doc__ = 'CRS definition formats.\n\n.. versionadded:: 3.24\n\n' + '* ``FormatWkt``: ' + Qgis.CrsDefinitionFormat.Wkt.__doc__ + '\n' + '* ``FormatProj``: ' + Qgis.CrsDefinitionFormat.Proj.__doc__
# --
Qgis.CrsDefinitionFormat.baseClass = Qgis
@@ -189,12 +189,6 @@ both flavors.
EpsgCrsId
};

enum Format
{
FormatWkt,
FormatProj,
};

QgsCoordinateReferenceSystem();
%Docstring
Constructs an invalid CRS object
@@ -982,7 +976,7 @@ Update proj.4 parameters in our database from proj.4
This is used internally and should not be necessary to call in client code
%End

long saveAsUserCrs( const QString &name, Format nativeFormat = FormatWkt );
long saveAsUserCrs( const QString &name, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );
%Docstring
Saves the CRS as a new custom ("USER") CRS.

@@ -64,7 +64,7 @@ Returns a list containing the details of all registered
custom (user-defined) CRSes.
%End

long addUserCrs( const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat = QgsCoordinateReferenceSystem::FormatWkt );
long addUserCrs( const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );
%Docstring
Adds a new ``crs`` definition as a custom ("USER") CRS.

@@ -83,7 +83,7 @@ definition. FormatWkt is recommended as it is a lossless format.
.. seealso:: :py:func:`userCrsAdded`
%End

bool updateUserCrs( long id, const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat = QgsCoordinateReferenceSystem::FormatWkt );
bool updateUserCrs( long id, const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );
%Docstring
Updates the definition of the existing user CRS with matching ``id``.

@@ -773,6 +773,12 @@ The development version
typedef QFlags<Qgis::HistoryProviderBackend> HistoryProviderBackends;


enum class CrsDefinitionFormat
{
Wkt,
Proj,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
@@ -36,7 +36,7 @@ An invalid CRS may be returned if no CRS is defined in the widget.
.. seealso:: :py:func:`setCrs`
%End

void setCrs( const QgsCoordinateReferenceSystem &crs, QgsCoordinateReferenceSystem::Format nativeFormat = QgsCoordinateReferenceSystem::Format::FormatWkt );
void setCrs( const QgsCoordinateReferenceSystem &crs, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );
%Docstring
Sets the current ``crs`` to display in the widget.

@@ -46,14 +46,14 @@ with the custom CRS.
.. seealso:: :py:func:`crs`
%End

QgsCoordinateReferenceSystem::Format format() const;
Qgis::CrsDefinitionFormat format() const;
%Docstring
Returns the selected CRS format.

.. seealso:: :py:func:`setFormat`
%End

void setFormat( QgsCoordinateReferenceSystem::Format format );
void setFormat( Qgis::CrsDefinitionFormat format );
%Docstring
Sets the CRS ``format``.

@@ -71,16 +71,16 @@ QgsCustomProjectionDialog::QgsCustomProjectionDialog( QWidget *parent, Qt::Windo
mBlockUpdates++;

QgsCoordinateReferenceSystem crs;
QgsCoordinateReferenceSystem::Format format;
Qgis::CrsDefinitionFormat format;
if ( mDefinitions[0].wkt.isEmpty() )
{
crs.createFromProj( mDefinitions[0].proj );
format = QgsCoordinateReferenceSystem::FormatProj;
format = Qgis::CrsDefinitionFormat::Proj;
}
else
{
crs.createFromWkt( mDefinitions[0].wkt );
format = QgsCoordinateReferenceSystem::FormatWkt;
format = Qgis::CrsDefinitionFormat::Wkt;
}
mCrsDefinitionWidget->setCrs( crs, format );

@@ -136,7 +136,7 @@ void QgsCustomProjectionDialog::populateList()
}
}

bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &existingId, bool newEntry, QgsCoordinateReferenceSystem::Format format )
bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &existingId, bool newEntry, Qgis::CrsDefinitionFormat format )
{
QString id = existingId;
if ( newEntry )
@@ -155,8 +155,8 @@ bool QgsCustomProjectionDialog::saveCrs( QgsCoordinateReferenceSystem crs, const
}
}

mExistingCRSwkt[id] = format == QgsCoordinateReferenceSystem::FormatWkt ? crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED, false ) : QString();
mExistingCRSproj[id] = format == QgsCoordinateReferenceSystem::FormatProj ? crs.toProj() : QString();
mExistingCRSwkt[id] = format == Qgis::CrsDefinitionFormat::Wkt ? crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED, false ) : QString();
mExistingCRSproj[id] = format == Qgis::CrsDefinitionFormat::Proj ? crs.toProj() : QString();
mExistingCRSnames[id] = name;

return true;
@@ -180,7 +180,7 @@ void QgsCustomProjectionDialog::pbnAdd_clicked()
leName->selectAll();
leName->setFocus();

mCrsDefinitionWidget->setFormat( QgsCoordinateReferenceSystem::FormatWkt );
mCrsDefinitionWidget->setFormat( Qgis::CrsDefinitionFormat::Wkt );
}

void QgsCustomProjectionDialog::pbnRemove_clicked()
@@ -229,12 +229,12 @@ void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *
mDefinitions[previousIndex].name = leName->text();
switch ( mCrsDefinitionWidget->format() )
{
case QgsCoordinateReferenceSystem::FormatWkt:
case Qgis::CrsDefinitionFormat::Wkt:
mDefinitions[previousIndex].wkt = mCrsDefinitionWidget->crs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED );
mDefinitions[previousIndex].proj.clear();
break;

case QgsCoordinateReferenceSystem::FormatProj:
case Qgis::CrsDefinitionFormat::Proj:
mDefinitions[previousIndex].proj = mCrsDefinitionWidget->crs().toProj();
mDefinitions[previousIndex].wkt.clear();
break;
@@ -252,7 +252,7 @@ void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *

mBlockUpdates++;
mCrsDefinitionWidget->setDefinitionString( !mDefinitions[currentIndex].wkt.isEmpty() ? current->data( 0, FormattedWktRole ).toString() : mDefinitions[currentIndex].proj );
mCrsDefinitionWidget->setFormat( mDefinitions[currentIndex].wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatProj : QgsCoordinateReferenceSystem::FormatWkt );
mCrsDefinitionWidget->setFormat( mDefinitions[currentIndex].wkt.isEmpty() ? Qgis::CrsDefinitionFormat::Proj : Qgis::CrsDefinitionFormat::Wkt );
mBlockUpdates--;
}
else
@@ -261,7 +261,7 @@ void QgsCustomProjectionDialog::leNameList_currentItemChanged( QTreeWidgetItem *
leName->clear();
mBlockUpdates++;
mCrsDefinitionWidget->setDefinitionString( QString() );
mCrsDefinitionWidget->setFormat( QgsCoordinateReferenceSystem::FormatWkt );
mCrsDefinitionWidget->setFormat( Qgis::CrsDefinitionFormat::Wkt );
mBlockUpdates--;
return;
}
@@ -350,7 +350,7 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
//Test if we just added this CRS (if it has no existing ID)
if ( def.id.isEmpty() )
{
saveSuccess &= saveCrs( crs, def.name, QString(), true, !def.wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatWkt : QgsCoordinateReferenceSystem::FormatProj );
saveSuccess &= saveCrs( crs, def.name, QString(), true, !def.wkt.isEmpty() ? Qgis::CrsDefinitionFormat::Wkt : Qgis::CrsDefinitionFormat::Proj );
}
else
{
@@ -359,7 +359,7 @@ void QgsCustomProjectionDialog::buttonBox_accepted()
|| ( !def.proj.isEmpty() && mExistingCRSproj[def.id] != def.proj )
)
{
saveSuccess &= saveCrs( crs, def.name, def.id, false, !def.wkt.isEmpty() ? QgsCoordinateReferenceSystem::FormatWkt : QgsCoordinateReferenceSystem::FormatProj );
saveSuccess &= saveCrs( crs, def.name, def.id, false, !def.wkt.isEmpty() ? Qgis::CrsDefinitionFormat::Wkt : Qgis::CrsDefinitionFormat::Proj );
}
}
if ( ! saveSuccess )
@@ -395,12 +395,12 @@ void QgsCustomProjectionDialog::updateListFromCurrentItem()
mDefinitions[currentIndex].name = leName->text();
switch ( mCrsDefinitionWidget->format() )
{
case QgsCoordinateReferenceSystem::FormatWkt:
case Qgis::CrsDefinitionFormat::Wkt:
mDefinitions[currentIndex].wkt = mCrsDefinitionWidget->definitionString();
mDefinitions[currentIndex].proj.clear();
break;

case QgsCoordinateReferenceSystem::FormatProj:
case Qgis::CrsDefinitionFormat::Proj:
mDefinitions[currentIndex].proj = mCrsDefinitionWidget->definitionString();
mDefinitions[currentIndex].wkt.clear();
break;
@@ -49,7 +49,7 @@ class APP_EXPORT QgsCustomProjectionDialog : public QDialog, private Ui::QgsCust

//helper functions
void populateList();
bool saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &id, bool newEntry, QgsCoordinateReferenceSystem::Format format );
bool saveCrs( QgsCoordinateReferenceSystem crs, const QString &name, const QString &id, bool newEntry, Qgis::CrsDefinitionFormat format );
void showHelp();
QString multiLineWktToSingleLine( const QString &wkt );

@@ -2047,7 +2047,7 @@ QString QgsCoordinateReferenceSystem::validationHint()
return mValidationHint;
}

long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, Format nativeFormat )
long QgsCoordinateReferenceSystem::saveAsUserCrs( const QString &name, Qgis::CrsDefinitionFormat nativeFormat )
{
return QgsApplication::coordinateReferenceSystemRegistry()->addUserCrs( *this, name, nativeFormat );
}
@@ -225,13 +225,6 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
EpsgCrsId //!< EPSG code
};

//! Projection definition formats
enum Format
{
FormatWkt = 0, //!< WKT format (always recommended over proj string format)
FormatProj, //!< Proj string format
};

//! Constructs an invalid CRS object
QgsCoordinateReferenceSystem();

@@ -912,7 +905,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*
* \note Since QGIS 3.18, internally this calls QgsCoordinateReferenceSystemRegistry::addUserCrs().
*/
long saveAsUserCrs( const QString &name, Format nativeFormat = FormatWkt );
long saveAsUserCrs( const QString &name, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );

//! Returns auth id of related geographic CRS
QString geographicCrsAuthId() const;
@@ -79,7 +79,7 @@ QList<QgsCoordinateReferenceSystemRegistry::UserCrsDetails> QgsCoordinateReferen
return res;
}

long QgsCoordinateReferenceSystemRegistry::addUserCrs( const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat )
long QgsCoordinateReferenceSystemRegistry::addUserCrs( const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat )
{
if ( !crs.isValid() )
{
@@ -113,7 +113,7 @@ long QgsCoordinateReferenceSystemRegistry::addUserCrs( const QgsCoordinateRefere
+ ',' + quotedEllipsoidString
+ ',' + ( !proj4String.isEmpty() ? QgsSqliteUtils::quotedString( proj4String ) : QStringLiteral( "''" ) )
+ ",0," // <-- is_geo shamelessly hard coded for now
+ ( nativeFormat == QgsCoordinateReferenceSystem::FormatWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ( nativeFormat == Qgis::CrsDefinitionFormat::Wkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ')';
}
else
@@ -124,7 +124,7 @@ long QgsCoordinateReferenceSystemRegistry::addUserCrs( const QgsCoordinateRefere
+ ',' + quotedEllipsoidString
+ ',' + ( !proj4String.isEmpty() ? QgsSqliteUtils::quotedString( proj4String ) : QStringLiteral( "''" ) )
+ ",0," // <-- is_geo shamelessly hard coded for now
+ ( nativeFormat == QgsCoordinateReferenceSystem::FormatWkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ( nativeFormat == Qgis::CrsDefinitionFormat::Wkt ? QgsSqliteUtils::quotedString( wktString ) : QStringLiteral( "''" ) )
+ ')';
}
sqlite3_database_unique_ptr database;
@@ -171,7 +171,7 @@ long QgsCoordinateReferenceSystemRegistry::addUserCrs( const QgsCoordinateRefere
return returnId;
}

bool QgsCoordinateReferenceSystemRegistry::updateUserCrs( long id, const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat )
bool QgsCoordinateReferenceSystemRegistry::updateUserCrs( long id, const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat )
{
if ( !crs.isValid() )
{
@@ -185,7 +185,7 @@ bool QgsCoordinateReferenceSystemRegistry::updateUserCrs( long id, const QgsCoor
+ ",ellipsoid_acronym=" + ( !crs.ellipsoidAcronym().isEmpty() ? QgsSqliteUtils::quotedString( crs.ellipsoidAcronym() ) : QStringLiteral( "''" ) )
+ ",parameters=" + ( !crs.toProj().isEmpty() ? QgsSqliteUtils::quotedString( crs.toProj() ) : QStringLiteral( "''" ) )
+ ",is_geo=0" // <--shamelessly hard coded for now
+ ",wkt=" + ( nativeFormat == QgsCoordinateReferenceSystem::FormatWkt ? QgsSqliteUtils::quotedString( crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED, false ) ) : QStringLiteral( "''" ) )
+ ",wkt=" + ( nativeFormat == Qgis::CrsDefinitionFormat::Wkt ? QgsSqliteUtils::quotedString( crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED, false ) ) : QStringLiteral( "''" ) )
+ " where srs_id=" + QgsSqliteUtils::quotedString( QString::number( id ) )
;

@@ -96,7 +96,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystemRegistry : public QObject
* \see updateUserCrs()
* \see userCrsAdded()
*/
long addUserCrs( const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat = QgsCoordinateReferenceSystem::FormatWkt );
long addUserCrs( const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );

/**
* Updates the definition of the existing user CRS with matching \a id.
@@ -114,7 +114,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystemRegistry : public QObject
* \see addUserCrs()
* \see userCrsChanged()
*/
bool updateUserCrs( long id, const QgsCoordinateReferenceSystem &crs, const QString &name, QgsCoordinateReferenceSystem::Format nativeFormat = QgsCoordinateReferenceSystem::FormatWkt );
bool updateUserCrs( long id, const QgsCoordinateReferenceSystem &crs, const QString &name, Qgis::CrsDefinitionFormat nativeFormat = Qgis::CrsDefinitionFormat::Wkt );

/**
* Removes the existing user CRS with matching \a id.
@@ -1264,6 +1264,18 @@ class CORE_EXPORT Qgis
Q_DECLARE_FLAGS( HistoryProviderBackends, HistoryProviderBackend )
Q_FLAG( HistoryProviderBackends )

/**
* CRS definition formats.
*
* \since QGIS 3.24
*/
enum class CrsDefinitionFormat SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsCoordinateReferenceSystem, Format ) : int
{
Wkt SIP_MONKEYPATCH_COMPAT_NAME( FormatWkt ), //!< WKT format (always recommended over proj string format)
Proj SIP_MONKEYPATCH_COMPAT_NAME( FormatProj ), //!< Proj string format
};
Q_ENUM( CrsDefinitionFormat )

/**
* Identify search radius in mm
* \since QGIS 2.3

0 comments on commit 6e7e8d3

Please sign in to comment.