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