diff --git a/python/core/auto_generated/qgscoordinatereferencesystem.sip.in b/python/core/auto_generated/qgscoordinatereferencesystem.sip.in index 6408d1f4abe6..61aeda934cfa 100644 --- a/python/core/auto_generated/qgscoordinatereferencesystem.sip.in +++ b/python/core/auto_generated/qgscoordinatereferencesystem.sip.in @@ -648,7 +648,14 @@ Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94". .. seealso:: :py:func:`userFriendlyIdentifier` %End - QString userFriendlyIdentifier( bool shortString = false ) const; + enum IdentifierType + { + ShortString, + MediumString, + FullString, + }; + + QString userFriendlyIdentifier( IdentifierType type = MediumString ) const; %Docstring Returns a user friendly identifier for the CRS. @@ -659,8 +666,6 @@ of the CRS. In most cases this is the best method to use when showing a friendly identifier for the CRS to a user. -If ``shortString`` is ``True`` than an abbreviated identifier will be returned. - .. seealso:: :py:func:`description` .. versionadded:: 3.10.3 diff --git a/src/app/qgsappcoordinateoperationhandlers.cpp b/src/app/qgsappcoordinateoperationhandlers.cpp index 3faeb192bc65..8a4c346b2620 100644 --- a/src/app/qgsappcoordinateoperationhandlers.cpp +++ b/src/app/qgsappcoordinateoperationhandlers.cpp @@ -70,8 +70,8 @@ void QgsAppMissingGridHandler::onMissingRequiredGrid( const QgsCoordinateReferen if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) ) return; - const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ), - destinationCrs.userFriendlyIdentifier( true ) ); + const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), + destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) ); QString downloadMessage; const QString gridName = grid.shortName; @@ -117,8 +117,8 @@ void QgsAppMissingGridHandler::onMissingPreferredGrid( const QgsCoordinateRefere if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) ) return; - const QString shortMessage = tr( "Cannot use preferred transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ), - destinationCrs.userFriendlyIdentifier( true ) ); + const QString shortMessage = tr( "Cannot use preferred transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), + destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) ); QString gridMessage; QString downloadMessage; @@ -185,7 +185,7 @@ void QgsAppMissingGridHandler::onCoordinateOperationCreationError( const QgsCoor if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) ) return; - const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ), destinationCrs.userFriendlyIdentifier( true ) ); + const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) ); const QString longMessage = tr( "
No transform is available between %1 and %2.
%3
" ).arg( sourceCrs.userFriendlyIdentifier(), destinationCrs.userFriendlyIdentifier(), error ); QgsMessageBar *bar = QgisApp::instance()->messageBar(); @@ -209,8 +209,8 @@ void QgsAppMissingGridHandler::onMissingGridUsedByContextHandler( const QgsCoord if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) ) return; - const QString shortMessage = tr( "Cannot use project transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ), - destinationCrs.userFriendlyIdentifier( true ) ); + const QString shortMessage = tr( "Cannot use project transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ), + destinationCrs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) ); QString gridMessage; QString downloadMessage; diff --git a/src/core/qgscoordinatereferencesystem.cpp b/src/core/qgscoordinatereferencesystem.cpp index 20e0fbf85c0c..0f118bab9680 100644 --- a/src/core/qgscoordinatereferencesystem.cpp +++ b/src/core/qgscoordinatereferencesystem.cpp @@ -1283,22 +1283,25 @@ QString QgsCoordinateReferenceSystem::description() const } } -QString QgsCoordinateReferenceSystem::userFriendlyIdentifier( bool shortString ) const +QString QgsCoordinateReferenceSystem::userFriendlyIdentifier( IdentifierType type ) const { if ( !authid().isEmpty() ) { - if ( !shortString && !description().isEmpty() ) + if ( type != ShortString && !description().isEmpty() ) return QStringLiteral( "%1 - %2" ).arg( authid(), description() ); return authid(); } else if ( !description().isEmpty() ) return description(); - else if ( shortString ) + else if ( type == ShortString ) return QObject::tr( "Unknown CRS" ); else if ( !toWkt( WKT2_2018 ).isEmpty() ) - return QObject::tr( "Unknown CRS: %1" ).arg( toWkt( WKT2_2018 ).left( 50 ) + QString( QChar( 0x2026 ) ) ); + return QObject::tr( "Unknown CRS: %1" ).arg( + type == MediumString ? ( toWkt( WKT2_2018 ).left( 50 ) + QString( QChar( 0x2026 ) ) ) + : toWkt( WKT2_2018 ) ); else if ( !toProj().isEmpty() ) - return QObject::tr( "Unknown CRS: %1" ).arg( toProj().left( 50 ) + QString( QChar( 0x2026 ) ) ); + return QObject::tr( "Unknown CRS: %1" ).arg( type == MediumString ? ( toProj().left( 50 ) + QString( QChar( 0x2026 ) ) ) + : toProj() ); else return QString(); } diff --git a/src/core/qgscoordinatereferencesystem.h b/src/core/qgscoordinatereferencesystem.h index 053ce09c679d..06924c6d7048 100644 --- a/src/core/qgscoordinatereferencesystem.h +++ b/src/core/qgscoordinatereferencesystem.h @@ -608,6 +608,18 @@ class CORE_EXPORT QgsCoordinateReferenceSystem */ QString description() const; + /** + * Type of identifier string to create. + * + * \since QGIS 3.10.3 + */ + enum IdentifierType + { + ShortString, //!< A heavily abbreviated string, for use when a compact representation is required + MediumString, //!< A medium-length string, recommended for general purpose use + FullString, //!< Full definition -- possibly a very lengthy string, e.g. with no truncation of custom WKT definitions + }; + /** * Returns a user friendly identifier for the CRS. * @@ -618,12 +630,10 @@ class CORE_EXPORT QgsCoordinateReferenceSystem * In most cases this is the best method to use when showing a friendly identifier for the CRS to a * user. * - * If \a shortString is TRUE than an abbreviated identifier will be returned. - * * \see description() * \since QGIS 3.10.3 */ - QString userFriendlyIdentifier( bool shortString = false ) const; + QString userFriendlyIdentifier( IdentifierType type = MediumString ) const; /** * Returns the projection acronym for the projection used by the CRS. diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index e8640e21b389..c3579ea94c60 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -4909,7 +4909,7 @@ QString QgsVectorLayer::htmlMetadata() const myMetadata += QStringLiteral( "