Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TreeModel.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49
50 #ifndef TREEMODEL_H
51 #define TREEMODEL_H
52
53 #include <QAbstractItemModel>
54 #include <QModelIndex>
55 #include <QVariant>
56
57 #include "TreeItem.hh"
58
59 class TreeModel : public QAbstractItemModel
60 {
61 Q_OBJECT
62
63 signals:
64 // the connected TreeView changed data
65 void dataChangedInside(int _id, int _column, const QVariant& _value);
66
67 public:
68
70 TreeModel(QObject *_parent = 0);
71
73 ~TreeModel();
74
75 //===========================================================================
78 //===========================================================================
79
80 public:
81
83 QVariant data(const QModelIndex &_index, int _role) const;
84
86 Qt::ItemFlags flags(const QModelIndex &_index) const;
87
89 QVariant headerData(int _section,
90 Qt::Orientation _orientation,
91 int _role = Qt::DisplayRole) const;
92
94 QModelIndex index(int _row, int _column,
95 const QModelIndex &_parent = QModelIndex()) const;
96
98 QModelIndex parent(const QModelIndex &_index) const;
99
101 int rowCount(const QModelIndex &_parent = QModelIndex()) const;
102
108 int columnCount(const QModelIndex &_parent = QModelIndex()) const;
109
117 bool setData(const QModelIndex &_index, const QVariant &_value , int _role);
118
121 //===========================================================================
124 //===========================================================================
125
126 public:
127
129 QModelIndex getModelIndex(TreeItem* _object, int _column );
130
132 QModelIndex getModelIndex(int _id, int _column );
133
135 bool isRoot(TreeItem* _item);
136
138 bool getObjectName(TreeItem* _object , QString& _name);
139
141 TreeItem *getItem(const QModelIndex &_index) const;
142
144 QString itemName(const QModelIndex &_index) const;
145
147 int itemId(const QModelIndex &_index) const;
148
149
151 void objectChanged(int id_);
152
154 void objectAdded(BaseObject* _object);
155
157 void objectAdded(BaseObject* _object, BaseObject* _parent);
158
160 void objectDeleted(int id_);
161
163 void moveItem(TreeItem* _item, TreeItem* _parent );
164 private:
165
167 TreeItem* rootItem_;
168
169
170 void propagateUpwards(TreeItem* _obj, int _column, bool _value );
171 void propagateDownwards(TreeItem* _obj, int _column );
172
176 };
177
178 #endif
179
TreeModel::objectAdded
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
Definition: TreeModel.cc:436
TreeModel::itemName
QString itemName(const QModelIndex &_index) const
Get the name of a TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:535
TreeModel::TreeModel
TreeModel(QObject *_parent=0)
Constructor.
Definition: TreeModel.cc:71
TreeModel::parent
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
Definition: TreeModel.cc:322
TreeModel::propagateUpwards
void propagateUpwards(TreeItem *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
Definition: TreeModel.cc:522
TreeModel::isRoot
bool isRoot(TreeItem *_item)
Check if the given item is the root item.
Definition: TreeModel.cc:602
TreeItem
Definition: TreeItem.hh:59
TreeModel::propagateDownwards
void propagateDownwards(TreeItem *_obj, int _column)
Recursively update a column up to the root of the tree.
Definition: TreeModel.cc:552
TreeModel::index
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
Definition: TreeModel.cc:295
TreeModel::headerData
QVariant headerData(int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
return the header data of the model
Definition: TreeModel.cc:268
TreeModel::rootItem_
TreeItem * rootItem_
Root item of the tree.
Definition: TreeModel.hh:167
TreeModel::objectChanged
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
Definition: TreeModel.cc:363
TreeModel::rowCount
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
Definition: TreeModel.cc:344
BaseObject
Definition: BaseObject.hh:94
TreeModel::itemId
int itemId(const QModelIndex &_index) const
Get the id of a TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:552
TreeModel::flags
Qt::ItemFlags flags(const QModelIndex &_index) const
return the types of the corresponding entry
Definition: TreeModel.cc:231
TreeModel::data
QVariant data(const QModelIndex &_index, int _role) const
Get the data of the corresponding entry.
Definition: TreeModel.cc:105
TreeModel::setData
bool setData(const QModelIndex &_index, const QVariant &_value, int _role)
Set Data at 'index' to 'value'.
Definition: TreeModel.cc:585
TreeModel::getObjectName
bool getObjectName(TreeItem *_object, QString &_name)
Get the name of a given object.
TreeModel::~TreeModel
~TreeModel()
Destructor.
Definition: TreeModel.cc:82
TreeModel
Definition: TreeModel.hh:59
TreeModel::columnCount
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
Definition: TreeModel.cc:90
TreeModel::objectDeleted
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
Definition: TreeModel.cc:471
TreeModel::getItem
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:518
TreeModel::getModelIndex
QModelIndex getModelIndex(TreeItem *_object, int _column)
Return the ModelIndex corresponding to a given TreeItem and Column.
Definition: TreeModel.cc:572
TreeModel::moveItem
void moveItem(TreeItem *_item, TreeItem *_parent)
move the item to a new parent
Definition: TreeModel.cc:498