Skip to content

Commit 9c7bbb5

Browse files
committed
De-Duplicate code from 'copy/paste style' found in 'import/export named style'
1 parent ef4b5ea commit 9c7bbb5

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

src/app/qgisapp.cpp

+8-23
Original file line numberDiff line numberDiff line change
@@ -6799,21 +6799,12 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
67996799

68006800
if ( selectionLayer )
68016801
{
6802-
QDomImplementation DomImplementation;
6803-
QDomDocumentType documentType =
6804-
DomImplementation.createDocumentType(
6805-
"qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" );
6806-
QDomDocument doc( documentType );
6807-
QDomElement rootNode = doc.createElement( "qgis" );
6808-
rootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
6809-
doc.appendChild( rootNode );
6810-
6811-
rootNode.setAttribute( "hasScaleBasedVisibilityFlag", selectionLayer->hasScaleBasedVisibility() ? 1 : 0 );
6812-
rootNode.setAttribute( "minimumScale", QString::number( selectionLayer->minimumScale() ) );
6813-
rootNode.setAttribute( "maximumScale", QString::number( selectionLayer->maximumScale() ) );
6814-
68156802
QString errorMsg;
6816-
if ( !selectionLayer->writeSymbology( rootNode, doc, errorMsg ) )
6803+
QDomDocument doc( "qgis" );
6804+
selectionLayer->exportNamedStyle( doc, errorMsg );
6805+
6806+
6807+
if ( !errorMsg.isEmpty() )
68176808
{
68186809
messageBar()->pushMessage( errorMsg,
68196810
tr( "Cannot copy style: %1" ),
@@ -6827,7 +6818,7 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
68276818
}
68286819
}
68296820
/**
6830-
\param destinatioLayer The layer that the clipboard will be pasted to
6821+
\param destinationLayer The layer that the clipboard will be pasted to
68316822
(defaults to the active layer on the legend)
68326823
*/
68336824

@@ -6851,20 +6842,14 @@ void QgisApp::pasteStyle( QgsMapLayer * destinationLayer )
68516842
return;
68526843
}
68536844

6854-
QDomElement rootNode = doc.firstChildElement( "qgis" );
6855-
6856-
if ( !selectionLayer->readSymbology( rootNode, errorMsg ) )
6845+
if ( !selectionLayer->importNamedStyle( doc, errorMsg ) )
68576846
{
68586847
messageBar()->pushMessage( errorMsg,
6859-
tr( "Cannot read style: %1" ),
6848+
tr( "Cannot paste style: %1" ),
68606849
QgsMessageBar::CRITICAL, messageTimeout() );
68616850
return;
68626851
}
68636852

6864-
selectionLayer->setScaleBasedVisibility( rootNode.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
6865-
selectionLayer->setMinimumScale( rootNode.attribute( "minimumScale" ).toFloat() );
6866-
selectionLayer->setMaximumScale( rootNode.attribute( "maximumScale" ).toFloat() );
6867-
68686853
mLayerTreeView->refreshLayerSymbology( selectionLayer->id() );
68696854
mMapCanvas->clearCache();
68706855
mMapCanvas->refresh();

0 commit comments

Comments
 (0)