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 // an object was moved via dragNdrop
61 void moveBaseObject(int _id, int _newParentId);
62
63 public:
64
66 explicit TreeModel(QObject *_parent = 0);
67
69 ~TreeModel();
70
71 //===========================================================================
74 //===========================================================================
75
76 public:
77
79 QVariant data(const QModelIndex &_index,int _role) const;
80
82 Qt::ItemFlags flags(const QModelIndex &_index) const;
83
85 QVariant headerData(int _section,
86 Qt::Orientation _orientation,
87 int _role = Qt::DisplayRole) const;
88
90 QModelIndex index(int _row, int _column,
91 const QModelIndex &_parent = QModelIndex()) const;
92
94 QModelIndex parent(const QModelIndex &_index) const;
95
97 int rowCount(const QModelIndex &_parent = QModelIndex()) const;
98
104 int columnCount(const QModelIndex &_parent = QModelIndex()) const;
105
113 bool setData(const QModelIndex &_index, const QVariant &_value , int _role);
114
117 //===========================================================================
120 //===========================================================================
121
122 public:
123
125 QModelIndex getModelIndex(TreeItem* _object, int _column );
126
128 bool isRoot(TreeItem* _item);
129
131 bool getObjectName(TreeItem* _object , QString& _name);
132
134 TreeItem *getItem(const QModelIndex &_index) const;
135
137 TreeItem *getItem(const int _id) const;
138
140 QString itemName(const QModelIndex &_index) const;
141
143 int itemId(const QModelIndex &_index) const;
144
145
147 void objectChanged(int _id);
148
150 void objectAdded(BaseObject* _object);
151
153 void objectDeleted(int _id);
154
156 void moveItem(TreeItem* _item, TreeItem* _parent );
157
158 private:
159
161 TreeItem* rootItem_;
162
165 //===========================================================================
168 //===========================================================================
169
170 public:
171
173 Qt::DropActions supportedDropActions() const;
174
176 QStringList mimeTypes() const;
177
179 QMimeData* mimeData(const QModelIndexList& indexes) const;
180
190 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
191
194 };
195
196 #endif
197
TreeModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const
get the mimeData for a given ModelIndex
Definition: TreeModel.cc:631
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::mimeTypes
QStringList mimeTypes() const
stores the mimeType for Drag & Drop
Definition: TreeModel.cc:616
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::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::supportedDropActions
Qt::DropActions supportedDropActions() const
supported drag & Drop actions
Definition: TreeModel.cc:604
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::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
This is called when mimeData is dropped.
Definition: TreeModel.cc:659
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