Skip to content

Commit

Permalink
New flag to disable checkboxes for legend nodes in layer tree model
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 8dba8af commit 0fc7fc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/core/layertree/qgslayertreemodel.sip
Expand Up @@ -57,6 +57,7 @@ class QgsLayerTreeModel : QAbstractItemModel
AllowNodeReorder, //!< Allow reordering with drag'n'drop
AllowNodeRename, //!< Allow renaming of groups and layers
AllowNodeChangeVisibility, //!< Allow user to set node visibility with a check box
AllowSymbologyChangeState, //!< Allow check boxes for symbology items (if supported by layer's legend)
};
typedef QFlags<QgsLayerTreeModel::Flag> Flags;

Expand Down
11 changes: 9 additions & 2 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -33,7 +33,7 @@
QgsLayerTreeModel::QgsLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *parent )
: QAbstractItemModel( parent )
, mRootNode( rootNode )
, mFlags( ShowSymbology )
, mFlags( ShowSymbology | AllowSymbologyChangeState )
, mAutoCollapseSymNodesCount( -1 )
{
Q_ASSERT( mRootNode );
Expand Down Expand Up @@ -166,6 +166,8 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const

if ( QgsLayerTreeModelLegendNode* sym = index2symnode( index ) )
{
if ( role == Qt::CheckStateRole && !testFlag( AllowSymbologyChangeState ) )
return QVariant();
return sym->data( role );
}

Expand Down Expand Up @@ -289,7 +291,10 @@ Qt::ItemFlags QgsLayerTreeModel::flags( const QModelIndex& index ) const

if ( QgsLayerTreeModelLegendNode* symn = index2symnode( index ) )
{
return symn->flags();
Qt::ItemFlags f = symn->flags();
if ( !testFlag( AllowSymbologyChangeState ) )
f &= ~Qt::ItemIsUserCheckable;
return f;
}

Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
Expand Down Expand Up @@ -321,6 +326,8 @@ bool QgsLayerTreeModel::setData( const QModelIndex& index, const QVariant& value
QgsLayerTreeModelLegendNode *sym = index2symnode( index );
if ( sym )
{
if ( role == Qt::CheckStateRole && !testFlag( AllowSymbologyChangeState ) )
return false;
bool res = sym->setData( value, role );
if ( res )
emit dataChanged( index, index );
Expand Down
1 change: 1 addition & 0 deletions src/core/layertree/qgslayertreemodel.h
Expand Up @@ -77,6 +77,7 @@ class CORE_EXPORT QgsLayerTreeModel : public QAbstractItemModel
AllowNodeReorder = 0x1000, //!< Allow reordering with drag'n'drop
AllowNodeRename = 0x2000, //!< Allow renaming of groups and layers
AllowNodeChangeVisibility = 0x4000, //!< Allow user to set node visibility with a check box
AllowSymbologyChangeState = 0x8000, //!< Allow check boxes for symbology items (if supported by layer's legend)
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down

0 comments on commit 0fc7fc7

Please sign in to comment.