[yast-commit] r41064 - in /branches/tmp/sh/mod-ui/core/libyui/src: YTableItem.cc YTableItem.h
Author: sh-sh-sh Date: Mon Sep 24 18:34:11 2007 New Revision: 41064 URL: http://svn.opensuse.org/viewcvs/yast?rev=41064&view=rev Log: items for YTable widgets Added: branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h Added: branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc?rev=41064&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc Mon Sep 24 18:34:11 2007 @@ -0,0 +1,94 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YTreeItem.cc + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#include "YTreeItem.h" + + +YTreeItem::YTreeItem( const string & label, + bool isOpen ) + : YItem( label ) + , _parent( 0 ) + , _isOpen( isOpen ) + , _data( 0 ) +{ +} + + +YTreeItem::YTreeItem( const string & label, + const string & iconName, + bool isOpen ) + : YItem( label, iconName ) + , _parent( 0 ) + , _isOpen( isOpen ) + , _data( 0 ) +{ +} + + +YTreeItem::YTreeItem( YTreeItem * parent, + const string & label, + bool isOpen ) + : YItem( label ) + , _parent( parent ) + , _isOpen( isOpen ) + , _data( 0 ) +{ + if ( parent ) + parent->addChild( this ); +} + + +YTreeItem::YTreeItem( YTreeItem * parent, + const string & label, + const string & iconName, + bool isOpen ) + : YItem( label, iconName ) + , _parent( parent ) + , _isOpen( isOpen ) + , _data( 0 ) +{ + if ( parent ) + parent->addChild( this ); +} + + +YTreeItem::~YTreeItem() +{ + deleteChildren(); +} + + +void YTreeItem::addChild( YItem * child ) +{ + _children.push_back( child ); +} + + +void YTreeItem::deleteChildren() +{ + YItemIterator it = childrenBegin(); + + while ( it != childrenEnd() ) + { + YItem * child = *it; + ++it; + delete child; + } + + _children.clear(); +} Added: branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h?rev=41064&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h Mon Sep 24 18:34:11 2007 @@ -0,0 +1,173 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YTableItem.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YTableItem_h +#define YTableItem_h + +#include "YItem.h" + + + +class YTableCell +{ +public: + /** + * Constructor with label and icon name and optionally the selected state. + **/ + YTableCell( const string & label, const string & iconName ) + : _label( label ) + , _iconName( iconName ) + , _selected( selected ) + , _index( -1 ) + {} + + /** + * Return this cells's label. This is what the user sees in a dialog, so + * this will usually be a translated text. + **/ + string label() const { return _label; } + + /** + * Set this cell's label. + **/ + void setLabel( const string & newLabel ) { _label = newLabel; } + + /** + * Return this cell's icon name. + **/ + string iconName() const { return _iconName; } + + /** + * Return 'true' if this cell has an icon name. + **/ + bool hasIconName() const { return ! _iconName.empty(); } + + /** + * Set this cell's icon name. + **/ + void setIconName( const string & newIconName ) { _iconName = newIconName; } + + +private: + + string _label; + string _iconName; +} + + +/** + * Item class for table items. + * + * This class implements multiple cells per item. + **/ +class YTableItem: public YItem +{ +public: + + /** + * Default constructor. Use addCell() to give it any content. + **/ + YTableItem(); + + /** + * Convenience constructor for table items without any icons. + **/ + YTableItem( const string & label0, + const string & label1 = "", + const string & label2 = "", + const string & label3 = "", + const string & label4 = "", + const string & label5 = "", + const string & label6 = "", + const string & label7 = "", + const string & label8 = "", + const string & label9 = "" ); + + + /** + * Destructor. + * + * This will delete all cells. + **/ + virtual ~YTableItem(); + + /** + * Add a cell. This item will assume ownership over the cell and delete it + * when appropriate. + **/ + void addCell( YTableCell * cell ); + + /** + * Return the cell at the specified index (counting from 0 on) or 0 if there is none. + **/ + const YTableCell * cell( int index ) const; + + /** + * Return the number of cells this item has. + **/ + int cellCount() const; + + /** + * Return 'true' if this item has a cell with the specified index (counting + * from 0 on), 'false' otherwise. + **/ + bool hasCell( int index ) const; + + /** + * Return the label of cell no. 'index' (counting from 0 on) or an empty + * string if there is no cell with that index. + **/ + string label( int index ) const; + + /** + * Return the icon name of cell no. 'index' (counting from 0 on) or an empty + * string if there is no cell with that index. + **/ + string iconName( int index ) const; + + /** + * Return 'true' if there is a cell with the specified index that has an + * icon name. + **/ + bool hasIconName( int index ) const; + + + /** + * Set the opaque data pointer for application use. + * + * Applications can use this to store the pointer to a counterpart of this + * tree item. It is the application's responsibility to watch for dangling + * pointers and possibliy deleting the data. All this class ever does with + * this pointer is to store it. + **/ + void setData( void * newData ) { _data = newData; } + + /** + * Return the opaque data pointer. + **/ + void * data() const { return _data; } + +private: + + vector<YTableCell> _cells; + void * _data; +}; + + + +#endif // YTableItem_h -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org