From f0aeee8c5be6ed29ffc2ff636bc59c68cac19585 Mon Sep 17 00:00:00 2001 From: Salvatore Larosa Date: Sat, 14 Nov 2015 16:44:31 +0100 Subject: [PATCH] [FEATURE] allow applying the same style to selected layers or to legend group also fixes #10323 This adds the possibility to paste the style to group or selected layers. --- src/app/qgisapp.cpp | 26 +++++++++++++++++++++ src/app/qgisapp.h | 3 +++ src/app/qgsapplayertreeviewmenuprovider.cpp | 12 ++++++++++ 3 files changed, 41 insertions(+) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 38c76872261..dad2ac33af8 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -7746,7 +7746,33 @@ void QgisApp::legendLayerStretchUsingCurrentExtent() } } +void QgisApp::applyStyleToGroup() +{ + if ( !mLayerTreeView ) + return; + Q_FOREACH ( QgsLayerTreeNode* node, mLayerTreeView->selectedNodes() ) + { + if ( QgsLayerTree::isGroup( node ) ) + { + Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, QgsLayerTree::toGroup( node )->findLayers() ) + { + if ( nodeLayer->layer() ) + { + pasteStyle( nodeLayer->layer() ); + } + } + } + else if ( QgsLayerTree::isLayer( node ) ) + { + QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node ); + if ( nodeLayer->layer() ) + { + pasteStyle( nodeLayer->layer() ); + } + } + } +} void QgisApp::legendGroupSetCRS() { diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index b44b7652dbd..1ce78ffda37 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -748,6 +748,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow Only workds on raster layers*/ void legendLayerStretchUsingCurrentExtent(); + /** Apply the same style to selected layers or to current legend group*/ + void applyStyleToGroup(); + /** Set the CRS of the current legend group*/ void legendGroupSetCRS(); diff --git a/src/app/qgsapplayertreeviewmenuprovider.cpp b/src/app/qgsapplayertreeviewmenuprovider.cpp index 7489714c944..9137ee04957 100644 --- a/src/app/qgsapplayertreeviewmenuprovider.cpp +++ b/src/app/qgsapplayertreeviewmenuprovider.cpp @@ -66,6 +66,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu() if ( mView->selectedNodes( true ).count() >= 2 ) menu->addAction( actions->actionGroupSelected( menu ) ); + if ( QgisApp::instance()->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) ) + { + menu->addAction( tr( "Paste Style" ), QgisApp::instance(), SLOT( applyStyleToGroup() ) ); + } + menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) ); menu->addAction( actions->actionAddGroup( menu ) ); @@ -121,6 +126,13 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu() menu->addMenu( menuStyleManager ); } + else + { + if ( QgisApp::instance()->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) ) + { + menu->addAction( tr( "Paste Style" ), QgisApp::instance(), SLOT( applyStyleToGroup() ) ); + } + } menu->addSeparator();