Developer Documentation
VSI::TreeModel Class Reference
Inheritance diagram for VSI::TreeModel:

Signals

void dataChangedInside (int _id, int _column, const QVariant &_value)
 

Public Member Functions

 TreeModel (QObject *_parent=0)
 Constructor. More...
 
 ~TreeModel ()
 Destructor. More...
 
inherited from QAbstractItemModel
QVariant data (const QModelIndex &_index, int _role) const
 Get the data of the corresponding entry. More...
 
Qt::ItemFlags flags (const QModelIndex &_index) const
 return the types of the corresponding entry More...
 
QVariant headerData (int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
 return the header data of the model More...
 
QModelIndex index (int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
 Get the ModelIndex at given row,column. More...
 
QModelIndex parent (const QModelIndex &_index) const
 Get the parent ModelIndex. More...
 
int rowCount (const QModelIndex &_parent=QModelIndex()) const
 get the number of rows More...
 
int columnCount (const QModelIndex &_parent=QModelIndex()) const
 Return the number of columns. More...
 
bool setData (const QModelIndex &_index, const QVariant &_value, int _role)
 Set Data at 'index' to 'value'. More...
 

Internal DataStructure (the TreeItem Tree)

TreeItemrootItem_
 Rootitem of the tree.
 
QModelIndex getModelIndex (TreeItem *_object, int _column)
 Return the ModelIndex corresponding to a given TreeItem and Column. More...
 
QModelIndex getModelIndex (int _id, int _column)
 Return the ModelIndex corresponding to a given object id and Column. More...
 
bool isRoot (TreeItem *_item)
 Check if the given item is the root item. More...
 
bool getObjectName (TreeItem *_object, QString &_name)
 Get the name of a given object.
 
TreeItemgetItem (const QModelIndex &_index) const
 Get the TreeItem corresponding to a given ModelIndex. More...
 
QString itemName (const QModelIndex &_index) const
 Get the name of a TreeItem corresponding to a given ModelIndex. More...
 
int itemId (const QModelIndex &_index) const
 Get the id of a TreeItem corresponding to a given ModelIndex. More...
 
void objectChanged (int id_)
 The object with the given id has been changed. Check if model also has to be changed. More...
 
void objectAdded (BaseObject *_object)
 The object with the given id has been added. add it to the internal tree. More...
 
void objectAdded (BaseObject *_object, BaseObject *_parent)
 The object with the given id has been added. add it to the internal tree. More...
 
void objectDeleted (int id_)
 The object with the given id has been deleted. delete it from the internal tree. More...
 
void moveItem (TreeItem *_item, TreeItem *_parent)
 move the item to a new parent More...
 
void propagateUpwards (TreeItem *_obj, int _column, bool _value)
 Recursively update a column up to the root of the tree. More...
 
void propagateDownwards (TreeItem *_obj, int _column)
 Recursively update a column up to the root of the tree. More...
 

Detailed Description

Definition at line 55 of file TreeModel.hh.

Constructor & Destructor Documentation

◆ TreeModel()

TreeModel::TreeModel ( QObject *  _parent = 0)
explicit

Constructor.

Parameters
_parentparent Object

Definition at line 62 of file TreeModel.cc.

◆ ~TreeModel()

TreeModel::~TreeModel ( )

Destructor.

Definition at line 73 of file TreeModel.cc.

Member Function Documentation

◆ columnCount()

int TreeModel::columnCount ( const QModelIndex &  _parent = QModelIndex()) const

Return the number of columns.

Parameters
_parentunused
Returns
return always 2

Definition at line 81 of file TreeModel.cc.

◆ data()

QVariant TreeModel::data ( const QModelIndex &  _index,
int  _role 
) const

Get the data of the corresponding entry.

Returns the data stored under the given role for the item referred to by the index.

Parameters
_indexa ModelIndex that defines the item in the tree
_roledefines the kind of data requested
Returns
requested data

Definition at line 96 of file TreeModel.cc.

◆ flags()

Qt::ItemFlags TreeModel::flags ( const QModelIndex &  _index) const

return the types of the corresponding entry

Returns the item flags for the given index.

Parameters
_indexModelIndex that defines an item in the tree
Returns
flags for the given ModelIndex

Definition at line 141 of file TreeModel.cc.

◆ getItem()

TreeItem * TreeModel::getItem ( const QModelIndex &  _index) const

Get the TreeItem corresponding to a given ModelIndex.

Return item at given index.

Parameters
_indexa ModelIndex
Returns
item at given index

Definition at line 427 of file TreeModel.cc.

◆ getModelIndex() [1/2]

QModelIndex TreeModel::getModelIndex ( TreeItem _object,
int  _column 
)

Return the ModelIndex corresponding to a given TreeItem and Column.

Return index of given item.

Warning: Only use this function if you know that all ModelIndices are created

Parameters
_objectan object
_columna column
Returns
index of object and column

Definition at line 481 of file TreeModel.cc.

◆ getModelIndex() [2/2]

QModelIndex TreeModel::getModelIndex ( int  _id,
int  _column 
)

Return the ModelIndex corresponding to a given object id and Column.

Return index of given item.

Warning: Only use this function if you know that all ModelIndices are created

Parameters
_idan object id
_columna column
Returns
index of object and column

Definition at line 502 of file TreeModel.cc.

◆ headerData()

QVariant TreeModel::headerData ( int  _section,
Qt::Orientation  _orientation,
int  _role = Qt::DisplayRole 
) const

return the header data of the model

Returns the data in the header.

Parameters
_sectionthe column in the header
_orientationheader orientation (only horizontal handled)
_rolethe role that defines the type of data
Returns
the requested data

Definition at line 174 of file TreeModel.cc.

◆ index()

QModelIndex TreeModel::index ( int  _row,
int  _column,
const QModelIndex &  _parent = QModelIndex() 
) const

Get the ModelIndex at given row,column.

Returns the index of the item in the model specified by the given row, column and parent index.

Parameters
_rowthe row
_columnthe column
_parentparent item
Returns
corresponding ModelIndex

Definition at line 200 of file TreeModel.cc.

◆ isRoot()

bool TreeModel::isRoot ( TreeItem _item)

Check if the given item is the root item.

return if an object is equal to the root object

Parameters
_itemthe item to be checked
Returns
is it the root object?

Definition at line 602 of file TreeModel.cc.

◆ itemId()

int TreeModel::itemId ( const QModelIndex &  _index) const

Get the id of a TreeItem corresponding to a given ModelIndex.

Return item-id at given index.

Parameters
_indexa ModelIndex
Returns
item-id at given index

Definition at line 461 of file TreeModel.cc.

◆ itemName()

QString TreeModel::itemName ( const QModelIndex &  _index) const

Get the name of a TreeItem corresponding to a given ModelIndex.

Return item-name at given index.

Parameters
_indexa ModelIndex
Returns
name of the item at given index

Definition at line 444 of file TreeModel.cc.

◆ moveItem()

void TreeModel::moveItem ( TreeItem _item,
TreeItem _parent 
)

move the item to a new parent

Parameters
_itemthe item
_parentnew parent

Definition at line 398 of file TreeModel.cc.

◆ objectAdded() [1/2]

void TreeModel::objectAdded ( BaseObject _object)

The object with the given id has been added. add it to the internal tree.

Parameters
_objectThe added object

Definition at line 326 of file TreeModel.cc.

◆ objectAdded() [2/2]

void TreeModel::objectAdded ( BaseObject _object,
BaseObject _parent 
)

The object with the given id has been added. add it to the internal tree.

Parameters
_objectThe added object
_parentThe new parent object

Definition at line 336 of file TreeModel.cc.

◆ objectChanged()

void TreeModel::objectChanged ( int  _id)

The object with the given id has been changed. Check if model also has to be changed.

The object with the given id has been changed. Update the model.

Parameters
_idid of an object

Definition at line 267 of file TreeModel.cc.

◆ objectDeleted()

void TreeModel::objectDeleted ( int  _id)

The object with the given id has been deleted. delete it from the internal tree.

Parameters
_idid of the object

Definition at line 371 of file TreeModel.cc.

◆ parent()

QModelIndex TreeModel::parent ( const QModelIndex &  _index) const

Get the parent ModelIndex.

Return index of parent item.

Parameters
_indexa ModelIndex
Returns
parent of the given ModelIndex

Definition at line 224 of file TreeModel.cc.

◆ propagateDownwards()

void TreeModel::propagateDownwards ( TreeItem _item,
int  _column 
)
private

Recursively update a column up to the root of the tree.

Parameters
_itemitem to start with
_columncolumn which needs the update (1: visibility)

Definition at line 551 of file TreeModel.cc.

◆ propagateUpwards()

void TreeModel::propagateUpwards ( TreeItem _item,
int  _column,
bool  _value 
)
private

Recursively update a column up to the root of the tree.

Parameters
_itemitem to start with
_columncolumn which needs the update (1: visibility)
_valuevalue which will be assigned

Definition at line 521 of file TreeModel.cc.

◆ rowCount()

int TreeModel::rowCount ( const QModelIndex &  _parent = QModelIndex()) const

get the number of rows

Returns the number of rows under given parent.

Parameters
_parentparent Item
Returns
number of rows that are children of given parent

Definition at line 246 of file TreeModel.cc.

◆ setData()

bool TreeModel::setData ( const QModelIndex &  _index,
const QVariant &  _value,
int  _role 
)

Set Data at 'index' to 'value'.

Parameters
_indexa ModelIndex defining the positin in the model
_valuethe new value
_roleunused
Returns
return if the data was set successfully

Definition at line 586 of file TreeModel.cc.


The documentation for this class was generated from the following files: