libyui  3.10.0
YTreeItem.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YTreeItem.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YTreeItem_h
26 #define YTreeItem_h
27 
28 #include "YItem.h"
29 
30 /**
31  * Item class for tree items.
32  *
33  * This class implements children management.
34  **/
35 class YTreeItem: public YItem
36 {
37 public:
38  /**
39  * Constructors for toplevel items.
40  **/
41  YTreeItem( const std::string & label,
42  bool isOpen = false );
43 
44  YTreeItem( const std::string & label,
45  const std::string & iconName,
46  bool isOpen = false );
47 
48  /**
49  * Constructors for items that have a parent item.
50  *
51  * They will automatically register this item with the parent item. The
52  * parent assumes ownership of this item and will delete it in its (the
53  * parent's) destructor.
54  **/
56  const std::string & label,
57  bool isOpen = false );
58 
60  const std::string & label,
61  const std::string & iconName,
62  bool isOpen = false );
63 
64  /**
65  * Destructor.
66  *
67  * This will delete all children.
68  **/
69  virtual ~YTreeItem();
70 
71  /**
72  * Return 'true' if this item has any child items.
73  *
74  * Reimplemented from YItem.
75  **/
76  virtual bool hasChildren() const { return ! _children.empty(); }
77 
78  /**
79  * Return an iterator that points to the first child item of this item.
80  *
81  * Reimplemented from YItem.
82  **/
83  virtual YItemIterator childrenBegin() { return _children.begin(); }
84  virtual YItemConstIterator childrenBegin() const { return _children.begin(); }
85 
86  /**
87  * Return an iterator that points after the last child item of this item.
88  *
89  * Reimplemented from YItem.
90  **/
91  virtual YItemIterator childrenEnd() { return _children.end(); }
92  virtual YItemConstIterator childrenEnd() const { return _children.end(); }
93 
94  /**
95  * Add a child item to this item.
96  *
97  * Note that the constructors that accept a parent pointer will
98  * automatically add themselves to their parent, so applications will
99  * normally not have to call this function.
100  **/
101  virtual void addChild( YItem * item_disown );
102 
103  /**
104  * Delete all child items.
105  **/
106  virtual void deleteChildren();
107 
108  /**
109  * Return 'true' if this tree item should be displayed open (with its
110  * children visible) by default.
111  *
112  * Notice that this will always return 'false' for tree items without
113  * children.
114  **/
115  bool isOpen() const;
116 
117  /**
118  * Change the 'isOpen' flag.
119  **/
120  void setOpen( bool open );
121 
122  /**
123  * Returns this item's parent item or 0 if it is a toplevel item.
124  *
125  * Reimplemented from YItem.
126  **/
127  virtual YTreeItem * parent() const { return _parent; }
128 
129 private:
130 
131  YTreeItem * _parent;
132  YItemCollection _children;
133  bool _isOpen;
134 };
135 
136 
137 #endif // YTreeItem_h
YTreeItem
Item class for tree items.
Definition: YTreeItem.h:35
YItem::label
std::string label() const
Return this item's label.
Definition: YItem.h:82
YItemIterator
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
Definition: YItem.h:40
YItemCollection
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
Definition: YItem.h:38
YItem::iconName
std::string iconName() const
Return this item's icon name.
Definition: YItem.h:92
YTreeItem::deleteChildren
virtual void deleteChildren()
Delete all child items.
Definition: YTreeItem.cc:86
YTreeItem::hasChildren
virtual bool hasChildren() const
Return 'true' if this item has any child items.
Definition: YTreeItem.h:76
YTreeItem::childrenBegin
virtual YItemIterator childrenBegin()
Return an iterator that points to the first child item of this item.
Definition: YTreeItem.h:83
YTreeItem::isOpen
bool isOpen() const
Return 'true' if this tree item should be displayed open (with its children visible) by default.
Definition: YTreeItem.cc:101
YTreeItem::childrenEnd
virtual YItemIterator childrenEnd()
Return an iterator that points after the last child item of this item.
Definition: YTreeItem.h:91
YTreeItem::addChild
virtual void addChild(YItem *item_disown)
Add a child item to this item.
Definition: YTreeItem.cc:80
YTreeItem::YTreeItem
YTreeItem(const std::string &label, bool isOpen=false)
Constructors for toplevel items.
Definition: YTreeItem.cc:30
YTreeItem::parent
virtual YTreeItem * parent() const
Returns this item's parent item or 0 if it is a toplevel item.
Definition: YTreeItem.h:127
YTreeItem::setOpen
void setOpen(bool open)
Change the 'isOpen' flag.
Definition: YTreeItem.cc:107
YTreeItem::~YTreeItem
virtual ~YTreeItem()
Destructor.
Definition: YTreeItem.cc:74
YItem.h
YItemConstIterator
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
Definition: YItem.h:42
YItem
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
Definition: YItem.h:49