Implementation of the model/view API based on the tree of SUIT_DataObject class instances. More...
#include <SUIT_TreeModel.h>
Classes | |
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. More... | |
virtual void | updateTree (SUIT_DataObject *=0) |
Update tree model. More... | |
Signals | |
void | modelUpdated () |
void | clicked (SUIT_DataObject *, int) |
void | dropped (const QList< SUIT_DataObject * > &, SUIT_DataObject *, int, Qt::DropAction) |
void | renamed (SUIT_DataObject *) |
Public Member Functions | |
SUIT_TreeModel (QObject *=0) | |
Constructor. More... | |
SUIT_TreeModel (SUIT_DataObject *, QObject *=0) | |
Constructor. More... | |
~SUIT_TreeModel () | |
Destructor. More... | |
SUIT_DataObject * | root () const |
Get data tree root object. More... | |
void | setRoot (SUIT_DataObject *) |
Set data tree root object. More... | |
virtual QVariant | data (const QModelIndex &, int=DisplayRole) const |
Get data for the specified model index and data role. More... | |
virtual bool | setData (const QModelIndex &, const QVariant &, int=EditRole) |
Set data for the specified model index and data role. More... | |
virtual Qt::ItemFlags | flags (const QModelIndex &) const |
Get data flags for specified model index. More... | |
virtual QVariant | headerData (int, Qt::Orientation, int=Qt::DisplayRole) const |
Get header data (can be used in any data view). More... | |
virtual Qt::DropActions | supportedDropActions () const |
virtual QModelIndex | index (int, int, const QModelIndex &=QModelIndex()) const |
Create model index. More... | |
virtual QModelIndex | parent (const QModelIndex &) const |
Get parent model index. More... | |
virtual int | columnCount (const QModelIndex &=QModelIndex()) const |
Get number of data columns. More... | |
virtual int | rowCount (const QModelIndex &=QModelIndex()) const |
Get number of data rows (children of the specified model index). More... | |
virtual void | registerColumn (const int group_id, const QString &name, const int custom_id) |
Register new column in the model. More... | |
virtual void | unregisterColumn (const int group_id, const QString &name) |
Remove column from the model. More... | |
virtual void | setColumnIcon (const QString &name, const QPixmap &icon) |
Change column icon. More... | |
virtual QPixmap | columnIcon (const QString &name) const |
Get column icon. More... | |
virtual void | setAppropriate (const QString &name, const Qtx::Appropriate appr) |
Change appropriate status. More... | |
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). More... | |
virtual void | setVisibilityState (const QString &id, Qtx::VisibilityState state, bool emitChanged=true) |
Set visibility state of the object. More... | |
virtual void | setVisibilityStateForAll (Qtx::VisibilityState state) |
Set visibility state for all objects. More... | |
virtual Qtx::VisibilityState | visibilityState (const QString &id) const |
Get visibility state of the object. More... | |
virtual void | setHeaderFlags (const QString &name, const Qtx::HeaderViewFlags flags) |
Set header flags. More... | |
virtual Qtx::HeaderViewFlags | headerFlags (const QString &name) const |
Get the header flags. More... | |
virtual void | emitClicked (SUIT_DataObject *obj, const QModelIndex &index) |
SUIT_DataObject * | object (const QModelIndex &=QModelIndex()) const |
Get data object by the specified model index. More... | |
QModelIndex | index (const SUIT_DataObject *, int=0) const |
Get model index by the specified data object. More... | |
bool | autoDeleteTree () const |
Get 'auto-delete data tree' flag value. More... | |
void | setAutoDeleteTree (const bool) |
Set 'auto-delete data tree' flag value. More... | |
bool | autoUpdate () const |
Get 'auto-update tree' flag value. More... | |
void | setAutoUpdate (const bool) |
Set 'auto-update tree' flag value. More... | |
bool | updateModified () const |
Get 'updateModified' flag value. More... | |
void | setUpdateModified (const bool) |
Set 'updateModified' flag value. More... | |
virtual bool | customSorting (const int) const |
Check if the specified column supports custom sorting. More... | |
virtual bool | lessThan (const QModelIndex &left, const QModelIndex &right) const |
Compares two model indexes for the sorting purposes. More... | |
virtual void | forgetObject (const SUIT_DataObject *) |
QAbstractItemDelegate * | delegate () const |
Get item delegate for the model. More... | |
virtual void | updateTreeModel (SUIT_DataObject *, TreeItem *) |
virtual QStringList | mimeTypes () const |
Drag and Drop support. More... | |
virtual QMimeData * | mimeData (const QModelIndexList &indexes) const |
Called when the data objects are exported(dragged) from the tree. More... | |
virtual bool | dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
Public Member Functions inherited from SUIT_AbstractModel | |
SUIT_AbstractModel () | |
operator const QAbstractItemModel * () const | |
operator QAbstractItemModel * () | |
operator const QObject * () const | |
virtual void | updateTree (const QModelIndex &)=0 |
virtual void | updateTree (SUIT_DataObject *=0)=0 |
virtual SUIT_DataSearcher * | searcher () const |
virtual void | setSearcher (SUIT_DataSearcher *) |
Private Types | |
typedef SUIT_DataObject * | ObjPtr |
typedef SUIT_TreeModel::TreeItem * | ItemPtr |
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. More... | |
void | onRemoved (SUIT_DataObject *, SUIT_DataObject *) |
Called when the data object is removed from the tree. More... | |
void | onModified (SUIT_DataObject *) |
Called when the data object is modified. TreeSync is not used here for maximum efficiency. It is assumed that it is up to the application to decide when its data objects are modified. More... | |
Private Member Functions | |
void | initialize () |
Initialize tree model. More... | |
TreeItem * | rootItem () const |
Get root tree item. More... | |
TreeItem * | treeItem (const QModelIndex &) const |
Get tree item corresponding to the specified model index. More... | |
TreeItem * | treeItem (const SUIT_DataObject *) const |
Get tree item corresponding to the specified data object. More... | |
SUIT_DataObject * | object (const TreeItem *) const |
Get data object corresponding to the specified tree item. More... | |
QString | objectId (const QModelIndex &=QModelIndex()) const |
Get unique object identifier. More... | |
TreeItem * | createItem (SUIT_DataObject *, TreeItem *=0, TreeItem *=0) |
Create an item corresponding to the data object. More... | |
TreeItem * | createItemAtPos (SUIT_DataObject *, TreeItem *=0, int pos=0) |
Create an item corresponding to the data object. More... | |
void | updateItem (TreeItem *, bool emitLayoutChanged) |
Update tree item. More... | |
void | removeItem (TreeItem *) |
Remove tree item (recursively). More... | |
Private Attributes | |
SUIT_DataObject * | myRoot |
TreeItem * | myRootItem |
ItemMap | myItems |
VisibilityMap | myVisibilityMap |
bool | myAutoDeleteTree |
bool | myAutoUpdate |
bool | myUpdateModified |
QVector< ColumnInfo > | myColumns |
Friends | |
class | SUIT_TreeModel::TreeSync |
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.
|
private |
|
private |
|
private |
|
private |
enum SUIT_TreeModel::Role |
SUIT_TreeModel::SUIT_TreeModel | ( | QObject * | parent = 0 | ) |
parent | parent object |
References initialize().
SUIT_TreeModel::SUIT_TreeModel | ( | SUIT_DataObject * | root, |
QObject * | parent = 0 |
||
) |
root | root data object |
parent | parent object |
References initialize().
SUIT_TreeModel::~SUIT_TreeModel | ( | ) |
References autoDeleteTree(), SUIT_DataObject::disconnect(), myRoot, myRootItem, onInserted(), onModified(), and onRemoved().
|
virtual |
Default implementation (if appropriate status is not specified yet) returns Shown
, it means that column should be always visible.
name | - column name |
Implements SUIT_AbstractModel.
References myColumns, myName, and Qtx::Shown.
|
virtual |
Implements SUIT_AbstractModel.
References myAutoDeleteTree.
|
virtual |
Implements SUIT_AbstractModel.
References myAutoUpdate.
|
signal |
|
virtual |
parent | parent model index (not used) |
References myColumns.
|
virtual |
|
private |
obj | source data object |
parent | parent tree item |
after | tree item after which new item should be inserted |
References SUIT_TreeModel::TreeItem::child(), SUIT_TreeModel::TreeItem::childCount(), index(), myItems, obj, object(), SUIT_DataObject::position(), SUIT_DataObject::setModified(), and SUIT_TreeModel::TreeItem::setPosition().
|
private |
obj | source data object |
parent | parent tree item |
pos | tree item position into which new item should be inserted |
References SUIT_TreeModel::TreeItem::child(), SUIT_TreeModel::TreeItem::childCount(), index(), myItems, obj, object(), SUIT_DataObject::setModified(), and SUIT_TreeModel::TreeItem::setPosition().
|
virtual |
column | column index on which data is being sorted |
true
if column requires custom sorting Implements SUIT_AbstractModel.
References SUIT_DataObject::customSorting(), and root().
|
virtual |
index | model index |
role | data role |
References SUIT_DataObject::alignment(), SUIT_DataObject::Background, BackgroundRole, SUIT_DataObject::Base, BaseColorRole, CheckStateRole, SUIT_DataObject::color(), DecorationRole, DisplayRole, EditRole, SUIT_DataObject::font(), FontRole, SUIT_DataObject::Foreground, ForegroundRole, SUIT_DataObject::groupId(), SUIT_DataObject::Highlight, SUIT_DataObject::HighlightedText, HighlightedTextRole, HighlightRole, SUIT_DataObject::icon(), SUIT_DataObject::isCheckable(), SUIT_DataObject::isOn(), QtxResourceMgr::loadPixmap(), myColumns, SUIT_TreeModel::ColumnInfo::myIds, myVisibilityMap, obj, object(), objectId(), SUIT_Session::resourceMgr(), SUIT_Session::session(), Qtx::ShownState, SizeHintRole, SUIT_DataObject::statusTip(), StatusTipRole, SUIT_DataObject::Text, SUIT_DataObject::text(), TextAlignmentRole, TextColorRole, SUIT_DataObject::toolTip(), ToolTipRole, SUIT_DataObject::VisibilityId, SUIT_DataObject::whatsThis(), and WhatsThisRole.
|
virtual |
Implements SUIT_AbstractModel.
|
virtual |
References dropped(), SUIT_DataSearcher::findObject(), obj, object(), and SUIT_AbstractModel::searcher().
|
signal |
|
virtual |
Implements SUIT_AbstractModel.
References clicked(), SUIT_DataObject::groupId(), myColumns, and SUIT_TreeModel::ColumnInfo::myIds.
|
virtual |
index | model index |
References SUIT_DataObject::isCheckable(), SUIT_DataObject::isDraggable(), SUIT_DataObject::isDropAccepted(), SUIT_DataObject::isEnabled(), SUIT_DataObject::isSelectable(), obj, object(), and SUIT_DataObject::renameAllowed().
|
virtual |
Implements SUIT_AbstractModel.
References removeItem(), and treeItem().
|
virtual |
column | column number |
orientation | header orientation |
role | data role |
References AppropriateRole, DecorationRole, DisplayRole, Horizontal, myColumns, root(), Qtx::ShowAll, Qtx::ShowIcon, and Qtx::ShowText.
|
virtual |
These flags allow show in the header of the column text (name of the column), icon or both text and icon.
name | - column name |
Implements SUIT_AbstractModel.
|
virtual |
row | data row |
column | data column |
parent | parent model index |
References SUIT_TreeModel::TreeItem::child(), and treeItem().
|
virtual |
obj | data object |
column | data object column |
Implements SUIT_AbstractModel.
References SUIT_TreeModel::TreeItem::position(), root(), and treeItem().
|
private |
References autoUpdate(), SUIT_DataObject::connect(), SUIT_DataObject::disconnect(), QtxResourceMgr::loadPixmap(), myItems, myRootItem, SUIT_DataObject::NameId, onInserted(), onModified(), onRemoved(), registerColumn(), SUIT_Session::resourceMgr(), SUIT_Session::session(), setColumnIcon(), setHeaderFlags(), Qtx::ShowIcon, updateTree(), and SUIT_DataObject::VisibilityId.
This method is called only for those columns for which customSorting() method returns true
.
left | first index to compare |
right | second index to compare |
Implements SUIT_AbstractModel.
References SUIT_DataObject::compare(), data(), and root().
indexes | the list of exported objects |
References index(), and objectId().
|
virtual |
|
signal |
|
virtual |
index | model index |
Implements SUIT_AbstractModel.
References treeItem().
|
private |
item | tree item |
References SUIT_TreeModel::TreeItem::dataObject(), myItems, obj, root(), and rootItem().
|
private |
Object identifier is customized via the Qtx::IdType custom data
index | model index |
References SUIT_DataObject::customData(), data(), Qtx::IdType, obj, and object().
|
privateslot |
object | data object being inserted |
parent | parent data object |
References autoUpdate(), and updateTree().
|
privateslot |
obj | data object that has been modified |
References autoUpdate(), columnCount(), index(), and SUIT_DataObject::setModified().
|
privateslot |
object | data object being removed |
parent | parent data object |
References autoUpdate(), and updateTree().
|
virtual |
index | model index |
References SUIT_TreeModel::TreeItem::parent(), SUIT_TreeModel::TreeItem::position(), rootItem(), and treeItem().
|
virtual |
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, myName, SUIT_TreeModel::ColumnInfo::myName, Qtx::ShowAll, and Qtx::Shown.
|
private |
item | tree item to be removed |
References SUIT_TreeModel::TreeItem::child(), SUIT_TreeModel::TreeItem::childCount(), index(), myItems, obj, object(), SUIT_TreeModel::TreeItem::parent(), parent(), SUIT_TreeModel::TreeItem::position(), SUIT_TreeModel::TreeItem::removeChild(), root(), SUIT_TreeModel::TreeItem::setPosition(), and setRoot().
|
signal |
|
virtual |
|
private |
References myRootItem.
|
virtual |
parent | parent model index |
References SUIT_TreeModel::TreeItem::childCount(), and treeItem().
|
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.
name | - column name |
appr | - new appropriate status |
Implements SUIT_AbstractModel.
References Horizontal, myColumns, and myName.
|
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
.
on | 'auto-delete data tree' flag value |
Implements SUIT_AbstractModel.
References myAutoDeleteTree.
|
virtual |
If this flag is set to true
(by default), the model is updated automatically when data tree is changed.
on | 'auto-update tree' flag value |
Implements SUIT_AbstractModel.
References SUIT_DataObject::connect(), SUIT_DataObject::disconnect(), myAutoUpdate, onInserted(), onModified(), onRemoved(), and updateTree().
name | - column name |
icon | - new icon of the specified column |
Implements SUIT_AbstractModel.
|
virtual |
index | model index |
value | new data value |
role | data role |
true
if data is set References CheckStateRole, EditRole, SUIT_DataObject::isCheckable(), SUIT_DataObject::name(), obj, object(), renamed(), SUIT_DataObject::setName(), and SUIT_DataObject::setOn().
|
virtual |
These flags allow show in the header of the column text (name of the column), icon or both text and icon.
name | - column name |
flags | - header flags |
Implements SUIT_AbstractModel.
References flags(), Horizontal, myColumns, and myName.
|
virtual |
r | new data tree root |
Implements SUIT_AbstractModel.
References autoDeleteTree(), SUIT_TreeModel::TreeItem::children(), SUIT_DataObject::disconnect(), modelUpdated(), myRoot, myRootItem, onInserted(), onModified(), onRemoved(), and root().
|
virtual |
on | 'updateModified' flag value |
Implements SUIT_AbstractModel.
References myUpdateModified.
|
virtual |
id | - column name |
state | - visible state |
emitChanged | - if set to false, blocks dataChanged() signal, this can be used to prevent emitting dataChanged() several times for the same data object |
Implements SUIT_AbstractModel.
References DisplayRole, SUIT_DataSearcher::findObject(), Qtx::IdType, index(), myVisibilityMap, root(), SUIT_AbstractModel::searcher(), Qtx::UnpresentableState, and SUIT_DataObject::VisibilityId.
|
virtual |
state | - visible state |
Implements SUIT_AbstractModel.
References myVisibilityMap, and setVisibilityState().
|
virtual |
|
private |
index | model index |
References rootItem().
|
private |
obj | data object |
References myItems, root(), and rootItem().
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
group_id | - unique data object identificator allowing the classification of objects |
name | - translated column name |
Implements SUIT_AbstractModel.
|
private |
item | tree item to be updated |
emitLayoutChanged | if signal about changed layout should be emitted |
References columnCount(), index(), obj, object(), and SUIT_DataObject::setModified().
|
virtual |
|
virtualslot |
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.
index | starting index for the updating |
|
virtualslot |
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.
obj | starting data object for the updating |
References modelUpdated(), obj, SUIT_DataObject::root(), root(), treeItem(), updateModified(), and updateTreeModel().
|
virtual |
References SUIT_TreeModel::TreeItem::child(), SUIT_DataObject::childCount(), SUIT_TreeModel::TreeItem::childCount(), SUIT_DataObject::childObject(), createItemAtPos(), SUIT_TreeModel::TreeItem::dataObject(), SUIT_DataObject::modified(), removeItem(), treeItem(), SUIT_DataObject::update(), and updateItem().
|
virtual |
id | - column name |
Implements SUIT_AbstractModel.
References myVisibilityMap, and Qtx::UnpresentableState.
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |