|
4 | 4 | #include "qgisapp.h"
|
5 | 5 | #include "qgsapplication.h"
|
6 | 6 | #include "qgsclipboard.h"
|
| 7 | +#include "qgscolorwidgets.h" |
| 8 | +#include "qgscolorschemeregistry.h" |
| 9 | +#include "qgscolorswatchgrid.h" |
7 | 10 | #include "qgslayertree.h"
|
8 | 11 | #include "qgslayertreemodel.h"
|
9 | 12 | #include "qgslayertreemodellegendnode.h"
|
@@ -205,6 +208,22 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
|
205 | 208 | menu->addAction( QgsApplication::getThemeIcon( "/mActionHideAllLayers.png" ), tr( "&Hide All Items" ),
|
206 | 209 | symbolNode, SLOT( uncheckAllItems() ) );
|
207 | 210 | menu->addSeparator();
|
| 211 | + |
| 212 | + if ( symbolNode->symbol() ) |
| 213 | + { |
| 214 | + QgsColorWheel* colorWheel = new QgsColorWheel( menu ); |
| 215 | + colorWheel->setColor( symbolNode->symbol()->color() ); |
| 216 | + QgsColorWidgetAction* colorAction = new QgsColorWidgetAction( colorWheel, menu, menu ); |
| 217 | + colorAction->setDismissOnColorSelection( false ); |
| 218 | + connect( colorAction, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setSymbolLegendNodeColor( const QColor& ) ) ); |
| 219 | + //store the layer id and rule key in action, so we can later retrieve the corresponding |
| 220 | + //legend node, if it still exists |
| 221 | + colorAction->setProperty( "layerId", symbolNode->layerNode()->layerId() ); |
| 222 | + colorAction->setProperty( "ruleKey", symbolNode->data( QgsLayerTreeModelLegendNode::RuleKeyRole ).toString() ); |
| 223 | + menu->addAction( colorAction ); |
| 224 | + menu->addSeparator(); |
| 225 | + } |
| 226 | + |
208 | 227 | QAction* editSymbolAction = new QAction( tr( "Edit Symbol..." ), menu );
|
209 | 228 | //store the layer id and rule key in action, so we can later retrieve the corresponding
|
210 | 229 | //legend node, if it still exists
|
@@ -391,3 +410,25 @@ void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol()
|
391 | 410 | node->setSymbol( symbol.take() );
|
392 | 411 | }
|
393 | 412 | }
|
| 413 | + |
| 414 | +void QgsAppLayerTreeViewMenuProvider::setSymbolLegendNodeColor( const QColor &color ) |
| 415 | +{ |
| 416 | + QAction* action = qobject_cast< QAction*>( sender() ); |
| 417 | + if ( !action ) |
| 418 | + return; |
| 419 | + |
| 420 | + QString layerId = action->property( "layerId" ).toString(); |
| 421 | + QString ruleKey = action->property( "ruleKey" ).toString(); |
| 422 | + |
| 423 | + QgsSymbolV2LegendNode* node = dynamic_cast<QgsSymbolV2LegendNode*>( mView->layerTreeModel()->findLegendNode( layerId, ruleKey ) ); |
| 424 | + if ( !node ) |
| 425 | + return; |
| 426 | + |
| 427 | + const QgsSymbolV2* originalSymbol = node->symbol(); |
| 428 | + if ( !originalSymbol ) |
| 429 | + return; |
| 430 | + |
| 431 | + QgsSymbolV2* newSymbol = originalSymbol->clone(); |
| 432 | + newSymbol->setColor( color ); |
| 433 | + node->setSymbol( newSymbol ); |
| 434 | +} |
0 commit comments