Merge pull request #2575 from slarosa/style_grp_layers

[FEATURE] allow applying the same style to selected layers or to legend group
This commit is contained in:
Nyall Dawson 2015-12-13 21:48:02 +11:00
commit 2d9f36100e
3 changed files with 41 additions and 0 deletions

View File

@ -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()
{

View File

@ -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();

View File

@ -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();