Skip to content

Commit

Permalink
Add a method for retrieving a user friendly descriptive string for
Browse files Browse the repository at this point in the history
a CRS

And use this wherever we show CRS values to users
  • Loading branch information
nyalldawson committed Dec 20, 2019
1 parent e152685 commit fdf211a
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 59 deletions.
26 changes: 21 additions & 5 deletions python/core/auto_generated/qgscoordinatereferencesystem.sip.in
Expand Up @@ -645,17 +645,33 @@ internal QGIS CRS ID with "QGIS" authority, for example "QGIS:100005"


QString description() const; QString description() const;
%Docstring %Docstring
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94". In most Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
cases this is the best method to use when showing a friendly identifier for the CRS to a
user.

:return: descriptive name of the CRS


.. note:: .. note::


an empty string will be returned if the description is not available for the CRS an empty string will be returned if the description is not available for the CRS


.. seealso:: :py:func:`authid` .. seealso:: :py:func:`authid`

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

QString userFriendlyIdentifier( bool shortString = false ) const;
%Docstring
Returns a user friendly identifier for the CRS.

Depending on the format of the CRS, this may reflect the CRSes registered name, or for
CRSes not saved in the database it may reflect the underlying WKT or Proj string definition
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
%End %End


QString projectionAcronym() const; QString projectionAcronym() const;
Expand Down
Expand Up @@ -187,7 +187,7 @@ QVariantMap QgsRasterLayerUniqueValuesReportAlgorithm::processAlgorithm( const Q
out << QStringLiteral( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/></head><body>\n" ); out << QStringLiteral( "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/></head><body>\n" );
out << QStringLiteral( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Analyzed file" ), mSource, QObject::tr( "band" ) ).arg( mBand ); out << QStringLiteral( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Analyzed file" ), mSource, QObject::tr( "band" ) ).arg( mBand );
out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Extent" ), mExtent.toString() ); out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Extent" ), mExtent.toString() );
out << QObject::tr( "<p>%1: %2 (%3)</p>\n" ).arg( QObject::tr( "Projection" ), mCrs.description(), mCrs.authid() ); out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Projection" ), mCrs.userFriendlyIdentifier() );
out << QObject::tr( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Width in pixels" ) ).arg( mLayerWidth ).arg( QObject::tr( "units per pixel" ) ).arg( mRasterUnitsPerPixelX ); out << QObject::tr( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Width in pixels" ) ).arg( mLayerWidth ).arg( QObject::tr( "units per pixel" ) ).arg( mRasterUnitsPerPixelX );
out << QObject::tr( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Height in pixels" ) ).arg( mLayerHeight ).arg( QObject::tr( "units per pixel" ) ).arg( mRasterUnitsPerPixelY ); out << QObject::tr( "<p>%1: %2 (%3 %4)</p>\n" ).arg( QObject::tr( "Height in pixels" ) ).arg( mLayerHeight ).arg( QObject::tr( "units per pixel" ) ).arg( mRasterUnitsPerPixelY );
out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Total pixel count" ) ).arg( layerSize ); out << QObject::tr( "<p>%1: %2</p>\n" ).arg( QObject::tr( "Total pixel count" ) ).arg( layerSize );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -739,7 +739,7 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs )
{ {
srs.createFromOgcWmsCrs( QgsSettings().value( QStringLiteral( "Projections/layerDefaultCrs" ), geoEpsgCrsAuthId() ).toString() ); srs.createFromOgcWmsCrs( QgsSettings().value( QStringLiteral( "Projections/layerDefaultCrs" ), geoEpsgCrsAuthId() ).toString() );
sAuthId = srs.authid(); sAuthId = srs.authid();
visibleMessageBar()->pushMessage( tr( "CRS was undefined" ), tr( "defaulting to CRS %1 - %2" ).arg( sAuthId, srs.description() ), Qgis::Warning, messageTimeout() ); visibleMessageBar()->pushMessage( tr( "CRS was undefined" ), tr( "defaulting to CRS %1" ).arg( srs.userFriendlyIdentifier() ), Qgis::Warning, messageTimeout() );
break; break;
} }


Expand Down Expand Up @@ -778,7 +778,7 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs )
srs = QgsProject::instance()->crs(); srs = QgsProject::instance()->crs();
sAuthId = srs.authid(); sAuthId = srs.authid();
QgsDebugMsg( "Layer srs set from project: " + sAuthId ); QgsDebugMsg( "Layer srs set from project: " + sAuthId );
visibleMessageBar()->pushMessage( tr( "CRS was undefined" ), tr( "defaulting to project CRS %1 - %2" ).arg( sAuthId, srs.description() ), Qgis::Warning, messageTimeout() ); visibleMessageBar()->pushMessage( tr( "CRS was undefined" ), tr( "defaulting to project CRS %1" ).arg( srs.userFriendlyIdentifier() ), Qgis::Warning, messageTimeout() );
break; break;
} }
} }
Expand Down Expand Up @@ -12783,7 +12783,7 @@ void QgisApp::updateCrsStatusBar()
mOnTheFlyProjectionStatusButton->setText( QgsProject::instance()->crs().authid() ); mOnTheFlyProjectionStatusButton->setText( QgsProject::instance()->crs().authid() );


