Developer Documentation
Loading...
Searching...
No Matches
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
53class TreeModel : public QAbstractItemModel
54{
55 Q_OBJECT
56
57signals:
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
63public:
64
66 explicit TreeModel(QObject *_parent = 0);
67
69 ~TreeModel();
70
71//===========================================================================
74//===========================================================================
75
76public:
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
122public:
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
158private:
159
162
165//===========================================================================
168//===========================================================================
169
170public:
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
bool isRoot(TreeItem *_item)
Check if the given item is the root item.
Definition TreeModel.cc:601
QStringList mimeTypes() const
stores the mimeType for Drag & Drop
Definition TreeModel.cc:625
QString itemName(const QModelIndex &_index) const
Get the name of a TreeItem corresponding to a given ModelIndex.
Definition TreeModel.cc:534
bool setData(const QModelIndex &_index, const QVariant &_value, int _role)
Set Data at 'index' to 'value'.
Definition TreeModel.cc:584
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:668
bool getObjectName(TreeItem *_object, QString &_name)
Get the name of a given object.
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
Definition TreeModel.cc:343
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
Definition TreeModel.cc:470
QVariant headerData(int _section, Qt::Orientation _orientation, int _role=Qt::DisplayRole) const
return the header data of the model
Definition TreeModel.cc:267
QMimeData * mimeData(const QModelIndexList &indexes) const
get the mimeData for a given ModelIndex
Definition TreeModel.cc:640
void moveItem(TreeItem *_item, TreeItem *_parent)
move the item to a new parent
Definition TreeModel.cc:497
int itemId(const QModelIndex &_index) const
Get the id of a TreeItem corresponding to a given ModelIndex.
Definition TreeModel.cc:551
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
Definition TreeModel.cc:80
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
Definition TreeModel.cc:321
TreeItem * rootItem_
Root item of the tree.
Definition TreeModel.hh:161
QVariant data(const QModelIndex &_index, int _role) const
Get the data of the corresponding entry.
Definition TreeModel.cc:95
Qt::DropActions supportedDropActions() const
supported drag & Drop actions
Definition TreeModel.cc:613
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
Definition TreeModel.cc:362
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
Definition TreeModel.cc:435
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
Definition TreeModel.cc:517
Qt::ItemFlags flags(const QModelIndex &_index) const
return the types of the corresponding entry
Definition TreeModel.cc:221
~TreeModel()
Destructor.
Definition TreeModel.cc:72
QModelIndex getModelIndex(TreeItem *_object, int _column)
Return the ModelIndex corresponding to a given TreeItem and Column.
Definition TreeModel.cc:571
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
Definition TreeModel.cc:294