Skip to content

Commit 08bf81d

Browse files
committedApr 24, 2023
Add methods to clear recent crs or remove one crs
1 parent 8282b66 commit 08bf81d

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
 

‎python/core/auto_generated/proj/qgscoordinatereferencesystem.sip.in

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,20 @@ Pushes a recently used CRS to the top of the recent CRS list.
11231123
.. versionadded:: 3.10.3
11241124
%End
11251125

1126+
static void removeRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs );
1127+
%Docstring
1128+
Removes a CRS from the list of recently used CRS.
1129+
1130+
.. versionadded:: 3.32
1131+
%End
1132+
1133+
static void clearRecentCoordinateReferenceSystems();
1134+
%Docstring
1135+
Cleans the list of recently used CRS.
1136+
1137+
.. versionadded:: 3.32
1138+
%End
1139+
11261140

11271141
static void invalidateCache();
11281142
%Docstring

‎src/core/proj/qgscoordinatereferencesystem.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,6 +2942,40 @@ void QgsCoordinateReferenceSystem::pushRecentCoordinateReferenceSystem( const Qg
29422942
settings.setValue( QStringLiteral( "UI/recentProjectionsProj4" ), proj );
29432943
}
29442944

2945+
2946+
void QgsCoordinateReferenceSystem::removeRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs )
2947+
{
2948+
if ( crs.srsid() == 0 || !crs.isValid() )
2949+
return;
2950+
2951+
QList<QgsCoordinateReferenceSystem> recent = recentCoordinateReferenceSystems();
2952+
recent.removeAll( crs );
2953+
QStringList authids;
2954+
authids.reserve( recent.size() );
2955+
QStringList proj;
2956+
proj.reserve( recent.size() );
2957+
QStringList wkt;
2958+
wkt.reserve( recent.size() );
2959+
for ( const QgsCoordinateReferenceSystem &c : std::as_const( recent ) )
2960+
{
2961+
authids << c.authid();
2962+
proj << c.toProj();
2963+
wkt << c.toWkt( WKT_PREFERRED );
2964+
}
2965+
QgsSettings settings;
2966+
settings.setValue( QStringLiteral( "UI/recentProjectionsAuthId" ), authids );
2967+
settings.setValue( QStringLiteral( "UI/recentProjectionsWkt" ), wkt );
2968+
settings.setValue( QStringLiteral( "UI/recentProjectionsProj4" ), proj );
2969+
}
2970+
2971+
void QgsCoordinateReferenceSystem::clearRecentCoordinateReferenceSystems()
2972+
{
2973+
QgsSettings settings;
2974+
settings.remove( QStringLiteral( "UI/recentProjectionsAuthId" ) );
2975+
settings.remove( QStringLiteral( "UI/recentProjectionsWkt" ) );
2976+
settings.remove( QStringLiteral( "UI/recentProjectionsProj4" ) );
2977+
}
2978+
29452979
void QgsCoordinateReferenceSystem::invalidateCache( bool disableCache )
29462980
{
29472981
sSrIdCacheLock()->lockForWrite();

‎src/core/proj/qgscoordinatereferencesystem.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,18 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
10631063
*/
10641064
static void pushRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs );
10651065

1066+
/**
1067+
* Removes a CRS from the list of recently used CRS.
1068+
* \since QGIS 3.32
1069+
*/
1070+
static void removeRecentCoordinateReferenceSystem( const QgsCoordinateReferenceSystem &crs );
1071+
1072+
/**
1073+
* Cleans the list of recently used CRS.
1074+
* \since QGIS 3.32
1075+
*/
1076+
static void clearRecentCoordinateReferenceSystems();
1077+
10661078
#ifndef SIP_RUN
10671079

10681080
/**

0 commit comments

Comments
 (0)
Please sign in to comment.