libyui  3.10.0
YTreeItem.cc
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.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #include "YTreeItem.h"
26 
27 using std::string;
28 
29 
30 YTreeItem::YTreeItem( const string & label,
31  bool isOpen )
32  : YItem( label )
33  , _parent( 0 )
34  , _isOpen( isOpen )
35 {
36 }
37 
38 
39 YTreeItem::YTreeItem( const string & label,
40  const string & iconName,
41  bool isOpen )
42  : YItem( label, iconName )
43  , _parent( 0 )
44  , _isOpen( isOpen )
45 {
46 }
47 
48 
50  const string & label,
51  bool isOpen )
52  : YItem( label )
53  , _parent( parent )
54  , _isOpen( isOpen )
55 {
56  if ( parent )
57  parent->addChild( this );
58 }
59 
60 
62  const string & label,
63  const string & iconName,
64  bool isOpen )
65  : YItem( label, iconName )
66  , _parent( parent )
67  , _isOpen( isOpen )
68 {
69  if ( parent )
70  parent->addChild( this );
71 }
72 
73 
75 {
77 }
78 
79 
80 void YTreeItem::addChild( YItem * child )
81 {
82  _children.push_back( child );
83 }
84 
85 
87 {
89 
90  while ( it != childrenEnd() )
91  {
92  YItem * child = *it;
93  ++it;
94  delete child;
95  }
96 
97  _children.clear();
98 }
99 
100 
101 bool YTreeItem::isOpen() const
102 {
103  return hasChildren() ? _isOpen : false;
104 }
105 
106 
107 void YTreeItem::setOpen( bool open )
108 {
109  _isOpen = open;
110 }
YItemCollection::iterator YItemIterator
Mutable iterator over YItemCollection.
Definition: YItem.h:40
Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc.
Definition: YItem.h:50
Item class for tree items.
Definition: YTreeItem.h:36
virtual void deleteChildren()
Delete all child items.
Definition: YTreeItem.cc:86
virtual ~YTreeItem()
Destructor.
Definition: YTreeItem.cc:74
void setOpen(bool open)
Change the 'isOpen' flag.
Definition: YTreeItem.cc:107
virtual bool hasChildren() const
Return 'true' if this item has any child items.
Definition: YTreeItem.h:76
virtual YTreeItem * parent() const
Returns this item's parent item or 0 if it is a toplevel item.
Definition: YTreeItem.h:127
virtual YItemIterator childrenBegin()
Return an iterator that points to the first child item of this item.
Definition: YTreeItem.h:83
virtual YItemIterator childrenEnd()
Return an iterator that points after the last child item of this item.
Definition: YTreeItem.h:91
virtual void addChild(YItem *item_disown)
Add a child item to this item.
Definition: YTreeItem.cc:80
bool isOpen() const
Return 'true' if this tree item should be displayed open (with its children visible) by default.
Definition: YTreeItem.cc:101
YTreeItem(const std::string &label, bool isOpen=false)
Constructors for toplevel items.
Definition: YTreeItem.cc:30