Public Types | Public Slots | Public Member Functions | Properties | Friends | List of all members
pqCompositeDataInformationTreeModel Class Reference

Tree model that use vtkPVDataInformation to model composite data tree. More...

#include <pqCompositeDataInformationTreeModel.h>

Inherits QAbstractItemModel.

Public Types

enum  { ValueInheritedRole = Qt::UserRole, LeafIndexRole, CompositeIndexRole }
 Custom roles available for data. More...
 

Public Slots

bool reset (vtkPVDataInformation *info=nullptr)
 Reset and rebuild the model using the data information object provided. More...
 

Public Member Functions

 pqCompositeDataInformationTreeModel (QObject *parent=0)
 
 ~pqCompositeDataInformationTreeModel () override
 
QList< unsigned intcheckedNodes () const
 API to get flat-indices for checked nodes. More...
 
QList< unsigned intcheckedLeaves () const
 API to get flat-indices for checked nodes. More...
 
void setChecked (const QList< unsigned int > &indices)
 API to set the flat-indices for checked nodes. More...
 
QList< QPair< unsigned int, bool > > checkStates () const
 Returns check state for nodes explicitly toggled. More...
 
void setCheckStates (const QList< QPair< unsigned int, bool > > &states)
 Set check states. More...
 
unsigned int compositeIndex (const QModelIndex &idx) const
 Returns the flat or composite index associated with the node. More...
 
QModelIndex find (unsigned int compositeIndex) const
 Return the QModelIndex for composite idx. More...
 
const QModelIndex rootIndex () const
 Returns the index for the root of the tree. More...
 
int addColumn (const QString &propertyName)
 Add a custom column to model. More...
 
int columnIndex (const QString &propertyName)
 Returns the index for a custom column with the given name. More...
 
void clearColumns ()
 Remove all extra columns added via addColumn API. More...
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 QAbstractItemModel interface implementation. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 QAbstractItemModel interface implementation. More...
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 QAbstractItemModel interface implementation. More...
 
QModelIndex parent (const QModelIndex &index=QModelIndex()) const override
 QAbstractItemModel interface implementation. More...
 
QVariant data (const QModelIndex &index, int role) const override
 QAbstractItemModel interface implementation. More...
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 QAbstractItemModel interface implementation. More...
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 QAbstractItemModel interface implementation. More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
 QAbstractItemModel interface implementation. More...
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::DisplayRole) override
 QAbstractItemModel interface implementation. More...
 
void setUserCheckable (bool val)
 Toggle whether the model allows user to change check state. More...
 
bool userCheckable () const
 Toggle whether the model allows user to change check state. More...
 
void setOnlyLeavesAreUserCheckable (bool val)
 When UserCheckable is true, this limits use-checkability to leaf nodes only. More...
 
bool onlyLeavesAreUserCheckable () const
 When UserCheckable is true, this limits use-checkability to leaf nodes only. More...
 
void setDefaultCheckState (bool checked)
 Get/Set the default check state for nodes. More...
 
bool defaultCheckState () const
 Get/Set the default check state for nodes. More...
 
void setExpandMultiPiece (bool val)
 Toggle whether multipiece datasets are expanded (default false). More...
 
bool expandMultiPiece () const
 Get/Set the default check state for nodes. More...
 
void setExclusivity (bool val)
 When set to true for a userCheckable model, if the user checks a node, the all other nodes that are not children of the checked node are unchecked. More...
 
bool exclusivity () const
 When set to true for a userCheckable model, if the user checks a node, the all other nodes that are not children of the checked node are unchecked. More...
 
QList< unsigned intcheckedLevels () const
 This is useful when dealing with AMR datasets. More...
 
void setCheckedLevels (const QList< unsigned int > &indices)
 This is useful when dealing with AMR datasets. More...
 
QList< QPair< unsigned int, unsigned int > > checkedLevelDatasets () const
 This is useful when dealing with AMR datasets. More...
 
void setCheckedLevelDatasets (const QList< QPair< unsigned int, unsigned int > > &indices)
 This is useful when dealing with AMR datasets. More...
 
void setColumnStates (const QString &propertyName, const QList< QPair< unsigned int, QVariant > > &values)
 Methods to get/set custom column values. More...
 
QList< QPair< unsigned int, QVariant > > columnStates (const QString &propertyName) const
 Methods to get/set custom column values. More...
 

Properties

bool userCheckable
 
bool expandMultiPiece
 
bool exclusivity
 
bool defaultCheckState
 

Friends

class pqCompositeDataInformationTreeModelNS::CNode
 

Detailed Description

Tree model that use vtkPVDataInformation to model composite data tree.

property widget for a vtkSMIntVectorProperty with vtkSMCompositeTreeDomain.

pqCompositeDataInformationTreeModel is designed to map a data set hierarchy represented by vtkCompositeDataSet (and subclasses) to a Qt tree model.

To use this model, one calls pqCompositeDataInformationTreeModel::reset() with the data information object to use to build the structure from.

model->reset(sourceProxy->GetDataInformation(0));

pqCompositeDataInformationTreeModel does not save a reference to the vtkPVDataInformation instance passed to reset. Hence it cannot update itself when the data information changes. Updating the model to reflect any potential changes in the hierarchy require another call to reset. As name suggests, reset is complete reset on the model. Hence all data about check states, or values for custom columns is discarded. If the should be preserved, you will have to handle that externally (see pqMultiBlockInspectorWidget).

QTreeView typically collapses the tree when the model is reset, thus discarded expand state for the nodes in the hierarchy. If the hierarchy change was a minor update, then this can be quite jarring. You can use pqTreeViewExpandState to attempt to preserve expand state on QTreeView nodes across model resets.

There are few properties on this model that should be set prior to calling reset that determine how the model behaves. To allow the user to check/uncheck nodes on the tree, set userCheckable to true (default: false). To expand datasets in a multi-piece (vtkMultiPieceDataSet), set expandMultiPiece to true (default: false). If userCheckable is true, and you want to only allow the user to select one sub-tree at a time, set exclusivity to true (default: false). Also, the default checked state for the tree can be configured using defaultCheckState (defaults to false i.e. unchecked).

Custom Columns

This model presents a single column tree. The check-state on this 0th column is optionally settable. There may be need for saving additional properties with the tree nodes, e.g. color or opacity values. Such use-cases are supported via custom columns.

One can add custom columns to the model using addColumn. If custom columns are changed, you will need to call reset on the model. The model will behave unpredictably otherwise. Custom column values are stored as data for Qt::DisplayRole for the corresponding column. Hence they can be set/get using setData and data API on the QAbstractItemModel with an appropriate QModelIndex.

Setting column value on a non-leaf node in the tree will cause the subtree anchored at that node to inherit the value, unless any of the nodes in the subtree themselves have a value set. To clear the value set at any node, simply call setData with an invalid QVariant.

To determine if a custom column value is inherited or explicitly set, you can use pqCompositeDataInformationTreeModel::ValueInheritedRole). By making a data call with this role, you can determine if a particular node's custom column value is explicitly set or inherited.

Since custom columns only support Qt::DisplayRole storage, one can use a proxy model (e.g. QIdentityProxyModel subclass) to change how the column data is communicated to the view. e.g. pqMultiBlockInspectorWidget renders pixmaps for color and opacity columns.

Setting and querying check states

pqCompositeDataInformationTreeModel provides multiple APIs to set and query check states for nodes in the tree. The set methods clear current state before setting, hence are not additive.

checkedNodes returns a list of composite indexes (or flat indexes) for nodes in the tree that are checked. If non-leaf node is checked, it is assumed that all its children nodes are checked as well and hence node included in the returned list.

checkedLeaves returns a list of composite indexes for leaf nodes that are checked. The list will never include a node with children.

setChecked can be used as the set-counterpart for checkedNodes and checkedLeaves. It argument can be a list of composite indexes for nodes that are checked (either leaf or non-leaf). If a non-leaf node is included in the list, then all its children are automatically checked.

checkedLevels and setCheckedLevels is intended for AMR datasets. The list is simply the child index for a checked child under the root. This corresponds to levels in an AMR dataset.

