Version: 6.3.1
Data Structures | Public Types | Public Slots | Signals | Public Member Functions | Private Types | Private Slots | Private Member Functions | Private Attributes | Friends

SUIT_TreeModel Class Reference

Implementation of the model/view API based on the tree of SUIT_DataObject class instances. More...

#include <SUIT_TreeModel.h>

Inheritance diagram for SUIT_TreeModel:
Inheritance graph

Data Structures

struct  ColumnInfo
class  TreeItem
 Internal class used for tree view synchronizaton with data object tree. More...
class  TreeSync
 Functor class for synchronizing data tree and tree model when the data tree is changed outside the model. More...

Public Types

enum  Role {
  DisplayRole = Qt::DisplayRole, DecorationRole = Qt::DecorationRole, EditRole = Qt::EditRole, ToolTipRole = Qt::ToolTipRole,
  StatusTipRole = Qt::StatusTipRole, WhatsThisRole = Qt::WhatsThisRole, FontRole = Qt::FontRole, TextAlignmentRole = Qt::TextAlignmentRole,
  BackgroundRole = Qt::BackgroundRole, ForegroundRole = Qt::ForegroundRole, CheckStateRole = Qt::CheckStateRole, SizeHintRole = Qt::SizeHintRole,
  BaseColorRole = Qt::UserRole, TextColorRole, HighlightRole, HighlightedTextRole,
  AppropriateRole = Qtx::AppropriateRole
}
 

Data role.

More...

Public Slots

virtual void updateTree (const QModelIndex &)
 Update tree model.
virtual void updateTree (SUIT_DataObject *=0)
 Update tree model.

Signals

void modelUpdated ()
void clicked (SUIT_DataObject *, int)

Public Member Functions

 SUIT_TreeModel (QObject *=0)
 Constructor.
 SUIT_TreeModel (SUIT_DataObject *, QObject *=0)
 Constructor.
 ~SUIT_TreeModel ()
 Destructor.
SUIT_DataObjectroot () const
 Get data tree root object.
void setRoot (SUIT_DataObject *)
 Set data tree root object.
virtual QVariant data (const QModelIndex &, int=DisplayRole) const
 Get data for the specified model index and data role.
virtual bool setData (const QModelIndex &, const QVariant &, int=EditRole)
 Set data for the specified model index and data role.
virtual Qt::ItemFlags flags (const QModelIndex &) const
 Get data flags for specified model index.
virtual QVariant headerData (int, Qt::Orientation, int=Qt::DisplayRole) const
 Get header data (can be used in any data view).
virtual QModelIndex index (int, int, const QModelIndex &=QModelIndex()) const
 Create model index.
virtual QModelIndex parent (const QModelIndex &) const
 Get parent model index.
virtual int columnCount (const QModelIndex &=QModelIndex()) const
 Get number of data columns.
virtual int rowCount (const QModelIndex &=QModelIndex()) const
 Get number of data rows (children of the specified model index).
virtual void registerColumn (const int group_id, const QString &name, const int custom_id)
 Register new column in the model.
virtual void unregisterColumn (const int group_id, const QString &name)
 Remove column from the model.
virtual void setColumnIcon (const QString &name, const QPixmap &icon)
 Change column icon.
virtual QPixmap columnIcon (const QString &name) const
 Get column icon.
virtual void setAppropriate (const QString &name, const Qtx::Appropriate appr)
 Change appropriate status.
virtual Qtx::Appropriate appropriate (const QString &name) const
 Check if the column should appear in the tree view header popup menu (to show/hide the column).
virtual void setVisibilityState (const QString &id, Qtx::VisibilityState state)
 Set visibility state of the object.
virtual void setVisibilityStateForAll (Qtx::VisibilityState state)
 Set visibility state for all objects.
virtual Qtx::VisibilityState visibilityState (const QString &id) const
 Get visibility state of the object.
virtual void setHeaderFlags (const QString &name, const Qtx::HeaderViewFlags flags)
 Set header flags.
virtual Qtx::HeaderViewFlags headerFlags (const QString &name) const
 Get the header flags.
virtual void emitClicked (SUIT_DataObject *obj, const QModelIndex &index)
SUIT_DataObjectobject (const QModelIndex &=QModelIndex()) const
 Get data object by the specified model index.
QModelIndex index (const SUIT_DataObject *, int=0) const
 Get model index by the specified data object.
bool autoDeleteTree () const
 Get 'auto-delete data tree' flag value.
void setAutoDeleteTree (const bool)
 Set 'auto-delete data tree' flag value.
bool autoUpdate () const
 Get 'auto-update tree' flag value.
void setAutoUpdate (const bool)
 Set 'auto-update tree' flag value.
bool updateModified () const
 Get 'updateModified' flag value.
void setUpdateModified (const bool)
 Set 'updateModified' flag value.
virtual bool customSorting (const int) const
 Check if the specified column supports custom sorting.
virtual bool lessThan (const QModelIndex &left, const QModelIndex &right) const
 Compares two model indexes for the sorting purposes.
QAbstractItemDelegate * delegate () const
 Get item delegate for the model.
virtual void updateTreeModel (SUIT_DataObject *, TreeItem *)
 operator const QAbstractItemModel * () const
 operator QAbstractItemModel * ()
 operator const QObject * () const
virtual SUIT_DataSearchersearcher () const
virtual void setSearcher (SUIT_DataSearcher *)

Private Types

typedef SUIT_DataObjectObjPtr
typedef SUIT_TreeModel::TreeItemItemPtr
typedef QMap< SUIT_DataObject
*, TreeItem * > 
ItemMap
typedef QMap< QString,
Qtx::VisibilityState
VisibilityMap

Private Slots

void onInserted (SUIT_DataObject *, SUIT_DataObject *)
 Called when the data object is inserted to the tree.
void onRemoved (SUIT_DataObject *, SUIT_DataObject *)
 Called when the data object is removed from the tree.

Private Member Functions

void initialize ()
 Initialize tree model.
TreeItemrootItem () const
 Get root tree item.
TreeItemtreeItem (const QModelIndex &) const
 Get tree item corresponding to the specified model index.
TreeItemtreeItem (const SUIT_DataObject *) const
 Get tree item corresponding to the specified data object.
SUIT_DataObjectobject (const TreeItem *) const
 Get data object corresponding to the specified tree item.
TreeItemcreateItem (SUIT_DataObject *, TreeItem *=0, TreeItem *=0)
 Create an item corresponding to the data object.
TreeItemcreateItemAtPos (SUIT_DataObject *, TreeItem *=0, int pos=0)
 Create an item corresponding to the data object.
void updateItem (TreeItem *)
 Update tree item.
void removeItem (TreeItem *)
 Remove tree item (recursively).

Private Attributes

SUIT_DataObjectmyRoot
TreeItemmyRootItem
ItemMap myItems
VisibilityMap myVisibilityMap
bool myAutoDeleteTree
bool myAutoUpdate
bool myUpdateModified
QVector< ColumnInfomyColumns

Friends

class SUIT_TreeModel::TreeSync

Detailed Description

The SUIT_TreeModel class does not support insertion/removal of rows. It is synchronized automatically with the tree of data objects used by SUIT-based applications to expose their data in a hierarchical form to the user.


Member Typedef Documentation

typedef QMap<SUIT_DataObject*, TreeItem*> SUIT_TreeModel.ItemMap [private]
typedef QMap<QString,Qtx::VisibilityState> SUIT_TreeModel.VisibilityMap [private]

Member Enumeration Documentation

Enumerator:
DisplayRole 

text label

DecorationRole 

icon

EditRole 

edit mode

ToolTipRole 

tooltip

StatusTipRole 

status tip

WhatsThisRole 

what's this info

FontRole 

font

TextAlignmentRole 

text alignment

BackgroundRole 

background color

ForegroundRole 

text color

CheckStateRole 

check state

SizeHintRole 

size hint

BaseColorRole 

(editor) background color

TextColorRole 

(editor) text color (Qt.UserRole + 1)

HighlightRole 

highlight color (Qt.UserRole + 2)

HighlightedTextRole 

highlighted text color (Qt.UserRole + 3)

AppropriateRole 

appropriate flag (Qt.UserRole + 100)


Constructor & Destructor Documentation

SUIT_TreeModel::SUIT_TreeModel ( QObject parent = 0)
Parameters:
parentparent object

References initialize().

SUIT_TreeModel::SUIT_TreeModel ( SUIT_DataObject root,
QObject parent = 0 
)
Parameters:
rootroot data object
parentparent object

References initialize().

SUIT_TreeModel::~SUIT_TreeModel ( )

Member Function Documentation

SUIT_DataObject * SUIT_TreeModel::root ( ) const [virtual]
Returns:
data tree root
See also:
setRoot()

Implements SUIT_AbstractModel.

References myRoot.

void SUIT_TreeModel::setRoot ( SUIT_DataObject r) [virtual]
Parameters:
rnew data tree root
See also:
root()

