Skip to content

Commit 2d9f361

Browse files
committed
Merge pull request #2575 from slarosa/style_grp_layers
[FEATURE] allow applying the same style to selected layers or to legend group
2 parents 262514d + f0aeee8 commit 2d9f361

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/app/qgisapp.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -7746,7 +7746,33 @@ void QgisApp::legendLayerStretchUsingCurrentExtent()
77467746
}
77477747
}
77487748

7749+
void QgisApp::applyStyleToGroup()
7750+
{
7751+
if ( !mLayerTreeView )
7752+
return;
77497753

7754+
Q_FOREACH ( QgsLayerTreeNode* node, mLayerTreeView->selectedNodes() )
7755+
{
7756+
if ( QgsLayerTree::isGroup( node ) )
7757+
{
7758+
Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, QgsLayerTree::toGroup( node )->findLayers() )
7759+
{
7760+
if ( nodeLayer->layer() )
7761+
{
7762+
pasteStyle( nodeLayer->layer() );
7763+
}
7764+
}
7765+
}
7766+
else if ( QgsLayerTree::isLayer( node ) )
7767+
{
7768+
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
7769+
if ( nodeLayer->layer() )
7770+
{
7771+
pasteStyle( nodeLayer->layer() );
7772+
}
7773+
}
7774+
}
7775+
}
77507776

77517777
void QgisApp::legendGroupSetCRS()
77527778
{

src/app/qgisapp.h

+3
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
748748
Only workds on raster layers*/
749749
void legendLayerStretchUsingCurrentExtent();
750750

751+
/** Apply the same style to selected layers or to current legend group*/
752+
void applyStyleToGroup();
753+
751754
/** Set the CRS of the current legend group*/
752755
void legendGroupSetCRS();
753756

src/app/qgsapplayertreeviewmenuprovider.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
6666
if ( mView->selectedNodes( true ).count() >= 2 )
6767
menu->addAction( actions->actionGroupSelected( menu ) );
6868

69+
if ( QgisApp::instance()->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
70+
{
71+
menu->addAction( tr( "Paste Style" ), QgisApp::instance(), SLOT( applyStyleToGroup() ) );
72+
}
73+
6974
menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) );
7075

7176
menu->addAction( actions->actionAddGroup( menu ) );
@@ -121,6 +126,13 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
121126

122127
menu->addMenu( menuStyleManager );
123128
}
129+
else
130+
{
131+
if ( QgisApp::instance()->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
132+
{
133+
menu->addAction( tr( "Paste Style" ), QgisApp::instance(), SLOT( applyStyleToGroup() ) );
134+
}
135+
}
124136

125137
menu->addSeparator();
126138

0 commit comments

Comments
 (0)