Developer Documentation
TreeModel Class Reference
Inheritance diagram for TreeModel:

Signals

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

Public Member Functions

 TreeModel (QObject *_parent=0)
 Constructor. More...
 
 ~TreeModel ()
 Destructor. More...
 
 TreeModel (QObject *_parent=0)
 Constructor.
 
 ~TreeModel ()
 Destructor.
 
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...
 
QVariant data (const QModelIndex &_index, int _role) const
 Get the data of the corresponding entry.
 
Qt::ItemFlags flags (const QModelIndex &_index) const
 return the types of the corresponding entry
 
QVariant headerData (int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
 return the header data of the model
 
QModelIndex index (int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
 Get the ModelIndex at given row,column.
 
QModelIndex parent (const QModelIndex &_index) const
 Get the parent ModelIndex.
 
int rowCount (const QModelIndex &_parent=QModelIndex()) const
 get the number of rows
 
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...
 
Drag and Drop
Qt::DropActions supportedDropActions () const
 supported drag & Drop actions More...
 
QStringList mimeTypes () const
 stores the mimeType for Drag & Drop More...
 
QMimeData * mimeData (const QModelIndexList &indexes) const
 get the mimeData for a given ModelIndex More...
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 This is called when mimeData is dropped. More...
 

Internal DataStructure (the TreeItem Tree)

TreeItemrootItem_
 Root item of the tree. More...
 
QModelIndex getModelIndex (TreeItem *_object, int _column)
 Return the ModelIndex corresponding to a given TreeItem 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...
 
TreeItemgetItem (const int _id) const
 Get the TreeItem corresponding to a given OpenFlipper ObjectID.
 
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 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...
 
QModelIndex getModelIndex (TreeItem *_object, int _column)
 Return the ModelIndex corresponding to a given TreeItem and Column.
 
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.
 
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.
 
QString itemName (const QModelIndex &_index) const
 Get the name of a TreeItem corresponding to a given ModelIndex.
 
int itemId (const QModelIndex &_index) const
 Get the id of a TreeItem corresponding to a given ModelIndex.
 
void objectChanged (int id_)
 The object with the given id has been changed. Check if model also has to be changed.
 
void objectAdded (BaseObject *_object)
 The object with the given id has been added. add it to the internal tree.
 
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.
 
void moveItem (TreeItem *_item, TreeItem *_parent)
 move the item to a new parent
 
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 53 of file TreeModel.hh.

Constructor & Destructor Documentation

◆ TreeModel()

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

Constructor.

Parameters
_parentparent Object

Definition at line 61 of file TreeModel.cc.

◆ ~TreeModel()

TreeModel::~TreeModel ( )

Destructor.

Definition at line 72 of file TreeModel.cc.

Member Function Documentation

◆ columnCount() [1/2]

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

Return the number of columns.

Parameters
_parentunused
Returns
return always 2

◆ columnCount() [2/2]

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

Return the number of columns.

Parameters
_parentunused
Returns
return always 4

Definition at line 80 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 95 of file TreeModel.cc.

◆ dropMimeData()

bool TreeModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)

This is called when mimeData is dropped.

Parameters
dataThe dropped data
actionThe definition of the dropAction which occurred
rowUnused
columnUnused
parentParent under which the drop occurred
Returns
returns if the drop was successful

Definition at line 659 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 221 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 508 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 562 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 494 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 258 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 285 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 592 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 542 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
Parameters
_indexa ModelIndex
Returns
name of the item at given index

Definition at line 525 of file TreeModel.cc.

◆ mimeData()

QMimeData * TreeModel::mimeData ( const QModelIndexList &  _indexes) const

get the mimeData for a given ModelIndex

generate mimeData for given ModelIndexes

Parameters
_indexeslist of ModelIndexes
Returns
the mimeData

Definition at line 631 of file TreeModel.cc.

◆ mimeTypes()

QStringList TreeModel::mimeTypes ( ) const

stores the mimeType for Drag & Drop

return the mimeType for drag & drop

Returns
the mimeType

Definition at line 616 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 488 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 426 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 328 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 353 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 461 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 312 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 543 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 513 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 334 of file TreeModel.cc.

◆ setData() [1/2]

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

◆ setData() [2/2]

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 575 of file TreeModel.cc.

◆ supportedDropActions()

Qt::DropActions TreeModel::supportedDropActions ( ) const

supported drag & Drop actions

return the supported drop actions

Returns
drop actions

Definition at line 604 of file TreeModel.cc.

Member Data Documentation

◆ rootItem_

TreeItem * TreeModel::rootItem_
private

Root item of the tree.

Rootitem of the tree.

Definition at line 161 of file TreeModel.hh.


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