libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YTreeItem.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YTreeItem.cc
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #include "YTreeItem.h"
00026 
00027 
00028 YTreeItem::YTreeItem( const std::string &       label,
00029                       bool                      isOpen )
00030     : YItem( label )
00031     , _parent( 0 )
00032     , _isOpen( isOpen )
00033 {
00034 }
00035 
00036 
00037 YTreeItem::YTreeItem( const std::string &       label,
00038                       const std::string &       iconName,
00039                       bool                      isOpen )
00040     : YItem( label, iconName )
00041     , _parent( 0 )
00042     , _isOpen( isOpen )
00043 {
00044 }
00045 
00046 
00047 YTreeItem::YTreeItem( YTreeItem *               parent,
00048                       const std::string &       label,
00049                       bool                      isOpen )
00050     : YItem( label )
00051     , _parent( parent )
00052     , _isOpen( isOpen )
00053 {
00054     if ( parent )
00055         parent->addChild( this );
00056 }
00057 
00058 
00059 YTreeItem::YTreeItem( YTreeItem *               parent,
00060                       const std::string &       label,
00061                       const std::string &       iconName,
00062                       bool                      isOpen )
00063     : YItem( label, iconName )
00064     , _parent( parent )
00065     , _isOpen( isOpen )
00066 {
00067     if ( parent )
00068         parent->addChild( this );
00069 }
00070 
00071 
00072 YTreeItem::~YTreeItem()
00073 {
00074     deleteChildren();
00075 }
00076 
00077 
00078 void YTreeItem::addChild( YItem * child )
00079 {
00080     _children.push_back( child );
00081 }
00082 
00083 
00084 void YTreeItem::deleteChildren()
00085 {
00086     YItemIterator it = childrenBegin();
00087 
00088     while ( it != childrenEnd() )
00089     {
00090         YItem * child = *it;
00091         ++it;
00092         delete child;
00093     }
00094 
00095     _children.clear();
00096 }
00097 
00098 
00099 bool YTreeItem::isOpen() const
00100 {
00101     return hasChildren() ? _isOpen : false;
00102 }
00103 
00104 
00105 void YTreeItem::setOpen( bool open )
00106 {
00107     _isOpen = open;
00108 }
 All Classes Functions Variables Enumerations Friends