Author: sh-sh-sh
Date: Fri Oct 5 17:53:40 2007
New Revision: 41269
URL: http://svn.opensuse.org/viewcvs/yast?rev=41269&view=rev
Log:
ported table widget
Added:
branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.h
branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h
Modified:
branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table1.ycp
branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table5.ycp
branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc
branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h
branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItem.h
branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc
branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc
branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h
branches/tmp/sh/mod-ui/core/libyui/src/YTable.cc
branches/tmp/sh/mod-ui/core/libyui/src/YTable.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/YUI.h
branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h
branches/tmp/sh/mod-ui/core/libyui/src/YUISymbols.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
branches/tmp/sh/mod-ui/qt/src/QY2ListView.cc
branches/tmp/sh/mod-ui/qt/src/QY2ListView.h
branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h
branches/tmp/sh/mod-ui/qt/src/YQTable.cc
branches/tmp/sh/mod-ui/qt/src/YQTable.h
branches/tmp/sh/mod-ui/qt/src/YQTree.cc
branches/tmp/sh/mod-ui/qt/src/YQUI.h
branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc
branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc
branches/tmp/sh/mod-ui/qt/src/YQWizard.cc
branches/tmp/sh/mod-ui/qt/src/YQWizard.h
branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgConflictList.cc
branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgObjList.cc
branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgVersionsView.cc
Modified: branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table1.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table1.ycp?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table1.ycp (original)
+++ branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table1.ycp Fri Oct 5 17:53:40 2007
@@ -8,7 +8,7 @@
[
`item(`id(1), "Chili", 6),
`item(`id(2), "Salami Baguette", nil),
- `item(`id(3), "Spaghetti", 8),
+ `item(`id(3), "Spaghetti", 8),
`item(`id(4), "Steak Sandwich", 12)
]
)
Modified: branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table5.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table5.ycp?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table5.ycp (original)
+++ branches/tmp/sh/mod-ui/core/libyui/doc/examples/Table5.ycp Fri Oct 5 17:53:40 2007
@@ -21,10 +21,9 @@
while ( UI::UserInput() != `cancel)
{
integer current_item_no = (integer) UI::QueryWidget(`id(`table), `CurrentItem);
- term current_item = (term) UI::QueryWidget(`table, `Item( current_item_no ) );
- y2debug( "current_item: %1", current_item );
- integer amount = tointeger( current_item[2]:nil );
- UI::ChangeWidget(`id(`table), `Item( current_item_no, 1 ), amount+1 );
+ integer amount = tointeger( (string) UI::QueryWidget(`table, `Cell( current_item_no, 1 ) ) );
+ y2debug( "amount: %1", amount );
+ UI::ChangeWidget(`id(`table), `Item( current_item_no, 1 ), sformat( "%1", amount+1 ) );
}
UI::CloseDialog();
Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Fri Oct 5 17:53:40 2007
@@ -339,4 +339,13 @@
2007-07-13 19:20 sh@suse.de
* Ported MultiProgressMeter
- - now using float values internally to safeguard against huge numbers
\ No newline at end of file
+ - now using float values internally to safeguard against huge numbers
+
+
+2007-10-05 18:00 sh@suse.de
+
+* Ported Table
+ - now based on SelectionWidget
+ - much streamlined with the other selection widgets
+ - QueryWidget(table) can now return the complete item term
+ as well as individual cells
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=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Fri Oct 5 17:53:40 2007
@@ -16,6 +16,8 @@
YCPDialogParser.cc \
YCPItemParser.cc \
YCPTreeItemParser.cc \
+ YCPTableItemParser.cc \
+ YCPTableItemWriter.cc \
YCPPropertyHandler.cc \
YCPValueWidgetID.cc \
YItem.cc \
@@ -95,6 +97,8 @@
YCPItemParser.h \
YCPTreeItem.h \
YCPTreeItemParser.h \
+ YCPTableItemParser.h \
+ YCPTableItemWriter.h \
YCPTableItem.h \
YCPPropertyHandler.h \
YCPValueWidgetID.h \
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc Fri Oct 5 17:53:40 2007
@@ -34,6 +34,7 @@
#include "YCPValueWidgetID.h"
#include "YCPItemParser.h"
#include "YCPTreeItemParser.h"
+#include "YCPTableItemParser.h"
#include "YCP_UI_Exception.h"
#include "YDialog.h"
#include "YUI_util.h"
@@ -80,7 +81,7 @@
const YCPTerm & term )
{
YUI_CHECK_PTR( p );
-
+
// Extract optional widget ID, if present
int n;
YCPValue id = getWidgetId( term, &n );
@@ -323,7 +324,7 @@
y2warning( "Late adding child %s to %s", w->widgetClass(), p->widgetClass() );
p->addChild( w );
}
-
+
// FIXME: Obsolete
// FIXME: Obsolete
// FIXME: Obsolete
@@ -1745,12 +1746,12 @@
term->toString().c_str() );
return 0;
}
-
+
rejectAllOptions( term, optList );
string label = term->value( argnr )->asString()->value();
string initialValue;
-
+
if ( term->size() >= argnr + 2 )
initialValue = term->value( argnr+1 )->asString()->value();
@@ -1809,10 +1810,10 @@
}
string label = term->value( argnr )->asString()->value();
-
+
bool shrinkable = false;
bool immediate = false;
-
+
for ( int o=0; o < optList->size(); o++ )
{
if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_shrinkable ) shrinkable = true;
@@ -1883,7 +1884,7 @@
string label = term->value( argnr )->asString()->value();
bool shrinkable = false;
-
+
for ( int o=0; o < optList->size(); o++ )
{
if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_shrinkable ) shrinkable = true;
@@ -1957,7 +1958,7 @@
string label = term->value( argnr )->asString()->value();
bool editable = false;
-
+
for ( int o=0; o < optList->size(); o++ )
{
if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_editable ) editable = true;
@@ -2052,7 +2053,7 @@
rejectAllOptions( term,optList );
string label = term->value ( argnr )->asString()->value();
-
+
YTree * tree = YUI::widgetFactory()->createTree( parent, label );
if ( numArgs > 1 )
@@ -2084,31 +2085,80 @@
*
* @description
*
- * A Table widget is a generalization of the SelectionBox. Information is
- * displayed in a number of columns. Each column has a header. The number of
- * columns and their titles are described by the first argument, which is a
- * term with the symbol <tt>header</tt>. For each column you add a string
- * specifying its title. For example <tt>`header( "Name", "Price" )</tt> creates
- * the two columns "Name" and "Price".
- *
- * The second argument is an optional list of items (rows) that are inserted in
- * the table. Each item has the form <tt>`item( `id( </tt> id <tt> ), first
- * column, second column, ... )</tt>. For each column one argument has to be
- * specified, which must be of type void, string or integer. Strings are being
- * left justified, integer right and a nil denote an empty cell, just as the
- * empty string.
+ * The Table widget is a selection list with multiple columns. The user can
+ * select exactly one row (with all its columns) from that list.
+ *
+ * Each cell (each column within each row) has a label text and an optional
+ * icon.
*
+ * (Note: Not all UIs (in particular not text-based UIs) support displaying
+ * icons, so an icon should never be an exclusive means to display any kind of
+ * information).
+ *
+ * This widget is similar to SelectionBox, but it has several columns for each
+ * item (each row). If just one column is desired, consider using SelectionBox
+ * instead.
+ *
+ * Note: This is not something like a spread sheet, and it doesn't pretend or
+ * want to be. Actions are performed on rows, not on individual cells (columns
+ * within one row).
+ *
+ * The first argument (after `opt() and `id() which both are optional) is
+ * `header() which specifies the column headers (and implicitly the number of
+ * columns) and optionally the alignment for each column. Default alignment is
+ * left.
+ *
+ * In the list of items, an ID is specified for each item. Each item can have
+ * less cells (columns) than the table has columns (from `header()), in which
+ * case any missing cells are assumed to be empty. If an item has more cells
+ * than the table has columns, any extra cells are ignored.
+ *
+ * Each cell has a text label (which might also be an empty string) and
+ * optionally an icon. If a cell has an icon, it has to be specified with
+ * `cell(`icon("myiconname.png", "Label text")).
+ *
+ * A simple table is specified like this:
+ *
+ * `Table(`id(`players),
+ * `header("Nick", "Age", "Role"),
+ * [
+ * `item(`id("Bluebird"), "Bluebird, 18, "Scout" ),
+ * `item(`id("Ozzz" ), "Ozzz", 23, "Wizard" ),
+ * `item(`id("Wannabe" ), "Wannabe", 17 ),
+ * `item(`id("Coxxan" ), "Coxxan", 26, "Warrior")
+ * ]
+ * )
+ *
+ * This will create a 3-column table. The first column ("Nick") and the third
+ * column ("Role") will be left aligned. The second column ("Age") will be
+ * right aligned. note that "Wannabe" doesn't have a Role. This field will be
+ * empty.
+ *
+ * A table that uses icons is specified like this:
+ *
+ * `Table(`id(`players),
+ * `header("Nick", "Age", "Role"),
+ * [
+ * `item(`id("Bluebird"), "Bluebird, 18, `cell(`icon("scout.png"), "Scout" ) ),
+ * `item(`id("Ozzz" ), "Ozzz", 23, "Wizard" ),
+ * `item(`id("Wannabe" ), "Wannabe", `cell(`icon("underage.png", 17 ) ),
+ * `item(`id("Coxxan" ), "Coxxan", `cell(`icon("oldman.png", 26 ), "Warrior" )
+ * ]
+ * )
+ *
+ * In this example, "Bluebird" has an additional icon in his "Role" column, and
+ * "Wannabe" and "Coxxan" both have additional icons in their "Age" columns.
**/
YWidget *
YCPDialogParser::parseTable( YWidget * parent, YWidgetOpt & opt,
const YCPTerm & term, const YCPList & optList, int argnr )
{
- int numargs = term->size() - argnr;
- if ( numargs < 1 || numargs > 2
+ int numArgs = term->size() - argnr;
+ if ( numArgs < 1 || numArgs > 2
|| !term->value(argnr)->isTerm()
|| term->value(argnr)->asTerm()->name() != YUISymbol_header
- || (numargs == 2 && !term->value(argnr+1)->isList()))
+ || (numArgs == 2 && !term->value(argnr+1)->isList()))
{
y2error( "Invalid arguments for the Table widget: %s",
term->toString().c_str() );
@@ -2117,76 +2167,87 @@
// Parse options
+ bool immediate = false;
+ bool keepSorting = false;
+
for ( int o=0; o < optList->size(); o++ )
{
- if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_immediate ) opt.immediateMode.setValue( true );
- else if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_keepSorting ) opt.keepSorting.setValue( true );
+ if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_immediate ) immediate = true;
+ else if ( optList->value(o)->isSymbol() && optList->value(o)->asSymbol()->symbol() == YUIOpt_keepSorting ) keepSorting = true;
else logUnknownOption( term, optList->value(o) );
}
- // Build header. The header is a vector of strings, each defining
- // one column. The first string is one of the characters L, R or C
- // denoting left, right or center justification, resp.
+ YCPTerm headerTerm = term->value( argnr )->asTerm();
+ YCPList itemList = term->value( argnr+1 )->asList();
+ int columns = headerTerm->size();
- vector<string> header;
- YCPTerm headerterm = term->value( argnr )->asTerm();
- for ( int i=0; i< headerterm->size(); i++ )
- {
- YCPValue v = headerterm->value(i);
- string this_column;
+ YTable * table = YUI::widgetFactory()->createTable( parent, columns );
+
+ if ( keepSorting )
+ table->setKeepSorting( true );
+
+ if ( immediate )
+ table->setImmediateMode( true );
+
+
+ //
+ // Parse header term
+ //
- if ( v->isString() )
- this_column = "L" + v->asString()->value(); // left justified per default
+ for ( int i=0; i < headerTerm->size(); i++ )
+ {
+ YCPValue colHeader = headerTerm->value( i );
- else if ( v->isTerm() )
+ if ( colHeader->isString() )
{
- YCPTerm t=v->asTerm();
- if ( t->size() != 1 ||
- ! t->value(0)->isString() )
- {
- y2error( "Invalid Table column specification %s",
- t->toString().c_str() );
- return 0;
- }
+ table->setHeader( i, colHeader->asString()->value() );
+ }
+ else if ( colHeader->isTerm() )
+ {
+ YCPTerm colHeaderTerm = colHeader->asTerm();
- string s = t->name();
- string just;
- if ( s == "Left" ) just = "L";
- else if ( s == "Right" ) just = "R";
- else if ( s == "Center" ) just = "C";
+ if ( colHeaderTerm->name() == YUISymbol_Left ) table->setAlignment( i, YTable::Left );
+ else if ( colHeaderTerm->name() == YUISymbol_Right ) table->setAlignment( i, YTable::Right );
+ else if ( colHeaderTerm->name() == YUISymbol_Center ) table->setAlignment( i, YTable::Center );
else
{
- y2error( "Invalid Table column specification %s",
- t->toString().c_str() );
- return 0;
+ string msg = string( "Unknown table header alignment: " )
+ + colHeaderTerm->name().c_str();
+ y2error ( "%s", msg.c_str() );
+ ycperror( "%s", msg.c_str() );
}
- this_column = just + t->value(0)->asString()->value();
- }
- else
- {
- y2error( "Invalid header declaration in Table widget: %s",
- headerterm->toString().c_str() );
- return 0;
- }
- header.push_back( this_column );
- }
+ if ( colHeaderTerm->size() > 0 )
+ {
+ if ( colHeaderTerm->value(0)->isString() )
+ table->setHeader( i, colHeaderTerm->value(0)->asString()->value() );
+ else
+ {
+ string msg = string( "Expected string for table header, not " )
+ + colHeaderTerm->value(0)->toString();
- // Empty header not allowed!
- if ( header.size() == 0 )
- {
- y2error( "empty header in Table widget not allowed" );
- return 0;
- }
+ y2error ( "%s", msg.c_str() );
+ ycperror( "%s", msg.c_str() );
+ }
+ if ( colHeaderTerm->size() > 1 )
+ {
+ string msg = string( "Ignoring extra parameters of %s" )
+ + colHeaderTerm->toString();
- YTable *table = dynamic_cast ( YUI::ui()->createTable( parent, opt, header ) );
+ y2error ( "%s", msg.c_str() );
+ ycperror( "%s", msg.c_str() );
+ }
+ }
+ }
+ }
- if ( table && numargs == 2 ) // Fill table with items, if item list is specified
+ if ( numArgs >= 2 ) // Fill table with items, if item list is specified
{
- YCPList itemlist = term->value( argnr+1 )->asList();
- table->addItems( itemlist );
+ YCPList itemList = term->value( argnr+1 )->asList();
+ table->addItems( YCPTableItemParser::parseTableItemList( itemList ) );
}
+
return table;
}
@@ -2228,11 +2289,11 @@
}
rejectAllOptions( term,optList );
-
+
string label = term->value( argnr )->asString()->value();
int maxValue = 100;
int initialValue = 0;
-
+
if ( s >= 2 ) maxValue = term->value( argnr+1 )->asInteger()->value();
if ( s >= 3 ) initialValue = term->value( argnr+2 )->asInteger()->value();
@@ -2273,7 +2334,7 @@
*
* This option implicitly sets `opt( `zeroWidth ) and `opt( zeroHeight ),
* too since there is no useful default size for such an image. Use MinSize()
- * or other layout helpers to explicitly set a size on such a widget.
+ * or other layout helpers to explicitly set a size on such a widget.
*
* Please note that setting both `opt( `tiled ) and `opt( `scaleToFit ) at once
* doesn't make any sense.
@@ -2896,7 +2957,7 @@
}
vector<float> maxValues;
-
+
try
{
maxValues = parseNumList( term->value( argnr )->asList() );
@@ -2905,7 +2966,7 @@
{
YUI_RETHROW( exception );
}
-
+
if ( maxValues.size() < 1 )
{
YUI_THROW( YCPDialogSyntaxErrorException( "Expected list<integer> or list<float>",
@@ -2921,11 +2982,11 @@
YCPDialogParser::parseNumList( const YCPList & yList )
{
vector<float> result;
-
+
for ( int i=0; i < yList->size(); i++ )
{
YCPValue val = yList->value( i );
-
+
if ( val->isInteger() )
{
result.push_back( (float) val->asInteger()->value() );
@@ -3143,7 +3204,7 @@
}
rejectAllOptions( term, optList );
-
+
return YUI::optionalWidgetFactory()->createPatternSelector( parent );
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc Fri Oct 5 17:53:40 2007
@@ -41,6 +41,8 @@
}
catch ( YUIException & exception )
{
+ // Delete all items created so far
+
YItemIterator it = itemCollection.begin();
while ( it != itemCollection.end() )
@@ -50,8 +52,7 @@
delete item;
}
- itemCollection.clear();
- YUI_RETHROW( exception );
+ throw;
}
return itemCollection;
@@ -97,7 +98,7 @@
YCPString label = YCPNull();
YCPBoolean selected = YCPNull();
- string usage =
+ const char * usage =
"Expected: `item(`id(`myID), `icon(\"MyIcon.png\"), \"MyItemText\", boolean selected )";
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc Fri Oct 5 17:53:40 2007
@@ -38,6 +38,8 @@
#include "YCPTreeItem.h"
#include "YCPItemParser.h"
#include "YCPTreeItemParser.h"
+#include "YCPTableItemParser.h"
+#include "YCPTableItemWriter.h"
#include "YCPValueWidgetID.h"
#include "YCheckBox.h"
@@ -48,6 +50,7 @@
#include "YRadioButtonGroup.h"
#include "YSelectionBox.h"
#include "YTree.h"
+#include "YTable.h"
#include "YUISymbols.h"
using std::list;
@@ -65,6 +68,7 @@
if ( trySetCheckBoxValue ( widget, val ) ) return true;
if ( trySetSelectionBoxValue ( widget, val ) ) return true;
if ( trySetTreeValue ( widget, val ) ) return true;
+ if ( trySetTableValue ( widget, val ) ) return true;
if ( trySetComboBoxValue ( widget, val ) ) return true;
}
if ( propertyName == YUIProperty_Values )
@@ -75,14 +79,21 @@
{
if ( trySetSelectionBoxValue ( widget, val ) ) return true;
if ( trySetTreeValue ( widget, val ) ) return true;
+ if ( trySetTableValue ( widget, val ) ) return true;
}
else if ( propertyName == YUIProperty_Items )
{
- // Make sure to try YTree before YSelectionWidget: YTree inherits YSelectionWidget!
-
+ // Make sure to try YTree and YTable before YSelectionWidget: both inherit YSelectionWidget!
+
if ( trySetTreeItems ( widget, val ) ) return true;
+ if ( trySetTableItems ( widget, val ) ) return true;
if ( trySetSelectionWidgetItems ( widget, val ) ) return true;
}
+ else if ( propertyName == YUIProperty_Cell ||
+ propertyName == YUIProperty_Item )
+ {
+ if ( trySetTableCell ( widget, val ) ) return true;
+ }
else if ( propertyName == YUIProperty_CurrentButton )
{
if ( trySetRadioButtonGroupCurrentButton( widget, val ) ) return true;
@@ -109,12 +120,14 @@
val = tryGetCheckBoxValue ( widget ); if ( ! val.isNull() ) return val;
val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val;
val = tryGetTreeValue ( widget ); if ( ! val.isNull() ) return val;
+ val = tryGetTableValue ( widget ); if ( ! val.isNull() ) return val;
val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val;
}
else if ( propertyName == YUIProperty_CurrentItem )
{
val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val;
val = tryGetTreeValue ( widget ); if ( ! val.isNull() ) return val;
+ val = tryGetTableValue ( widget ); if ( ! val.isNull() ) return val;
val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val;
// tryGetMultiSelectionBoxCurrentItem
@@ -135,14 +148,37 @@
{
val = tryGetTreeCurrentBranch ( widget ); if ( ! val.isNull() ) return val;
}
+ else if ( propertyName == YUIProperty_Items )
+ {
+ val = tryGetTableItems ( widget ); if ( ! val.isNull() ) return val;
+
+ // FIXME: TO DO:
+ // FIXME: TO DO:
+ // FIXME: TO DO:
+
+ // tryGetTreeItems
+ // tryGetSelectionWidgetItems
+ }
+
+ y2error( "Can't handle property %s::%s - returning 'nil'",
+ widget->widgetClass(), propertyName.c_str() );
+
+ return YCPVoid();
+}
- // FIXME: TO DO:
- // FIXME: TO DO:
- // FIXME: TO DO:
- // tryGetTreeItems
- // tryGetSelectionWidgetItems
+YCPValue
+YCPPropertyHandler::getComplexProperty( YWidget * widget, const YCPTerm & propertyTerm )
+{
+ YCPValue val = YCPNull();
+ string propertyName = propertyTerm->name();
+
+ if ( propertyName == YUIProperty_Cell ||
+ propertyName == YUIProperty_Item )
+ {
+ val = tryGetTableCell ( widget, propertyTerm ); if ( ! val.isNull() ) return val;
+ }
y2error( "Can't handle property %s::%s - returning 'nil'",
widget->widgetClass(), propertyName.c_str() );
@@ -217,12 +253,11 @@
{
wantedId = val->asTerm()->value(0);
}
-
+
return findItem( wantedId, selWidget->itemsBegin(), selWidget->itemsEnd() );
}
-
template
bool trySetSelectionWidgetValue( YWidget * widget, const YCPValue & val )
{
@@ -264,6 +299,13 @@
bool
+YCPPropertyHandler::trySetTableValue( YWidget * widget, const YCPValue & val )
+{
+ return trySetSelectionWidgetValue( widget, val );
+}
+
+
+bool
YCPPropertyHandler::trySetComboBoxValue( YWidget * widget, const YCPValue & val )
{
YComboBox * comboBox = dynamic_cast (widget);
@@ -299,6 +341,27 @@
bool
+YCPPropertyHandler::trySetSelectionWidgetItems( YWidget * widget, const YCPValue & val )
+{
+ YSelectionWidget * selWidget = dynamic_cast (widget );
+
+ if ( ! selWidget )
+ return false;
+
+ if ( val->isList() )
+ {
+ selWidget->setItems( YCPItemParser::parseItemList( val->asList() ) );
+ return true;
+ }
+
+ YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Items,
+ YOtherProperty ),
+ widget ) );
+ return false;
+}
+
+
+bool
YCPPropertyHandler::trySetTreeItems( YWidget * widget, const YCPValue & val )
{
YTree * tree = dynamic_cast (widget );
@@ -320,16 +383,16 @@
bool
-YCPPropertyHandler::trySetSelectionWidgetItems( YWidget * widget, const YCPValue & val )
+YCPPropertyHandler::trySetTableItems( YWidget * widget, const YCPValue & val )
{
- YSelectionWidget * selWidget = dynamic_cast (widget );
+ YTable * table = dynamic_cast (widget );
- if ( ! selWidget )
+ if ( ! table )
return false;
if ( val->isList() )
{
- selWidget->setItems( YCPItemParser::parseItemList( val->asList() ) );
+ table->setItems( YCPTableItemParser::parseTableItemList( val->asList() ) );
return true;
}
@@ -341,6 +404,89 @@
bool
+YCPPropertyHandler::trySetTableCell( YWidget * widget, const YCPValue & val )
+{
+ YTable * table = dynamic_cast (widget );
+
+ if ( ! table )
+ return false;
+
+ if ( val->isTerm() )
+ {
+ YCPTerm term = val->asTerm();
+
+ if ( term->size() == 2
+ && term->value(1)->isInteger() )
+ {
+ YCPValue itemId = term->value(0);
+ int column = term->value(1)->asInteger()->value();
+
+ YCPTableItem * item = findItem<YCPTableItem>( table, itemId );
+
+ if ( item )
+ {
+ YTableCell * cell = item->cell( column );
+
+ if ( cell )
+ {
+ YCPValue newContent = term->value(0);
+
+ if ( newContent->isString() )
+ {
+ cell->setLabel( newContent->asString()->value() );
+ table->cellChanged( cell );
+ }
+ else if ( newContent->isInteger() ) // for backwards compatibility
+ {
+ cell->setLabel( newContent->toString().c_str() );
+ table->cellChanged( cell );
+ }
+ else if ( newContent->isTerm()
+ && newContent->asTerm()->name() == YUISymbol_icon // `icon()
+ && newContent->asTerm()->size() == 1
+ && newContent->asTerm()->value(0)->isString() )
+ {
+ YCPString iconName = newContent->asTerm()->value(0)->asString();
+ cell->setIconName( iconName->value().c_str() );
+ table->cellChanged( cell );
+ }
+ else // any other type
+ {
+ string msg = "Expected string, integer, or `icon(\"myicon.png\"), not ";
+ msg += newContent->toString().c_str();
+ YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Item,
+ YOtherProperty ),
+ table, msg ) );
+ }
+ }
+ else // ! cell
+ {
+ y2error( "%s item %s doesn't have a column #%d",
+ table->widgetClass(),
+ itemId->toString().c_str(),
+ column );
+ }
+ }
+ else // ! item
+ {
+ y2error( "%s %s has no item with ID %s",
+ table->widgetClass(),
+ table->debugLabel().c_str(),
+ itemId->toString().c_str() );
+ }
+
+ return true;
+ }
+ }
+
+ YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Items,
+ YOtherProperty ),
+ widget ) );
+ return false;
+}
+
+
+bool
YCPPropertyHandler::trySetRadioButtonGroupCurrentButton( YWidget * widget, const YCPValue & val )
{
YRadioButtonGroup * radioButtonGroup = dynamic_cast (widget);
@@ -384,13 +530,13 @@
YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_SelectedItems,
YOtherProperty ),
widget, msg ) );
-
+
}
YCPList itemIdList = val->asList();
multiSelBox->deselectAllItems();
-
+
for ( int i=0; i < itemIdList.size(); i++ )
{
YCPItem * item = findItem<YCPItem>( multiSelBox, itemIdList->value( i ) );
@@ -426,7 +572,7 @@
YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Values,
YOtherProperty ),
widget, msg ) );
-
+
}
multiProgressMeter->setCurrentValues( YCPDialogParser::parseNumList( val->asList() ) );
@@ -497,6 +643,13 @@
YCPValue
+YCPPropertyHandler::tryGetTableValue( YWidget * widget )
+{
+ return tryGetSelectionWidgetValue( widget );
+}
+
+
+YCPValue
YCPPropertyHandler::tryGetComboBoxValue( YWidget * widget )
{
YCPValue result = tryGetSelectionWidgetValue( widget );
@@ -507,7 +660,7 @@
if ( ! comboBox )
return YCPNull();
-
+
result = YCPString( comboBox->value() );
}
@@ -529,7 +682,7 @@
return YCPVoid();
y2debug( "Current radio button: %s", currentButton->debugLabel().c_str() );
-
+
if ( currentButton->hasId() )
{
YCPValueWidgetID * id = dynamic_cast ( currentButton->id() );
@@ -556,7 +709,7 @@
YCPList selectedItemsList;
YItemCollection selectedItems = multiSelBox->selectedItems();
-
+
for ( YItemIterator it = selectedItems.begin();
it != selectedItems.end();
++it )
@@ -648,7 +801,7 @@
}
YCPList currentBranch;
-
+
for ( list::iterator it = path.begin(); it != path.end(); ++it )
{
YCPTreeItem * ycpTreeItem = dynamic_cast (*it);
@@ -661,3 +814,109 @@
return currentBranch;
}
+
+
+YCPValue
+YCPPropertyHandler::tryGetTableCell( YWidget * widget, const YCPTerm & propTerm )
+{
+ YTable * table = dynamic_cast (widget);
+
+ if ( ! table )
+ return YCPNull();
+
+ YCPValue result = YCPVoid();
+ string property = propTerm->name();
+
+ if ( property == YUIProperty_Item && propTerm->size() == 1 ) // `Item("myItemID")
+ {
+ return tryGetTableItem( widget, propTerm );
+ }
+
+ if ( propTerm->size() != 2 || // `Item("myItemID", index)
+ ! propTerm->value(1)->isInteger() )
+ {
+ YUI_THROW( YUIBadPropertyArgException( YProperty( property, YOtherProperty ),
+ table ) );
+ }
+
+ YCPValue itemId = propTerm->value(0);
+ int column = propTerm->value(1)->asInteger()->value();
+
+ const YCPTableItem * item = findItem<YCPTableItem>( table, itemId );
+
+ if ( item )
+ {
+ const YTableCell * cell = item->cell( column );
+
+ if ( cell )
+ {
+ result = YCPTableItemWriter::cellValue( cell );
+ }
+ else // ! cell
+ {
+ y2error( "%s item %s doesn't have a column #%d",
+ table->widgetClass(),
+ itemId->toString().c_str(),
+ column );
+ }
+ }
+ else // ! item
+ {
+ y2error( "%s %s has no item with ID %s",
+ table->widgetClass(),
+ table->debugLabel().c_str(),
+ itemId->toString().c_str() );
+ }
+
+ return result;
+}
+
+
+YCPValue
+YCPPropertyHandler::tryGetTableItem( YWidget * widget, const YCPTerm & propTerm )
+{
+ YTable * table = dynamic_cast (widget);
+
+ if ( ! table )
+ return YCPNull();
+
+ YCPValue result = YCPVoid();
+ string property = propTerm->name();
+
+ if ( propTerm->size() != 1 )
+ {
+ YUI_THROW( YUIBadPropertyArgException( YProperty( property, YOtherProperty ),
+ table ) );
+ }
+
+ YCPValue itemId = propTerm->value(0);
+ const YCPTableItem * item = findItem<YCPTableItem>( table, itemId );
+
+ if ( item )
+ {
+ result = YCPTableItemWriter::itemTerm( item );
+ }
+ else // ! item
+ {
+ y2error( "%s %s has no item with ID %s",
+ table->widgetClass(),
+ table->debugLabel().c_str(),
+ itemId->toString().c_str() );
+ }
+
+ return result;
+}
+
+
+YCPValue
+YCPPropertyHandler::tryGetTableItems( YWidget * widget )
+{
+ YTable * table = dynamic_cast (widget);
+
+ if ( ! table )
+ return YCPNull();
+
+ return YCPTableItemWriter::itemList( table->itemsBegin(), table->itemsEnd() );
+}
+
+
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h Fri Oct 5 17:53:40 2007
@@ -24,6 +24,7 @@
#include
#include
+#include
#include <string>
#include "YItem.h"
@@ -66,6 +67,14 @@
static YCPValue getComplexProperty( YWidget * widget,
const string & propertyName );
+ /**
+ * Get a complex property from a term (like `Item(`someID) )
+ *
+ * Return YCPNull upon failure, a non-null YCPValue (the result) upon success.
+ **/
+ static YCPValue getComplexProperty( YWidget * widget,
+ const YCPTerm & propertyTerm );
+
protected:
@@ -78,8 +87,11 @@
static bool trySetCheckBoxValue ( YWidget * widget, const YCPValue & val );
static bool trySetSelectionBoxValue ( YWidget * widget, const YCPValue & val );
static bool trySetTreeValue ( YWidget * widget, const YCPValue & val );
+ static bool trySetTableValue ( YWidget * widget, const YCPValue & val );
static bool trySetComboBoxValue ( YWidget * widget, const YCPValue & val );
static bool trySetTreeItems ( YWidget * widget, const YCPValue & val );
+ static bool trySetTableItems ( YWidget * widget, const YCPValue & val );
+ static bool trySetTableCell ( YWidget * widget, const YCPValue & val );
static bool trySetSelectionWidgetItems ( YWidget * widget, const YCPValue & val );
static bool trySetRadioButtonGroupCurrentButton ( YWidget * widget, const YCPValue & val );
static bool trySetMultiSelectionBoxSelectedItems ( YWidget * widget, const YCPValue & val );
@@ -94,11 +106,15 @@
static YCPValue tryGetCheckBoxValue ( YWidget * widget );
static YCPValue tryGetSelectionBoxValue ( YWidget * widget );
static YCPValue tryGetTreeValue ( YWidget * widget );
+ static YCPValue tryGetTableValue ( YWidget * widget );
static YCPValue tryGetComboBoxValue ( YWidget * widget );
static YCPValue tryGetRadioButtonGroupCurrentButton ( YWidget * widget );
static YCPValue tryGetMultiSelectionBoxSelectedItems( YWidget * widget );
static YCPValue tryGetTreeOpenItems ( YWidget * widget );
static YCPValue tryGetTreeCurrentBranch ( YWidget * widget );
+ static YCPValue tryGetTableCell ( YWidget * widget, const YCPTerm & propertyTerm );
+ static YCPValue tryGetTableItem ( YWidget * widget, const YCPTerm & propertyTerm );
+ static YCPValue tryGetTableItems ( YWidget * widget );
/**
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItem.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItem.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItem.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItem.h Fri Oct 5 17:53:40 2007
@@ -21,7 +21,8 @@
#include
#include
-#include "YItem.h"
+#include
+#include "YTableItem.h"
/**
@@ -32,13 +33,18 @@
public:
/**
- * Constructor
+ * Constructors
**/
YCPTableItem( const YCPValue & id )
: YTableItem()
, _id( id )
{}
+ YCPTableItem()
+ : YTableItem()
+ , _id( YCPVoid() )
+ {}
+
/**
* Destructor.
**/
@@ -65,7 +71,11 @@
* 'iconName' are empty).
**/
void addCell( const YCPString & label, const YCPString & iconName )
- YTableItem::addCell( label->value(), iconName->value() );
+ { YTableItem::addCell( label->value(), iconName->value() ); }
+
+ void addCell( const YCPString & label )
+ { YTableItem::addCell( label->value() ); }
+
/**
* Return the label of cell no. 'index' (counting from 0 on) as a YCPString
@@ -77,7 +87,7 @@
* Return the icon of cell no. 'index' (counting from 0 on) as a YCPString
* or an empty YCPString if there is no cell with that index.
**/
- YCPString iconName( int index ) const { return YCPString( YItem::iconName( index ) ); }
+ YCPString iconName( int index ) const { return YCPString( YTableItem::iconName( index ) ); }
private:
Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.cc?rev=41269&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.cc (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.cc Fri Oct 5 17:53:40 2007
@@ -0,0 +1,210 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPTableItemParser.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include
+#include
+
+#define y2log_component "ui"
+#include
+
+#include "YCPTableItemParser.h"
+#include "YCP_UI_Exception.h"
+#include "YUISymbols.h"
+
+#define VERBOSE_PARSER 0
+
+
+YItemCollection
+YCPTableItemParser::parseTableItemList( const YCPList & itemList )
+{
+ YItemCollection itemCollection;
+ itemCollection.reserve( itemList.size() );
+
+ try
+ {
+ for ( int i=0; i < itemList->size(); i++ )
+ {
+ YCPValue itemTerm = itemList->value(i);
+
+ if ( itemTerm->isTerm() &&
+ itemTerm->asTerm()->name() == YUISymbol_item ) // `item(...)
+ {
+ YCPTableItem * item = parseTableItem( itemTerm->asTerm() );
+ itemCollection.push_back( item );
+ }
+ else // not `item(...)
+ {
+ YUI_THROW( YCPDialogSyntaxErrorException( "Expected `item(...)", itemTerm ) );
+ }
+ }
+ }
+ catch ( YUIException & exception )
+ {
+ // Delete all items created so far
+
+ YItemIterator it = itemCollection.begin();
+
+ while ( it != itemCollection.end() )
+ {
+ YItem * item = *it;
+ ++it;
+ delete item;
+ }
+
+ throw;
+ }
+
+#if VERBOSE_PARSER
+ y2debug( "%d items", itemCollection.size() );
+#endif
+
+ return itemCollection;
+}
+
+
+YCPTableItem *
+YCPTableItemParser::parseTableItem( const YCPTerm & itemTerm )
+{
+ YCPTableItem * item = new YCPTableItem();
+ YUI_CHECK_NEW( item );
+
+ const char * usage =
+ "Expected: `item(`id(`myID), (\"MyLabelText\"|`cell(...)), ... )";
+
+#if VERBOSE_PARSER
+ y2debug( "Parsing: %s", itemTerm->toString().c_str() );
+#endif
+
+ try
+ {
+ for ( int i=0; i < itemTerm->size(); i++ )
+ {
+ YCPValue arg = itemTerm->value(i);
+
+#if VERBOSE_PARSER
+ y2debug( "Parsing term arg #%d: %s", i, arg->toString().c_str() );
+#endif
+
+ if ( arg->isTerm() ) // `id(), `cell()
+ {
+ YCPTerm term = arg->asTerm();
+
+ if ( term->name() == YUISymbol_id // `id(...)
+ && term->size() == 1
+ && ! item->hasId() ) // and don't have an ID yet
+ {
+ item->setId( term->value(0) );
+ }
+ else if ( term->name() == YUISymbol_cell ) // `cell(...)
+ {
+ parseTableCell( item, term );
+ }
+ else
+ {
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) );
+ }
+ }
+ else if ( arg->isString() ) // label (the user-visible text)
+ {
+ item->addCell( arg->asString() );
+ }
+ else if ( arg->isInteger() ) // integer label (for backwards compatibility)
+ {
+ item->addCell( arg->toString() );
+ }
+ else if ( arg->isVoid() )
+ {
+ item->addCell( YCPString("") );
+ }
+ else
+ {
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) );
+ }
+ }
+
+ if ( ! item->hasId() ) // No ID specified?
+ {
+ // Use the first non-empty cell label as ID for the entire item
+
+ for ( YTableCellConstIterator it = item->cellsBegin();
+ ! item->hasId() && it != item->cellsEnd();
+ ++it )
+ {
+ if ( ! (*it)->label().empty() )
+ item->setId( YCPString( (*it)->label() ) );
+ }
+ }
+ }
+ catch ( YUIException & exception )
+ {
+ delete item;
+ throw;
+ }
+
+ return item;
+}
+
+
+void
+YCPTableItemParser::parseTableCell( YCPTableItem * parent, const YCPTerm & cellTerm )
+{
+ YCPString label = YCPNull();
+ YCPString iconName = YCPNull();
+ const char * usage = "Expected `cell(`icon(\"myicon.png\"), \"mylabel\")";
+
+ if ( cellTerm->size() < 1 || cellTerm->size() > 2 )
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, cellTerm ) );
+
+ for ( int i=0; i < cellTerm->size(); ++i )
+ {
+ YCPValue arg = cellTerm->value(i);
+
+ if ( arg->isString() ) // label
+ {
+ if ( ! label.isNull() ) // already have a label for this cell?
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, cellTerm ) );
+
+ label = arg->asString();
+ }
+ else if ( arg->isTerm() ) // `icon("myicon.png")
+ {
+ YCPTerm iconTerm = arg->asTerm();
+
+ if ( iconTerm->name() == YUISymbol_icon &&
+ iconTerm->size() == 1 &&
+ iconTerm->value(0)->isString() &&
+ iconName.isNull() ) // no icon name yet
+ {
+ iconName = iconTerm->value(0)->asString();
+ }
+ else
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, cellTerm ) );
+ }
+ else // other types
+ {
+ YUI_THROW( YCPDialogSyntaxErrorException( usage, cellTerm ) );
+ }
+ }
+
+ // Don't need to check if at least one of label or iconName found:
+ // The cellTerm->size() check above and the other checks in the loop handle that.
+
+ YUI_CHECK_PTR( parent );
+ parent->addCell( label, iconName );
+}
Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.h?rev=41269&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.h (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemParser.h Fri Oct 5 17:53:40 2007
@@ -0,0 +1,77 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPTableItemParser.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YCPTableItemParser_h
+#define YCPTableItemParser_h
+
+#include
+#include "YCPTableItem.h"
+
+
+/**
+ * Parser for table item lists
+ **/
+class YCPTableItemParser
+{
+public:
+
+ /**
+ * Parse a table item list:
+ *
+ * [
+ * `item(`id(`myID1 ), "Label1", "Label2", "Label3" ),
+ * `item(`id(`myID1 ), "Label1", `cell("Label2"), "Label3" ),
+ * `item(`id(`myID2 ), "Label1", `cell(`icon( "icon2.png"), "Label2" ), "Label3" ),
+ * `item(`id(`myID2 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" )
+ * ]
+ *
+ * Return a list of newly created YTableItem-derived objects.
+ *
+ * This function throws exceptions if there are syntax errors.
+ **/
+ static YItemCollection parseTableItemList( const YCPList & ycpItemList );
+
+
+protected:
+
+ /**
+ * Parse an item term:
+ *
+ * `item(`id(`myID1 ), "Label1", "Label2", "Label3" )
+ * `item(`id(`myID1 ), "Label1", `cell( "Label2" ), "Label3" )
+ * `item(`id(`myID2 ), "Label1", `cell(`icon( "icon2.png" ), "Label2" ), "Label3" )
+ * `item(`id(`myID2 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" )
+ *
+ * `cell() is optional if there is only a label and no icon for that cell.
+ *
+ * This function throws exceptions if there are syntax errors.
+ **/
+ static YCPTableItem * parseTableItem( const YCPTerm & itemTerm );
+
+ /**
+ * Parse a cell term and add a YTableCell to the parent YCPTableItem:
+ *
+ * `cell( "Label" )
+ * `cell( `icon( "icon.png"), "Label" )
+ * `cell( "Label", `icon( "icon.png" ) )
+ **/
+ static void parseTableCell( YCPTableItem * parent, const YCPTerm & cellTerm );
+};
+
+
+#endif // YCPTableItemParser_h
Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc?rev=41269&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.cc Fri Oct 5 17:53:40 2007
@@ -0,0 +1,88 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPTableItemWriter.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#include "ycp/YCPVoid.h"
+#include "YCPTableItemWriter.h"
+#include "YUISymbols.h"
+
+
+YCPList
+YCPTableItemWriter::itemList( YItemIterator begin, YItemIterator end )
+{
+ YCPList itemList;
+
+ for ( YItemIterator it = begin; it != end; ++it )
+ {
+ YTableItem * item = dynamic_cast (*it);
+
+ if ( item )
+ {
+ itemList->add( itemTerm( item ) );
+ }
+ }
+
+ return itemList;
+}
+
+
+YCPValue
+YCPTableItemWriter::itemTerm( const YTableItem * item )
+{
+ if ( ! item )
+ return YCPVoid();
+
+ YCPTerm itemTerm( YUISymbol_item ); // `item()
+
+ const YCPTableItem * ycpItem = dynamic_cast (item);
+
+ if ( ycpItem && ycpItem->hasId() )
+ {
+ YCPTerm idTerm( YUISymbol_id ); // `id()
+ idTerm->add( ycpItem->id() );
+ }
+
+ for ( YTableCellConstIterator it = item->cellsBegin(); it != item->cellsEnd(); ++it )
+ itemTerm->add( cellValue( *it ) );
+
+ return itemTerm;
+}
+
+
+YCPValue
+YCPTableItemWriter::cellValue( const YTableCell * cell )
+{
+ if ( ! cell )
+ return YCPVoid();
+
+ if ( cell->hasIconName() )
+ {
+ YCPTerm iconTerm( YUISymbol_icon ); // `icon()
+ iconTerm->add( YCPString( cell->iconName() ) ); // `icon("myicon.png")
+
+ YCPTerm cellTerm( YUISymbol_cell ); // `cell()
+ cellTerm->add( iconTerm ); // `cell(`icon("myicon.png"))
+ cellTerm->add( YCPString( cell->label() ) ); // `cell(`icon("myicon.png"), "mylabel")
+
+ return cellTerm;
+ }
+ else // no icon
+ {
+ return YCPString( cell->label() ); // "mylabel"
+ }
+}
+
Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h?rev=41269&view=auto
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h (added)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTableItemWriter.h Fri Oct 5 17:53:40 2007
@@ -0,0 +1,72 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YCPTableItemWriter.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YCPTableItemWriter_h
+#define YCPTableItemWriter_h
+
+#include
+#include
+#include
+
+#include "YCPTableItem.h"
+
+
+/**
+ * Writer for table item lists
+ **/
+class YCPTableItemWriter
+{
+public:
+
+ /**
+ * Create a YCPList from a table item collection:
+ *
+ * [
+ * `item(`id(`myID1 ), "Label1", "Label2", "Label3" ),
+ * `item(`id(`myID1 ), "Label1", `cell("Label2"), "Label3" ),
+ * `item(`id(`myID2 ), "Label1", `cell(`icon( "icon2.png"), "Label2" ), "Label3" )
+ * `item(`id(`myID2 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" )
+ * ]
+ **/
+ static YCPList itemList( YItemIterator begin, YItemIterator end );
+
+
+ /**
+ * Create a YCPTerm for one table item:
+ *
+ * `item(`id(`myID1 ), "Label1", "Label2", "Label3" )
+ * `item(`id(`myID1 ), "Label1", `cell( "Label2" ), "Label3" )
+ * `item(`id(`myID2 ), "Label1", `cell(`icon( "icon2.png" ), "Label2" ), "Label3" )
+ * `item(`id(`myID2 ), "Label1", `cell( "Label2", `icon( "icon2.png")), "Label3" )
+ *
+ * `cell() will be created only if a cell has an icon.
+ **/
+ static YCPValue itemTerm( const YTableItem * item );
+
+ /**
+ * Create a YCPValue for one table cell: A YCPString if a cell has only a
+ * label and no icon, and a YCPTerm with `cell() otherwise.
+ *
+ * "Label"
+ * `cell( `icon( "icon.png"), "Label" )
+ **/
+ static YCPValue cellValue( const YTableCell * cell );
+};
+
+
+#endif // YCPTableItemWriter_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc Fri Oct 5 17:53:40 2007
@@ -51,12 +51,13 @@
while ( it != itemCollection.end() )
{
+ // Delete all items created so far
+
YItem * item = *it;
++it;
delete item;
}
- itemCollection.clear();
throw;
}
@@ -112,7 +113,7 @@
YCPBoolean isOpen = YCPNull();
YCPList subItemList = YCPNull();
- string usage =
+ const char * usage =
"Expected: `item(`id(`myID), `icon(\"MyIcon.png\"), \"MyItemText\", boolean isOpen, list subItemList )";
#if VERBOSE_PARSER
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc Fri Oct 5 17:53:40 2007
@@ -26,6 +26,9 @@
using std::string;
+#define VERBOSE_DIALOGS 0
+
+
std::stack YDialog::_dialogStack;
@@ -43,13 +46,17 @@
_dialogStack.push( this );
+#if VERBOSE_DIALOGS
y2debug( "New YDialog at %p", this );
+#endif
}
YDialog::~YDialog()
{
+#if VERBOSE_DIALOGS
y2debug( "Destroying YDialog at %p", this );
+#endif
}
@@ -102,7 +109,10 @@
void YDialog::setInitialSize()
{
+#if VERBOSE_DIALOGS
y2debug( "Setting initial size for YDialog at %p", this );
+#endif
+
// Trigger geometry management
setSize( preferredWidth(), preferredHeight() );
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc Fri Oct 5 17:53:40 2007
@@ -114,11 +114,11 @@
}
-string YSelectionWidget::iconFullPath( YItem * item ) const
+string YSelectionWidget::iconFullPath( const string & iconName ) const
{
string fullPath;
- if ( item && ! item->iconName().empty() )
+ if ( ! iconName.empty() )
{
if ( priv->iconBasePath.empty() ||
priv->iconBasePath[0] != '/' )
@@ -126,13 +126,22 @@
fullPath = YUI::yApp()->iconBasePath();
}
- fullPath += priv->iconBasePath + "/" + item->iconName();
+ fullPath += priv->iconBasePath + "/" + iconName;
}
return fullPath;
}
+string YSelectionWidget::iconFullPath( YItem * item ) const
+{
+ if ( item )
+ return iconFullPath( item->iconName() );
+ else
+ return "";
+}
+
+
void YSelectionWidget::addItem( YItem * item )
{
YUI_CHECK_PTR( item );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h Fri Oct 5 17:53:40 2007
@@ -214,6 +214,13 @@
string iconBasePath() const;
/**
+ * Return the full path + file name for the specified icon name.
+ *
+ * If 'iconName' is empty, this will return an empty string.
+ **/
+ string iconFullPath( const string & iconName ) const;
+
+ /**
* Return the full path + file name for the icon of the specified item.
*
* If 'item' does not have an iconName specified, this will return an empty
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTable.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTable.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTable.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTable.cc Fri Oct 5 17:53:40 2007
@@ -31,254 +31,190 @@
#include "YCPValueWidgetID.h"
-YTable::YTable( const YWidgetOpt & opt, int num_cols )
- : YWidget( opt )
- , num_cols( num_cols )
+struct YTablePrivate
{
+ YTablePrivate( int col )
+ : columns( col )
+ , keepSorting( false )
+ , immediateMode( false )
+ {
+ headers.resize( columns ); // Fill with empty strings (from default constructor)
+ alignments.resize( columns, YTable::Left );
+ }
+
+ int columns;
+ bool keepSorting;
+ bool immediateMode;
+ vector<string> headers;
+ vectorYTable::Alignment alignments;
+};
+
+
+
+
+YTable::YTable( YWidget * parent, int columns )
+ : YSelectionWidget( parent,
+ "", // label
+ true ) // enforceSingleSelection
+ , priv( new YTablePrivate( columns ) )
+{
+ YUI_CHECK_NEW( priv );
+
setDefaultStretchable( YD_HORIZ, true );
setDefaultStretchable( YD_VERT, true );
}
-YCPValue YTable::changeWidget( const YCPSymbol & property,
- const YCPValue & newValue )
+YTable::~YTable()
{
- string s = property->symbol();
+ // NOP
+}
- /*
- * @property integer CurrentItem the ID of the currently selected item
- * Alias: Value
- */
- if ( s == YUIProperty_CurrentItem ||
- s == YUIProperty_Value ) // Sort for item with that id
- {
- int index = itemWithId( newValue, true ); // true: log error
- if ( index < 0 ) return YCPBoolean( false );
- else
- {
- setCurrentItem( index );
- return YCPBoolean( true );
- }
- }
- /*
- * @property list(item) Items a list of all table items
- */
- else if ( s == YUIProperty_Items ) // Change whole selection box!
- {
- if ( ! newValue->isList() )
- {
- y2warning( "Items property of Table widget must be a list" );
- return YCPBoolean( false );
- }
- OptimizeChanges below( *this ); // delay screen updates until this block is left
-
- itemsCleared();
- rows.clear();
- return YCPBoolean( addItems( newValue->asList() ) );
- }
- else return YWidget::changeWidget( property, newValue );
+int
+YTable::columns() const
+{
+ return priv->columns;
}
-
-YCPValue YTable::changeWidgetTerm( const YCPTerm & property, const YCPValue & newvalue )
+bool
+YTable::hasColumn( int column ) const
{
- string s = property->name();
- /*
- * @property item Item(id) read: a single item (string or term)
- * @property integer|string Item(id,column) write: replacement for one specific cell ( see example )
- */
- if ( s == YUIProperty_Item )
- {
- if ( property->size() != 2 || ! property->value(1)->isInteger() )
- {
- y2error( "Table %s: property `Item() needs two arguments: item id and column number",
- id()->toString().c_str() );
- return YCPBoolean( false );
- }
- YCPValue itemid = property->value(0);
- int item_nr = itemWithId( itemid, true );
- if ( item_nr < 0 ) return YCPBoolean( false );
-
- int colnum = (int)( property->value(1)->asInteger()->value() );
- if ( colnum >= numCols() || colnum < 0 )
- {
- y2error( "Table %s: Invalid column number %d",
- id()->toString().c_str(), colnum );
- return YCPBoolean( false );
- }
-
- string newtext;
- if ( newvalue->isString() ) newtext = newvalue->asString()->value();
- else if ( newvalue->isInteger() ) newtext = newvalue->asInteger()->toString();
- else
- {
- y2error( "Table %s: Invalid value for cell (%s|%d). Must be string or integer",
- id()->toString().c_str(), itemid->toString().c_str(), colnum );
- return YCPBoolean( false );
- }
-
- rows[ item_nr].elements[colnum ] = newtext;
- cellChanged( item_nr, colnum, YCPString( newtext ) );
- return YCPBoolean( true );
- }
- else return YWidget::changeWidgetTerm( property, newvalue );
+ return column >= 0 && column <= priv->columns;
}
-YCPValue YTable::queryWidget( const YCPSymbol & property )
+void
+YTable::setHeader( int column, const string & text )
{
- string s = property->symbol();
- if ( s == YUIProperty_CurrentItem ||
- s == YUIProperty_Value )
- {
- int index = getCurrentItem();
- // y2debug( "current item: %d", index );
- if ( index >= 0 ) return rows[ index ].id;
- else return YCPVoid();
- }
- else if ( s == YUIProperty_Items )
- {
- YCPList result;
- for ( int i = 0 ; i < numItems () ; i ++ )
- {
- result->add ( rows[ i ].makeTerm () );
- }
- return result;
- }
- else return YWidget::queryWidget( property );
+ if ( hasColumn( column ) )
+ priv->headers[ column ] = text;
}
-YCPValue YTable::queryWidgetTerm( const YCPTerm & property )
+string
+YTable::header( int column ) const
{
- string s = property->name();
- if ( s == YUIProperty_Item )
- {
- if ( property->size() != 1 )
- {
- y2error( "Table %s: property `Item() needs one argument",
- id()->toString().c_str() );
- return YCPVoid();
- }
- int item_nr = itemWithId( property->value(0), true );
- if ( item_nr < 0 ) return YCPVoid();
- else return rows[ item_nr ].makeTerm();
- }
- else return YWidget::queryWidgetTerm( property );
+ if ( hasColumn( column ) )
+ return priv->headers[ column ];
+ else
+ return "";
}
-/*
- * Insert a number of items.
- * Reimplemented in YQTable to keep QListView happy.
- */
-bool YTable::addItems( const YCPList & itemlist )
+void
+YTable::setAlignment( int column, YTable::Alignment alignment )
{
- for ( int i = 0; i < itemlist->size(); i++ )
- {
- YCPValue item = itemlist->value(i);
+ if ( hasColumn( column ) )
+ priv->alignments[ column ] = alignment;
+}
- if ( ! addItem( item ) )
- return false; // Error
- }
- return true; // Success
+YTable::Alignment
+YTable::alignment( int column ) const
+{
+ if ( hasColumn( column ) )
+ return priv->alignments[ column ];
+ else
+ return YTable::Left;
}
-bool YTable::addItem( const YCPValue & item )
+bool
+YTable::immediateMode() const
{
- if ( ! item->isTerm() || item->asTerm()->name() != YUISymbol_item )
- {
- y2error( "Invalid item specification %s: Must be `" YUISymbol_item "() term",
- item->toString().c_str() );
- return false;
- }
-
- YCPList collist = item->asTerm()->args();
- if ( collist->size() != numCols() + 1 )
- {
- y2error( "Invalid item specification %s: Wrong number of elements",
- item->toString().c_str() );
- return false;
- }
+ return priv->immediateMode;
+}
- if ( ! collist->value(0)->isTerm()
- || collist->value(0)->asTerm()->name() != YUISymbol_id
- || collist->value(0)->asTerm()->size() != 1)
- {
- y2error( "Invalid item specification %s: Must begin with `" YUISymbol_id "() term",
- item->toString().c_str() );
- return false;
- }
- YCPValue id = collist->value(0)->asTerm()->value(0);
+void
+YTable::setImmediateMode( bool immediateMode )
+{
+ priv->immediateMode = immediateMode;
- // Prepare stl vector of strings of the content
- vector<string> row;
- for ( int r=1; r< collist->size(); r++ )
- {
- YCPValue value = collist->value(r);
- if ( value->isString() ) row.push_back( value->asString()->value() );
- else if ( value->isInteger() ) row.push_back( value->toString() );
- else if ( value->isVoid() ) row.push_back( "" );
- else
- {
- y2error( "Invalid value %s in item. Must be string, integer or void",
- value->toString().c_str() );
- row.push_back( "" );
- }
- }
- addItem( id, row );
- return true;
+ if ( immediateMode )
+ setNotify( true );
}
-
-void YTable::addItem( const YCPValue & id, vector<string> elements )
+bool
+YTable::keepSorting() const
{
- rows.push_back( YTableRow( id, elements ) );
- itemAdded( elements, rows.size() - 1 );
+ return priv->keepSorting;
}
-
-int YTable::numItems() const
+void
+YTable::setKeepSorting( bool keepSorting )
{
- return rows.size();
+ priv->keepSorting = keepSorting;
}
-int YTable::itemWithId( const YCPValue & id, bool report_error )
+
+const YPropertySet &
+YTable::propertySet()
{
- for ( int i=0; iequal( id ) ) return i;
+ /*
+ * @property itemID Value The currently selected item
+ * @property itemID CurrentItem The currently selected item
+ * @property itemList Items All items
+ * @property string Cell One cell (one column of one item)
+ * @property integer Cell (ChangeWidget only) One cell as integer
+ * @property `icon(...) Cell Icon for one one cell
+ * @property string Item Alias for Cell
+ * @property string Item QueryWidget only: Return one complete item
+ */
+ propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Cell, YOtherProperty ) );
+ propSet.add( YProperty( YUIProperty_Item, YOtherProperty ) );
+ propSet.add( YWidget::propertySet() );
}
- if ( report_error )
- y2error( "Table: No item %s existing", id->toString().c_str() );
- return -1;
+ return propSet;
}
-int YTable::numCols() const
+
+bool
+YTable::setProperty( const string & propertyName, const YPropertyValue & val )
{
- return num_cols;
+ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
+
+ if ( propertyName == YUIProperty_Value ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_CurrentItem ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_Cell ) return false; // Needs special handling
+ else if ( propertyName == YUIProperty_Item ) return false; // Needs special handling
+ else
+ {
+ return YWidget::setProperty( propertyName, val );
+ }
+
+ return true; // success -- no special processing necessary
}
-YCPTerm YTableRow::makeTerm() const
+YPropertyValue
+YTable::getProperty( const string & propertyName )
{
- // Return the item as term
- YCPTerm itemterm( YUISymbol_item );
- YCPTerm idterm( YUISymbol_id );
- idterm->add( id );
- itemterm->add( idterm );
- for ( unsigned int c=0; c < elements.size(); c++ )
- itemterm->add( YCPString( elements[c] ) );
- return itemterm;
+ propertySet().check( propertyName ); // throws exceptions if not found
+
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_Cell ) return YPropertyValue( YOtherProperty );
+ else if ( propertyName == YUIProperty_Item ) return YPropertyValue( YOtherProperty );
+ else
+ {
+ return YWidget::getProperty( propertyName );
+ }
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTable.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTable.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTable.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTable.h Fri Oct 5 17:53:40 2007
@@ -19,156 +19,183 @@
#ifndef YTable_h
#define YTable_h
-#include "YWidget.h"
-#include
-#include
+#include "YSelectionWidget.h"
+#include "YTableItem.h"
+
class YMacroRecorder;
+class YTablePrivate;
+
+using std::string;
/**
- * @short helper class for the table widget: one single table row
+ * Table: Selection list with multiple columns. The user can select exactly one
+ * row (with all its columns) from that list. Each cell (each column within
+ * each row) has a label text and an optional icon (*).
+ *
+ * This widget is similar to SelectionBox, but it has several columns for each
+ * item (each row). If just one column is desired, consider using SelectionBox
+ * instead.
+ *
+ * Note: This is not something like a spread sheet, and it doesn't pretend or
+ * want to be. Actions are performed on rows, not on individual cells (columns
+ * within one row).
+ *
+ *
+ * (*) Not all UIs (in particular not text-based UIs) support displaying icons,
+ * so an icon should never be an exclusive means to display any kind of
+ * information.
**/
-class YTableRow
+class YTable : public YSelectionWidget
{
- YCPValue id;
- vector<string> elements;
- YTableRow( YCPValue id, vector<string> elements )
- : id( id ), elements( elements ) {};
- friend class YTable;
-
+protected:
/**
- * Construct a `item( `id( .. ), "asdf", "asdf", ... ) term
+ * Constructor. 'columns' is the number of columns to be created.
**/
- YCPTerm makeTerm() const;
-};
-
+ YTable( YWidget * parent, int columns );
+public:
-/**
- * @short the table widget
- **/
-class YTable : public YWidget
-{
-protected:
/**
- * Creates a new and empty Table
- * @param num_cols The number of columns of the table
+ * Destructor.
**/
- YTable( const YWidgetOpt & opt, int num_cols );
+ virtual ~YTable();
-public:
/**
- * Returns a descriptive name of this widget class for logging,
+ * Return a descriptive name of this widget class for logging,
* debugging etc.
**/
virtual const char * widgetClass() const { return "YTable"; }
/**
- * Adds an item to the table that is given as term
- * yet to be parsed.
+ * Return the number of coluns of this table.
+ * Note that this can only be set in the constructor.
**/
- bool addItem( const YCPValue & item );
+ int columns() const;
/**
- * Adds a list of items to the table. The list
- * contains item specifications yet to be parsed.
+ * Return 'true' if this table has 'column' columns.
**/
- virtual bool addItems( const YCPList & itemlist );
+ bool hasColumn( int column ) const;
/**
- * Adds an item to the table.
+ * Set the header text for the specified column (counting from 0 on).
+ *
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
**/
- void addItem( const YCPValue & id, vector<string> elements );
+ virtual void setHeader( int column, const string & text );
/**
- * Implements the ui command changeWidget.
+ * Return the header text for the specified column.
**/
- YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
+ string header( int column ) const;
- /**
- * Implements the ui command changeWidget with property given as term.
- **/
- YCPValue changeWidgetTerm( const YCPTerm & property, const YCPValue & newvalue );
+ enum Alignment
+ {
+ Left,
+ Center,
+ Right
+ };
/**
- * Implements the ui command queryWidget
+ * Set the alignment for the specified column (counting from 0 on):
+ * YTable::Left, YTable::Center, YTable::Right
+ *
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
**/
- YCPValue queryWidget( const YCPSymbol & property );
+ virtual void setAlignment( int column, YTable::Alignment alignment );
/**
- * Implements the ui command queryWidget with property given as term.
+ * Return the alignment for the specified column.
**/
- YCPValue queryWidgetTerm( const YCPTerm & property );
+ YTable::Alignment alignment( int column ) const;
/**
- * Returns the number of columns of the table.
- **/
- int numCols() const;
-
- /**
- * The name of the widget property that will return user input.
- * Inherited from YWidget.
- **/
- const char *userInputProperty() { return YUIProperty_CurrentItem; }
-
-
-protected:
- /**
- * Called when an item (a row) has been added. Overload this to
- * fill the ui specific widget with items.
- * @param elements the strings of the elements, one for each column.
- * @param index index of the new item.
+ * Deliver even more events than with notify() set.
+ *
+ * With "notify" alone, a table widget sends an ActivatedEvent when the
+ * user double-clicks an item or presses the "space" key on it. It does not
+ * send an event when the user just sends another item.
+ *
+ * With "immediate", it also sends a SelectionChangedEvent when the user
+ * selects another item. "immediate" implicitly includes "notify".
**/
- virtual void itemAdded( vector<string> elements, int index ) = 0;
+ bool immediateMode() const;
/**
- * Is called, when all items have been cleared. Overload this
- * and clear the ui specific table.
+ * Set immediateMode() on or off.
**/
- virtual void itemsCleared() = 0;
+ void setImmediateMode( bool immediateMode = true );
/**
- * Is called, when the contents of a cell has been changed. Overload
- * this and change the cell text.
+ * Return 'true' if the sort order is to be kept in item insertion order,
+ * i.e. if sorting the table by clicking on a column header should be
+ * disabled.
**/
- virtual void cellChanged( int index, int colnum, const YCPString & newtext ) = 0;
+ bool keepSorting() const;
/**
- * Returns the index of the currently
- * selected item or -1 if no item is selected.
+ * Switch between sorting by item insertion order (keepSorting: true) or
+ * allowing the user to sort by an arbitrary column (by clicking on the
+ * column header).
+ *
+ * Derived classes can overwrite this function, but they should call this
+ * base class function in the new implementation.
**/
- virtual int getCurrentItem() = 0;
+ virtual void setKeepSorting( bool keepSorting );
/**
- * Makes another item the selected one.
+ * Notification that a cell (its text and/or its icon) was changed from the
+ * outside. Applications are required to call this whenever a table cell is
+ * changed after adding the corresponding table item (the row) to the table
+ * widget.
+ *
+ * Derived classes are required to implement this and update the display
+ * accordingly.
+ *
+ * Note that the position of this cell can be retrieved with cell->column()
+ * and cell->itemIndex().
**/
- virtual void setCurrentItem( int index ) = 0;
-
+ virtual void cellChanged( const YTableCell * cell ) = 0;
-protected:
/**
- * The current data in the table
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This function may throw YUIPropertyExceptions.
+ *
+ * This function returns 'true' if the value was successfully set and
+ * 'false' if that value requires special handling (not in error cases:
+ * those are covered by exceptions).
**/
- vector<YTableRow> rows;
+ virtual bool setProperty( const string & propertyName,
+ const YPropertyValue & val );
/**
- * The number of columns of the table
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw YUIPropertyExceptions.
**/
- int num_cols;
+ virtual YPropertyValue getProperty( const string & propertyName );
/**
- * Returns the current number of items
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ *
+ * Reimplemented from YWidget.
**/
- int numItems() const;
+ virtual const YPropertySet & propertySet();
+
/**
- * Searches for an item with a certain id or a certain label.
- * Returns the index of the found item or -1 if none was found
- * @param report_error set this to true, if you want me to
- * report an error if non item can be found.
+ * The name of the widget property that will return user input.
+ * Inherited from YWidget.
**/
- int itemWithId( const YCPValue & id, bool report_error );
+ const char *userInputProperty() { return YUIProperty_CurrentItem; }
private:
@@ -179,6 +206,9 @@
* handled by the abstract libyui level, not by a specific UI.
**/
virtual void saveUserInput( YMacroRecorder *macroRecorder );
+
+
+ ImplPtr<YTablePrivate> priv;
};
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=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.cc Fri Oct 5 17:53:40 2007
@@ -102,6 +102,8 @@
{
YUI_CHECK_PTR( cell );
_cells.push_back( cell );
+
+ cell->reparent( this, _cells.size() - 1 );
}
@@ -111,7 +113,14 @@
YTableCell * cell = new YTableCell( label, iconName );
YUI_CHECK_NEW( cell );
- _cells.push_back( cell );
+ addCell( cell );
+}
+
+
+bool
+YTableItem::hasCell( int index ) const
+{
+ return index >= 0 && (unsigned) index < _cells.size();
}
@@ -123,6 +132,14 @@
}
+YTableCell *
+YTableItem::cell( int index )
+{
+ return hasCell( index ) ?
+ _cells[ index ] : 0;
+}
+
+
string
YTableItem::label( int index ) const
{
@@ -142,3 +159,19 @@
{
return hasCell( index ) ? _cells[ index ]->hasIconName() : false;
}
+
+
+
+
+
+void YTableCell::reparent( YTableItem * parent, int column )
+{
+ YUI_CHECK_PTR( parent );
+
+ if ( _parent && _parent != parent && column != column )
+ YUI_THROW( YUIException( string( "Cannot reparent YTableCell \"" )
+ + _label
+ + "to different parent." ) );
+ _parent = parent;
+ _column = column;
+}
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=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YTableItem.h Fri Oct 5 17:53:40 2007
@@ -90,7 +90,12 @@
/**
* Add a cell. This item will assume ownership over the cell and delete it
- * when appropriate.
+ * when appropriate (when the table is destroyed or when table items are
+ * replaced), at which time the pointer will become invalid.
+ *
+ * Cells can still be changed after they (and the item they belong to) are
+ * added, but in that case, YTable::cellChanged() needs to be called to
+ * update the table display accordingly.
**/
void addCell( YTableCell * cell );
@@ -122,6 +127,7 @@
* or 0 if there is none.
**/
const YTableCell * cell( int index ) const;
+ YTableCell * cell( int index );
/**
* Return the number of cells this item has.
@@ -132,8 +138,7 @@
* Return 'true' if this item has a cell with the specified index
* (counting from 0 on), 'false' otherwise.
**/
- bool hasCell( int index ) const
- { return index >= 0 && (unsigned) index < _cells.size(); }
+ bool hasCell( int index ) const;
/**
* Return the label of cell no. 'index' (counting from 0 on) or an empty
@@ -168,13 +173,17 @@
**/
void * data() const { return _data; }
+ /**
+ * Just for debugging.
+ **/
+ string label() const { return label(0); }
+
private:
// 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 & ) {}
@@ -201,7 +210,7 @@
* 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 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.
*
@@ -216,11 +225,29 @@
{
public:
/**
- * Constructor with label and icon name and optionally the selected state.
+ * Constructor with label and optional icon name for cells that don't have
+ * a parent item yet (that will be added to a parent later with
+ * setParent()).
**/
YTableCell( const string & label, const string & iconName = "" )
: _label( label )
, _iconName( iconName )
+ , _parent( 0 )
+ , _column ( -1 )
+ {}
+
+ /**
+ * Constructor with parent, column no., label and optional icon name for
+ * cells that are created with a parent.
+ **/
+ YTableCell( YTableItem * parent,
+ int column,
+ const string & label,
+ const string & iconName = "" )
+ : _label( label )
+ , _iconName( iconName )
+ , _parent( parent )
+ , _column ( column )
{}
// No virtual destructor. This saves a vtable for this class since there
@@ -234,6 +261,10 @@
/**
* Set this cell's label.
+ *
+ * If this is called after the corresponding table item (table row) is
+ * added to the table widget, call YTable::cellChanged() to notify the
+ * table widget about the fact. Only then will the display be updated.
**/
void setLabel( const string & newLabel ) { _label = newLabel; }
@@ -249,16 +280,47 @@
/**
* Set this cell's icon name.
+ *
+ * If this is called after the corresponding table item (table row) is
+ * added to the table widget, call YTable::cellChanged() to notify the
+ * table widget about the fact. Only then will the display be updated.
**/
void setIconName( const string & newIconName ) { _iconName = newIconName; }
+ /**
+ * Return this cell's parent item or 0 if it doesn't have one yet.
+ **/
+ YTableItem * parent() const { return _parent; }
+
+ /**
+ * Return this cell's column no. (counting from 0on) or -1 if it doesn't
+ * have a parent yet.
+ **/
+ int column() const { return _column; }
+
+ /**
+ * Convenience function: Return this cell's parent item's index within its
+ * table widget or -1 if there is no parent item or no parent table.
+ **/
+ int itemIndex() const { return _parent ? _parent->index() : -1; }
+
+ /**
+ * Set this cell's parent item and column no. if it doesn't have a parent
+ * yet.
+ *
+ * This method will throw an exception if the cell already has a parent.
+ **/
+ void reparent( YTableItem * parent, int column );
+
private:
- string _label;
- string _iconName;
+ string _label;
+ string _iconName;
+ YTableItem * _parent;
+ int _column;
};
-#endif // YTableItem_h
+ #endif // YTableItem_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Fri Oct 5 17:53:40 2007
@@ -455,7 +455,6 @@
virtual YDialog *createDialog( YWidgetOpt & opt ) = 0;
virtual YWidget *createLogView( YWidget *parent, YWidgetOpt & opt, const YCPString & label, int visibleLines, int maxLines ) = 0;
virtual YWidget *createMenuButton( YWidget *parent, YWidgetOpt & opt, const YCPString & label ) = 0;
- virtual YWidget *createTable( YWidget *parent, YWidgetOpt & opt, vector<string> header ) = 0;
virtual YWidget *createIntField( YWidget *parent, YWidgetOpt & opt, const YCPString & label, int minValue, int maxValue, int initialValue ) = 0;
// FIXME: Obsolete
// FIXME: Obsolete
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUIException.h Fri Oct 5 17:53:40 2007
@@ -85,20 +85,20 @@
* Drops a log line and throws the YUIException.
**/
#define YUI_THROW( EXCEPTION ) \
- _YUI_THROW( EXCEPTION, YUI_EXCEPTION_CODE_LOCATION )
+ _YUI_THROW( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION )
/**
* Drops a log line telling the YUIException was caught and handled.
**/
#define YUI_CAUGHT( EXCEPTION ) \
- _YUI_CAUGHT( EXCEPTION, YUI_EXCEPTION_CODE_LOCATION )
+ _YUI_CAUGHT( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION )
/**
* Drops a log line and rethrows, updating the YCodeLocation.
**/
#define YUI_RETHROW( EXCEPTION ) \
- _YUI_RETHROW( EXCEPTION, YUI_EXCEPTION_CODE_LOCATION )
+ _YUI_RETHROW( ( EXCEPTION ), YUI_EXCEPTION_CODE_LOCATION )
/**
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUISymbols.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUISymbols.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUISymbols.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUISymbols.h Fri Oct 5 17:53:40 2007
@@ -145,6 +145,7 @@
// Widget properties
+#define YUIProperty_Cell "Cell"
#define YUIProperty_CurrentButton "CurrentButton"
#define YUIProperty_CurrentBranch "CurrentBranch"
#define YUIProperty_CurrentItem "CurrentItem"
@@ -283,6 +284,7 @@
#define YUISymbol_opt "opt"
#define YUISymbol_icon "icon"
#define YUISymbol_item "item"
+#define YUISymbol_cell "cell"
#define YUISymbol_menu "menu"
#define YUISymbol_header "header"
#define YUISymbol_rgb "rgb"
@@ -292,5 +294,9 @@
#define YUISymbol_bottomMargin "bottomMargin"
#define YUISymbol_BackgroundPixmap "BackgroundPixmap"
+#define YUISymbol_Left "Left"
+#define YUISymbol_Right "Right"
+#define YUISymbol_Center "Center"
+
#endif // YUISymbols_h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc Fri Oct 5 17:53:40 2007
@@ -991,31 +991,33 @@
if ( ! widget )
return YCPVoid();
- if ( property->isSymbol() )
- {
- YPropertySet propSet = widget->propertySet();
- YCPSymbol sym = property->asSymbol();
+ YPropertySet propSet = widget->propertySet();
- if ( propSet.size() == 5 ) // unchanged from YWidget, no properties supported
+ if ( propSet.size() == 5 ) // unchanged from YWidget, no properties supported
+ {
+ if ( property->isSymbol() )
{
// FIXME: Get rid of this
// FIXME: Get rid of this
// FIXME: Get rid of this
+ YCPSymbol sym = property->asSymbol();
y2debug( "Old style UI::QueryWidget() for %s::%s",
widget->widgetClass(), sym->symbol().c_str() );
- return widget->queryWidget( property->asSymbol() );
- // FIXME: Get rid of this
- // FIXME: Get rid of this
- // FIXME: Get rid of this
+ return widget->queryWidget( sym );
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
+ // FIXME: Get rid of this
}
- else
- {
- // y2debug( "New style UI::QueryWidget() for %s::%s", widget->widgetClass(), sym->symbol().c_str() );
-
- string propertyName = sym->symbol();
+ }
+ else
+ {
+ // y2debug( "New style UI::QueryWidget() for %s::%s", widget->widgetClass(), sym->symbol().c_str() );
- try
+ try
+ {
+ if ( property->isSymbol() ) // The normal case: UI::QueryWidget(`myWidget, `SomeProperty)
{
+ string propertyName = property->asSymbol()->symbol();
YPropertyValue val = widget->getProperty( propertyName );
switch ( val.type() )
@@ -1026,25 +1028,31 @@
case YOtherProperty: return YCPPropertyHandler::getComplexProperty( widget, propertyName );
default:
- y2error( "Unknown result for setProperty( %s )", sym->symbol().c_str() );
+ y2error( "Unknown result for setProperty( %s )", propertyName.c_str() );
return YCPVoid();
}
}
- catch( YUIException & exception )
+ else if ( property->isTerm() ) // Very rare: UI::QueryWidget(`myTable, `Item("abc", 3) )
{
- YUI_CAUGHT( exception );
- ycperror( "UI::QueryWidget() failed for property %s of %s with ID %s",
- property->toString().c_str(),
- widget->widgetClass(),
- id->toString().c_str() );
-
- return YCPVoid();
+ return YCPPropertyHandler::getComplexProperty( widget, property->asTerm() );
+ }
+ else
+ {
+ YUI_THROW( YUIException( "Bad QueryWidget args" ) );
}
}
+ catch( YUIException & exception )
+ {
+ YUI_CAUGHT( exception );
+ ycperror( "UI::QueryWidget() failed for property %s of %s with ID %s",
+ property->toString().c_str(),
+ widget->widgetClass(),
+ id->toString().c_str() );
+ }
}
- else
- return widget->queryWidgetTerm( property->asTerm() );
+
+ return YCPVoid();
}
@@ -1094,7 +1102,7 @@
if ( ! child->hasParent() )
child->setParent( replacePoint );
-
+
replacePoint->showChild();
#if VERBOSE_REPLACE_WIDGET
Modified: branches/tmp/sh/mod-ui/qt/src/QY2ListView.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/QY2ListView.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/QY2ListView.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/QY2ListView.cc Fri Oct 5 17:53:40 2007
@@ -30,6 +30,7 @@
, _mousePressedItem(0)
, _mousePressedCol( -1 )
, _mousePressedButton( NoButton )
+ , _sortByInsertionSequence( false )
, _nextSerial(0)
, _mouseButton1PressedInHeader( false )
, _finalSizeChangeExpected( false )
@@ -233,7 +234,7 @@
if ( item && item->isEnabled() )
{
int col = header()->sectionAt( ev->pos().x() );
- emit( columnDoubleClicked( ev->button(), ( QY2ListViewItem * ) item, col, ev->globalPos() ) );
+ emit( columnDoubleClicked( ev->button(), (QY2ListViewItem *) item, col, ev->globalPos() ) );
}
// invalidate last click data
@@ -310,25 +311,29 @@
}
+bool
+QY2ListView::setSortByInsertionSequence( bool sortByInsertionSequence )
+{
+ _sortByInsertionSequence = sortByInsertionSequence;
+ sort();
+}
+
+
QY2ListViewItem::QY2ListViewItem( QY2ListView * parentListView,
- const QString & text,
- bool sortByInsertionSequence )
+ const QString & text )
: QListViewItem( parentListView, text )
- , _sortByInsertionSequence( sortByInsertionSequence )
{
_serial = parentListView->nextSerial();
}
QY2ListViewItem::QY2ListViewItem( QListViewItem * parentItem,
- const QString & text,
- bool sortByInsertionSequence )
+ const QString & text )
: QListViewItem( parentItem, text )
- , _sortByInsertionSequence( sortByInsertionSequence )
{
_serial = 0;
@@ -357,7 +362,13 @@
int col,
bool ascending ) const
{
- if ( sortByInsertionSequence() )
+ bool sortByInsertionSequence = false;
+ QY2ListView * parentListView = dynamic_cast (listView());
+
+ if ( parentListView )
+ sortByInsertionSequence = parentListView->sortByInsertionSequence();
+
+ if ( sortByInsertionSequence )
{
QY2ListViewItem * other = dynamic_cast (otherListViewItem);
@@ -407,53 +418,36 @@
QY2CheckListItem::QY2CheckListItem( QY2ListView * parentListView,
const QString & text,
- QCheckListItem::Type type,
- bool sortByInsertionSequence )
+ QCheckListItem::Type type )
: QCheckListItem( parentListView, text, type )
- , _sortByInsertionSequence( sortByInsertionSequence )
{
- _serial = 0;
-
- if ( _sortByInsertionSequence )
- _serial = parentListView->nextSerial();
+ _serial = parentListView->nextSerial();
}
QY2CheckListItem::QY2CheckListItem( QListViewItem * parentItem,
const QString & text,
- QCheckListItem::Type type,
- bool sortByInsertionSequence )
+ QCheckListItem::Type type )
: QCheckListItem( parentItem, text, type )
- , _sortByInsertionSequence( sortByInsertionSequence )
{
_serial = 0;
+ QY2ListView * parentListView = dynamic_cast ( listView() );
- if ( _sortByInsertionSequence )
- {
- QY2ListView * parentListView = dynamic_cast ( listView() );
-
- if ( parentListView )
- _serial = parentListView->nextSerial();
- }
+ if ( parentListView )
+ _serial = parentListView->nextSerial();
}
QY2CheckListItem::QY2CheckListItem( QCheckListItem * parentItem,
const QString & text,
- QCheckListItem::Type type,
- bool sortByInsertionSequence )
+ QCheckListItem::Type type )
: QCheckListItem( parentItem, text, type )
- , _sortByInsertionSequence( sortByInsertionSequence )
{
_serial = 0;
+ QY2ListView * parentListView = dynamic_cast ( listView() );
- if ( _sortByInsertionSequence )
- {
- QY2ListView * parentListView = dynamic_cast ( listView() );
-
- if ( parentListView )
- _serial = parentListView->nextSerial();
- }
+ if ( parentListView )
+ _serial = parentListView->nextSerial();
}
@@ -475,7 +469,13 @@
int col,
bool ascending ) const
{
- if ( sortByInsertionSequence() )
+ bool sortByInsertionSequence = false;
+ QY2ListView * parentListView = dynamic_cast (listView());
+
+ if ( parentListView )
+ sortByInsertionSequence = parentListView->sortByInsertionSequence();
+
+ if ( sortByInsertionSequence )
{
QY2CheckListItem * other = dynamic_cast (otherListViewItem);
Modified: branches/tmp/sh/mod-ui/qt/src/QY2ListView.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/QY2ListView.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/QY2ListView.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/QY2ListView.h Fri Oct 5 17:53:40 2007
@@ -128,6 +128,19 @@
virtual QString toolTip( QListViewItem * item, int column );
/**
+ * Returns 'true' if the sort order should always be the item insertion
+ * order, 'false' if the user can change the sort order by clicking on a
+ * column header.
+ **/
+ bool sortByInsertionSequence() const { return _sortByInsertionSequence; }
+
+ /**
+ * Enforce sorting by item insertion order (true) or let user change
+ * sorting by clicking on a column header (false).
+ **/
+ virtual bool setSortByInsertionSequence( bool sortByInsertionSequence );
+
+ /**
* Returns the next free serial number for items that want to be ordered in
* insertion sequence.
**/
@@ -184,6 +197,7 @@
int _mousePressedButton;
std::vector<int> _savedColumnWidth;
+ bool _sortByInsertionSequence;
int _nextSerial;
QY2ListViewToolTip * _toolTip;
@@ -202,26 +216,16 @@
/**
* Constructor for toplevel items.
- *
- * 'sortByInsertionSequence' indicates if this item keeps the insertion
- * order ( true ) or leaves sorting to the user ( false - sort-by-click on
- * column headers ).
- **/
- QY2ListViewItem( QY2ListView * parentListView,
- const QString & text = QString::null,
- bool sortByInsertionSequence = false );
+ **/
+ QY2ListViewItem( QY2ListView * parentListView,
+ const QString & text = QString::null );
/**
* Constructor for deeper level items.
- *
- * 'sortByInsertionSequence' indicates if this item keeps the insertion
- * order ( true ) or leaves sorting to the user ( false - sort-by-click on
- * column headers ).
- **/
- QY2ListViewItem( QListViewItem * parentItem,
- const QString & text = QString::null,
- bool sortByInsertionSequence = false );
+ **/
+ QY2ListViewItem( QListViewItem * parentItem,
+ const QString & text = QString::null );
/**
* Destructor
@@ -264,18 +268,6 @@
int serial() const { return _serial; }
/**
- * Returns true if this item sorts itself by insertion sequence.
- **/
- bool sortByInsertionSequence() const { return _sortByInsertionSequence; }
-
- /**
- * Set sort policy: 'true' to sort by insertion sequence, 'false' for user
- * sort-by-click on column headers.
- **/
- void setSortByInsertionSequence( bool doit )
- { _sortByInsertionSequence = doit; }
-
- /**
* Set the text foreground color for all columns.
* For more specific purposes reimiplement paintCell().
**/
@@ -317,7 +309,6 @@
//
int _serial;
- bool _sortByInsertionSequence;
QColor _textColor;
QColor _backgroundColor;
@@ -334,41 +325,26 @@
/**
* Constructor for toplevel items.
- *
- * 'sortByInsertionSequence' indicates if this item keeps the insertion
- * order ( true ) or leaves sorting to the user ( false - sort-by-click on
- * column headers ).
**/
QY2CheckListItem( QY2ListView * parentListView,
const QString & text,
- QCheckListItem::Type type,
- bool sortByInsertionSequence = false );
+ QCheckListItem::Type type );
/**
* Constructor for deeper level items.
- *
- * 'sortByInsertionSequence' indicates if this item keeps the insertion
- * order ( true ) or leaves sorting to the user ( false - sort-by-click on
- * column headers ).
**/
QY2CheckListItem( QListViewItem * parentItem,
const QString & text,
- QCheckListItem::Type type,
- bool sortByInsertionSequence = false );
+ QCheckListItem::Type type );
/**
* Constructor for deeper level items for QCheckListItem parents.
- *
- * 'sortByInsertionSequence' indicates if this item keeps the insertion
- * order ( true ) or leaves sorting to the user ( false - sort-by-click on
- * column headers ).
**/
QY2CheckListItem( QCheckListItem * parentItem,
const QString & text,
- QCheckListItem::Type type,
- bool sortByInsertionSequence = false );
+ QCheckListItem::Type type );
/**
* Destructor
@@ -411,18 +387,6 @@
int serial() const { return _serial; }
/**
- * Returns true if this item sorts itself by insertion sequence.
- **/
- bool sortByInsertionSequence() const { return _sortByInsertionSequence; }
-
- /**
- * Set sort policy: 'true' to sort by insertion sequence, 'false' for user
- * sort-by-click on column headers.
- **/
- void setSortByInsertionSequence( bool doit )
- { _sortByInsertionSequence = doit; }
-
- /**
* Set the text foreground color for all columns.
* For more specific purposes reimiplement paintCell().
**/
@@ -464,7 +428,6 @@
//
int _serial;
- bool _sortByInsertionSequence;
QColor _textColor;
QColor _backgroundColor;
@@ -501,11 +464,11 @@
**/
virtual void maybeTip( const QPoint & p );
-
+
//
// Data members
//
-
+
QY2ListView * _listView;
};
Modified: branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.h Fri Oct 5 17:53:40 2007
@@ -117,7 +117,9 @@
virtual bool setKeyboardFocus();
/**
- * Event filter - inherited from QWidget
+ * Event filter.
+ *
+ * Reimplemented from QWidget.
**/
bool eventFilter( QObject * obj, QEvent * ev );
Modified: branches/tmp/sh/mod-ui/qt/src/YQTable.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQTable.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQTable.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQTable.cc Fri Oct 5 17:53:40 2007
@@ -16,8 +16,6 @@
/-*/
-#include
-#include
#include
#define y2log_component "qt-ui"
#include
@@ -25,264 +23,313 @@
#include "utf8.h"
#include "YQUI.h"
#include "YEvent.h"
-#include "YQTable.h"
#include "YQSignalBlocker.h"
+#include "YUIException.h"
+#include "QY2ListView.h"
+#include "YQTable.h"
-class YQListViewItem : public QListViewItem
+YQTable::YQTable( YWidget * parent,
+ int columns )
+ : QVBox( (QWidget *) parent->widgetRep() )
+ , YTable( parent, columns )
{
-public:
-
- int index;
+ setWidgetRep( this );
+ setMargin( YQWidgetMargin );
- /**
- * Constructor for auto-sorting
- **/
- YQListViewItem( YQTable * table,
- QListView * list_view,
- int index );
+ _qt_listView = new QY2ListView( this );
+ YUI_CHECK_NEW( _qt_listView );
- /**
- * Constructor for maintaining insertion order.
- * 'after' is the item this one is to be inserted after.
- **/
- YQListViewItem( YQTable * table,
- QListView * list_view,
- YQListViewItem * after,
- int index );
+ for ( int i=0; i < columns; i++ )
+ _qt_listView->addColumn( "" ); // Headers are not known yet
-protected:
+ _qt_listView->setAllColumnsShowFocus( true );
- YQTable * table;
-};
+ connect( _qt_listView, SIGNAL( doubleClicked ( QListViewItem * ) ),
+ this, SLOT ( slotActivated ( QListViewItem * ) ) );
+ connect( _qt_listView, SIGNAL( spacePressed ( QListViewItem * ) ),
+ this, SLOT ( slotActivated ( QListViewItem * ) ) );
-YQListViewItem::YQListViewItem( YQTable * table,
- QListView * list_view,
- int index )
- : QListViewItem( list_view )
- , index( index )
- , table( table )
-{
+ connect( _qt_listView, SIGNAL( selectionChanged ( QListViewItem * ) ),
+ this, SLOT ( slotSelected ( QListViewItem * ) ) );
}
-YQListViewItem::YQListViewItem( YQTable * table,
- QListView * list_view,
- YQListViewItem * after,
- int index )
- : QListViewItem( list_view, after )
- , index( index )
- , table( table )
+YQTable::~YQTable()
{
+ // NOP
}
-YQTable::YQTable( QWidget * parent,
- const YWidgetOpt & opt,
- vector<string> header )
- : QVBox( parent )
- , YTable( opt, header.size() )
- , _last_item(0)
+void
+YQTable::setHeader( int column, const string & text )
{
- _sort_by_insertion_order = true;
- _enable_user_sort = ! opt.keepSorting.value();
- setWidgetRep( this );
- setMargin( YQWidgetMargin );
-
- _qt_listview = new QListView( this );
+ YTable::setHeader( column, text );
-
- if ( ! _enable_user_sort )
+ if ( hasColumn( column ) )
{
- y2debug( "User sorting disabled" );
- _qt_listview->setSorting( -1, true ); // disable sorting by click
+ _qt_listView->header()->setLabel( column, fromUTF8( text ) );
+ _qt_listView->adjustColumn( column );
}
- else
- {
- connect( _qt_listview->header(), SIGNAL( clicked (int) ),
- this, SLOT ( userSort(int) ) );
- _qt_listview->setSorting( 65530, true ); // leave initial sorting
- }
-
- // The header is a vector of strings, each defining one
- // column. The first string is one of the characters L, R or C
- // denoting left, right or center justification, resp.
+}
- for ( unsigned c=0; c < header.size(); c++ )
- {
- _qt_listview->addColumn( fromUTF8(header[c].substr(1 ) ) );
- switch ( header[c][0] )
- {
- case 'R':
- _qt_listview->setColumnAlignment( c, AlignRight );
- break;
- case 'C':
- _qt_listview->setColumnAlignment( c, AlignCenter );
- break;
- case 'L':
- default:
- _qt_listview->setColumnAlignment( c, AlignLeft );
- break;
- }
- }
- _qt_listview->setAllColumnsShowFocus( true );
+void
+YQTable::setAlignment( int column, YTable::Alignment alignment )
+{
+ YTable::setAlignment( column, alignment );
- if ( opt.notifyMode.value() )
+ if ( hasColumn( column ) )
{
- connect( _qt_listview, SIGNAL( doubleClicked ( QListViewItem * ) ), this, SLOT( slotActivated( QListViewItem * ) ) );
- connect( _qt_listview, SIGNAL( spacePressed ( QListViewItem * ) ), this, SLOT( slotActivated( QListViewItem * ) ) );
+ int qt_alignment = Qt::Left;
- if ( opt.immediateMode.value() )
+ switch ( alignment )
{
- connect( _qt_listview, SIGNAL( selectionChanged ( QListViewItem * ) ),
- this, SLOT ( slotSelected ( QListViewItem * ) ) );
+ case YTable::Left: qt_alignment = Qt::AlignLeft; break;
+ case YTable::Center: qt_alignment = Qt::AlignCenter; break;
+ case YTable::Right: qt_alignment = Qt::AlignRight; break;
}
+ _qt_listView->setColumnAlignment( column, qt_alignment );
}
}
-void YQTable::userSort( int column ) // column
+void
+YQTable::setKeepSorting( bool keepSorting )
{
- if ( _enable_user_sort )
+ YTable::setKeepSorting( keepSorting );
+ _qt_listView->setSortByInsertionSequence( keepSorting );
+}
+
+
+void
+YQTable::addItem( YItem * yitem )
+{
+ YTableItem * item = dynamic_cast (yitem);
+ YUI_CHECK_PTR( item );
+
+ YTable::addItem( item );
+
+ YQTableListViewItem * clone = new YQTableListViewItem( this, _qt_listView, item );
+ YUI_CHECK_NEW( clone );
+
+ if ( item->selected() )
{
- _sort_by_insertion_order = false;
+ YQSignalBlocker sigBlocker( _qt_listView );
+ _qt_listView->setSelected( clone, true );
}
}
-int YQTable::preferredWidth()
+void
+YQTable::selectItem( YItem * yitem, bool selected )
{
- // Arbitrary value.
- // Use a MinSize widget to set a size that is useful for the application.
+ YQSignalBlocker sigBlocker( _qt_listView );
+
+ YTableItem * item = dynamic_cast (yitem);
+ YUI_CHECK_PTR( item );
- return 30;
+ YQTableListViewItem * clone = (YQTableListViewItem *) item->data();
+ YUI_CHECK_PTR( clone );
+
+ if ( ! selected && clone == _qt_listView->selectedItem() )
+ {
+ deselectAllItems();
+ }
+ else
+ {
+ _qt_listView->setSelected( clone, true );
+ YTable::selectItem( item, selected );
+ }
}
-int YQTable::preferredHeight()
+void
+YQTable::deselectAllItems()
{
- // Arbitrary value.
- // Use a MinSize widget to set a size that is useful for the application.
+ YQSignalBlocker sigBlocker( _qt_listView );
- return 30;
+ YTable::deselectAllItems();
+ _qt_listView->clearSelection();
}
-void YQTable::setSize( int newWidth, int newHeight )
+void
+YQTable::deleteAllItems()
{
- resize( newWidth, newHeight );
+ _qt_listView->clear();
+ YTable::deleteAllItems();
}
-void YQTable::setEnabled( bool enabled )
+void
+YQTable::cellChanged( const YTableCell * cell )
{
- _qt_listview->setEnabled( enabled );
- _qt_listview->triggerUpdate();
- YWidget::setEnabled( enabled );
+ YTableItem * item = cell->parent();
+ YUI_CHECK_PTR( item );
+
+ YQTableListViewItem * clone = (YQTableListViewItem *) item->data();
+ YUI_CHECK_PTR( clone );
+
+ clone->updateCell( cell );
}
-void YQTable::itemAdded( vector<string> elements, int index )
+void
+YQTable::selectOrigItem( QListViewItem * listViewItem )
{
- YQListViewItem * item;
-
- if ( _sort_by_insertion_order && _last_item )
- item = new YQListViewItem( this, _qt_listview, _last_item, index );
- else
- item = new YQListViewItem( this, _qt_listview, index );
+ if ( listViewItem )
+ {
+ YQTableListViewItem * tableListViewItem = dynamic_cast (listViewItem);
+ YUI_CHECK_PTR( tableListViewItem );
- _last_item = item;
+ YTable::selectItem( tableListViewItem->origItem(), true );
+ }
+}
- for ( unsigned int i=0; i < elements.size(); i++ )
- item->setText( i, fromUTF8( elements[i] ) );
- if ( ! _qt_listview->selectedItem() )
+void
+YQTable::slotSelected( QListViewItem * listViewItem )
+{
+ selectOrigItem( listViewItem );
+
+ if ( immediateMode() )
{
- YQSignalBlocker sigBlocker( _qt_listview );
- item->setSelected( true );
+ if ( ! YQUI::ui()->eventPendingFor( this ) )
+ {
+ // Avoid overwriting a (more important) Activated event with a SelectionChanged event
+
+ YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) );
+ }
}
}
-void YQTable::itemsCleared()
+
+void
+YQTable::slotActivated( QListViewItem * listViewItem )
{
- YQSignalBlocker sigBlocker( _qt_listview );
- _qt_listview->clear();
+ selectOrigItem( listViewItem );
+
+ if ( notify() )
+ YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) );
}
-void YQTable::cellChanged( int index, int colnum, const YCPString & newtext )
+void
+YQTable::setEnabled( bool enabled )
{
- QListViewItem * item = findItem( index );
- if ( item ) item->setText( colnum, fromUTF8( newtext->value() ) );
+ _qt_listView->setEnabled( enabled );
+ _qt_listView->triggerUpdate();
+ YWidget::setEnabled( enabled );
}
-int YQTable::getCurrentItem()
+
+int
+YQTable::preferredWidth()
{
- YQListViewItem * ci = ( YQListViewItem * )( _qt_listview->currentItem() );
- if ( ci ) return ci->index;
- else return -1;
+ // Arbitrary value.
+ // Use a MinSize widget to set a size that is useful for the application.
+
+ return 30;
}
-void YQTable::setCurrentItem( int index )
+int
+YQTable::preferredHeight()
{
- QListViewItem * item = findItem( index );
-
- if ( item ) // should be always true
- {
- YQSignalBlocker sigBlocker( _qt_listview );
-
- _qt_listview->setCurrentItem( item );
- _qt_listview->ensureItemVisible( item );
- }
+ // Arbitrary value.
+ // Use a MinSize widget to set a size that is useful for the application.
+
+ return 30;
}
-QListViewItem * YQTable::findItem( int index )
+void
+YQTable::setSize( int newWidth, int newHeight )
{
- // Scan all items and look for the one with the right index.
- QListViewItem * item = _qt_listview->firstChild();
- while ( item )
- {
- if ( ( ( YQListViewItem *)item )->index == index )
- return item;
- item = item->nextSibling();
- }
- return 0;
+ resize( newWidth, newHeight );
}
-bool YQTable::setKeyboardFocus()
+bool
+YQTable::setKeyboardFocus()
{
- _qt_listview->setFocus();
+ _qt_listView->setFocus();
return true;
}
-void YQTable::slotSelected( QListViewItem * )
-{
- if ( notify() )
- {
- if ( ! YQUI::ui()->eventPendingFor( this ) )
- {
- // Avoid overwriting a (more important) Activated event with a SelectionChanged event
- YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) );
- }
+
+
+
+YQTableListViewItem::YQTableListViewItem( YQTable * table,
+ QY2ListView * parent,
+ YTableItem * origItem )
+ : QY2ListViewItem( parent )
+ , _table( table )
+ , _origItem( origItem )
+{
+ YUI_CHECK_PTR( _table );
+ YUI_CHECK_PTR( _origItem );
+
+ _origItem->setData( this );
+
+ for ( YTableCellIterator it = _origItem->cellsBegin();
+ it != _origItem->cellsEnd();
+ ++it )
+ {
+ updateCell( *it );
}
+
+ if ( _origItem->selected() )
+ QY2ListViewItem::setSelected( true );
}
-void YQTable::slotActivated( QListViewItem * )
+void
+YQTableListViewItem::updateCell( const YTableCell * cell )
{
- if ( notify() )
- YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) );
+ if ( ! cell )
+ return;
+
+ int column = cell->column();
+
+ //
+ // Set label text
+ //
+
+ setText( column, fromUTF8( cell->label() ) );
+
+
+ //
+ // Set icon (if specified)
+ //
+
+ if ( cell->hasIconName() )
+ {
+ // _table is checked against 0 in the constructor
+
+ string iconName = _table->iconFullPath( cell->iconName() );
+ QPixmap icon = QPixmap( iconName.c_str() );
+
+ if ( icon.isNull() )
+ y2error( "Can't load icon %s", iconName.c_str() );
+ else
+ setPixmap( column, icon );
+ }
+ else // No pixmap name
+ {
+ if ( pixmap( column ) ) // Was there a pixmap before?
+ {
+ setPixmap( column, QPixmap() ); // Set empty pixmap
+ }
+ }
}
Modified: branches/tmp/sh/mod-ui/qt/src/YQTable.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQTable.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQTable.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQTable.h Fri Oct 5 17:53:40 2007
@@ -25,7 +25,7 @@
#include "YTable.h"
-class QListView;
+class QY2ListView;
class QListViewItem;
class YQListViewItem;
@@ -38,127 +38,176 @@
/**
* Constructor.
**/
- YQTable( QWidget * parent, const YWidgetOpt & opt, vector<string> header );
+ YQTable( YWidget * parent, int columns );
/**
- * Inherited from YWidget: Sets the enabled state of the
- * widget. All new widgets are enabled per definition. Only
- * enabled widgets can take user input.
+ * Destructor.
**/
- void setEnabled( bool enabled );
+ virtual ~YQTable();
/**
- * Preferred width of the widget.
+ * Set the header text for the specified column (counting from 0 on).
*
* Reimplemented from YWidget.
**/
- virtual int preferredWidth();
+ virtual void setHeader( int column, const string & text );
/**
- * Preferred height of the widget.
+ * Set the alignment for the specified column (counting from 0 on):
+ * YTable::Left, YTable::Center, YTable::Right
*
* Reimplemented from YWidget.
**/
- virtual int preferredHeight();
+ virtual void setAlignment( int column, YTable::Alignment alignment );
/**
- * Set the new size of the widget.
+ * Switch between sorting by item insertion order (keepSorting: true) or
+ * allowing the user to sort by an arbitrary column (by clicking on the
+ * column header).
*
- * Reimplemented from YWidget.
+ * Reimplemented from YTable.
**/
- virtual void setSize( int newWidth, int newHeight );
+ virtual void setKeepSorting( bool keepSorting );
/**
- * Notification that new items have been added.
+ * Add an item.
*
- * Reimplemented from YTable.
+ * Reimplemented from YSelectionWidget.
**/
- void itemAdded( vector<string> elements, int index );
+ virtual void addItem( YItem * item );
/**
- * Inherited from YTable. Is called, when alls items are cleared.
+ * Select or deselect an item.
+ *
+ * Reimplemented from YSelectionWidget.
**/
- void itemsCleared();
+ virtual void selectItem( YItem * item, bool selected = true );
/**
- * Inherited from YTable. is called, when the text of a cell has changed.
+ * Deselect all items.
+ *
+ * Reimplemented from YSelectionWidget.
**/
- void cellChanged( int index, int colnum, const YCPString & newtext );
+ virtual void deselectAllItems();
/**
- * Inherited from YTable. Returns the index of the currently
- * selected item or -1 if no item is selected.
+ * Delete all items.
+ *
+ * Reimplemented from YSelectionWidget.
**/
- int getCurrentItem();
+ virtual void deleteAllItems();
/**
- * Inherited from YTable. Makes another item selected.
+ * Notification that a cell (its text and/or its icon) was changed from the
+ * outside. Applications are required to call this whenever a table cell is
+ * changed after adding the corresponding table item (the row) to the table
+ * widget.
+ *
+ * Reimplemented from YTable.
**/
- void setCurrentItem( int index );
+ virtual void cellChanged( const YTableCell * cell );
/**
- * Accept the keyboard focus.
+ * Set enabled/disabled state.
+ *
+ * Reimplemented from YWidget.
**/
- virtual bool setKeyboardFocus();
+ virtual void setEnabled( bool enabled );
/**
- * Returns 'true' if items should be ordered by insertion order
+ * Preferred width of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- bool sortByInsertionOrder() const { return _sort_by_insertion_order; }
+ virtual int preferredWidth();
+ /**
+ * Preferred height of the widget.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual int preferredHeight();
+
+ /**
+ * Set the new size of the widget.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setSize( int newWidth, int newHeight );
+
+ /**
+ * Accept the keyboard focus.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual bool setKeyboardFocus();
protected slots:
/**
- * Notification that an item is selected.
- * Only relevant if `opt(`notify, `immediate) is set.
+ * Notification that an item is selected (single click or keyboard).
**/
void slotSelected( QListViewItem * );
/**
- * Notification that an item is activated.
- * Only relevant if `opt(`notify) is set.
+ * Notification that an item is activated (double click or keyboard).
**/
void slotActivated( QListViewItem * );
+protected:
+
/**
- * Notification that the user wishes to change the sort order.
+ * Select the original item (the YTableItem) that corresponds to the
+ * specified listViewItem.
**/
- void userSort( int column );
+ void selectOrigItem( QListViewItem * listViewItem );
+ //
+ // Data members
+ //
-protected:
- /**
- * Helper function. Find item with given id.
- **/
- QListViewItem * findItem( int index );
+ QY2ListView * _qt_listView;
+};
+
+
+
+/**
+ * Visual representation of a YTableItem.
+ **/
+class YQTableListViewItem: public QY2ListViewItem
+{
+public:
/**
- * The Qt widget representing the table
+ * Constructor.
**/
- QListView * _qt_listview;
+ YQTableListViewItem( YQTable * table,
+ QY2ListView * parent,
+ YTableItem * origItem );
-
- //
- // Data members
- //
-
/**
- * Sorting strategy
+ * Return the parent table widget.
**/
- bool _sort_by_insertion_order;
+ YQTable * table() const { return _table; }
/**
- * Flag: User may re-sort the table by clicking on a header?
+ * Return the corresponding YTableItem.
**/
- bool _enable_user_sort;
+ YTableItem * origItem() const { return _origItem; }
/**
- * For maintaining insertion order
+ * Update this item's display with the content of 'cell'.
**/
- YQListViewItem * _last_item;
+ void updateCell( const YTableCell * cell );
+
+protected:
+
+ YQTable * _table;
+ YTableItem * _origItem;
};
+
+
#endif // YQLabel_h
Modified: branches/tmp/sh/mod-ui/qt/src/YQTree.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQTree.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQTree.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQTree.cc Fri Oct 5 17:53:40 2007
@@ -131,8 +131,7 @@
if ( ! selected && yqTreeItem == _qt_listView->selectedItem() )
{
- _qt_listView->clearSelection();
- YTree::deselectAllItems();
+ deselectAllItems();
}
else
{
Modified: branches/tmp/sh/mod-ui/qt/src/YQUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQUI.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQUI.h Fri Oct 5 17:53:40 2007
@@ -82,7 +82,7 @@
/**
* Create the widget factory that provides all the createXY() methods for
* optional ("special") widgets and the corresponding hasXYWidget()
- * methods.
+ * methods.
*
* Reimplemented from YUI.
**/
@@ -94,9 +94,9 @@
* Reimplemented from YUI.
**/
virtual YApplication * createApplication();
-
+
public:
-
+
/**
* Returns the UI's default font.
**/
@@ -435,7 +435,6 @@
YWidget * createIntField ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int minValue, int maxValue, int initialValue);
YWidget * createLogView ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int visibleLines, int maxLines );
YWidget * createMenuButton ( YWidget * parent, YWidgetOpt & opt, const YCPString & label);
- YWidget * createTable ( YWidget * parent, YWidgetOpt & opt, vector<string> header);
/*** Widget creation methods for optional widgets, all reimplemented from YUI ***/
Modified: branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc Fri Oct 5 17:53:40 2007
@@ -107,14 +107,6 @@
}
-YWidget * YQUI::createTable ( YWidget * parent,
- YWidgetOpt & opt,
- vector<string> header )
-{
- return new YQTable( (QWidget *) ( parent->widgetRep() ), opt, header);
-}
-
-
YWidget * YQUI::createIntField ( YWidget * parent,
YWidgetOpt & opt,
const YCPString & label,
Modified: branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc Fri Oct 5 17:53:40 2007
@@ -174,7 +174,7 @@
{
YQTree * tree = new YQTree( parent, label );
YUI_CHECK_NEW( tree );
-
+
return tree;
}
@@ -183,7 +183,10 @@
YQTable *
YQWidgetFactory::createTable( YWidget * parent, int columns )
{
- return 0; // FIXME: TO DO
+ YQTable * table = new YQTable( parent, columns );
+ YUI_CHECK_NEW( table );
+
+ return table;
}
@@ -193,7 +196,7 @@
{
YQProgressBar * progressBar = new YQProgressBar( parent, label, maxValue );
YUI_CHECK_NEW( progressBar );
-
+
return progressBar;
}
@@ -236,7 +239,7 @@
{
YQMultiLineEdit * multiLineEdit = new YQMultiLineEdit( parent, label );
YUI_CHECK_NEW( multiLineEdit );
-
+
return multiLineEdit;
}
Modified: branches/tmp/sh/mod-ui/qt/src/YQWizard.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWizard.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQWizard.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQWizard.cc Fri Oct 5 17:53:40 2007
@@ -824,9 +824,11 @@
_tree = new QY2ListView( vbox );
YUI_CHECK_NEW( _tree );
+
_tree->addColumn( "" );
_tree->header()->hide();
_tree->setRootIsDecorated( true );
+ _tree->setSortByInsertionSequence( true );
connect( _tree, SIGNAL( selectionChanged ( void ) ),
this, SLOT ( treeSelectionChanged ( void ) ) );
Modified: branches/tmp/sh/mod-ui/qt/src/YQWizard.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWizard.h?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQWizard.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQWizard.h Fri Oct 5 17:53:40 2007
@@ -695,14 +695,14 @@
TreeItem( QY2ListView * parent,
const QString & text,
const QString & id )
- : QY2ListViewItem( parent, text, true )
+ : QY2ListViewItem( parent, text )
, _id( id )
{}
TreeItem( YQWizard::TreeItem * parent,
const QString & text,
const QString & id )
- : QY2ListViewItem( parent, text, true )
+ : QY2ListViewItem( parent, text )
, _id( id )
{}
Modified: branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgConflictList.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgConflictList.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgConflictList.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgConflictList.cc Fri Oct 5 17:53:40 2007
@@ -59,6 +59,7 @@
{
addColumn( _( "Dependency Conflict" ) );
setRootIsDecorated( true );
+ setSortByInsertionSequence( true );
}
@@ -251,7 +252,7 @@
if ( ! header.isEmpty() )
{
- parent = new QY2ListViewItem( parent, header, true );
+ parent = new QY2ListViewItem( parent, header );
CHECK_PTR( parent );
parent->setOpen( true );
}
@@ -273,7 +274,7 @@
int more = lines.size() - count + 1;
QString text = ( _( "%1 more..." ) ).arg( more );
- QY2ListViewItem * sublist = new QY2ListViewItem( parent, text, true );
+ QY2ListViewItem * sublist = new QY2ListViewItem( parent, text );
didSplit = true;
if ( sublist )
@@ -283,7 +284,7 @@
}
}
- new QY2ListViewItem( parent, *it, true );
+ new QY2ListViewItem( parent, *it );
++it;
}
}
@@ -329,8 +330,7 @@
// Heading for the choices
// how to resolve this conflict
_( "Conflict Resolution:" ),
- QCheckListItem::Controller,
- true );
+ QCheckListItem::Controller );
CHECK_PTR( _resolutionsHeader );
_resolutionsHeader->setOpen( true );
_resolutionsHeader->setBackgroundColor( LIGHT_GREY );
@@ -392,8 +392,7 @@
zypp::ProblemSolution_Ptr solution )
: QY2CheckListItem( parent,
fromUTF8( solution->description() ),
- QCheckListItem::RadioButton,
- true )
+ QCheckListItem::RadioButton )
, _solution( solution )
{
YQPkgConflictList::dumpList( this, fromUTF8( solution->details() ) );
Modified: branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgObjList.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgObjList.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgObjList.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgObjList.cc Fri Oct 5 17:53:40 2007
@@ -102,7 +102,7 @@
const QString & summary,
FSize size )
{
- QY2ListViewItem * item = new QY2ListViewItem( this, QString::null, true );
+ QY2ListViewItem * item = new QY2ListViewItem( this, QString::null );
if ( item )
{
Modified: branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgVersionsView.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgVersionsView.cc?rev=41269&r1=41268&r2=41269&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgVersionsView.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/pkg/YQPkgVersionsView.cc Fri Oct 5 17:53:40 2007
@@ -61,6 +61,8 @@
_nameCol = _versionCol;
_summaryCol = _repoCol;
+ setSortByInsertionSequence( true );
+
// saveColumnWidths(); // Minimize column widths
// header()->hide();
@@ -117,7 +119,7 @@
return;
QY2CheckListItem * root = new QY2CheckListItem( this, selectable->theObj()->name().c_str(),
- QCheckListItem::Controller, true );
+ QCheckListItem::Controller );
CHECK_PTR( root );
root->setOpen( true );
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org