mOnTheFlyProjectionStatusButton->setToolTip( mOnTheFlyProjectionStatusButton->setToolTip(
tr( "Current CRS: %1" ).arg( QgsProject::instance()->crs().description() ) ); tr( "Current CRS: %1" ).arg( QgsProject::instance()->crs().userFriendlyIdentifier() ) );
mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mIconProjectionEnabled.svg" ) ) ); mOnTheFlyProjectionStatusButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mIconProjectionEnabled.svg" ) ) );
} }
else else
Expand Down
44 changes: 14 additions & 30 deletions src/app/qgsappcoordinateoperationhandlers.cpp
Expand Up @@ -65,29 +65,13 @@ QgsAppMissingGridHandler::QgsAppMissingGridHandler( QObject *parent )


} }


QString displayIdentifierForCrs( const QgsCoordinateReferenceSystem &crs, bool shortString = false )
{
if ( !crs.authid().isEmpty() )
{
if ( !shortString && !crs.description().isEmpty() )
return QStringLiteral( "%1 [%2]" ).arg( crs.authid(), crs.description() );
return crs.authid();
}
else if ( !crs.description().isEmpty() )
return crs.description();
else if ( !crs.toProj().isEmpty() )
return crs.toProj();
else
return crs.toWkt();
}

void QgsAppMissingGridHandler::onMissingRequiredGrid( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, const QgsDatumTransform::GridDetails &grid ) void QgsAppMissingGridHandler::onMissingRequiredGrid( const QgsCoordinateReferenceSystem &sourceCrs, const QgsCoordinateReferenceSystem &destinationCrs, const QgsDatumTransform::GridDetails &grid )
{ {
if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) ) if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) )
return; return;


const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( displayIdentifierForCrs( sourceCrs, true ), const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ),
displayIdentifierForCrs( destinationCrs, true ) ); destinationCrs.userFriendlyIdentifier( true ) );


QString downloadMessage; QString downloadMessage;
const QString gridName = grid.shortName; const QString gridName = grid.shortName;
Expand All @@ -104,8 +88,8 @@ void QgsAppMissingGridHandler::onMissingRequiredGrid( const QgsCoordinateReferen
} }


const QString longMessage = tr( "<p>No transform is available between <i>%1</i> and <i>%2</i>.</p>" const QString longMessage = tr( "<p>No transform is available between <i>%1</i> and <i>%2</i>.</p>"
"<p>This transformation requires the grid file “%3”, which is not available for use on the system.</p>" ).arg( displayIdentifierForCrs( sourceCrs ), "<p>This transformation requires the grid file “%3”, which is not available for use on the system.</p>" ).arg( sourceCrs.userFriendlyIdentifier(),
displayIdentifierForCrs( destinationCrs ), destinationCrs.userFriendlyIdentifier(),
grid.shortName ); grid.shortName );


QgsMessageBar *bar = QgisApp::instance()->messageBar(); QgsMessageBar *bar = QgisApp::instance()->messageBar();
Expand Down Expand Up @@ -133,8 +117,8 @@ void QgsAppMissingGridHandler::onMissingPreferredGrid( const QgsCoordinateRefere
if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) ) if ( !shouldWarnAboutPair( sourceCrs, destinationCrs ) )
return; return;


