Skip to content

Commit 2fb8580

Browse files
committedApr 15, 2023
Handle bad migration
1 parent ba589a7 commit 2fb8580

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed
 

‎src/core/settings/qgssettingsregistrycore.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const QgsSettingsEntryBool *QgsSettingsRegistryCore::settingsLayerTreeShowFeatur
107107

108108
const QgsSettingsEntryBool *QgsSettingsRegistryCore::settingsEnableWMSTilePrefetching = new QgsSettingsEntryBool( QStringLiteral( "enable_wms_tile_prefetch" ), QgsSettingsTree::sTreeWms, false, QStringLiteral( "Whether to include WMS layers when rendering tiles adjacent to the visible map area" ) );
109109

110-
const QgsSettingsEntryStringList *QgsSettingsRegistryCore::settingsMapScales = new QgsSettingsEntryStringList( QStringLiteral( "scales" ), QgsSettingsTree::sTreeMap, Qgis::defaultProjectScales().split( ',' ) );
110+
const QgsSettingsEntryStringList *QgsSettingsRegistryCore::settingsMapScales = new QgsSettingsEntryStringList( QStringLiteral( "default_scales" ), QgsSettingsTree::sTreeMap, Qgis::defaultProjectScales().split( ',' ) );
111111

112112

113113
QgsSettingsRegistryCore::QgsSettingsRegistryCore()
@@ -150,10 +150,37 @@ void QgsSettingsRegistryCore::migrateOldSettings()
150150
pal::Pal::settingsRenderingLabelCandidatesLimitLines->copyValueFromKey( QStringLiteral( "core/rendering/label_candidates_limit_lines" ), true );
151151
pal::Pal::settingsRenderingLabelCandidatesLimitPolygons->copyValueFromKey( QStringLiteral( "core/rendering/label_candidates_limit_polygons" ), true );
152152

153-
// migrate only one way for map scales
154-
if ( !settingsMapScales->exists() && QgsSettings().contains( QStringLiteral( "Map/scales" ) ) )
155-
settingsMapScales->setValue( QgsSettings().value( QStringLiteral( "Map/scales" ) ).toString().split( ',' ) );
153+
// handle bad migration - Fix profiles for old QGIS versions (restore the Map/scales key on windows)
154+
if ( QgsSettings().contains( QStringLiteral( "Map/scales" ) ) )
155+
{
156+
const QStringList oldScales = QgsSettings().value( QStringLiteral( "Map/scales" ) ).toStringList();
157+
if ( ! oldScales.isEmpty() && !oldScales.at( 0 ).isEmpty() )
158+
QgsSettings().setValue( QStringLiteral( "Map/scales" ), oldScales.join( ',' ) );
159+
else
160+
QgsSettings().setValue( QStringLiteral( "Map/scales" ), Qgis::defaultProjectScales() );
161+
}
156162

163+
// migrate only one way for map scales
164+
if ( !settingsMapScales->exists() )
165+
{
166+
// Handle bad migration. Prefer map/scales over Map/scales
167+
const QStringList oldScales = QgsSettings().value( QStringLiteral( "map/scales" ) ).toStringList();
168+
if ( ! oldScales.isEmpty() && !oldScales.at( 0 ).isEmpty() )
169+
{
170+
// If migration has failed before (QGIS < 3.30.2), all scales might be
171+
// concatenated in the first element of the list
172+
QStringList actualScales;
173+
for ( const QString &element : oldScales )
174+
{
175+
actualScales << element.split( "," );
176+
}
177+
settingsMapScales->setValue( actualScales );
178+
}
179+
else if ( QgsSettings().contains( QStringLiteral( "Map/scales" ) ) )
180+
{
181+
settingsMapScales->setValue( QgsSettings().value( QStringLiteral( "Map/scales" ) ).toString().split( ',' ) );
182+
}
183+
}
157184

158185
// digitizing settings - added in 3.30
159186
{

0 commit comments

Comments
 (0)
Please sign in to comment.