Developer Documentation
TreeItem.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 #ifndef TREEITEM_HH
44 #define TREEITEM_HH
45 
46 #include <QString>
47 #include <QList>
48 #include <vector>
49 
51 
52 class TreeItem {
53 
54  public :
55 
56  TreeItem(int _id, QString _name, DataType _type, TreeItem* _parent);
57 
58  ~TreeItem();
59 
60  // static members
61  public:
63  int id();
64 
67  bool dataType(DataType _type);
68 
70  int group();
71  bool isGroup();
72 
73  private:
74  int id_;
75  DataType dataType_;
76 
77  // dynamic members
78  public:
80  bool target();
81  void target(bool _target);
82 
84  bool source();
85  void source(bool _source);
86 
88  bool visible();
89  void visible(bool _visible);
90 
92  QString name( );
93  void name( QString _name );
94 
95  private:
96  bool target_;
97  bool source_;
98  bool visible_;
99  QString name_;
100 
101  // tree traversal
102  public:
103 
106  TreeItem* next();
107 
110  int level();
111 
112  private:
115 
117  int row_;
118 
120  QList<TreeItem*> childItems_;
121 
123  static QMap<int,TreeItem*> kTreeMap_;
124 
125  public:
126  //===========================================================================
129  //===========================================================================
130 
132  int row() const;
133 
135  TreeItem *parent();
136 
138  void setParent(TreeItem* _parent);
139 
142  //===========================================================================
145  //===========================================================================
146 
148  TreeItem* childExists(int _objectId);
149 
151  void appendChild(TreeItem *child);
152 
154  TreeItem *child(int row);
155 
157  int childCount() const;
158 
160  void removeChild( TreeItem* _item );
161 
163  QList< TreeItem* > getLeafs();
164 
166  void deleteSubtree();
167 
168 };
169 
170 
171 //=============================================================================
172 #endif // TREEITEM_HH defined
173 //=============================================================================
DataType dataType()
dataType
Definition: TreeItem.cc:94
int row() const
get the row of this item from the parent
Definition: TreeItem.cc:228
void deleteSubtree()
delete the whole subtree below this item ( The item itself is not touched )
Definition: TreeItem.cc:343
bool target()
target
Definition: TreeItem.cc:127
int level()
Definition: TreeItem.cc:213
int group()
group
Definition: TreeItem.cc:100
TreeItem * child(int row)
return a child
Definition: TreeItem.cc:257
TreeItem * childExists(int _objectId)
Check if the element exists in the subtree of this element.
Definition: TreeItem.cc:271
bool visible()
visible
Definition: TreeItem.cc:151
void setParent(TreeItem *_parent)
Set the parent pointer.
Definition: TreeItem.cc:242
TreeItem * parent()
Get the parent item ( 0 if root item )
Definition: TreeItem.cc:235
int row_
Index of this node in parent&#39;s childen.
Definition: TreeItem.hh:117
Predefined datatypes.
Definition: DataTypes.hh:83
QList< TreeItem *> getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
Definition: TreeItem.cc:326
void appendChild(TreeItem *child)
add a child to this node
Definition: TreeItem.cc:248
bool source()
source
Definition: TreeItem.cc:139
QList< TreeItem * > childItems_
Children of this node.
Definition: TreeItem.hh:120
TreeItem * next()
Definition: TreeItem.cc:177
int id()
id
Definition: TreeItem.cc:78
QString name()
name
Definition: TreeItem.cc:163
TreeItem * parentItem_
Parent item or 0 if root node.
Definition: TreeItem.hh:114
static QMap< int, TreeItem * > kTreeMap_
Acceleration map.
Definition: TreeItem.hh:123
void removeChild(TreeItem *_item)
Remove a child from this object.
Definition: TreeItem.cc:308
int childCount() const
get the number of children
Definition: TreeItem.cc:264