Developer Documentation
Loading...
Searching...
No Matches
TreeModelObjectSelection.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 TREEMODELOBJECTSELECTION_H
45#define TREEMODELOBJECTSELECTION_H
46
47#include <QAbstractItemModel>
48#include <QModelIndex>
49#include <QVariant>
50
51#include "TreeItemObjectSelection.hh"
52
53class TreeModelObjectSelection : 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 TreeModelObjectSelection(QObject *_parent = 0);
65
68
69//===========================================================================
72//===========================================================================
73
74public:
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
120public:
121
123 QModelIndex getModelIndex(TreeItemObjectSelection* _object, int _column );
124
126 QModelIndex getModelIndex(int _id, int _column );
127
129 bool isRoot(TreeItemObjectSelection* _item);
130
132 bool getObjectName(TreeItemObjectSelection* _object , QString& _name);
133
135 TreeItemObjectSelection *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
158private:
159
162
163
164 void propagateUpwards(TreeItemObjectSelection* _obj, int _column, bool _value );
165 void propagateDownwards(TreeItemObjectSelection* _obj, int _column );
166
170};
171
172#endif
173
void objectChanged(int id_)
The object with the given id has been changed. Check if model also has to be changed.
void moveItem(TreeItemObjectSelection *_item, TreeItemObjectSelection *_parent)
move the item to a new parent
bool getObjectName(TreeItemObjectSelection *_object, QString &_name)
Get the name of a given object.
TreeItemObjectSelection * rootItem_
Rootitem of the tree.
QVariant data(const QModelIndex &index, int role) const
Get the data of the corresponding entry.
int columnCount(const QModelIndex &_parent=QModelIndex()) const
Return the number of columns.
bool isRoot(TreeItemObjectSelection *_item)
Check if the given item is the root item.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
return the header data of the model
int itemId(const QModelIndex &index) const
Get the id of a TreeItemObjectSelection corresponding to a given ModelIndex.
void objectDeleted(int id_)
The object with the given id has been deleted. delete it from the internal tree.
bool setData(const QModelIndex &index, const QVariant &value, int role)
Set Data at 'index' to 'value'.
QModelIndex parent(const QModelIndex &index) const
Get the parent ModelIndex.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Get the ModelIndex at given row,column.
int rowCount(const QModelIndex &parent=QModelIndex()) const
get the number of rows
QModelIndex getModelIndex(TreeItemObjectSelection *_object, int _column)
Return the ModelIndex corresponding to a given TreeItemObjectSelection and Column.
Qt::ItemFlags flags(const QModelIndex &index) const
return the types of the corresponding entry
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
void propagateDownwards(TreeItemObjectSelection *_obj, int _column)
Recursively update a column up to the root of the tree.
void propagateUpwards(TreeItemObjectSelection *_obj, int _column, bool _value)
Recursively update a column up to the root of the tree.
TreeItemObjectSelection * getItem(const QModelIndex &index) const
Get the TreeItemObjectSelection corresponding to a given ModelIndex.
QString itemName(const QModelIndex &index) const
Get the name of a TreeItemObjectSelection corresponding to a given ModelIndex.