Hi,
The Project Tree is now implemented as a QAbstractItemModel which
allows the items to be dynamically initialized. This is done by
overloading the hasChildren(), canFetchMore() and fetchMore(). Since
this is a nice feature, I thought other developers might be interested
in this.
hasChildren(const QModelIndex &parent): Qt uses this function to
determine if the QTreeView should draw an expand icon (plus sign or
triangle) next to the item.
canFetchMore(const QModelIndex &parent) const: Used by Qt for
performance reasons I think, we just return hasChildren(…)
fetcMore(const QModelIndex &parent): This function gets called when
the user clicks the plus sign or triangle to expand an item. In this
function we can initialize the children and connect signals if needed.
The ProjectTreeModel delegates the actual creation and management of
ProjectTreeItems to ProjectTreeModelDelegate derived classes. The
Model exposes some public functions to the delegates to make it easier
to add items, change data, etc…
When the ProjectTreeModel is created it reads the tree structure (from
QSettings) and creates the various Delegates as needed. The model also
calls ProjectTreeModelDelegate::initStructure(…) which adds the main
labels (“Molecule”, “Atoms”, “User Selections”, …). The actual
creation of items for each atom/bond/… is delayed until the user
expands the main label and ProjectTreeModelDelegate::fetchMore(…) is
called. (the model handles the dispatching of the fetchMore calls to
the correct delegates, also see ProjectTreeModel::importDelegate(…))
Let me know if you have any questions or feedback…
Cheers,
Tim