All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Slots | Signals | Public Member Functions | Protected Member Functions
Qtilities::CoreGui::ObserverTreeModel Class Reference

The ObserverTreeModel class provides an ready-to-use model that can be used to show the children of an Qtilities::Core::Observer in a QTreeView. More...

#include <ObserverTreeModel.h>

Inheritance diagram for Qtilities::CoreGui::ObserverTreeModel:
Inheritance graph
[legend]

List of all members.

Public Slots

ObservercalculateSelectionParent (QModelIndexList index_list)
 Function which will calculate the selection parent of a selected object.
void handleContextDataChanged (Observer *observer)
 Handle context data changes where the context is defined by an Observer reference.
void handleContextDataChanged (const QModelIndex &set_data_index)
 Handle context data changes where the context is defined by a child QModelIndex.
void handleObserverContextDeleted ()
 This slot will clean up the tree and refresh the view when the top level observer is deleted.
void recordObserverChange (QList< QPointer< QObject > > new_selection=QList< QPointer< QObject > >())
 When the observer context changes, this function will take note of the change and when needed, the model will rebuild the internal tree structure using rebuildTreeStructure();.
virtual void setReadOnly (bool read_only)
 Sets if this model must be read only, thus its actions and property editor will be read only.
void setSelectedCategories (QList< QtilitiesCategory > selected_categories)
 Function to let the model know which categories is currently selected in the view connected to the model.
void setSelectedObjects (QList< QPointer< QObject > > selected_objects)
 Function to let the model know which objects are currently selected in the view connected to this model.

Signals

void expandItemsRequest (QModelIndexList indexes)
 Signal which requests for a set of items to be expanded in the view.
void selectCategories (QList< QtilitiesCategory > categories) const
 This signal will be handled by a slot in the ObserverWidget parent of this model and the objects will be selected. The signal is emitted when the tree finished to rebuild itself.
void selectionParentChanged (Observer *new_observer)
 Signal which is emmited when the current selection parent changed. If the root item is selected, new_observer will be null.
void selectObjects (QList< QPointer< QObject > > objects) const
 This signal will be handled by a slot in the ObserverWidget parent of this model and the objects will be selected. The signal is emitted when the tree finished to rebuild itself.
void selectObjects (QList< QObject * > objects) const
 This signal will be handled by a slot in the ObserverWidget parent of this model and the objects will be selected. The signal is emitted when the tree finished to rebuild itself.
void treeModelBuildAboutToStart () const
 Signal which is emitted just before a tree model rebuild will start.
void treeModelBuildEnded () const
 Signal which is emitted when a new tree building cycle ends.
void treeModelBuildStarted (int task_id) const
 Signal which is emitted when a new tree building cycle starts.

Public Member Functions

int columnPosition (AbstractObserverItemModel::ColumnID column_id) const
 The model implementation must return the index (starting at 0) for the requested column.
int columnVisiblePosition (AbstractObserverItemModel::ColumnID column_id) const
 Function which gives the visible column position. Thus it takes into account if columns are hidden.
QModelIndex findCategory (QtilitiesCategory category) const
 Function to get the model index of a category. If the category does not exist, QModelIndex() is returned.
QModelIndexList findExpandedNodeIndexes (const QStringList &node_names) const
 Finds the matching QModelIndex indexes for all nodes with display names specified by node_names.
QModelIndex findObject (QObject *obj, int column=-1) const
 Function to get the model index of an object in the tree. If the object does not exist, QModelIndex() is returned.
QModelIndexList getAllIndexes (ObserverTreeItem *item=0) const
 Gets all indexes under a specified model index.
QModelIndex getIndex (QObject *obj, int column=-1) const
 Function to get the model index of an object in the tree. If the object does not exist, QModelIndex() is returned.
ObserverTreeItemgetItem (const QModelIndex &index) const
 Returns the ObserverTreeItem at a the specified index.
QObject * getObject (const QModelIndex &index) const
 Abstract function which must be implemented to get the object at the given index.
QStack< int > getParentHierarchy (const QModelIndex &index) const
 Returns a QStack with the parent hierarchy (in terms of observer IDs) for the object at the given index.
QModelIndexList getPersistentIndexList () const
 Returns the persistent index list of the model.
int getSubjectID (const QModelIndex &index) const
 Abstract function which must be implemented to get the subject ID of the object at the given index.
ObserverparentOfIndex (const QModelIndex &index) const
 Returns the parent observer of the item at the specified index.
bool readOnly () const
 Gets if this model must be read only, thus its actions and property editor will be read only.
void refresh ()
 Forces this model to refresh its layout.
ObserverselectionParent () const
 Returns the parent observer of the current selection, it only works if a single item is selected, otherwise returns 0.
void setExpandedItems (QStringList expanded_items)
 Sets all expanded nodes and categories.
virtual bool setObserverContext (Observer *observer)
 Implement the virtual function to get references to known filters.
- Public Member Functions inherited from Qtilities::CoreGui::AbstractObserverItemModel
ObserverHintsactiveHints () const
 This function will provide the hints which should be used by this model at any time.
QString columnChildCountBaseClass () const
 Gets the base class to use for tree count operations in the ColumnChildCount column if shown.
int columnChildCountLimit () const
 Gets the upper limit to use for tree count operations in the ColumnChildCount column if shown.
bool lazyInitEnabled () const
 Gets if lazy initialization is enabled.
bool respondToObserverChanges () const
 Gets if this model responds to changes from the observer context displayed.
void setColumnChildCountBaseClass (const QString &base_class_name)
 Sets the base class to use for tree count operations in the ColumnChildCount column if shown.
void setColumnChildCountLimit (int limit)
 Sets the upper limit tree count operations in the ColumnChildCount column if shown.
bool setCustomHints (ObserverHints *custom_hints)
 This function allows you to copy the custom hints used by this model from a different ObserverHints instance.
void setRespondToObserverChanges (bool respond_to_observer_changes)
 Sets if this model responds to changes from the observer context displayed.
void toggleLazyInit (bool enabled)
 Enables/disables lazy initialization.
void toggleUseObserverHints (bool toggle)
 Function to toggle usage of hints from the active parent observer. If not custom hints will be used.
bool usesObserverHints () const
 Function to indicate if observer hints are used in this model. If not, the default hints in the model base class is used.
- Public Member Functions inherited from Qtilities::Core::ObserverAwareBase
ObserverobserverContext () const
 Gets a pointer to the observer context.

Protected Member Functions

void deleteRootItem ()
 Deletes all tree items, starting with the root item.
QModelIndex findCategory (const QModelIndex &index, QtilitiesCategory category) const
 Recursive function used by findCategory() to traverse through the tree trying to find a category.
ObserverTreeItemfindCategory (ObserverTreeItem *item, QtilitiesCategory category) const
 Recursive function to get the ObserverTreeItem associacted with a category.
QModelIndex findObject (const QModelIndex &index, QObject *obj, int column=-1) const
 Recursive function used by findObject() to traverse through the tree trying to find an object.
ObserverTreeItemfindObject (ObserverTreeItem *item, QObject *obj) const
 Recursive function to get the ObserverTreeItem associacted with an object.

Additional Inherited Members

- Public Types inherited from Qtilities::CoreGui::AbstractObserverItemModel
enum  ColumnID
 The possible columns which can be requested by views for an module.

Detailed Description

The ObserverTreeModel class provides an ready-to-use model that can be used to show the children of an Qtilities::Core::Observer in a QTreeView.

To view the contents of an Qtilities::Core::Observer, use the setObserverContext function. This function will initialize the model and show the names of subjects attached to a specific observer in a QTreeView. ObserverTreeModel has knowledge of the standard subject filters which are included in the Qtilities libraries. Thus it will for example automatically show check boxes etc. if the observer context has an Qtilities::Core::ActivityPolicyFilter installed.

To customize this model you can simply subclass it and reimplement the virtual functions of QAbstractItemModel. This allows you to add columns etc. to your view. The Clipboard Example shows how to do this.

See also:
ObserverTableModel

Member Function Documentation

Qtilities::Core::Observer * Qtilities::CoreGui::ObserverTreeModel::calculateSelectionParent ( QModelIndexList  index_list)
slot

Function which will calculate the selection parent of a selected object.

Parameters:
index_listThe list of indexes currently selected in the tree view. This function will only calculate the selection parent if the list contain only one item.
int Qtilities::CoreGui::ObserverTreeModel::columnPosition ( AbstractObserverItemModel::ColumnID  column_id) const
virtual

The model implementation must return the index (starting at 0) for the requested column.

Note:
If your model does not support a specific column, return -1.
ColumnLast must return the number of columns you use in your model.

Implements Qtilities::CoreGui::AbstractObserverItemModel.

QModelIndexList Qtilities::CoreGui::ObserverTreeModel::findExpandedNodeIndexes ( const QStringList &  node_names) const

