Skip to content

Commit f0aeee8

Browse files
committed
[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.
1 parent 262514d commit f0aeee8

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/app/qgisapp.cpp

Lines changed: 26 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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)