Skip to content

Commit

Permalink
De-Duplicate code from 'copy/paste style' found in 'import/export nam…
Browse files Browse the repository at this point in the history
…ed style'
  • Loading branch information
SebDieBln committed Nov 21, 2015
1 parent ef4b5ea commit 9c7bbb5
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/app/qgisapp.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6799,21 +6799,12 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )


if ( selectionLayer ) if ( selectionLayer )
{ {
QDomImplementation DomImplementation;
QDomDocumentType documentType =
DomImplementation.createDocumentType(
"qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" );
QDomDocument doc( documentType );
QDomElement rootNode = doc.createElement( "qgis" );
rootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
doc.appendChild( rootNode );

rootNode.setAttribute( "hasScaleBasedVisibilityFlag", selectionLayer->hasScaleBasedVisibility() ? 1 : 0 );
rootNode.setAttribute( "minimumScale", QString::number( selectionLayer->minimumScale() ) );
rootNode.setAttribute( "maximumScale", QString::number( selectionLayer->maximumScale() ) );

QString errorMsg; QString errorMsg;
if ( !selectionLayer->writeSymbology( rootNode, doc, errorMsg ) ) QDomDocument doc( "qgis" );
selectionLayer->exportNamedStyle( doc, errorMsg );


if ( !errorMsg.isEmpty() )
{ {
messageBar()->pushMessage( errorMsg, messageBar()->pushMessage( errorMsg,
tr( "Cannot copy style: %1" ), tr( "Cannot copy style: %1" ),
Expand All @@ -6827,7 +6818,7 @@ void QgisApp::copyStyle( QgsMapLayer * sourceLayer )
} }
} }
/** /**
\param destinatioLayer The layer that the clipboard will be pasted to \param destinationLayer The layer that the clipboard will be pasted to
(defaults to the active layer on the legend) (defaults to the active layer on the legend)
*/ */


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


QDomElement rootNode = doc.firstChildElement( "qgis" ); if ( !selectionLayer->importNamedStyle( doc, errorMsg ) )

if ( !selectionLayer->readSymbology( rootNode, errorMsg ) )
{ {
messageBar()->pushMessage( errorMsg, messageBar()->pushMessage( errorMsg,
tr( "Cannot read style: %1" ), tr( "Cannot paste style: %1" ),
QgsMessageBar::CRITICAL, messageTimeout() ); QgsMessageBar::CRITICAL, messageTimeout() );
return; return;
} }


selectionLayer->setScaleBasedVisibility( rootNode.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
selectionLayer->setMinimumScale( rootNode.attribute( "minimumScale" ).toFloat() );
selectionLayer->setMaximumScale( rootNode.attribute( "maximumScale" ).toFloat() );

mLayerTreeView->refreshLayerSymbology( selectionLayer->id() ); mLayerTreeView->refreshLayerSymbology( selectionLayer->id() );
mMapCanvas->clearCache(); mMapCanvas->clearCache();
mMapCanvas->refresh(); mMapCanvas->refresh();
Expand Down

0 comments on commit 9c7bbb5

Please sign in to comment.