Add methods to clear recent crs or remove one crs

This commit is contained in:
Yoann Quenach de Quivillic 2023-04-24 09:22:32 +02:00
parent 8282b6631e
commit 08bf81dbeb
3 changed files with 60 additions and 0 deletions

View File

@ -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

View File

@ -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<QgsCoordinateReferenceSystem> 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();

View File

@ -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
/**