|
9 | 9 | #include "qgslayertreemodellegendnode.h"
|
10 | 10 | #include "qgslayertreeviewdefaultactions.h"
|
11 | 11 | #include "qgsmaplayerstyleguiutils.h"
|
| 12 | +#include "qgsmaplayerregistry.h" |
12 | 13 | #include "qgsproject.h"
|
13 | 14 | #include "qgsrasterlayer.h"
|
| 15 | +#include "qgsrendererv2.h" |
| 16 | +#include "qgssymbolv2.h" |
| 17 | +#include "qgsstylev2.h" |
14 | 18 | #include "qgsvectordataprovider.h"
|
15 | 19 | #include "qgsvectorlayer.h"
|
16 | 20 | #include "qgslayertreeregistrybridge.h"
|
17 |
| - |
| 21 | +#include "qgssymbolv2selectordialog.h" |
18 | 22 |
|
19 | 23 | QgsAppLayerTreeViewMenuProvider::QgsAppLayerTreeViewMenuProvider( QgsLayerTreeView* view, QgsMapCanvas* canvas )
|
20 | 24 | : mView( view )
|
@@ -200,6 +204,14 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
200 | 204 | symbolNode, SLOT( checkAllItems() ) );
|
201 | 205 | menu->addAction( QgsApplication::getThemeIcon( "/mActionHideAllLayers.png" ), tr( "&Hide All Items" ),
|
202 | 206 | symbolNode, SLOT( uncheckAllItems() ) );
|
| 207 | + menu->addSeparator(); |
| 208 | + QAction* editSymbolAction = new QAction( tr( "Edit Symbol..." ), menu ); |
| 209 | + //store the layer id and rule key in action, so we can later retrieve the corresponding |
| 210 | + //legend node, if it still exists |
| 211 | + editSymbolAction->setProperty( "layerId", symbolNode->layerNode()->layerId() ); |
| 212 | + editSymbolAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() ); |
| 213 | + connect( editSymbolAction, SIGNAL( triggered() ), this, SLOT( editSymbolLegendNodeSymbol() ) ); |
| 214 | + menu->addAction( editSymbolAction ); |
203 | 215 | }
|
204 | 216 | }
|
205 | 217 | }
|
@@ -352,3 +364,30 @@ void QgsAppLayerTreeViewMenuProvider::addCustomLayerActions( QMenu* menu, QgsMap
|
352 | 364 | menu->addSeparator();
|
353 | 365 | }
|
354 | 366 | }
|
| 367 | + |
| 368 | +void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol() |
| 369 | +{ |
| 370 | + QAction* action = qobject_cast< QAction*>( sender() ); |
| 371 | + if ( !action ) |
| 372 | + return; |
| 373 | + |
| 374 | + QString layerId = action->property( "layerId" ).toString(); |
| 375 | + QString ruleKey = action->property( "ruleKey" ).toString(); |
| 376 | + |
| 377 | + QgsSymbolV2LegendNode* node = dynamic_cast<QgsSymbolV2LegendNode*>( mView->layerTreeModel()->findLegendNode( layerId, ruleKey ) ); |
| 378 | + if ( !node ) |
| 379 | + return; |
| 380 | + |
| 381 | + const QgsSymbolV2* originalSymbol = node->symbol(); |
| 382 | + if ( !originalSymbol ) |
| 383 | + return; |
| 384 | + |
| 385 | + QScopedPointer< QgsSymbolV2 > symbol( originalSymbol->clone() ); |
| 386 | + QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() ); |
| 387 | + QgsSymbolV2SelectorDialog dlg( symbol.data(), QgsStyleV2::defaultStyle(), vlayer, mView ); |
| 388 | + dlg.setMapCanvas( mCanvas ); |
| 389 | + if ( dlg.exec() ) |
| 390 | + { |
| 391 | + node->setSymbol( symbol.take() ); |
| 392 | + } |
| 393 | +} |
0 commit comments