Skip to content

Commit

Permalink
[FEATURE] Double clicking a legend node opens symbol editor directly
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 9, 2015
1 parent 2026fce commit c7c5c00
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions python/gui/layertree/qgslayertreeview.sip
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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() )
{
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layertree/qgslayertreeview.cpp
Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/gui/layertree/qgslayertreeview.h
Expand Up @@ -22,6 +22,7 @@ class QgsLayerTreeGroup;
class QgsLayerTreeLayer;
class QgsLayerTreeModel;
class QgsLayerTreeNode;
class QgsLayerTreeModelLegendNode;
class QgsLayerTreeViewDefaultActions;
class QgsLayerTreeViewMenuProvider;
class QgsMapLayer;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c7c5c00

Please sign in to comment.