checkedLevelDatasets and setCheckedLevelDatasets is also intended for AMR datasets. The list is pair where first value is the level number and second value is the dataset index in that level. This corresponds to level index and dataset index at a level in an AMR dataset.

checkStates and setCheckStates differ from other get/set API in that the argument (or return value) list is not merely the collection of checked nodes, but nodes and their states and hence can include unchecked nodes.

See also
pqMultiBlockInspectorWidget

pqCompositeDataInformationTreeModel is a subclass of pqPropertyWidget that is created by default for any vtkSMIntVectorProperty having a vtkSMCompositeTreeDomain. This widgets creates a tree view which shows the composite-dataset hierarchy. It supports both multiblock and AMR datasets with ability to select blocks either using flat or composite index or AMR-specific, level number or level number and block number.

Internally, it uses pqCompositeDataInformationTreeModel and keeps it updated as the vtkSMCompositeTreeDomain changes.

Definition at line 150 of file pqCompositeDataInformationTreeModel.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Custom roles available for data.

Enumerator
ValueInheritedRole 

Used to get whether a custom column's value is inherited from a parent node or explicitly specified.

data will return true if inherited and false otherwise.

LeafIndexRole 

For a leaf node (i.e node with any children) return it's position in a ordered list of simply all leaf nodes of the tree.

Returned value is a unsigned int indicating the location or invalid QVariant for non-leaf nodes.

CompositeIndexRole 

For a node this return the flat index/composite index for that node.

Definition at line 330 of file pqCompositeDataInformationTreeModel.h.

Constructor & Destructor Documentation

◆ pqCompositeDataInformationTreeModel()

pqCompositeDataInformationTreeModel::pqCompositeDataInformationTreeModel ( QObject *  parent = 0)

◆ ~pqCompositeDataInformationTreeModel()

pqCompositeDataInformationTreeModel::~pqCompositeDataInformationTreeModel ( )
override

Member Function Documentation

◆ columnCount()

int pqCompositeDataInformationTreeModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

QAbstractItemModel interface implementation.

◆ rowCount()

int pqCompositeDataInformationTreeModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

QAbstractItemModel interface implementation.

◆ index()

QModelIndex pqCompositeDataInformationTreeModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

QAbstractItemModel interface implementation.

◆ parent()

QModelIndex pqCompositeDataInformationTreeModel::parent ( const QModelIndex &  index = QModelIndex()) const
override

QAbstractItemModel interface implementation.

◆ data()

QVariant pqCompositeDataInformationTreeModel::data ( const QModelIndex &  index,
int  role 
) const
override

QAbstractItemModel interface implementation.

◆ flags()

Qt::ItemFlags pqCompositeDataInformationTreeModel::flags ( const QModelIndex &  index) const
override

QAbstractItemModel interface implementation.

◆ setData()

bool pqCompositeDataInformationTreeModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
override

QAbstractItemModel interface implementation.

◆ headerData()

QVariant pqCompositeDataInformationTreeModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const
override

QAbstractItemModel interface implementation.

◆ setHeaderData()

bool pqCompositeDataInformationTreeModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant &  value,
int  role = Qt::DisplayRole 
)
override

QAbstractItemModel interface implementation.

◆ setUserCheckable()

void pqCompositeDataInformationTreeModel::setUserCheckable ( bool  val)
inline

Toggle whether the model allows user to change check state.

Note: please call reset() after changing this.

Definition at line 186 of file pqCompositeDataInformationTreeModel.h.

◆ userCheckable()

bool pqCompositeDataInformationTreeModel::userCheckable ( ) const
inline

Toggle whether the model allows user to change check state.

Note: please call reset() after changing this.

Definition at line 187 of file pqCompositeDataInformationTreeModel.h.

◆ setOnlyLeavesAreUserCheckable()

void pqCompositeDataInformationTreeModel::setOnlyLeavesAreUserCheckable ( bool  val)
inline

When UserCheckable is true, this limits use-checkability to leaf nodes only.

Note that this has no effect if userCheckable is false. Also please call reset() after changing this.

Definition at line 196 of file pqCompositeDataInformationTreeModel.h.

◆ onlyLeavesAreUserCheckable()

bool pqCompositeDataInformationTreeModel::onlyLeavesAreUserCheckable ( ) const
inline

When UserCheckable is true, this limits use-checkability to leaf nodes only.

Note that this has no effect if userCheckable is false. Also please call reset() after changing this.

Definition at line 197 of file pqCompositeDataInformationTreeModel.h.

◆ setDefaultCheckState()

void pqCompositeDataInformationTreeModel::setDefaultCheckState ( bool  checked)
inline

Get/Set the default check state for nodes.

Default is unchecked (false). Note: please call reset() after changing this.

Definition at line 205 of file pqCompositeDataInformationTreeModel.h.

◆ defaultCheckState()

bool pqCompositeDataInformationTreeModel::defaultCheckState ( ) const
inline

Get/Set the default check state for nodes.

Default is unchecked (false). Note: please call reset() after changing this.

Definition at line 206 of file pqCompositeDataInformationTreeModel.h.

◆ setExpandMultiPiece()

void pqCompositeDataInformationTreeModel::setExpandMultiPiece ( bool  val)
inline

Toggle whether multipiece datasets are expanded (default false).

Note: please call reset() after changing this.

Definition at line 213 of file pqCompositeDataInformationTreeModel.h.

◆ expandMultiPiece()

bool pqCompositeDataInformationTreeModel::expandMultiPiece ( ) const
inline

Get/Set the default check state for nodes.

Default is unchecked (false). Note: please call reset() after changing this.

Definition at line 214 of file pqCompositeDataInformationTreeModel.h.

◆ setExclusivity()

void pqCompositeDataInformationTreeModel::setExclusivity ( bool  val)
inline

When set to true for a userCheckable model, if the user checks a node, the all other nodes that are not children of the checked node are unchecked.

Definition at line 222 of file pqCompositeDataInformationTreeModel.h.

◆ exclusivity()

bool pqCompositeDataInformationTreeModel::exclusivity ( ) const
inline

When set to true for a userCheckable model, if the user checks a node, the all other nodes that are not children of the checked node are unchecked.

Definition at line 223 of file pqCompositeDataInformationTreeModel.h.

◆ checkedNodes()

QList<unsigned int> pqCompositeDataInformationTreeModel::checkedNodes ( ) const

API to get flat-indices for checked nodes.

checkedNodes may return a combination of leaf and non-leaf nodes i.e. if all child nodes of a node are checked, then it will prefer the parent node's index rather than indices of each of the children.

◆ checkedLeaves()

QList<unsigned int> pqCompositeDataInformationTreeModel::checkedLeaves ( ) const

API to get flat-indices for checked nodes.

checkedLeaves returns indices for the leaf nodes. The flat-index for a non-leaf node is never returned by this method.

◆ setChecked()

void pqCompositeDataInformationTreeModel::setChecked ( const QList< unsigned int > &  indices)

API to set the flat-indices for checked nodes.

This methods accepts indices for both non-leaf and leaf nodes. Note that if a non-leaf node is checked, then all its children are also considered as checked.

◆ checkStates()

QList<QPair<unsigned int, bool> > pqCompositeDataInformationTreeModel::checkStates ( ) const

Returns check state for nodes explicitly toggled.

◆ setCheckStates()

void pqCompositeDataInformationTreeModel::setCheckStates ( const QList< QPair< unsigned int, bool > > &  states)

Set check states.

◆ checkedLevels()

QList<unsigned int> pqCompositeDataInformationTreeModel::checkedLevels ( ) const

This is useful when dealing with AMR datasets.

It sets/returns the level numbers for selected levels in the AMR dataset.

◆ setCheckedLevels()

void pqCompositeDataInformationTreeModel::setCheckedLevels ( const QList< unsigned int > &  indices)

This is useful when dealing with AMR datasets.

It sets/returns the level numbers for selected levels in the AMR dataset.

◆ checkedLevelDatasets()

