fix : allow copying style from an unavailable layer

This commit is contained in:
olivierdalang 2020-06-09 11:59:28 +02:00 committed by Nyall Dawson
parent ce9f519468
commit 2bcb63edc4
2 changed files with 5 additions and 2 deletions

View File

@ -1061,7 +1061,7 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
QgsWkbTypes::GeometryType importLayerGeometryType = static_cast<QgsWkbTypes::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
if ( vl->geometryType() != importLayerGeometryType )
if ( importLayerGeometryType != QgsWkbTypes::GeometryType::UnknownGeometry && vl->geometryType() != importLayerGeometryType )
{
myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
return false;

View File

@ -2800,7 +2800,10 @@ bool QgsVectorLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &err
emit writeCustomSymbology( mapLayerNode, doc, errorMessage );
if ( isSpatial() )
// we must try to write the renderer if our geometry type is unknown
// as this allows the renderer to be correctly restored even for layers
// with broken sources
if ( isSpatial() || mWkbType == QgsWkbTypes::Unknown )
{
if ( categories.testFlag( Symbology ) )
{