TreeProxyItemModel Class Reference
[Some utility classes]
Class to transform a table model to a tree model. More...
#include <treeproxyitemmodel.h>

Classes | |
| struct | Mapping |
Public Member Functions | |
| TreeProxyItemModel (QObject *parent=0) | |
| Create the TreeProxyItemModel. | |
| virtual | ~TreeProxyItemModel () |
| Destroy the TreeProxyItemModel class. | |
| virtual QModelIndex | index (int id) const |
| Return the QModelIndex for a given identifier id. | |
| virtual QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
Return the index for row, column and the parent parent. | |
| virtual QModelIndex | parent (const QModelIndex &index) const |
Return the parent of the index index. | |
| virtual QVariant | data (const QModelIndex &proxyIndex, int role) const |
Return the data for proxyIndex for the role role. | |
| virtual Qt::ItemFlags | flags (const QModelIndex &index) const |
Return the number of flags of the index index. | |
| virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const |
Return the number of row of the index index. | |
| virtual int | columnCount (const QModelIndex &parent=QModelIndex()) const |
Return the number of column of the index index. | |
| virtual QModelIndex | mapFromSource (const QModelIndex &sourceIndex) const |
| For the given source index, this method return the corresponding index in the proxy (See QAbstractProxyModel). | |
| virtual QModelIndex | mapToSource (const QModelIndex &proxyIndex) const |
| For the given proxy index, this method return the corresponding source index (See QAbstractProxyModel). | |
| bool | resetModel () const |
| void | setResetModel (bool value) |
| Set the value of resetModel property. | |
Protected Slots | |
| void | printMapping (int id=0, int niveau=0) const |
Protected Member Functions | |
| virtual int | getUniqueIdentifier (const QModelIndex &sourceIndex) const =0 |
| Method to reimplement to TreeProxyItemModel know the identifer for a source line. | |
| virtual int | getParentUniqueIdentifier (const QModelIndex &sourceIndex) const =0 |
| Method to reimplement to TreeProxyItemModel know the parent identifer for a source line. | |
| virtual void | setSourceModel (QAbstractItemModel *sourceModel) |
| Set the value of the source model (See QAbstractProxyModel). | |
| virtual void | createMapping () |
| Create the internal structure. | |
| void | setParentId (int id, int parentId) |
| Change the parent of an identifier. | |
Properties | |
| bool | resetModel |
| Return the value of the resetModel property. | |
Detailed Description
Class to transform a table model to a tree model.
- Since:
- 0.9.0.0
This class is used to transform a table model (with only row and column as QSqlQuery) to a tree model. To do this the subclass must redefine getParentUniqueIdentifier() and getUniqueIdentifier() to give the QModelIndex in the source model.
- Warning:
- This proxy read all the content of the table and generate a tree. If there is a large amount of data or if the medium of the source model is slow, another approach must be study. (ie: The Generix dictionary is too big to be transform by this class)
This model have been made to used with a source model connected to a little Sqlite base.
In debug mode the internal structure can be printed with qDebug() when error is triggered by ExceptionManager. For this you must uncomment the line in the constructor.
Constructor & Destructor Documentation
| TreeProxyItemModel::TreeProxyItemModel | ( | QObject * | parent = 0 |
) | [explicit] |
Create the TreeProxyItemModel.
By default the model is not reseted before createMapping() fill the internal structure. But if you want speed up the createMapping() method, you can switch setResetModel to true. If the model is reseted, all persistent index is lost.
| TreeProxyItemModel::~TreeProxyItemModel | ( | ) | [virtual] |
Destroy the TreeProxyItemModel class.
Member Function Documentation
| int TreeProxyItemModel::columnCount | ( | const QModelIndex & | index = QModelIndex() |
) | const [virtual] |
Return the number of column of the index index.
- See also:
- QAbstractItemModel::columnCount()
Reimplemented in CategoryItemModel, SnipetDockItemModel, and SnipetItemModel.
| void TreeProxyItemModel::createMapping | ( | ) | [protected, virtual] |
Create the internal structure.
Create the mapping of all index in the source model to the generate a tree. In normal case, this method should not be call.
| QVariant TreeProxyItemModel::data | ( | const QModelIndex & | proxyIndex, | |
| int | role | |||
| ) | const [virtual] |
Return the data for proxyIndex for the role role.
- See also:
- QAbstractItemModel::data()
Reimplemented in BaseSnipetItemModel, CategoryItemModel, SnipetDockItemModel, and SnipetItemModel.
| Qt::ItemFlags TreeProxyItemModel::flags | ( | const QModelIndex & | index | ) | const [virtual] |
Return the number of flags of the index index.
- See also:
- QAbstractItemModel::flags()
Reimplemented in CategoryItemModel, SnipetDockItemModel, SnipetItemModel, and SnipetMenuModel.
| int TreeProxyItemModel::getParentUniqueIdentifier | ( | const QModelIndex & | sourceIndex | ) | const [protected, pure virtual] |
Method to reimplement to TreeProxyItemModel know the parent identifer for a source line.
This method must be reimplemented to give a unique identifer for the parent of a given line in the source model. The column in the index must be ignore.
Implemented in BaseSnipetItemModel, and CategoryItemModel.
| int TreeProxyItemModel::getUniqueIdentifier | ( | const QModelIndex & | sourceIndex | ) | const [protected, pure virtual] |
Method to reimplement to TreeProxyItemModel know the identifer for a source line.
This method must be reimplemented to give a unique identifer for a given line in the source model. The column in the index must be ignore.
Implemented in BaseSnipetItemModel, and CategoryItemModel.
| QModelIndex TreeProxyItemModel::index | ( | int | row, | |
| int | column, | |||
| const QModelIndex & | parent = QModelIndex() | |||
| ) | const [virtual] |
Return the index for row, column and the parent parent.
- See also:
- QAbstractItemModel::index()
Reimplemented in BaseSnipetItemModel.
| QModelIndex TreeProxyItemModel::index | ( | int | id | ) | const [virtual] |
Return the QModelIndex for a given identifier id.
| QModelIndex TreeProxyItemModel::mapFromSource | ( | const QModelIndex & | sourceIndex | ) | const [virtual] |
For the given source index, this method return the corresponding index in the proxy (See QAbstractProxyModel).
Reimplemented in CategoryItemModel, SnipetDockItemModel, and SnipetItemModel.
| QModelIndex TreeProxyItemModel::mapToSource | ( | const QModelIndex & | proxyIndex | ) | const [virtual] |
For the given proxy index, this method return the corresponding source index (See QAbstractProxyModel).
Reimplemented in CategoryItemModel, SnipetDockItemModel, and SnipetItemModel.
| QModelIndex TreeProxyItemModel::parent | ( | const QModelIndex & | index | ) | const [virtual] |
Return the parent of the index index.
- See also:
- QAbstractItemModel::parent()
| void TreeProxyItemModel::printMapping | ( | int | id = 0, |
|
| int | niveau = 0 | |||
| ) | const [protected, slot] |
Print all the tree generated internally to the log file. This tree, is generated when error occure. In release mode this method is not necessary (and not usable).
- Parameters:
-
id The root id where to start the tree (0 by default) niveau The niveau where we are (0 by default). Used in recursivity.
| bool TreeProxyItemModel::resetModel | ( | ) | const |
| int TreeProxyItemModel::rowCount | ( | const QModelIndex & | index = QModelIndex() |
) | const [virtual] |
Return the number of row of the index index.
- See also:
- QAbstractItemModel::rowCount()
| void TreeProxyItemModel::setParentId | ( | int | id, | |
| int | parentId | |||
| ) | [protected] |
Change the parent of an identifier.
Change the parent identifier parentId for a given identifier id. Change the parent to -1 is equivalent to unassign an id. Change the parent to an unassigned id, is equivalent to assign an id.
| void TreeProxyItemModel::setResetModel | ( | bool | value | ) |
Set the value of resetModel property.
Set it to true, if you want increase performance and don't care of persistent index. Else if you set it to false, only inserted and deleted row are updated.
| void TreeProxyItemModel::setSourceModel | ( | QAbstractItemModel * | sourceModel | ) | [protected, virtual] |
Set the value of the source model (See QAbstractProxyModel).
Set the source model to sourceModel and create the mapping for this model if the sourceModel is not empty. If sourceModel is null, QAbstractProxModel use a empty model.
Reimplemented from QAbstractProxyModel.
Property Documentation
bool TreeProxyItemModel::resetModel [read, write] |
Return the value of the resetModel property.
- Returns:
- Return true if the model is reseted when the model is filling