@@ -1769,6 +1769,11 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
1769
1769
if ( labelingElement.isNull () ||
1770
1770
( labelingElement.attribute ( " type" ) == " simple" && labelingElement.firstChildElement ( QStringLiteral ( " settings" ) ).isNull () ) )
1771
1771
{
1772
+ // make sure we have custom properties for labeling for 2.x projects
1773
+ // (custom properties should be already loaded when reading the whole layer from XML,
1774
+ // but when reading style, custom properties are not read)
1775
+ readCustomProperties ( node, QStringLiteral ( " labeling" ) );
1776
+
1772
1777
// support for pre-QGIS 3 labeling configurations written in custom properties
1773
1778
labeling = readLabelingFromCustomProperties ();
1774
1779
}
@@ -1811,9 +1816,6 @@ bool QgsVectorLayer::readStyle( const QDomNode &node, QString &errorMessage, con
1811
1816
mSimplifyMethod .setForceLocalOptimization ( e.attribute ( QStringLiteral ( " simplifyLocal" ), QStringLiteral ( " 1" ) ).toInt () );
1812
1817
mSimplifyMethod .setMaximumScale ( e.attribute ( QStringLiteral ( " simplifyMaxScale" ), QStringLiteral ( " 1" ) ).toFloat () );
1813
1818
1814
- // also restore custom properties (for labeling-ng)
1815
- readCustomProperties ( node, QStringLiteral ( " labeling" ) );
1816
-
1817
1819
// diagram renderer and diagram layer settings
1818
1820
delete mDiagramRenderer ;
1819
1821
mDiagramRenderer = nullptr ;
@@ -4225,17 +4227,24 @@ QgsEditorWidgetSetup QgsVectorLayer::editorWidgetSetup( int index ) const
4225
4227
QgsAbstractVectorLayerLabeling *QgsVectorLayer::readLabelingFromCustomProperties ()
4226
4228
{
4227
4229
QgsAbstractVectorLayerLabeling *labeling = nullptr ;
4228
- if ( customProperty ( QStringLiteral ( " labeling" ) ).toString () == QLatin1String ( " pal" ) &&
4229
- customProperty ( QStringLiteral ( " labeling/enabled" ), QVariant ( false ) ).toBool () == true )
4230
+ if ( customProperty ( QStringLiteral ( " labeling" ) ).toString () == QLatin1String ( " pal" ) )
4230
4231
{
4231
- // try to load from custom properties
4232
- QgsPalLayerSettings settings;
4233
- settings.readFromLayerCustomProperties ( this );
4234
- labeling = new QgsVectorLayerSimpleLabeling ( settings );
4235
- }
4232
+ if ( customProperty ( QStringLiteral ( " labeling/enabled" ), QVariant ( false ) ).toBool () == true )
4233
+ {
4234
+ // try to load from custom properties
4235
+ QgsPalLayerSettings settings;
4236
+ settings.readFromLayerCustomProperties ( this );
4237
+ labeling = new QgsVectorLayerSimpleLabeling ( settings );
4238
+ }
4236
4239
4237
- // also clear old-style labeling config
4238
- removeCustomProperty ( QStringLiteral ( " labeling" ) );
4240
+ // also clear old-style labeling config
4241
+ removeCustomProperty ( QStringLiteral ( " labeling" ) );
4242
+ Q_FOREACH ( const QString &key, customPropertyKeys () )
4243
+ {
4244
+ if ( key.startsWith ( " labeling/" ) )
4245
+ removeCustomProperty ( key );
4246
+ }
4247
+ }
4239
4248
4240
4249
return labeling;
4241
4250
}
0 commit comments