const QString shortMessage = tr( "Cannot use preferred transform between %1 and %2" ).arg( displayIdentifierForCrs( sourceCrs, true ), const QString shortMessage = tr( "Cannot use preferred transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ),
displayIdentifierForCrs( destinationCrs, true ) ); destinationCrs.userFriendlyIdentifier( true ) );


QString gridMessage; QString gridMessage;
QString downloadMessage; QString downloadMessage;
Expand Down Expand Up @@ -172,8 +156,8 @@ void QgsAppMissingGridHandler::onMissingPreferredGrid( const QgsCoordinateRefere
accuracyMessage = tr( "<p>Current transform “<i>%1</i>” has an unknown accuracy, while the preferred transformation “<i>%2</i>” has accuracy %3 meters.</p>" ).arg( availableOperation.name ) accuracyMessage = tr( "<p>Current transform “<i>%1</i>” has an unknown accuracy, while the preferred transformation “<i>%2</i>” has accuracy %3 meters.</p>" ).arg( availableOperation.name )
.arg( preferredOperation.name ).arg( preferredOperation.accuracy ); .arg( preferredOperation.name ).arg( preferredOperation.accuracy );


const QString longMessage = tr( "<p>The preferred transform between <i>%1</i> and <i>%2</i> is not available for use on the system.</p>" ).arg( displayIdentifierForCrs( sourceCrs ), const QString longMessage = tr( "<p>The preferred transform between <i>%1</i> and <i>%2</i> is not available for use on the system.</p>" ).arg( sourceCrs.userFriendlyIdentifier(),
displayIdentifierForCrs( destinationCrs ) ) destinationCrs.userFriendlyIdentifier() )
+ gridMessage + accuracyMessage; + gridMessage + accuracyMessage;


QgsMessageBar *bar = QgisApp::instance()->messageBar(); QgsMessageBar *bar = QgisApp::instance()->messageBar();
Expand Down Expand Up @@ -201,8 +185,8 @@ void QgsAppMissingGridHandler::onCoordinateOperationCreationError( const QgsCoor
if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) ) if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) )
return; return;


const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( displayIdentifierForCrs( sourceCrs, true ), displayIdentifierForCrs( destinationCrs, true ) ); const QString shortMessage = tr( "No transform available between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ), destinationCrs.userFriendlyIdentifier( true ) );
const QString longMessage = tr( "<p>No transform is available between <i>%1</i> and <i>%2</i>.</p><p style=\"color: red\">%3</p>" ).arg( displayIdentifierForCrs( sourceCrs ), displayIdentifierForCrs( destinationCrs ), error ); const QString longMessage = tr( "<p>No transform is available between <i>%1</i> and <i>%2</i>.</p><p style=\"color: red\">%3</p>" ).arg( sourceCrs.userFriendlyIdentifier(), destinationCrs.userFriendlyIdentifier(), error );


QgsMessageBar *bar = QgisApp::instance()->messageBar(); QgsMessageBar *bar = QgisApp::instance()->messageBar();
QgsMessageBarItem *widget = bar->createMessage( QString(), shortMessage ); QgsMessageBarItem *widget = bar->createMessage( QString(), shortMessage );
Expand All @@ -225,8 +209,8 @@ void QgsAppMissingGridHandler::onMissingGridUsedByContextHandler( const QgsCoord
if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) ) if ( !shouldWarnAboutPairForCurrentProject( sourceCrs, destinationCrs ) )
return; return;


const QString shortMessage = tr( "Cannot use project transform between %1 and %2" ).arg( displayIdentifierForCrs( sourceCrs, true ), const QString shortMessage = tr( "Cannot use project transform between %1 and %2" ).arg( sourceCrs.userFriendlyIdentifier( true ),
displayIdentifierForCrs( destinationCrs, true ) ); destinationCrs.userFriendlyIdentifier( true ) );


QString gridMessage; QString gridMessage;
QString downloadMessage; QString downloadMessage;
Expand Down Expand Up @@ -256,8 +240,8 @@ void QgsAppMissingGridHandler::onMissingGridUsedByContextHandler( const QgsCoord
gridMessage = "<ul>" + gridMessage + "</ul>"; gridMessage = "<ul>" + gridMessage + "</ul>";
} }


