libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YTreeItem.h
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.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef YTreeItem_h
00026 #define YTreeItem_h
00027 
00028 #include "YItem.h"
00029 
00030 
00031 
00032 /**
00033  * Item class for tree items.
00034  *
00035  * This class implements children management.
00036  **/
00037 class YTreeItem: public YItem
00038 {
00039 public:
00040     /**
00041      * Constructors for toplevel items.
00042      **/
00043     YTreeItem( const std::string &      label,
00044                bool                     isOpen = false );
00045 
00046     YTreeItem( const std::string &      label,
00047                const std::string &      iconName,
00048                bool                     isOpen = false );
00049 
00050     /**
00051      * Constructors for items that have a parent item.
00052      *
00053      * They will automatically register this item with the parent item. The
00054      * parent assumes ownership of this item and will delete it in its (the
00055      * parent's) destructor.
00056      **/
00057     YTreeItem( YTreeItem *              parent,
00058                const std::string &      label,
00059                bool                     isOpen = false );
00060 
00061     YTreeItem( YTreeItem *              parent,
00062                const std::string &      label,
00063                const std::string &      iconName,
00064                bool                     isOpen = false );
00065 
00066     /**
00067      * Destructor.
00068      *
00069      * This will delete all children.
00070      **/
00071     virtual ~YTreeItem();
00072 
00073     /**
00074      * Return 'true' if this item has any child items.
00075      *
00076      * Reimplemented from YItem.
00077      **/
00078     virtual bool hasChildren() const { return ! _children.empty(); }
00079 
00080     /**
00081      * Return an iterator that points to the first child item of this item.
00082      *
00083      * Reimplemented from YItem.
00084      **/
00085     virtual YItemIterator       childrenBegin()         { return _children.begin(); }
00086     virtual YItemConstIterator  childrenBegin() const   { return _children.begin(); }
00087 
00088     /**
00089      * Return an iterator that points after the last child item of this item.
00090      *
00091      * Reimplemented from YItem.
00092      **/
00093     virtual YItemIterator       childrenEnd()           { return _children.end(); }
00094     virtual YItemConstIterator  childrenEnd() const     { return _children.end(); }
00095 
00096     /**
00097      * Add a child item to this item.
00098      *
00099      * Note that the constructors that accept a parent pointer will
00100      * automatically add themselves to their parent, so applications will
00101      * normally not have to call this function.
00102      **/
00103     virtual void addChild( YItem * item_disown );
00104 
00105     /**
00106      * Delete all child items.
00107      **/
00108     virtual void deleteChildren();
00109 
00110    /**
00111      * Return 'true' if this tree item should be displayed open (with its
00112      * children visible) by default.
00113      *
00114      * Notice that this will always return 'false' for tree items without
00115      * children.
00116      **/
00117     bool isOpen() const;
00118 
00119     /**
00120      * Change the 'isOpen' flag.
00121      **/
00122     void setOpen( bool open );
00123 
00124     /**
00125      * Returns this item's parent item or 0 if it is a toplevel item.
00126      *
00127      * Reimplemented from YItem.
00128      **/
00129     virtual YTreeItem * parent() const { return _parent; }
00130 
00131 private:
00132 
00133     YTreeItem *         _parent;
00134     YItemCollection     _children;
00135     bool                _isOpen;
00136 };
00137 
00138 
00139 #endif // YTreeItem_h
 All Classes Functions Variables Enumerations Friends