Skip to content
Permalink
Browse files

[FEATURE] Double clicking a legend node opens symbol editor directly

  • Loading branch information
nyalldawson committed Dec 9, 2015
1 parent 2026fce commit c7c5c007be90076ba023090152410e2294bd402b
@@ -54,6 +54,11 @@ class QgsLayerTreeView : QTreeView
//! Get current group node. If a layer is current node, the function will return parent group. May be null.
QgsLayerTreeGroup* currentGroupNode() const;

/** Get current legend node. May be null if current node is not a legend node.
* @note added in QGIS 2.14
*/
QgsLayerTreeModelLegendNode* currentLegendNode() const;

//! Return list of selected nodes
//! @arg skipInternal If true, will ignore nodes which have an ancestor in the selection
QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;
@@ -156,6 +156,7 @@
#include "qgslayertree.h"
#include "qgslayertreemapcanvasbridge.h"
#include "qgslayertreemodel.h"
#include "qgslayertreemodellegendnode.h"
#include "qgslayertreeregistrybridge.h"
#include "qgslayertreeutils.h"
#include "qgslayertreeview.h"
@@ -209,6 +210,8 @@
#include "qgssnappingdialog.h"
#include "qgssponsors.h"
#include "qgsstatisticalsummarydockwidget.h"
#include "qgssymbolv2selectordialog.h"
#include "qgsstylev2.h"
#include "qgssvgannotationitem.h"
#include "qgstextannotationitem.h"
#include "qgstipgui.h"
@@ -411,8 +414,32 @@ void QgisApp::layerTreeViewDoubleClicked( const QModelIndex& index )
switch ( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
{
case 0:
{
//show properties
if ( mLayerTreeView )
{
// if it's a legend node, open symbol editor directly
if ( QgsSymbolV2LegendNode* node = dynamic_cast<QgsSymbolV2LegendNode*>( mLayerTreeView->currentLegendNode() ) )
{
const QgsSymbolV2* originalSymbol = node->symbol();
if ( !originalSymbol )
return;

QScopedPointer< QgsSymbolV2 > symbol( originalSymbol->clone() );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() );
QgsSymbolV2SelectorDialog dlg( symbol.data(), QgsStyleV2::defaultStyle(), vlayer, this );
dlg.setMapCanvas( mMapCanvas );
if ( dlg.exec() )
{
node->setSymbol( symbol.take() );
}

return;
}
}
QgisApp::instance()->layerProperties();
break;
}
case 1:
QgisApp::instance()->attributeTable();
break;
@@ -403,7 +403,7 @@ void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol()

QScopedPointer< QgsSymbolV2 > symbol( originalSymbol->clone() );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() );
QgsSymbolV2SelectorDialog dlg( symbol.data(), QgsStyleV2::defaultStyle(), vlayer, mView );
QgsSymbolV2SelectorDialog dlg( symbol.data(), QgsStyleV2::defaultStyle(), vlayer, mView->window() );
dlg.setMapCanvas( mCanvas );
if ( dlg.exec() )
{
@@ -273,6 +273,11 @@ QgsLayerTreeGroup* QgsLayerTreeView::currentGroupNode() const
return 0;
}

QgsLayerTreeModelLegendNode* QgsLayerTreeView::currentLegendNode() const
{
return layerTreeModel()->index2legendNode( selectionModel()->currentIndex() );
}

QList<QgsLayerTreeNode*> QgsLayerTreeView::selectedNodes( bool skipInternal ) const
{
return layerTreeModel()->indexes2nodes( selectionModel()->selectedIndexes(), skipInternal );
@@ -22,6 +22,7 @@ class QgsLayerTreeGroup;
class QgsLayerTreeLayer;
class QgsLayerTreeModel;
class QgsLayerTreeNode;
class QgsLayerTreeModelLegendNode;
class QgsLayerTreeViewDefaultActions;
class QgsLayerTreeViewMenuProvider;
class QgsMapLayer;
@@ -72,6 +73,11 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView
//! Get current group node. If a layer is current node, the function will return parent group. May be null.
QgsLayerTreeGroup* currentGroupNode() const;

/** Get current legend node. May be null if current node is not a legend node.
* @note added in QGIS 2.14
*/
QgsLayerTreeModelLegendNode* currentLegendNode() const;

//! Return list of selected nodes
//! @arg skipInternal If true, will ignore nodes which have an ancestor in the selection
QList<QgsLayerTreeNode*> selectedNodes( bool skipInternal = false ) const;

0 comments on commit c7c5c00

Please sign in to comment.
You can’t perform that action at this time.