Skip to content

Commit 24f40ca

Browse files
authoredApr 19, 2023
Merge pull request #52580 from YoannQDQ/fix-new-profile-scales
Fix new profile map scales
2 parents f35a0ba + d2e75b3 commit 24f40ca

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed
 

‎src/core/settings/qgssettingsregistrycore.cpp

Lines changed: 34 additions & 3 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,41 @@ 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+
// handle bad migration - Fix profiles for old QGIS versions (restore the Map/scales key on windows)
154+
// TODO: Remove this from QGIS 3.36
155+
// PR Link: https://github.com/qgis/QGIS/pull/52580
156+
if ( QgsSettings().contains( QStringLiteral( "Map/scales" ) ) )
157+
{
158+
const QStringList oldScales = QgsSettings().value( QStringLiteral( "Map/scales" ) ).toStringList();
159+
if ( ! oldScales.isEmpty() && !oldScales.at( 0 ).isEmpty() )
160+
QgsSettings().setValue( QStringLiteral( "Map/scales" ), oldScales.join( ',' ) );
161+
else
162+
QgsSettings().setValue( QStringLiteral( "Map/scales" ), Qgis::defaultProjectScales() );
163+
}
164+
153165
// migrate only one way for map scales
154166
if ( !settingsMapScales->exists() )
155-
settingsMapScales->setValue( QgsSettings().value( QStringLiteral( "Map/scales" ) ).toString().split( ',' ) );
156-
167+
{
168+
// Handle bad migration. Prefer map/scales over Map/scales
169+
// TODO: Discard this part starting from QGIS 3.36
170+
const QStringList oldScales = QgsSettings().value( QStringLiteral( "map/scales" ) ).toStringList();
171+
if ( ! oldScales.isEmpty() && !oldScales.at( 0 ).isEmpty() )
172+
{
173+
// If migration has failed before (QGIS < 3.30.2), all scales might be
174+
// concatenated in the first element of the list
175+
QStringList actualScales;
176+
for ( const QString &element : oldScales )
177+
{
178+
actualScales << element.split( "," );
179+
}
180+
settingsMapScales->setValue( actualScales );
181+
}
182+
// TODO: keep only this part of the migration starting from QGIS 3.36
183+
else if ( QgsSettings().contains( QStringLiteral( "Map/scales" ) ) )
184+
{
185+
settingsMapScales->setValue( QgsSettings().value( QStringLiteral( "Map/scales" ) ).toString().split( ',' ) );
186+
}
187+
}
157188

158189
// digitizing settings - added in 3.30
159190
{

0 commit comments

Comments
 (0)
Please sign in to comment.