const QString longMessage = tr( "<p>This project specifies a preset transform between <i>%1</i> and <i>%2</i>, which is not available for use on the system.</p>" ).arg( displayIdentifierForCrs( sourceCrs ), const QString longMessage = tr( "<p>This project specifies a preset transform between <i>%1</i> and <i>%2</i>, which is not available for use on the system.</p>" ).arg( sourceCrs.userFriendlyIdentifier(),
displayIdentifierForCrs( destinationCrs ) ) destinationCrs.userFriendlyIdentifier() )
+ gridMessage + gridMessage
+ tr( "<p>The operation specified for use in the project is:</p><p><code>%1</code></p>" ).arg( desired.proj ) ; + tr( "<p>The operation specified for use in the project is:</p><p><code>%1</code></p>" ).arg( desired.proj ) ;


Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsmeasuredialog.cpp
Expand Up @@ -391,7 +391,7 @@ void QgsMeasureDialog::updateUi()
{ {
//both source and destination units are degrees //both source and destination units are degrees
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured area are in degrees, so area is calculated using Cartesian calculations in square degrees." ).arg( toolTip += "<br> * " + tr( "Both project CRS (%1) and measured area are in degrees, so area is calculated using Cartesian calculations in square degrees." ).arg(
mCanvas->mapSettings().destinationCrs().description() ); mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
mDa.setEllipsoid( geoNone() ); mDa.setEllipsoid( geoNone() );
mConvertToDisplayUnits = false; //not required since we will be measuring in degrees mConvertToDisplayUnits = false; //not required since we will be measuring in degrees
} }
Expand All @@ -410,7 +410,7 @@ void QgsMeasureDialog::updateUi()
resultUnit = QgsUnitTypes::distanceToAreaUnit( mCanvas->mapSettings().destinationCrs().mapUnits() ); resultUnit = QgsUnitTypes::distanceToAreaUnit( mCanvas->mapSettings().destinationCrs().mapUnits() );
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' '; toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), toolTip += tr( "Area is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mCanvas->mapSettings().destinationCrs().description() ); mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
} }
setWindowTitle( tr( "Measure" ) ); setWindowTitle( tr( "Measure" ) );


Expand Down Expand Up @@ -469,7 +469,7 @@ void QgsMeasureDialog::updateUi()
{ {
//both source and destination units are degrees //both source and destination units are degrees
toolTip += "<br> * " + tr( "Both project CRS (%1) and measured length are in degrees, so distance is calculated using Cartesian calculations in degrees." ).arg( toolTip += "<br> * " + tr( "Both project CRS (%1) and measured length are in degrees, so distance is calculated using Cartesian calculations in degrees." ).arg(
mCanvas->mapSettings().destinationCrs().description() ); mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
mDa.setEllipsoid( geoNone() ); mDa.setEllipsoid( geoNone() );
mConvertToDisplayUnits = false; //not required since we will be measuring in degrees mConvertToDisplayUnits = false; //not required since we will be measuring in degrees
} }
Expand All @@ -488,7 +488,7 @@ void QgsMeasureDialog::updateUi()
resultUnit = mCanvas->mapSettings().destinationCrs().mapUnits(); resultUnit = mCanvas->mapSettings().destinationCrs().mapUnits();
toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' '; toolTip += "<br> * " + tr( "Project ellipsoidal calculation is not selected." ) + ' ';
toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ), toolTip += tr( "Distance is calculated in %1, based on project CRS (%2)." ).arg( QgsUnitTypes::toString( resultUnit ),
mCanvas->mapSettings().destinationCrs().description() ); mCanvas->mapSettings().destinationCrs().userFriendlyIdentifier() );
} }
setWindowTitle( tr( "Measure" ) ); setWindowTitle( tr( "Measure" ) );


Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -95,7 +95,7 @@ QgsNewSpatialiteLayerDialog::QgsNewSpatialiteLayerDialog( QWidget *parent, Qt::W


// Set the SRID box to a default of WGS84 // Set the SRID box to a default of WGS84
mCrsId = defaultCrs.authid(); mCrsId = defaultCrs.authid();
leSRID->setText( defaultCrs.authid() + " - " + defaultCrs.description() ); leSRID->setText( defaultCrs.userFriendlyIdentifier() );


pbnFindSRID->setEnabled( mDatabaseComboBox->count() ); pbnFindSRID->setEnabled( mDatabaseComboBox->count() );


Expand Down Expand Up @@ -255,7 +255,7 @@ void QgsNewSpatialiteLayerDialog::pbnFindSRID_clicked()
if ( crsId != mCrsId ) if ( crsId != mCrsId )
{ {
mCrsId = crsId; mCrsId = crsId;
leSRID->setText( srs.authid() + " - " + srs.description() ); leSRID->setText( srs.userFriendlyIdentifier() );
} }
} }
delete mySelector; delete mySelector;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -994,7 +994,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->setCrs( srs ); QgsProject::instance()->setCrs( srs );
if ( srs.isValid() ) if ( srs.isValid() )
{ {
QgsDebugMsgLevel( QStringLiteral( "Selected CRS " ) + srs.description(), 4 ); QgsDebugMsgLevel( QStringLiteral( "Selected CRS " ) + srs.userFriendlyIdentifier(), 4 );
// write the currently selected projections _proj string_ to project settings // write the currently selected projections _proj string_ to project settings
QgsDebugMsgLevel( QStringLiteral( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( srs.toProj() ), 4 ); QgsDebugMsgLevel( QStringLiteral( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( srs.toProj() ), 4 );
} }
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsrecentprojectsitemsmodel.cpp
Expand Up @@ -66,7 +66,7 @@ QVariant QgsRecentProjectItemsModel::data( const QModelIndex &index, int role )
if ( !mRecentProjects.at( index.row() ).crs.isEmpty() ) if ( !mRecentProjects.at( index.row() ).crs.isEmpty() )
{ {
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mRecentProjects.at( index.row() ).crs ); QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mRecentProjects.at( index.row() ).crs );
return QStringLiteral( "%1 (%2)" ).arg( mRecentProjects.at( index.row() ).crs, crs.description() ); return QStringLiteral( "%1 (%2)" ).arg( mRecentProjects.at( index.row() ).crs, crs.userFriendlyIdentifier() );
} }
else else
{ {
Expand Down
18 changes: 18 additions & 0 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1167,6 +1167,24 @@ QString QgsCoordinateReferenceSystem::description() const
} }
} }


