@@ -1059,16 +1059,32 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe
10591059 styleFile.updateRevision ( thisVersion );
10601060 }
10611061
1062+ // Get source categories
1063+ QgsMapLayer::StyleCategories sourceCategories = QgsMapLayer::AllStyleCategories;
1064+ QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
1065+ QString sourceCategoriesStr ( myRoot.attribute ( " style_categories" , metaEnum.valueToKeys ( static_cast <int >( QgsMapLayer::AllStyleCategories ) ) ) );
1066+ if ( metaEnum.isValid () )
1067+ {
1068+ bool ok = false ;
1069+ const char *vs = sourceCategoriesStr.toUtf8 ().data ();
1070+ int newValue = metaEnum.keysToValue ( vs, &ok );
1071+ if ( ok )
1072+ sourceCategories = static_cast <QgsMapLayer::StyleCategories>( newValue );
1073+ }
1074+
10621075 // Test for matching geometry type on vector layers when applying, if geometry type is given in the style
1063- if ( type () == QgsMapLayer::VectorLayer && !myRoot.firstChildElement ( QStringLiteral ( " layerGeometryType" ) ).isNull () )
1076+ if ( ( sourceCategories.testFlag ( QgsMapLayer::Symbology ) || sourceCategories.testFlag ( QgsMapLayer::Symbology3D ) ) &&
1077+ ( categories.testFlag ( QgsMapLayer::Symbology ) || categories.testFlag ( QgsMapLayer::Symbology3D ) ) )
10641078 {
1065- QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
1066- QgsWkbTypes::GeometryType importLayerGeometryType = static_cast <QgsWkbTypes::GeometryType>( myRoot.firstChildElement ( QStringLiteral ( " layerGeometryType" ) ).text ().toInt () );
1067- if ( vl->geometryType () != importLayerGeometryType &&
1068- ( categories.testFlag ( QgsMapLayer::Symbology ) || categories.testFlag ( QgsMapLayer::Symbology3D ) ) )
1079+ if ( type () == QgsMapLayer::VectorLayer && !myRoot.firstChildElement ( QStringLiteral ( " layerGeometryType" ) ).isNull () )
10691080 {
1070- myErrorMessage = tr ( " Cannot apply style with symbology to layer with a different geometry type" );
1071- return false ;
1081+ QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
1082+ QgsWkbTypes::GeometryType importLayerGeometryType = static_cast <QgsWkbTypes::GeometryType>( myRoot.firstChildElement ( QStringLiteral ( " layerGeometryType" ) ).text ().toInt () );
1083+ if ( vl->geometryType () != importLayerGeometryType )
1084+ {
1085+ myErrorMessage = tr ( " Cannot apply style with symbology to layer with a different geometry type" );
1086+ return false ;
1087+ }
10721088 }
10731089 }
10741090
0 commit comments