Project Tree

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

Hi Tim,

First off, thanks so much for re-implementing the project tree. This
is great.

Let me know if you have any questions or feedback…

I just re-built and opened the project tree. But nothing appeared and
it wasn’t obvious how to add the tree. Am I missing something? Looking
at the avogadro binary, it does look like the code is included.

Thanks,
-Geoff

Hi Geoff,

On Sun, Nov 23, 2008 at 5:00 PM, Geoffrey Hutchison
geoff.hutchison@gmail.com wrote:

Hi Tim,

First off, thanks so much for re-implementing the project tree. This is
great.

Let me know if you have any questions or feedback…

I just re-built and opened the project tree. But nothing appeared and it
wasn’t obvious how to add the tree. Am I missing something? Looking at the
avogadro binary, it does look like the code is included.

You can edit the tree structure by going to Settings -> Project Tree Editor.

Thanks,
-Geoff