libyui  3.12.1
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 <shundhammer@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  * Returns a descriptive name of this widget class for logging,
73  * debugging etc.
74  **/
75  virtual const char * itemClass() const { return "YTreeItem"; }
76 
77  /**
78  * Return 'true' if this item has any child items.
79  *
80  * Reimplemented from YItem.
81  **/
82  virtual bool hasChildren() const { return ! _children.empty(); }
83 
84  /**
85  * Return an iterator that points to the first child item of this item.
86  *
87  * Reimplemented from YItem.
88  **/
89  virtual YItemIterator childrenBegin() { return _children.begin(); }
90  virtual YItemConstIterator childrenBegin() const { return _children.begin(); }
91 
92  /**
93  * Return an iterator that points after the last child item of this item.
94  *
95  * Reimplemented from YItem.
96  **/
97  virtual YItemIterator childrenEnd() { return _children.end(); }
98  virtual YItemConstIterator childrenEnd() const { return _children.end(); }
99 
100  /**
101  * Add a child item to this item.
102  *
103  * Note that the constructors that accept a parent pointer will
104  * automatically add themselves to their parent, so applications will
105  * normally not have to call this function.
106  **/
107  virtual void addChild( YItem * item_disown );
108 
109  /**
110  * Delete all child items.
111  **/
112  virtual void deleteChildren();
113 
114  /**
115  * Return 'true' if this tree item should be displayed open (with its
116  * children visible) by default.
117  *
118  * Notice that this will always return 'false' for tree items without
119  * children.
120  **/
121  bool isOpen() const;
122 
123  /**
124  * Change the 'isOpen' flag.
125  **/
126  void setOpen( bool open = true );
127  void setClosed() { setOpen( false ); }
128 
129  /**
130  * Returns this item's parent item or 0 if it is a toplevel item.
131  *
132  * Reimplemented from YItem.
133  **/
134  virtual YTreeItem * parent() const { return _parent; }
135 
136 private:
137 
138  YTreeItem * _parent;
139  YItemCollection _children;
140  bool _isOpen;
141 };
142 
143 
144 #endif // YTreeItem_h
YTreeItem
Item class for tree items.
Definition: YTreeItem.h:36
YItem::label
std::string label() const
Return this item's label.
Definition: YItem.h:97
YItemIterator
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
Definition: YItem.h:42
YItemCollection
std::vector< YItem * > YItemCollection
Collection of pointers to YItem.
Definition: YItem.h:39
YItem::iconName
std::string iconName() const
Return this item's icon name.
Definition: YItem.h:107
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:82
YTreeItem::childrenBegin
virtual YItemIterator childrenBegin()
Return an iterator that points to the first child item of this item.
Definition: YTreeItem.h:89
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:97
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:134
YTreeItem::setOpen
void setOpen(bool open=true)
Change the 'isOpen' flag.
Definition: YTreeItem.cc:107
YTreeItem::itemClass
virtual const char * itemClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YTreeItem.h:75
YTreeItem::~YTreeItem
virtual ~YTreeItem()
Destructor.
Definition: YTreeItem.cc:74
YItem.h
YItemConstIterator
YItemCollection::const_iterator YItemConstIterator
Const iterator over YItemCollection.
Definition: YItem.h:45
YItem
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
Definition: YItem.h:56