Implements SUIT_AbstractModel.

References autoDeleteTree(), SUIT_DataObject.disconnect(), modelUpdated(), myRoot, onInserted(), onRemoved(), and root().

QVariant SUIT_TreeModel::data ( const QModelIndex &  index,
int  role = DisplayRole 
) const [virtual]
bool SUIT_TreeModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role = EditRole 
) [virtual]
Parameters:
indexmodel index
valuenew data value
roledata role
Returns:
true if data is set
See also:
data()

References CheckStateRole, EditRole, SUIT_DataObject.isCheckable(), PyInterp.obj, object(), SUIT_DataObject.setName(), and SUIT_DataObject.setOn().

Qt::ItemFlags SUIT_TreeModel::flags ( const QModelIndex &  index) const [virtual]
QVariant SUIT_TreeModel::headerData ( int  column,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const [virtual]
Parameters:
columncolumn number
orientationheader orientation
roledata role
Returns:
header data

References AppropriateRole, DecorationRole, DisplayRole, Horizontal, myColumns, root(), Qtx.ShowAll, Qtx.ShowIcon, and Qtx.ShowText.

QModelIndex SUIT_TreeModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const [virtual]
Parameters:
rowdata row
columndata column
parentparent model index
Returns:
model index

References SUIT_TreeModel.TreeItem.child(), and treeItem().

QModelIndex SUIT_TreeModel::parent ( const QModelIndex &  index) const [virtual]
Parameters:
indexmodel index
Returns:
parent model index

References SUIT_TreeModel.TreeItem.parent(), SUIT_TreeModel.TreeItem.position(), rootItem(), and treeItem().

int SUIT_TreeModel::columnCount ( const QModelIndex &  = QModelIndex()) const [virtual]
Parameters:
parentparent model index (not used)
Returns:
data columns number
See also:
rowCount()

References myColumns.

int SUIT_TreeModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const [virtual]
Parameters:
parentparent model index
Returns:
data rows (children) number
See also:
columnCount()

References SUIT_TreeModel.TreeItem.childCount(), and treeItem().

void SUIT_TreeModel::registerColumn ( const int  group_id,
const QString &  name,
const int  custom_id 
) [virtual]
Parameters:
group_id- unique data object group identificator
name- translated column name
custom_id- custom column id that should be passed into method SUIT_DataObject.data()

Implements SUIT_AbstractModel.

References SUIT_TreeModel.ColumnInfo.myAppropriate, myColumns, SUIT_TreeModel.ColumnInfo.myHeaderFlags, SUIT_TreeModel.ColumnInfo.myIds, SUIT_TreeModel.ColumnInfo.myName, Qtx.ShowAll, and Qtx.Shown.

void SUIT_TreeModel::unregisterColumn ( const int  group_id,
const QString &  name 
) [virtual]

Please take into account that column is removed only for given group_id, it means that information of data objects with such group_id won't be shown. If there is not any registered group_id for this column after removing, the column will be hidden otherwise it continue to be shown

Parameters:
group_id- unique data object identificator allowing the classification of objects
name- translated column name

Implements SUIT_AbstractModel.

References myColumns.

void SUIT_TreeModel::setColumnIcon ( const QString &  name,
const QPixmap &  icon 
) [virtual]
Parameters:
name- column name
icon- new icon of the specified column

Implements SUIT_AbstractModel.

References myColumns.

QPixmap SUIT_TreeModel::columnIcon ( const QString &  name) const [virtual]
Parameters:
name- column name
Returns:
icon of the specified column

Implements SUIT_AbstractModel.

References myColumns.

void SUIT_TreeModel::setAppropriate ( const QString &  name,
const Qtx::Appropriate  appr 
) [virtual]

Appropriate status determines if the column should appear in the tree view header popup menu (to show/hide the column).

If appropriate status is not specified yet, the Shown value is taken, it means that column should be always visible.

Parameters:
name- column name
appr- new appropriate status

Implements SUIT_AbstractModel.

References Horizontal, and myColumns.

Qtx::Appropriate SUIT_TreeModel::appropriate ( const QString &  name) const [virtual]

Default implementation (if appropriate status is not specified yet) returns Shown, it means that column should be always visible.

Parameters:
name- column name
Returns:
appropriate status

Implements SUIT_AbstractModel.

References myColumns, and Qtx.Shown.

void SUIT_TreeModel::setVisibilityState ( const QString &  id,
Qtx::VisibilityState  state 
) [virtual]
void SUIT_TreeModel::setVisibilityStateForAll ( Qtx::VisibilityState  state) [virtual]
Qtx::VisibilityState SUIT_TreeModel::visibilityState ( const QString &  id) const [virtual]
Parameters:
id- column name
Returns:
visible state

Implements SUIT_AbstractModel.

References myVisibilityMap, and Qtx.UnpresentableState.

void SUIT_TreeModel::setHeaderFlags ( const QString &  name,
const Qtx::HeaderViewFlags  flags 
) [virtual]

These flags allow show in the header of the column text (name of the column), icon or both text and icon.

Parameters:
name- column name
flags- header flags

Implements SUIT_AbstractModel.

References flags(), Horizontal, and myColumns.

Qtx::HeaderViewFlags SUIT_TreeModel::headerFlags ( const QString &  name) const [virtual]

These flags allow show in the header of the column text (name of the column), icon or both text and icon.

Parameters:
name- column name
Returns:
header flags

Implements SUIT_AbstractModel.

References flags(), and myColumns.

void SUIT_TreeModel::emitClicked ( SUIT_DataObject obj,
const QModelIndex &  index 
) [virtual]
SUIT_DataObject * SUIT_TreeModel::object ( const QModelIndex &  index = QModelIndex()) const [virtual]
Parameters:
indexmodel index
Returns:
data object corresponding to the model index

Implements SUIT_AbstractModel.

References treeItem().

QModelIndex SUIT_TreeModel::index ( const SUIT_DataObject obj,
int  column = 0 
) const [virtual]
Parameters:
objdata object
columndata object column
Returns:
model index

Implements SUIT_AbstractModel.

References SUIT_TreeModel.TreeItem.position(), root(), and treeItem().

bool SUIT_TreeModel::autoDeleteTree ( ) const [virtual]
Returns:
'auto-delete data tree' flag value
See also:
setAutoDeleteTree()

Implements SUIT_AbstractModel.

References myAutoDeleteTree.

void SUIT_TreeModel::setAutoDeleteTree ( const bool  on) [virtual]

If this flag is set to true, the data tree is deleted when the tree model is destroyed. Default value for this flag is false.

Parameters:
on'auto-delete data tree' flag value
See also:
autoDeleteTree()

Implements SUIT_AbstractModel.

References myAutoDeleteTree.

bool SUIT_TreeModel::autoUpdate ( ) const [virtual]
Returns:
'auto-update tree' flag value
See also:
setAutoUpdate(), updateTree()

Implements SUIT_AbstractModel.

References myAutoUpdate.

void SUIT_TreeModel::setAutoUpdate ( const bool  on) [virtual]

If this flag is set to true (by default), the model is updated automatically when data tree is changed.

Parameters:
on'auto-update tree' flag value
See also:
autoUpdate(), updateTree()

Implements SUIT_AbstractModel.

References SUIT_DataObject.connect(), SUIT_DataObject.disconnect(), myAutoUpdate, onInserted(), onRemoved(), and updateTree().

bool SUIT_TreeModel::updateModified ( ) const [virtual]
Returns:
'updateModified' flag value

Implements SUIT_AbstractModel.

References myUpdateModified.

void SUIT_TreeModel::setUpdateModified ( const bool  on) [virtual]
Parameters:
on'updateModified' flag value

Implements SUIT_AbstractModel.

References myUpdateModified.

bool SUIT_TreeModel::customSorting ( const int  column) const [virtual]
Parameters:
columncolumn index on which data is being sorted
Returns:
true if column requires custom sorting
See also:
lessThan()

Implements SUIT_AbstractModel.

References SUIT_DataObject.customSorting(), and root().

bool SUIT_TreeModel::lessThan ( const QModelIndex &  left,
const QModelIndex &  right 
) const [virtual]

This method is called only for those columns for which customSorting() method returns true.

Parameters:
leftfirst index to compare
rightsecond index to compare
Returns:
result of the comparison
See also:
customSorting()

Implements SUIT_AbstractModel.

References SUIT_DataObject.compare(), data(), and root().

QAbstractItemDelegate * SUIT_TreeModel::delegate ( ) const [virtual]
Returns:
new item delegate

Implements SUIT_AbstractModel.

void SUIT_TreeModel::updateTreeModel ( SUIT_DataObject obj,
TreeItem item 
) [virtual]
void SUIT_TreeModel::updateTree ( const QModelIndex &  index) [virtual, slot]

Call this method when data tree is changed outside the model. If the 'auto-update' flag is set to true, the model is updated automatically when the data tree is changed.

Parameters:
indexstarting index for the updating
See also:
setAutoUpdate()

Implements SUIT_AbstractModel.

void SUIT_TreeModel::updateTree ( SUIT_DataObject obj = 0) [virtual, slot]

Call this method when data tree is changed outside the model. If the 'auto-update' flag is set to true, the model is updated automatically when the data tree is changed.

Parameters:
objstarting data object for the updating
See also:
setAutoUpdate()

Implements SUIT_AbstractModel.

References modelUpdated(), PyInterp.obj, SUIT_DataObject.root(), root(), treeItem(), updateModified(), and updateTreeModel().

void SUIT_TreeModel.modelUpdated ( ) [signal]
void SUIT_TreeModel.clicked ( SUIT_DataObject ,
int   
) [signal]
void SUIT_TreeModel::initialize ( ) [private]
SUIT_TreeModel::TreeItem * SUIT_TreeModel::rootItem ( ) const [private]
Returns:
root tree item

References myRootItem.

SUIT_TreeModel::TreeItem * SUIT_TreeModel::treeItem ( const QModelIndex &  index) const [private]
Parameters:
indexmodel index
Returns:
tree item or root item if index is invalid

References rootItem().

SUIT_TreeModel::TreeItem * SUIT_TreeModel::treeItem ( const SUIT_DataObject obj) const [private]
Parameters:
objdata object
Returns:
tree item or 0 if there is no tree item corresponding to obj

References myItems, root(), and rootItem().

SUIT_DataObject * SUIT_TreeModel::object ( const TreeItem item) const [private]
Parameters:
itemtree item
Returns:
data object or 0 if there is no data object corresponding to item

References SUIT_TreeModel.TreeItem.dataObject(), myItems, PyInterp.obj, root(), and rootItem().

SUIT_TreeModel::TreeItem * SUIT_TreeModel::createItem ( SUIT_DataObject obj,
SUIT_TreeModel::TreeItem parent = 0,
SUIT_TreeModel::TreeItem after = 0 
) [private]
Parameters:
objsource data object
parentparent tree item
aftertree item after which new item should be inserted
Returns:
created tree item or 0 if item could not be created

References SUIT_TreeModel.TreeItem.child(), SUIT_TreeModel.TreeItem.childCount(), index(), myItems, PyInterp.obj, object(), SUIT_DataObject.position(), SUIT_DataObject.setModified(), and SUIT_TreeModel.TreeItem.setPosition().

SUIT_TreeModel::TreeItem * SUIT_TreeModel::createItemAtPos ( SUIT_DataObject obj,
SUIT_TreeModel::TreeItem parent = 0,
int  pos = 0 
) [private]
Parameters:
objsource data object
parentparent tree item
postree item position into which new item should be inserted
Returns:
created tree item or 0 if item could not be created

References SUIT_TreeModel.TreeItem.child(), SUIT_TreeModel.TreeItem.childCount(), index(), myItems, PyInterp.obj, object(), SUIT_DataObject.setModified(), and SUIT_TreeModel.TreeItem.setPosition().

void SUIT_TreeModel::updateItem ( SUIT_TreeModel::TreeItem item) [private]
Parameters:
itemtree item to be updated

References columnCount(), index(), PyInterp.obj, object(), and SUIT_DataObject.setModified().

void SUIT_TreeModel::removeItem ( SUIT_TreeModel::TreeItem item) [private]
void SUIT_TreeModel::onInserted ( SUIT_DataObject ,
SUIT_DataObject parent 
) [private, slot]
Parameters:
objectdata object being inserted
parentparent data object

References autoUpdate(), and updateTree().

void SUIT_TreeModel::onRemoved ( SUIT_DataObject ,
SUIT_DataObject parent 
) [private, slot]
Parameters:
objectdata object being removed
parentparent data object

References autoUpdate(), and updateTree().

SUIT_AbstractModel::operator const QAbstractItemModel * ( ) const [inherited]
SUIT_AbstractModel::operator QAbstractItemModel * ( ) [inherited]
SUIT_AbstractModel::operator const QObject * ( ) const [inherited]
SUIT_DataSearcher * SUIT_AbstractModel::searcher ( ) const [virtual, inherited]

Reimplemented in SUIT_ProxyModel.

References SUIT_AbstractModel.mySearcher.

void SUIT_AbstractModel::setSearcher ( SUIT_DataSearcher s) [virtual, inherited]

Reimplemented in SUIT_ProxyModel.

References SUIT_AbstractModel.mySearcher.


Friends And Related Function Documentation

friend class SUIT_TreeModel::TreeSync [friend]

Field Documentation

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS