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 int > | checkedNodes () const |
API to get flat-indices for checked nodes. More... | |
QList< unsigned int > | checkedLeaves () 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 int > | checkedLevels () 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 |
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.
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).
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.
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.
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.
anonymous enum |
Custom roles available for data
.
Definition at line 330 of file pqCompositeDataInformationTreeModel.h.
pqCompositeDataInformationTreeModel::pqCompositeDataInformationTreeModel | ( | QObject * | parent = 0 | ) |
|
override |
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
override |
QAbstractItemModel interface implementation.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
inline |
Toggle whether multipiece datasets are expanded (default false).
Note: please call reset() after changing this.
Definition at line 213 of file pqCompositeDataInformationTreeModel.h.
|
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.
|
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.
|
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.
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.
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.
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.
QList<QPair<unsigned int, bool> > pqCompositeDataInformationTreeModel::checkStates | ( | ) | const |
Returns check state for nodes explicitly toggled.
void pqCompositeDataInformationTreeModel::setCheckStates | ( | const QList< QPair< unsigned int, bool > > & | states | ) |
Set check states.
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.
This is useful when dealing with AMR datasets.
It sets/returns the level numbers for selected levels in the AMR dataset.
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.
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.
Returns the flat or composite index associated with the node.
If idx is not valid, then this will simply return 0.
QModelIndex pqCompositeDataInformationTreeModel::find | ( | unsigned int | compositeIndex | ) | const |
Return the QModelIndex for composite idx.
May return an invalid QModelIndex if none found.
const QModelIndex pqCompositeDataInformationTreeModel::rootIndex | ( | ) | const |
Returns the index for the root of the tree.
Add a custom column to model.
Must call pqCompositeDataInformationTreeModel::reset
after adding/removing columns.
Returns the index for a custom column with the given name.
-1 if no such column exists.
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.
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.
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.
|
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.
|
friend |
Definition at line 376 of file pqCompositeDataInformationTreeModel.h.
|
readwrite |
Definition at line 153 of file pqCompositeDataInformationTreeModel.h.
|
readwrite |
Definition at line 153 of file pqCompositeDataInformationTreeModel.h.
|
readwrite |
Definition at line 154 of file pqCompositeDataInformationTreeModel.h.
|
readwrite |
Definition at line 155 of file pqCompositeDataInformationTreeModel.h.