diff --git a/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in b/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in index 0938af9c08a..9108f1f3130 100644 --- a/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in +++ b/python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in @@ -1123,6 +1123,20 @@ Pushes a recently used CRS to the top of the recent CRS list. .. versionadded:: 3.10.3 %End + static void removeRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs ); +%Docstring +Removes a CRS from the list of recently used CRS. + +.. versionadded:: 3.32 +%End + + static void clearRecentCoordinateReferenceSystems(); +%Docstring +Cleans the list of recently used CRS. + +.. versionadded:: 3.32 +%End + static void invalidateCache(); %Docstring diff --git a/src/core/proj/qgscoordinatereferencesystem.cpp b/src/core/proj/qgscoordinatereferencesystem.cpp index 80e92071ceb..351e2fce9d8 100644 --- a/src/core/proj/qgscoordinatereferencesystem.cpp +++ b/src/core/proj/qgscoordinatereferencesystem.cpp @@ -2942,6 +2942,40 @@ void QgsCoordinateReferenceSystem::pushRecentCoordinateReferenceSystem( const Qg settings.setValue( QStringLiteral( "UI/recentProjectionsProj4" ), proj ); } + +void QgsCoordinateReferenceSystem::removeRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs ) +{ + if ( crs.srsid() == 0 || !crs.isValid() ) + return; + + QList recent = recentCoordinateReferenceSystems(); + recent.removeAll( crs ); + QStringList authids; + authids.reserve( recent.size() ); + QStringList proj; + proj.reserve( recent.size() ); + QStringList wkt; + wkt.reserve( recent.size() ); + for ( const QgsCoordinateReferenceSystem &c : std::as_const( recent ) ) + { + authids << c.authid(); + proj << c.toProj(); + wkt << c.toWkt( WKT_PREFERRED ); + } + QgsSettings settings; + settings.setValue( QStringLiteral( "UI/recentProjectionsAuthId" ), authids ); + settings.setValue( QStringLiteral( "UI/recentProjectionsWkt" ), wkt ); + settings.setValue( QStringLiteral( "UI/recentProjectionsProj4" ), proj ); +} + +void QgsCoordinateReferenceSystem::clearRecentCoordinateReferenceSystems() +{ + QgsSettings settings; + settings.remove( QStringLiteral( "UI/recentProjectionsAuthId" ) ); + settings.remove( QStringLiteral( "UI/recentProjectionsWkt" ) ); + settings.remove( QStringLiteral( "UI/recentProjectionsProj4" ) ); +} + void QgsCoordinateReferenceSystem::invalidateCache( bool disableCache ) { sSrIdCacheLock()->lockForWrite(); diff --git a/src/core/proj/qgscoordinatereferencesystem.h b/src/core/proj/qgscoordinatereferencesystem.h index a912ee885a9..5f4764b5fc9 100644 --- a/src/core/proj/qgscoordinatereferencesystem.h +++ b/src/core/proj/qgscoordinatereferencesystem.h @@ -1063,6 +1063,18 @@ class CORE_EXPORT QgsCoordinateReferenceSystem */ static void pushRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs ); + /** + * Removes a CRS from the list of recently used CRS. + * \since QGIS 3.32 + */ + static void removeRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs ); + + /** + * Cleans the list of recently used CRS. + * \since QGIS 3.32 + */ + static void clearRecentCoordinateReferenceSystems(); + #ifndef SIP_RUN /**