Skip to content

Commit

Permalink
Merge pull request #2575 from slarosa/style_grp_layers
Browse files Browse the repository at this point in the history
[FEATURE] allow applying the same style to selected layers or to legend group
  • Loading branch information
nyalldawson committed Dec 13, 2015
2 parents 262514d + f0aeee8 commit 2d9f361
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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();

Expand Down
12 changes: 12 additions & 0 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 2d9f361

Please sign in to comment.