Author: sh-sh-sh
Date: Tue Sep 25 15:41:46 2007
New Revision: 41088
URL: http://svn.opensuse.org/viewcvs/yast?rev=41088&view=rev
Log:
items for tables
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
branches/tmp/sh/mod-ui/core/libyui/src/YItem.h
branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc
branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h
branches/tmp/sh/mod-ui/core/libyui/src/YTreeItem.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am?rev=41088&r1=41087&r2=41088&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Tue Sep 25 15:41:46 2007
@@ -20,6 +20,7 @@
YCPValueWidgetID.cc \
YItem.cc \
YTreeItem.cc \
+ YTableItem.cc \
YProperty.cc \
YUIComponent.cc \
YUIException.cc \
@@ -100,6 +101,7 @@
YChildrenManager.h \
YItem.h \
YTreeItem.h \
+ YTableItem.h \
YOptionalWidgetFactory.h \
YPackageSelectorPlugin.h \
YProperty.h \
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YItem.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YItem.h?rev=41088&r1=41087&r2=41088&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YItem.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YItem.h Tue Sep 25 15:41:46 2007
@@ -31,11 +31,6 @@
typedef YItemCollection::iterator YItemIterator;
typedef YItemCollection::const_iterator YItemConstIterator;
-typedef vector YConstItemCollection;
-typedef YConstItemCollection::iterator YConstItemIterator;
-typedef YConstItemCollection::const_iterator YConstItemConstIterator;
-
-
/**
* Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc. items.
@@ -90,7 +85,7 @@
bool hasIconName() const { return ! _iconName.empty(); }
/**
- * Set this icon's icon name.
+ * Set this item's icon name.
**/
void setIconName( const string & newIconName ) { _iconName = newIconName; }
Modified: 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=41088&r1=41087&r2=41088&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc Tue Sep 25 15:41:46 2007
@@ -10,85 +10,135 @@
| (C) SuSE GmbH |
\----------------------------------------------------------------------/
- File: YTreeItem.cc
+ File: YTableItem.cc
Author: Stefan Hundhammer
/-*/
-#include "YTreeItem.h"
+#include "YTableItem.h"
+#include "YUIException.h"
-YTreeItem::YTreeItem( const string & label,
- bool isOpen )
- : YItem( label )
- , _parent( 0 )
- , _isOpen( isOpen )
+YTableItem::YTableItem()
+ : YItem( "" )
, _data( 0 )
{
+
}
-YTreeItem::YTreeItem( const string & label,
- const string & iconName,
- bool isOpen )
- : YItem( label, iconName )
- , _parent( 0 )
- , _isOpen( isOpen )
+YTableItem::YTableItem( const string & label_0,
+ const string & label_1,
+ const string & label_2,
+ const string & label_3,
+ const string & label_4,
+ const string & label_5,
+ const string & label_6,
+ const string & label_7,
+ const string & label_8,
+ const string & label_9 )
+ : YItem( "" )
, _data( 0 )
{
+ vector<string> labels;
+ labels.reserve(10); // slight optimization
+ labels.push_back( label_0 );
+ labels.push_back( label_1 );
+ labels.push_back( label_2 );
+ labels.push_back( label_3 );
+ labels.push_back( label_4 );
+ labels.push_back( label_5 );
+ labels.push_back( label_6 );
+ labels.push_back( label_7 );
+ labels.push_back( label_8 );
+ labels.push_back( label_9 );
+
+ //
+ // Find the last non-empty label
+ //
+
+ unsigned lastLabel = labels.size() - 1;
+
+ while ( labels[ lastLabel ].empty() )
+ --lastLabel;
+
+ //
+ // Create cells
+ //
+
+ for ( unsigned i = 0; i <= lastLabel; ++i )
+ {
+ addCell( labels[i] );
+ }
}
-YTreeItem::YTreeItem( YTreeItem * parent,
- const string & label,
- bool isOpen )
- : YItem( label )
- , _parent( parent )
- , _isOpen( isOpen )
- , _data( 0 )
+
+YTableItem::~YTableItem()
{
- if ( parent )
- parent->addChild( this );
+ deleteCells();
}
-YTreeItem::YTreeItem( YTreeItem * parent,
- const string & label,
- const string & iconName,
- bool isOpen )
- : YItem( label, iconName )
- , _parent( parent )
- , _isOpen( isOpen )
- , _data( 0 )
+void
+YTableItem::deleteCells()
+{
+ YTableCellIterator it = cellsBegin();
+
+ while ( it != cellsEnd() )
+ {
+ YTableCell * cell = *it;
+ ++it;
+ delete cell;
+ }
+
+ _cells.clear();
+}
+
+
+void
+YTableItem::addCell( YTableCell * cell )
{
- if ( parent )
- parent->addChild( this );
+ YUI_CHECK_PTR( cell );
+ _cells.push_back( cell );
}
-YTreeItem::~YTreeItem()
+void
+YTableItem::addCell( const string & label, const string & iconName )
{
- deleteChildren();
+ YTableCell * cell = new YTableCell( label, iconName );
+ YUI_CHECK_NEW( cell );
+
+ _cells.push_back( cell );
}
-void YTreeItem::addChild( YItem * child )
+const YTableCell *
+YTableItem::cell( int index ) const
{
- _children.push_back( child );
+ return hasCell( index ) ?
+ _cells[ index ] : 0;
}
-void YTreeItem::deleteChildren()
+string
+YTableItem::label( int index ) const
{
- YItemIterator it = childrenBegin();
+ return hasCell( index ) ? _cells[ index ]->label() : "";
+}
+
+
+string
+YTableItem::iconName( int index ) const
+{
+ return hasCell( index ) ? _cells[ index ]->iconName() : "";
+}
- while ( it != childrenEnd() )
- {
- YItem * child = *it;
- ++it;
- delete child;
- }
- _children.clear();
+bool
+YTableItem::hasIconName( int index ) const
+{
+ return hasCell( index ) ? _cells[ index ]->hasIconName() : false;
}
Modified: 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=41088&r1=41087&r2=41088&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h Tue Sep 25 15:41:46 2007
@@ -1,18 +1,18 @@
/*---------------------------------------------------------------------\
-| |
-| __ __ ____ _____ ____ |
-| \ \ / /_ _/ ___|_ _|___ \ |
-| \ V / _` \___ \ | | __) | |
-| | | (_| |___) || | / __/ |
-| |_|\__,_|____/ |_| |_____| |
-| |
-| core system |
-| (C) SuSE GmbH |
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
\----------------------------------------------------------------------/
- File: YTableItem.h
+ File: YTableItem.h
- Author: Stefan Hundhammer
+ Author: Stefan Hundhammer
/-*/
@@ -21,59 +21,29 @@
#include "YItem.h"
+using std::string;
+using std::vector;
+class YTableCell;
-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;
-}
+typedef vector YTableCellCollection;
+typedef YTableCellCollection::iterator YTableCellIterator;
+typedef YTableCellCollection::const_iterator YTableCellConstIterator;
/**
- * Item class for table items.
+ * Item class for YTable items. Each YTableItem corresponds to one row in a
+ * YTable.
+ *
+ * A YTableItem might have any number of cells (columns within this row),
+ * including none. The YTable widget is free to ignore any excess cells if
+ * there are more than the YTable widget has columns. The YTable widget is to
+ * treat nonexistent cells like empty ones.
*
- * This class implements multiple cells per item.
+ * Note that while YTable items and their cells can be manipulated through
+ * pointers, their visual representation on screen might be updated only upon
+ * calling certain methods of the YTable widget. See the YTable reference for
+ * details.
**/
class YTableItem: public YItem
{
@@ -86,18 +56,30 @@
/**
* 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 = "" );
-
+ *
+ * This will create up to 10 (0..9) cells. Empty cells for empty labels at
+ * the end of the labels are not created, but empty cells in between are.
+ *
+ * new YTableItem( "one", "two", "", "", "five" );
+ *
+ * will create an item with 5 cells:
+ *
+ * cell[0] ==> "one"
+ * cell[1] ==> "two"
+ * cell[2] ==> ""
+ * cell[3] ==> ""
+ * cell[4] ==> "five"
+ **/
+ YTableItem( const string & label_0,
+ const string & label_1 = string(),
+ const string & label_2 = string(),
+ const string & label_3 = string(),
+ const string & label_4 = string(),
+ const string & label_5 = string(),
+ const string & label_6 = string(),
+ const string & label_7 = string(),
+ const string & label_8 = string(),
+ const string & label_9 = string() );
/**
* Destructor.
@@ -108,25 +90,49 @@
/**
* Add a cell. This item will assume ownership over the cell and delete it
- * when appropriate.
+ * when appropriate.
**/
void addCell( YTableCell * cell );
/**
+ * Create a new cell and add it (even if both 'label' and
+ * 'iconName' are empty).
+ **/
+ void addCell( const string & label, const string & iconName = "" );
+
+ /**
+ * Delete all cells.
+ **/
+ void deleteCells();
+
+ /**
+ * Return an iterator that points to the first cell of this item.
+ **/
+ YTableCellIterator cellsBegin() { return _cells.begin(); }
+ YTableCellConstIterator cellsBegin() const { return _cells.begin(); }
+
+ /**
+ * Return an iterator that points after the last cell of this item.
+ **/
+ YTableCellIterator cellsEnd() { return _cells.end(); }
+ YTableCellConstIterator cellsEnd() const { return _cells.end(); }
+
+ /**
* Return the cell at the specified index (counting from 0 on) or 0 if there is none.
**/
- const YTableCell * cell( int index ) const;
+ const YTableCell * cell( int index ) const;
/**
* Return the number of cells this item has.
- **/
- int cellCount() const;
+ **/
+ int cellCount() const { return _cells.size(); }
/**
* Return 'true' if this item has a cell with the specified index (counting
* from 0 on), 'false' otherwise.
**/
- bool hasCell( int index ) const;
+ bool hasCell( int index ) const
+ { return index >= 0 && (unsigned) index < _cells.size(); }
/**
* Return the label of cell no. 'index' (counting from 0 on) or an empty
@@ -146,7 +152,6 @@
**/
bool hasIconName( int index ) const;
-
/**
* Set the opaque data pointer for application use.
*
@@ -164,8 +169,93 @@
private:
- vector<YTableCell> _cells;
- void * _data;
+ // Disable unwanted base class methods. They don't make sense in this
+ // context since there is not just one single label or icon name, but one
+ // for each cell.
+
+ string label() const { return ""; }
+ string iconName() const { return ""; }
+ bool hasIconName() const { return false; }
+ void setLabel ( const string & ) {}
+ void setIconName ( const string & ) {}
+
+
+ //
+ // Data members
+ //
+
+ YTableCellCollection _cells;
+ void * _data;
+};
+
+
+
+/**
+ * One cell (one column in one row) of a YTableItem. Each cell has a label (a
+ * user visible text) and optionally an icon (*).
+ *
+ * Note that cells don't have individual IDs; they have just an index.
+ * The first cell in an item is cell(0). In an ideal world, each YTableItem
+ * would have exactly as many cells as there are columns in the YTable, but
+ * these classes make no such assumptions. A YTableItem might have any number
+ * of cells, including none.
+ *
+ * The YTable widget, is free to ignore any excess cells if there are more than
+ * the YTable widget has columns. If there are less cells than the table has
+ * columns, the nonexistent cells will be treated as empty.
+ *
+ *
+ * (*) Not all UIs can handle icons. UIs that can't handle them will simply
+ * ignore any icons specified for YTableCells. Thus, applications should either
+ * check the UI capabilities if it can handle icons or use icons only as an
+ * additional visual cue that still has a text counterpart (so the user can
+ * still make sense of the table content when no icons are visible).
+ **/
+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 )
+ {}
+
+ // No virtual destructor. This saves a vtable for this class since there
+ // are no other virtual methods either.
+
+ /**
+ * 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;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTreeItem.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTreeItem.h?rev=41088&r1=41087&r2=41088&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTreeItem.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTreeItem.h Tue Sep 25 15:41:46 2007
@@ -21,6 +21,9 @@
#include "YItem.h"
+using std::string;
+using std::vector;
+
/**
* Item class for tree items.
@@ -140,13 +143,4 @@
};
-typedef vector YTreeItemCollection;
-typedef YTreeItemCollection::iterator YTreeItemIterator;
-typedef YTreeItemCollection::const_iterator YTreeItemConstIterator;
-
-typedef vector YConstTreeItemCollection;
-typedef YConstTreeItemCollection::iterator YConstTreeItemIterator;
-typedef YConstTreeItemCollection::const_iterator YConstTreeItemConstIterator;
-
-
#endif // YTreeItem_h
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org