Developer Documentation

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 #ifndef TREEMODEL_H
45 #define TREEMODEL_H
46
47 #include <QAbstractItemModel>
48 #include <QModelIndex>
49 #include <QVariant>
50
51 #include "TreeItem.hh"
52
53 class TreeModel : public QAbstractItemModel
54 {
55 Q_OBJECT
56
57 signals:
58 // the connected TreeView changed data
59 void dataChangedInside(int _id, int _column, const QVariant& _value);
60
61 public:
62
64 explicit TreeModel(QObject *_parent = 0);
65
67 ~TreeModel();
68
69 //===========================================================================
72 //===========================================================================
73
74 public:
75
77 QVariant data(const QModelIndex &_index, int _role) const;
78
80 Qt::ItemFlags flags(const QModelIndex &_index) const;
81
83 QVariant headerData(int _section,
84 Qt::Orientation _orientation,
85 int _role = Qt::DisplayRole) const;
86
88 QModelIndex index(int _row, int _column,
89 const QModelIndex &_parent = QModelIndex()) const;
90
92 QModelIndex parent(const QModelIndex &_index) const;
93
95 int rowCount(const QModelIndex &_parent = QModelIndex()) const;
96
102 int columnCount(const QModelIndex &_parent = QModelIndex()) const;
103
111 bool setData(const QModelIndex &_index, const QVariant &_value , int _role);
112
115 //===========================================================================
118 //===========================================================================
119
120 public:
121
123 QModelIndex getModelIndex(TreeItem* _object, int _column );
124
126 QModelIndex getModelIndex(int _id, int _column );
127
129 bool isRoot(TreeItem* _item);
130
132 bool getObjectName(TreeItem* _object , QString& _name);
133
135 TreeItem *getItem(const QModelIndex &_index) const;
136
138 QString itemName(const QModelIndex &_index) const;
139
141 int itemId(const QModelIndex &_index) const;
142
143
145 void objectChanged(int id_);
146
148 void objectAdded(BaseObject* _object);
149
151 void objectAdded(BaseObject* _object, BaseObject* _parent);
152
154 void objectDeleted(int id_);
155
157 void moveItem(TreeItem* _item, TreeItem* _parent );
158 private:
159
161 TreeItem* rootItem_;
162
163
164 void propagateUpwards(TreeItem* _obj, int _column, bool _value );
165 void propagateDownwards(TreeItem* _obj, int _column );
166
170 };
171
172 #endif
173
TreeModel::objectDeleted
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
Definition: TreeModel.cc:461
TreeModel::index
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
Definition: TreeModel.cc:285
TreeModel::itemName
QString itemName(const QModelIndex &_index) const
Get the name of a TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:525
TreeModel::flags
Qt::ItemFlags flags(const QModelIndex &_index) const
return the types of the corresponding entry
Definition: TreeModel.cc:221
TreeModel::moveItem
void moveItem(TreeItem *_item, TreeItem *_parent)
move the item to a new parent
Definition: TreeModel.cc:488
TreeModel::getItem
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:508
TreeModel::rootItem_
TreeItem * rootItem_
Root item of the tree.
Definition: TreeModel.hh:161
TreeModel::columnCount
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
Definition: TreeModel.cc:80
TreeModel::itemId
int itemId(const QModelIndex &_index) const
Get the id of a TreeItem corresponding to a given ModelIndex.
Definition: TreeModel.cc:542
TreeModel::getModelIndex
QModelIndex getModelIndex(TreeItem *_object, int _column)
Return the ModelIndex corresponding to a given TreeItem and Column.
Definition: TreeModel.cc:562
TreeItem
Definition: TreeItem.hh:52
TreeModel::data
QVariant data(const QModelIndex &_index, int _role) const
Get the data of the corresponding entry.
Definition: TreeModel.cc:95
TreeModel::getObjectName
bool getObjectName(TreeItem *_object, QString &_name)
Get the name of a given object.
TreeModel::parent
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
Definition: TreeModel.cc:312
TreeModel::isRoot
bool isRoot(TreeItem *_item)
Check if the given item is the root item.
Definition: TreeModel.cc:592
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:353
TreeModel::propagateUpwards
void propagateUpwards(TreeItem *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
Definition: TreeModel.cc:513
TreeModel::headerData
QVariant headerData(int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
return the header data of the model
Definition: TreeModel.cc:258
TreeModel::propagateDownwards
void propagateDownwards(TreeItem *_obj, int _column)
Recursively update a column up to the root of the tree.
Definition: TreeModel.cc:543
TreeModel::rowCount
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
Definition: TreeModel.cc:334
TreeModel::TreeModel
TreeModel(QObject *_parent=0)
Constructor.
Definition: TreeModel.cc:61
BaseObject
Definition: BaseObject.hh:82
TreeModel::setData
bool setData(const QModelIndex &_index, const QVariant &_value, int _role)
Set Data at &#39;index&#39; to &#39;value&#39;.
Definition: TreeModel.cc:575
TreeModel
Definition: TreeModel.hh:53
TreeModel::~TreeModel
~TreeModel()
Destructor.
Definition: TreeModel.cc:72
TreeModel::objectAdded
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
Definition: TreeModel.cc:426