QList<QPair<unsigned int, unsigned int> > pqCompositeDataInformationTreeModel::checkedLevelDatasets ( ) const

This is useful when dealing with AMR datasets.

It sets/returns the level and dataset indices for AMR datasets.

◆ setCheckedLevelDatasets()

void pqCompositeDataInformationTreeModel::setCheckedLevelDatasets ( const QList< QPair< unsigned int, unsigned int > > &  indices)

This is useful when dealing with AMR datasets.

It sets/returns the level and dataset indices for AMR datasets.

◆ compositeIndex()

unsigned int pqCompositeDataInformationTreeModel::compositeIndex ( const QModelIndex &  idx) const

Returns the flat or composite index associated with the node.

If idx is not valid, then this will simply return 0.

◆ find()

QModelIndex pqCompositeDataInformationTreeModel::find ( unsigned int  compositeIndex) const

Return the QModelIndex for composite idx.

May return an invalid QModelIndex if none found.

◆ rootIndex()

const QModelIndex pqCompositeDataInformationTreeModel::rootIndex ( ) const

Returns the index for the root of the tree.

◆ addColumn()

int pqCompositeDataInformationTreeModel::addColumn ( const QString &  propertyName)

Add a custom column to model.

Must call pqCompositeDataInformationTreeModel::reset after adding/removing columns.

◆ columnIndex()

int pqCompositeDataInformationTreeModel::columnIndex ( const QString &  propertyName)

Returns the index for a custom column with the given name.

-1 if no such column exists.

◆ clearColumns()

void pqCompositeDataInformationTreeModel::clearColumns ( )

Remove all extra columns added via addColumn API.

The default column 0 is not removed. Must call pqCompositeDataInformationTreeModel::reset after adding/removing columns.

◆ setColumnStates()

void pqCompositeDataInformationTreeModel::setColumnStates ( const QString &  propertyName,
const QList< QPair< unsigned int, QVariant > > &  values 
)

Methods to get/set custom column values.

values is a list of pairs, where first value is the composite index for the node, and second is the column value. To clear a specific value, simply pass an invalid QVariant. setColumnStates will clear current state of the column before setting the new values specified. columnStates returns column values for nodes that have been set. It does not include any nodes that "inherited" the value from its parent.

◆ columnStates()

QList<QPair<unsigned int, QVariant> > pqCompositeDataInformationTreeModel::columnStates ( const QString &  propertyName) const

Methods to get/set custom column values.

values is a list of pairs, where first value is the composite index for the node, and second is the column value. To clear a specific value, simply pass an invalid QVariant. setColumnStates will clear current state of the column before setting the new values specified. columnStates returns column values for nodes that have been set. It does not include any nodes that "inherited" the value from its parent.

◆ reset

bool pqCompositeDataInformationTreeModel::reset ( vtkPVDataInformation info = nullptr)
slot

Reset and rebuild the model using the data information object provided.

The model does not maintain a reference to the vtkPVDataInformation instance. Hence it will not automatically update when info changes.

Returns
true is the data information refers to a composite dataset. Otherwise, returns false.

Friends And Related Function Documentation

◆ pqCompositeDataInformationTreeModelNS::CNode

friend class pqCompositeDataInformationTreeModelNS::CNode
friend

Definition at line 376 of file pqCompositeDataInformationTreeModel.h.

Property Documentation

◆ userCheckable

bool pqCompositeDataInformationTreeModel::userCheckable
readwrite

Definition at line 153 of file pqCompositeDataInformationTreeModel.h.

◆ expandMultiPiece

bool pqCompositeDataInformationTreeModel::expandMultiPiece
readwrite

Definition at line 153 of file pqCompositeDataInformationTreeModel.h.

◆ exclusivity

bool pqCompositeDataInformationTreeModel::exclusivity
readwrite

Definition at line 154 of file pqCompositeDataInformationTreeModel.h.

◆ defaultCheckState

bool pqCompositeDataInformationTreeModel::defaultCheckState
readwrite

Definition at line 155 of file pqCompositeDataInformationTreeModel.h.


The documentation for this class was generated from the following file: