Skip to content
Permalink
Browse files

New flag to disable checkboxes for legend nodes in layer tree model

  • Loading branch information
wonder-sk committed Sep 1, 2014
1 parent 8dba8af commit 0fc7fc7b070956761f446323622b8cf96702b025
@@ -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;

@@ -33,7 +33,7 @@
QgsLayerTreeModel::QgsLayerTreeModel( QgsLayerTreeGroup* rootNode, QObject *parent )
: QAbstractItemModel( parent )
, mRootNode( rootNode )
, mFlags( ShowSymbology )
, mFlags( ShowSymbology | AllowSymbologyChangeState )
, mAutoCollapseSymNodesCount( -1 )
{
Q_ASSERT( mRootNode );
@@ -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 );
}

@@ -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;
@@ -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 );
@@ -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 )

0 comments on commit 0fc7fc7

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