Finds the matching QModelIndex indexes for all nodes with display names specified by node_names.

See also:
Qtilities::CoreGui::ObserverWidget::expandedNodeNames()
QModelIndex Qtilities::CoreGui::ObserverTreeModel::findObject ( QObject *  obj,
int  column = -1 
) const

Function to get the model index of an object in the tree. If the object does not exist, QModelIndex() is returned.

Parameters:
objThe object to find.
columnThe column requested.
Returns:
The QModelIndex of the specified object. If the object was not found QModelIndex() is returned.
Note:
This function does exactly the same as getIndex()
QModelIndexList Qtilities::CoreGui::ObserverTreeModel::getAllIndexes ( ObserverTreeItem item = 0) const

Gets all indexes under a specified model index.

Just call getAllIndexes() when you want to use this function. It will automatically start with the root node.

QModelIndex Qtilities::CoreGui::ObserverTreeModel::getIndex ( QObject *  obj,
int  column = -1 
) const

Function to get the model index of an object in the tree. If the object does not exist, QModelIndex() is returned.

Parameters:
objThe object to find.
columnThe colum requested.
Returns:
The QModelIndex of the specified object. If the object was not found QModelIndex() is returned.
Note:
This function does exactly the same as findObject()
Qtilities::CoreGui::ObserverTreeItem * Qtilities::CoreGui::ObserverTreeModel::getItem ( const QModelIndex &  index) const

Returns the ObserverTreeItem at a the specified index.

Returns:
The ObserverTreeItem at the current index, or 0 if the index is invalid.
void Qtilities::CoreGui::ObserverTreeModel::handleContextDataChanged ( Observer observer)
slot

Handle context data changes where the context is defined by an Observer reference.

This function will emit the dataChanged() signal with the indexes of all items underneath this observer.

void Qtilities::CoreGui::ObserverTreeModel::handleContextDataChanged ( const QModelIndex &  set_data_index)
slot

Handle context data changes where the context is defined by a child QModelIndex.

This function will emit the dataChanged() signal with the indexes of all items in the same context as the item defined by index.

Qtilities::Core::Observer * Qtilities::CoreGui::ObserverTreeModel::parentOfIndex ( const QModelIndex &  index) const

Returns the parent observer of the item at the specified index.

Returns:
The parent observer of the current index, or 0 if the index is invalid.
Note:
For the root item the parent will also be 0.
bool Qtilities::CoreGui::ObserverTreeModel::readOnly ( ) const

Gets if this model must be read only, thus its actions and property editor will be read only.

See also:
setReadOnly()

Reimplemented from Qtilities::CoreGui::AbstractObserverItemModel.

void Qtilities::CoreGui::ObserverTreeModel::recordObserverChange ( QList< QPointer< QObject > >  new_selection = QList<QPointer<QObject> >())
slot

When the observer context changes, this function will take note of the change and when needed, the model will rebuild the internal tree structure using rebuildTreeStructure();.

Parameters:
new_selectionThe selection of object that must be selected when the internal tree structure is rebuilt.
void Qtilities::CoreGui::ObserverTreeModel::refresh ( )
virtual

Forces this model to refresh its layout.

This function was added in Qtilities v1.1.

Implements Qtilities::CoreGui::AbstractObserverItemModel.

Qtilities::Core::Observer * Qtilities::CoreGui::ObserverTreeModel::selectionParent ( ) const

Returns the parent observer of the current selection, it only works if a single item is selected, otherwise returns 0.

The selection parent is calculated using the calculateSelectionParent() function. This function return the parent identified the last time that function was called.

void Qtilities::CoreGui::ObserverTreeModel::setReadOnly ( bool  read_only)
virtualslot

Sets if this model must be read only, thus its actions and property editor will be read only.

See also:
readOnly()

Reimplemented from Qtilities::CoreGui::AbstractObserverItemModel.

void Qtilities::CoreGui::ObserverTreeModel::setSelectedCategories ( QList< QtilitiesCategory selected_categories)
slot

Function to let the model know which categories is currently selected in the view connected to the model.

Allows selection of categories after tree rebuilds.

See also:
setSelectedObjects()
void Qtilities::CoreGui::ObserverTreeModel::setSelectedObjects ( QList< QPointer< QObject > >  selected_objects)
slot

Function to let the model know which objects are currently selected in the view connected to this model.

This functionality is used when the layout of the tree changed externally (not in the view) and we need to rebuild the model. We attempt to select the previously selected objects when the tree rebuilding is done.

See also:
setSelectedCategories()


Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé