Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add methods to clear recent crs or remove one crs
  • Loading branch information
YoannQDQ committed Apr 24, 2023
1 parent 8282b66 commit 08bf81d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions src/core/proj/qgscoordinatereferencesystem.cpp
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions src/core/proj/qgscoordinatereferencesystem.h
Expand Up @@ -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

/**
Expand Down

0 comments on commit 08bf81d

Please sign in to comment.