mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
New flag to disable checkboxes for legend nodes in layer tree model
This commit is contained in:
parent
8dba8af60d
commit
0fc7fc7b07
@ -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 )
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user