QString QgsCoordinateReferenceSystem::userFriendlyIdentifier( bool shortString ) const
{
if ( !authid().isEmpty() )
{
if ( !shortString && !description().isEmpty() )
return QStringLiteral( "%1 - %2" ).arg( authid(), description() );
return authid();
}
else if ( !description().isEmpty() )
return description();
else if ( !toWkt().isEmpty() )
return toWkt().left( 30 ) + QChar( 0x2026 );
else if ( !toProj().isEmpty() )
return toProj().left( 30 ) + QChar( 0x2026 );
else
return QString();
}

QString QgsCoordinateReferenceSystem::projectionAcronym() const QString QgsCoordinateReferenceSystem::projectionAcronym() const
{ {
if ( d->mProjectionAcronym.isNull() ) if ( d->mProjectionAcronym.isNull() )
Expand Down
24 changes: 20 additions & 4 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -603,15 +603,31 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
QString authid() const; QString authid() const;


/** /**
* Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94". In most * Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
* cases this is the best method to use when showing a friendly identifier for the CRS to a
* user.
* \returns descriptive name of the CRS
* \note an empty string will be returned if the description is not available for the CRS * \note an empty string will be returned if the description is not available for the CRS
* \see authid() * \see authid()
* \see userFriendlyIdentifier()
*/ */
QString description() const; QString description() const;


/**
* Returns a user friendly identifier for the CRS.
*
* Depending on the format of the CRS, this may reflect the CRSes registered name, or for
* CRSes not saved in the database it may reflect the underlying WKT or Proj string definition
* 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 \a shortString is TRUE than an abbreviated identifier will be returned.
*
* \see description()
* \since QGIS 3.10.3
*/
QString userFriendlyIdentifier( bool shortString = false ) const;

/** /**
* Returns the projection acronym for the projection used by the CRS. * Returns the projection acronym for the projection used by the CRS.
* \returns the official Proj acronym for the projection family * \returns the official Proj acronym for the projection family
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsowssourceselect.cpp
Expand Up @@ -600,8 +600,8 @@ QString QgsOWSSourceSelect::descriptionForAuthId( const QString &authId )
return mCrsNames[ authId ]; return mCrsNames[ authId ];


QgsCoordinateReferenceSystem qgisSrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( authId ); QgsCoordinateReferenceSystem qgisSrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( authId );
mCrsNames.insert( authId, qgisSrs.description() ); mCrsNames.insert( authId, qgisSrs.userFriendlyIdentifier() );
return qgisSrs.description(); return qgisSrs.userFriendlyIdentifier();
} }


void QgsOWSSourceSelect::addDefaultServers() void QgsOWSSourceSelect::addDefaultServers()
Expand Down
12 changes: 6 additions & 6 deletions src/gui/qgsprojectionselectionwidget.cpp
Expand Up @@ -272,11 +272,11 @@ void QgsProjectionSelectionWidget::setLayerCrs( const QgsCoordinateReferenceSyst
{ {
if ( layerItemIndex > -1 ) if ( layerItemIndex > -1 )
{ {
mCrsComboBox->setItemText( layerItemIndex, tr( "Layer CRS: %1 - %2" ).arg( crs.authid(), crs.description() ) ); mCrsComboBox->setItemText( layerItemIndex, tr( "Layer CRS: %1" ).arg( crs.userFriendlyIdentifier() ) );
} }
else else
{ {
mCrsComboBox->insertItem( firstRecentCrsIndex(), tr( "Layer CRS: %1 - %2" ).arg( crs.authid(), crs.description() ), QgsProjectionSelectionWidget::LayerCrs ); mCrsComboBox->insertItem( firstRecentCrsIndex(), tr( "Layer CRS: %1" ).arg( crs.userFriendlyIdentifier() ), QgsProjectionSelectionWidget::LayerCrs );
} }
} }
else else
Expand All @@ -293,13 +293,13 @@ void QgsProjectionSelectionWidget::addProjectCrsOption()
{ {
if ( mProjectCrs.isValid() ) if ( mProjectCrs.isValid() )
{ {
mCrsComboBox->addItem( tr( "Project CRS: %1 - %2" ).arg( mProjectCrs.authid(), mProjectCrs.description() ), QgsProjectionSelectionWidget::ProjectCrs ); mCrsComboBox->addItem( tr( "Project CRS: %1" ).arg( mProjectCrs.userFriendlyIdentifier() ), QgsProjectionSelectionWidget::ProjectCrs );
} }
} }


void QgsProjectionSelectionWidget::addDefaultCrsOption() void QgsProjectionSelectionWidget::addDefaultCrsOption()
{ {
mCrsComboBox->addItem( tr( "Default CRS: %1 - %2" ).arg( mDefaultCrs.authid(), mDefaultCrs.description() ), QgsProjectionSelectionWidget::DefaultCrs ); mCrsComboBox->addItem( tr( "Default CRS: %1" ).arg( mDefaultCrs.userFriendlyIdentifier() ), QgsProjectionSelectionWidget::DefaultCrs );
} }


void QgsProjectionSelectionWidget::addCurrentCrsOption() void QgsProjectionSelectionWidget::addCurrentCrsOption()
Expand All @@ -312,7 +312,7 @@ void QgsProjectionSelectionWidget::addCurrentCrsOption()
QString QgsProjectionSelectionWidget::crsOptionText( const QgsCoordinateReferenceSystem &crs ) QString QgsProjectionSelectionWidget::crsOptionText( const QgsCoordinateReferenceSystem &crs )
{ {
if ( crs.isValid() ) if ( crs.isValid() )
return tr( "%1 - %2" ).arg( crs.authid(), crs.description() ); return crs.userFriendlyIdentifier();
else else
return tr( "invalid projection" ); return tr( "invalid projection" );
} }
Expand All @@ -332,7 +332,7 @@ void QgsProjectionSelectionWidget::addRecentCrs()


if ( crs.isValid() ) if ( crs.isValid() )
{ {
mCrsComboBox->addItem( tr( "%1 - %2" ).arg( crs.authid(), crs.description() ), QgsProjectionSelectionWidget::RecentCrs ); mCrsComboBox->addItem( crs.userFriendlyIdentifier(), QgsProjectionSelectionWidget::RecentCrs );
mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( ( long long )srsid ), Qt::UserRole + 1 ); mCrsComboBox->setItemData( mCrsComboBox->count() - 1, QVariant( ( long long )srsid ), Qt::UserRole + 1 );
} }
} }
Expand Down

0 comments on commit fdf211a

Please sign in to comment.