Skip to content
Permalink
Browse files

use the source style from clipbboard to avoid error when pasting with…

… all style
  • Loading branch information
3nids committed Oct 4, 2018
1 parent b004a41 commit 0cd6ea488dc69c083b58ead5a1d1925e8b850633
Showing with 23 additions and 7 deletions.
  1. +23 −7 src/core/qgsmaplayer.cpp
@@ -1059,16 +1059,32 @@ bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMe
styleFile.updateRevision( thisVersion );
}

// Get source categories
QgsMapLayer::StyleCategories sourceCategories = QgsMapLayer::AllStyleCategories;
QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
QString sourceCategoriesStr( myRoot.attribute( "style_categories", metaEnum.valueToKeys( static_cast<int>( QgsMapLayer::AllStyleCategories ) ) ) );
if ( metaEnum.isValid() )
{
bool ok = false;
const char *vs = sourceCategoriesStr.toUtf8().data();
int newValue = metaEnum.keysToValue( vs, &ok );
if ( ok )
sourceCategories = static_cast<QgsMapLayer::StyleCategories>( newValue );
}

//Test for matching geometry type on vector layers when applying, if geometry type is given in the style
if ( type() == QgsMapLayer::VectorLayer && !myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).isNull() )
if ( ( sourceCategories.testFlag( QgsMapLayer::Symbology ) || sourceCategories.testFlag( QgsMapLayer::Symbology3D ) ) &&
( categories.testFlag( QgsMapLayer::Symbology ) || categories.testFlag( QgsMapLayer::Symbology3D ) ) )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
QgsWkbTypes::GeometryType importLayerGeometryType = static_cast<QgsWkbTypes::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
if ( vl->geometryType() != importLayerGeometryType &&
( categories.testFlag( QgsMapLayer::Symbology ) || categories.testFlag( QgsMapLayer::Symbology3D ) ) )
if ( type() == QgsMapLayer::VectorLayer && !myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).isNull() )
{
myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
return false;
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
QgsWkbTypes::GeometryType importLayerGeometryType = static_cast<QgsWkbTypes::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
if ( vl->geometryType() != importLayerGeometryType )
{
myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
return false;
}
}
}

0 comments on commit 0cd6ea4

Please sign in to comment.
You can’t perform that action at this time.