[yast-commit] r39223 - in /branches/tmp/sh/mod-ui: core/libyui/src/ qt/src/
Author: sh-sh-sh Date: Fri Jul 6 18:44:27 2007 New Revision: 39223 URL: http://svn.opensuse.org/viewcvs/yast?rev=39223&view=rev Log: ported YTree Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItem.h branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.h branches/tmp/sh/mod-ui/core/libyui/src/YItem.cc branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.cc branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.h Modified: 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/YApplication.cc branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc branches/tmp/sh/mod-ui/core/libyui/src/YCPItem.h 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/YCheckBox.cc branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc branches/tmp/sh/mod-ui/core/libyui/src/YFrame.cc branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc branches/tmp/sh/mod-ui/core/libyui/src/YItem.h branches/tmp/sh/mod-ui/core/libyui/src/YLabel.cc branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc branches/tmp/sh/mod-ui/core/libyui/src/YMultiSelectionBox.cc branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc branches/tmp/sh/mod-ui/core/libyui/src/YRichText.cc branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.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/YTree.cc branches/tmp/sh/mod-ui/core/libyui/src/YTree.h branches/tmp/sh/mod-ui/core/libyui/src/YUI.h branches/tmp/sh/mod-ui/core/libyui/src/YUI_builtins.cc branches/tmp/sh/mod-ui/qt/src/Makefile.am branches/tmp/sh/mod-ui/qt/src/YQApplication.cc branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc branches/tmp/sh/mod-ui/qt/src/YQComboBox.h branches/tmp/sh/mod-ui/qt/src/YQInputField.cc branches/tmp/sh/mod-ui/qt/src/YQIntField.cc branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc branches/tmp/sh/mod-ui/qt/src/YQPartitionSplitter.cc branches/tmp/sh/mod-ui/qt/src/YQRadioButton.cc branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc branches/tmp/sh/mod-ui/qt/src/YQSlider.cc branches/tmp/sh/mod-ui/qt/src/YQTable.cc branches/tmp/sh/mod-ui/qt/src/YQTree.cc branches/tmp/sh/mod-ui/qt/src/YQTree.h branches/tmp/sh/mod-ui/qt/src/YQUI.h branches/tmp/sh/mod-ui/qt/src/YQUI_builtins.cc 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 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Fri Jul 6 18:44:27 2007 @@ -318,6 +318,8 @@ functions each - see the respective header files. See the YQ sample implementations for more details. +* YComboBox now also supports icons. + 2007-07-03 16:30 sh@suse.de @@ -328,3 +330,8 @@ * Ported YProgressBar - renamed setProgress() -> setValue() + + +2007-07-06 18:30 sh@suse.de + +* Ported YTree 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Fri Jul 6 18:44:27 2007 @@ -11,23 +11,25 @@ libyui_la_SOURCES = \ YApplication.cc \ - YWidget.cc \ + YCPDialogParser.cc \ + YCPItemParser.cc \ + YCPTreeItemParser.cc \ + YCPPropertyHandler.cc \ + YCPValueWidgetID.cc \ + YItem.cc \ + YProperty.cc \ YUIComponent.cc \ - YUI_core.cc \ + YUIException.cc \ + YUIPlugin.cc \ + YUI_bindings.cc \ YUI_builtins.cc \ + YUI_core.cc \ YUI_special_widgets.cc \ - YUI_bindings.cc \ YUI_util.cc \ - YUIPlugin.cc \ - YUIException.cc \ - YProperty.cc \ + YWidget.cc \ YWidgetFactory.cc \ YOptionalWidgetFactory.cc \ YWidgetID.cc \ - YCPValueWidgetID.cc \ - YCPDialogParser.cc \ - YCPItemParser.cc \ - YCPPropertyHandler.cc \ \ YAlignment.cc \ YBarGraph.cc \ @@ -87,6 +89,8 @@ YCPDialogParser.h \ YCPItem.h \ YCPItemParser.h \ + YCPTreeItem.h \ + YCPTreeItemParser.h \ YCPPropertyHandler.h \ YCPValueWidgetID.h \ YCP_UI_Exception.h \ Modified: branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YApplication.cc Fri Jul 6 18:44:27 2007 @@ -26,7 +26,7 @@ struct YApplicationPrivate { - int dummy; + string iconBasePath; }; @@ -53,3 +53,17 @@ return dialog->findWidget( id, doThrow ); } + + +string +YApplication::iconBasePath() const +{ + return priv->iconBasePath; +} + + +void YApplication::setIconBasePath( const string & newIconBasePath ) +{ + priv->iconBasePath = newIconBasePath; +} + Modified: branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YApplication.h Fri Jul 6 18:44:27 2007 @@ -19,12 +19,17 @@ #ifndef YApplication_h +#include <string> +#include "YUI.h" #include "ImplPtr.h" +using std::string; + class YWidget; class YWidgetID; class YApplicationPrivate; + /** * Class for application-wide values and functions. * This is a singleton. Access and create it via its static functions. @@ -42,7 +47,19 @@ **/ YWidget * findWidget( YWidgetID * id, bool doThrow = true ) const; - + /** + * Get the base path for icons used by the UI. Selection widgets like + * YSelectionBox, YComboBox, etc. or YWizard prepend this to icon + * specifications that don't use an absolute path. + **/ + virtual string iconBasePath() const; + + /** + * Set the icon base path. + **/ + virtual void setIconBasePath( const string & newIconBasePath ); + + protected: friend class YUI; 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc Fri Jul 6 18:44:27 2007 @@ -33,6 +33,7 @@ #include "YWidget.h" #include "YCPValueWidgetID.h" #include "YCPItemParser.h" +#include "YCPTreeItemParser.h" #include "YDialog.h" #include "YUI_util.h" #include "YWidgetFactory.h" @@ -2023,11 +2024,11 @@ YCPDialogParser::parseTree( YWidget * parent, YWidgetOpt & opt, const YCPTerm & term, const YCPList & optList, int argnr ) { - int termSize = term->size() - argnr; + int numArgs = term->size() - argnr; - if ( termSize < 1 || termSize > 2 + if ( numArgs < 1 || numArgs > 2 || ! term->value( argnr )->isString() - || ( termSize >= 2 && ! term->value( argnr+1 )->isList() ) ) + || ( numArgs >= 2 && ! term->value( argnr+1 )->isList() ) ) { y2error( "Invalid arguments for the Tree widget: %s", term->toString().c_str() ); @@ -2035,26 +2036,20 @@ } rejectAllOptions( term,optList ); - YTree *tree = dynamic_cast<YTree *> ( YUI::ui()->createTree ( parent, opt, term->value ( argnr )->asString() ) ); - if ( tree && termSize > 1 ) - { - if ( ! term->value( argnr+1 )->isList() ) - { - y2error( "Expecting tree item list instead of: %s", - term->value( argnr+1 )->toString().c_str() ); + string label = term->value ( argnr )->asString()->value(); + + YTree * tree = YUI::widgetFactory()->createTree( parent, label ); - return 0; - } + if ( numArgs > 1 ) + { + YCPList itemList = term->value( argnr+1 )->asList(); + tree->addItems( YCPTreeItemParser::parseTreeItemList( itemList ) ); - if ( ! tree->parseItemList( term->value ( argnr+1 )->asList() ) ) - return 0; + if ( tree->hasItems() ) + tree->selectItem( tree->firstItem() ); } - if ( tree ) - tree->rebuildTree(); - - return tree; } Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPItem.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPItem.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPItem.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItem.h Fri Jul 6 18:44:27 2007 @@ -34,18 +34,18 @@ /** * Constructors **/ - YCPItem( const YCPString & label, - const YCPValue & id, - bool sel = false ) - : YItem( label->value(), sel ) + YCPItem( const YCPString & label, + const YCPValue & id, + bool selected = false ) + : YItem( label->value(), selected ) , _id( id ) {} - YCPItem( const YCPString & label, - const YCPValue & id, - const YCPString & iconName, - bool sel = false ) - : YItem( label->value(), iconName->value(), sel ) + YCPItem( const YCPString & label, + const YCPValue & id, + const YCPString & iconName, + bool selected = false ) + : YItem( label->value(), iconName->value(), selected ) , _id( id ) {} 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPItemParser.cc Fri Jul 6 18:44:27 2007 @@ -21,7 +21,6 @@ #include <ycp/YCPBoolean.h> #include "YCPItemParser.h" -#include "YCPItem.h" #include "YCP_UI_Exception.h" #include "YUISymbols.h" 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.cc Fri Jul 6 18:44:27 2007 @@ -19,11 +19,14 @@ /-*/ -#include <ycp/YCPVoid.h> -#include <ycp/YCPString.h> -#include <ycp/YCPInteger.h> #include <ycp/YCPBoolean.h> +#include <ycp/YCPInteger.h> +#include <ycp/YCPMap.h> +#include <ycp/YCPString.h> #include <ycp/YCPTerm.h> +#include <ycp/YCPVoid.h> + +#include <list> #define y2log_component "ui" #include <ycp/y2log.h> @@ -32,7 +35,9 @@ #include "YCPDialogParser.h" #include "YCPItem.h" +#include "YCPTreeItem.h" #include "YCPItemParser.h" +#include "YCPTreeItemParser.h" #include "YCPValueWidgetID.h" #include "YCheckBox.h" @@ -41,8 +46,10 @@ #include "YRadioButton.h" #include "YRadioButtonGroup.h" #include "YSelectionBox.h" +#include "YTree.h" #include "YUISymbols.h" +using std::list; bool @@ -56,15 +63,20 @@ { if ( trySetCheckBoxValue ( widget, val ) ) return true; if ( trySetSelectionBoxValue ( widget, val ) ) return true; + if ( trySetTreeValue ( widget, val ) ) return true; if ( trySetComboBoxValue ( widget, val ) ) return true; } else if ( propertyName == YUIProperty_CurrentItem ) { if ( trySetSelectionBoxValue ( widget, val ) ) return true; + if ( trySetTreeValue ( widget, val ) ) return true; } else if ( propertyName == YUIProperty_Items ) { - if ( trySetSelectionWidgetItems( widget, val ) ) return true; + // Make sure to try YTree before YSelectionWidget: YTree inherits YSelectionWidget! + + if ( trySetTreeItems ( widget, val ) ) return true; + if ( trySetSelectionWidgetItems ( widget, val ) ) return true; } else if ( propertyName == YUIProperty_CurrentButton ) { @@ -90,12 +102,14 @@ if ( propertyName == YUIProperty_Value ) { val = tryGetCheckBoxValue ( widget ); if ( ! val.isNull() ) return val; - val = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val; val = tryGetSelectionBoxValue ( widget ); if ( ! val.isNull() ) return val; + val = tryGetTreeValue ( 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 = tryGetComboBoxValue ( widget ); if ( ! val.isNull() ) return val; // tryGetMultiSelectionBoxCurrentItem @@ -108,12 +122,21 @@ { val = tryGetMultiSelectionBoxSelectedItems( widget ); if ( ! val.isNull() ) return val; } + else if ( propertyName == YUIProperty_OpenItems ) + { + val = tryGetTreeOpenItems ( widget ); if ( ! val.isNull() ) return val; + } + else if ( propertyName == YUIProperty_CurrentBranch ) + { + val = tryGetTreeCurrentBranch ( 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'", @@ -153,23 +176,65 @@ } -bool -YCPPropertyHandler::trySetSelectionBoxValue( YWidget * widget, const YCPValue & val ) +template<class Item_t> +Item_t * findItem( const YCPValue & wantedId, + YItemConstIterator begin, + YItemConstIterator end ) +{ + for ( YItemConstIterator it = begin; it != end; ++it ) + { + Item_t * item = dynamic_cast<Item_t *> (*it); + + if ( item && wantedId->equal( item->id() ) ) + return item; + + if ( (*it)->hasChildren() ) + { + Item_t * result = findItem<Item_t>( wantedId, + (*it)->childrenBegin(), + (*it)->childrenEnd() ); + + if ( result ) + return result; + } + } + + return 0; +} + + +template<class Item_t> +Item_t * findItem( YSelectionWidget * selWidget, const YCPValue & val ) +{ + YCPValue wantedId( val ); + + if ( val->isTerm() && val->asTerm()->name() == YUISymbol_id ) // `id(..) ? + { + wantedId = val->asTerm()->value(0); + } + + return findItem<Item_t>( wantedId, selWidget->itemsBegin(), selWidget->itemsEnd() ); +} + + + +template<class Widget_t, class Item_t> +bool trySetSelectionWidgetValue( YWidget * widget, const YCPValue & val ) { - YSelectionBox * selBox = dynamic_cast<YSelectionBox *> (widget); + Widget_t * selWidget = dynamic_cast<Widget_t *> (widget); - if ( ! selBox ) + if ( ! selWidget ) return false; - YCPItem * item = findItem( selBox, val ); + Item_t * item = findItem<Item_t>( selWidget, val ); if ( item ) { - selBox->selectItem( item, true ); + selWidget->selectItem( item, true ); } else { - y2error( "%s %s has no item with ID %s", + y2error( "%s \"%s\" has no item with ID %s", widget->widgetClass(), widget->debugLabel().c_str(), val->toString().c_str() ); @@ -180,6 +245,20 @@ bool +YCPPropertyHandler::trySetSelectionBoxValue( YWidget * widget, const YCPValue & val ) +{ + return trySetSelectionWidgetValue<YSelectionBox, YCPItem>( widget, val ); +} + + +bool +YCPPropertyHandler::trySetTreeValue( YWidget * widget, const YCPValue & val ) +{ + return trySetSelectionWidgetValue<YTree, YCPTreeItem>( widget, val ); +} + + +bool YCPPropertyHandler::trySetComboBoxValue( YWidget * widget, const YCPValue & val ) { YComboBox * comboBox = dynamic_cast<YComboBox *> (widget); @@ -187,7 +266,7 @@ if ( ! comboBox ) return false; - YCPItem * item = findItem( comboBox, val ); + YCPItem * item = findItem<YCPItem>( comboBox, val ); if ( item ) { @@ -214,27 +293,24 @@ } -YCPItem * -YCPPropertyHandler::findItem( YSelectionWidget * selWidget, const YCPValue & val ) +bool +YCPPropertyHandler::trySetTreeItems( YWidget * widget, const YCPValue & val ) { - YCPValue wantedId( val ); + YTree * tree = dynamic_cast<YTree *> (widget ); - if ( val->isTerm() && val->asTerm()->name() == YUISymbol_id ) // `id(..) ? - { - wantedId = val->asTerm()->value(0); - } + if ( ! tree ) + return false; - for ( YItemConstIterator it = selWidget->itemsBegin(); - it != selWidget->itemsEnd(); - ++it ) + if ( val->isList() ) { - YCPItem * item = dynamic_cast<YCPItem *> (*it); - - if ( item && wantedId->equal( item->id() ) ) - return item; + tree->setItems( YCPTreeItemParser::parseTreeItemList( val->asList() ) ); + return true; } - return 0; + YUI_THROW( YUIBadPropertyArgException( YProperty( YUIProperty_Items, + YOtherProperty ), + widget ) ); + return false; } @@ -312,7 +388,7 @@ for ( int i=0; i < itemIdList.size(); i++ ) { - YCPItem * item = findItem( multiSelBox, itemIdList->value( i ) ); + YCPItem * item = findItem<YCPItem>( multiSelBox, itemIdList->value( i ) ); if ( ! item ) { @@ -354,51 +430,59 @@ } - -YCPValue -YCPPropertyHandler::tryGetComboBoxValue( YWidget * widget ) +template<class Widget_t, class Item_t > YCPValue tryGetSelectionWidgetValue( YWidget * widget ) { - YComboBox * comboBox = dynamic_cast<YComboBox *> (widget); + Widget_t * selWidget = dynamic_cast<Widget_t *> (widget); - if ( ! comboBox ) + if ( ! selWidget ) return YCPNull(); - - YItem * selectedItem = comboBox->selectedItem(); + YItem * selectedItem = selWidget->selectedItem(); if ( selectedItem ) { - YCPItem * item = dynamic_cast<YCPItem *> (selectedItem); + Item_t * item = dynamic_cast<Item_t *> (selectedItem); if ( item ) return item->id(); + else + y2error( "Item is not a YCPItem: \"%s\"", selectedItem->label().c_str() ); } - return YCPString( comboBox->value() ); + return YCPVoid(); } YCPValue YCPPropertyHandler::tryGetSelectionBoxValue( YWidget * widget ) { - YSelectionBox * selBox = dynamic_cast<YSelectionBox *> (widget); + return tryGetSelectionWidgetValue<YSelectionBox, YCPItem>( widget ); +} - if ( ! selBox ) - return YCPNull(); - YItem * selectedItem = selBox->selectedItem(); +YCPValue +YCPPropertyHandler::tryGetTreeValue( YWidget * widget ) +{ + return tryGetSelectionWidgetValue<YTree, YCPTreeItem>( widget ); +} - if ( selectedItem ) + +YCPValue +YCPPropertyHandler::tryGetComboBoxValue( YWidget * widget ) +{ + YCPValue result = tryGetSelectionWidgetValue<YComboBox, YCPItem>( widget ); + + if ( ! result.isNull() && result->isVoid() ) { - YCPItem * item = dynamic_cast<YCPItem *> (selectedItem); + YComboBox * comboBox = dynamic_cast<YComboBox *> (widget); - if ( item ) - return item->id(); - else - return YCPString( selectedItem->label() ); + if ( ! comboBox ) + return YCPNull(); + + result = YCPString( comboBox->value() ); } - return YCPVoid(); + return result; } @@ -442,9 +526,9 @@ return YCPNull(); YCPList selectedItemsList; - YConstItemCollection selectedItems = multiSelBox->selectedItems(); + YItemCollection selectedItems = multiSelBox->selectedItems(); - for ( YConstItemConstIterator it = selectedItems.begin(); + for ( YItemIterator it = selectedItems.begin(); it != selectedItems.end(); ++it ) { @@ -463,3 +547,88 @@ return selectedItemsList; } + + +YCPValue +YCPPropertyHandler::tryGetTreeOpenItems( YWidget * widget ) +{ + YTree * tree = dynamic_cast<YTree *> (widget); + + if ( ! tree ) + return YCPNull(); + + YCPMap openItems; + getTreeOpenItems( openItems, tree->itemsBegin(), tree->itemsEnd() ); + + return openItems; +} + + +void +YCPPropertyHandler::getTreeOpenItems( YCPMap & openItems, + YItemConstIterator begin, + YItemConstIterator end ) +{ + for ( YItemConstIterator it = begin; it != end; ++it ) + { + YTreeItem * item = dynamic_cast<YTreeItem *> (*it); + + if ( item && item->isOpen() ) + { + YCPTreeItem * ycpTreeItem = dynamic_cast<YCPTreeItem *> (item); + + if ( ycpTreeItem && ycpTreeItem->hasId() ) + openItems.add( ycpTreeItem->id(), YCPString( "ID" ) ); + else + openItems.add( YCPString( item->label() ), YCPString( "Text" ) ); + + if ( item->hasChildren() ) + getTreeOpenItems( openItems, item->childrenBegin(), item->childrenEnd() ); + } + } +} + + +YCPValue +YCPPropertyHandler::tryGetTreeCurrentBranch( YWidget * widget ) +{ + YTree * tree = dynamic_cast<YTree *> (widget); + + if ( ! tree ) + return YCPNull(); + + // YTree::CurrentBranch: The path from the root to the current item as a + // list of IDs or, if an item doesn't have an ID, its label + // + // "/" -> `usr -> `share -> "doc" + // + // -> [ "/", `usr, `share, "doc" ] + + list<YTreeItem *> path; + YItem * item = tree->selectedItem(); + + if ( item ) + { + YTreeItem * treeItem = dynamic_cast<YTreeItem *> (item); + + while ( treeItem ) + { + path.push_front( treeItem ); // prepend list + treeItem = treeItem->parent(); + } + } + + YCPList currentBranch; + + for ( list<YTreeItem *>::iterator it = path.begin(); it != path.end(); ++it ) + { + YCPTreeItem * ycpTreeItem = dynamic_cast<YCPTreeItem *> (*it); + + if ( ycpTreeItem && ycpTreeItem->hasId() ) + currentBranch.add( ycpTreeItem->id() ); + else + currentBranch.add( YCPString( (*it)->label() ) ); + } + + return currentBranch; +} 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPPropertyHandler.h Fri Jul 6 18:44:27 2007 @@ -23,7 +23,9 @@ #define YCPPropertyHandler_h #include <ycp/YCPValue.h> +#include <ycp/YCPMap.h> #include <string> +#include "YItem.h" using std::string; @@ -63,16 +65,8 @@ **/ static YCPValue getComplexProperty( YWidget * widget, const string & propertyName ); - - /** - * Find a YSelectionWidget's (YSelectionBox, YComboBox, YMultiSelectionBox) - * item by its ID. If the ID is wrapped in `id(...), use the inner part of that. - * - * Return the item or 0 if there is no item with that ID. - **/ - static YCPItem * findItem( YSelectionWidget * selWidget, const YCPValue & id ); - + protected: /** @@ -83,7 +77,9 @@ **/ 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 trySetComboBoxValue ( YWidget * widget, const YCPValue & val ); + static bool trySetTreeItems ( 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 ); @@ -95,10 +91,22 @@ * They all return YCPNull upon failure and a non-null YCPValue upon success. **/ static YCPValue tryGetCheckBoxValue ( YWidget * widget ); - static YCPValue tryGetComboBoxValue ( YWidget * widget ); static YCPValue tryGetSelectionBoxValue ( YWidget * widget ); + static YCPValue tryGetTreeValue ( 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 ); + + + /** + * Helper function for tryGetTreeOpenItems(): Get any open tree items + * between iterators 'begin' and 'end' and add them to the 'openItems' map. + **/ + static void getTreeOpenItems( YCPMap & openItems, + YItemConstIterator begin, + YItemConstIterator end ); }; Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItem.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItem.h?rev=39223&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItem.h (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItem.h Fri Jul 6 18:44:27 2007 @@ -0,0 +1,123 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPTreeItem.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YCPTreeItem_h +#define YCPTreeItem_h + +#include <ycp/YCPValue.h> +#include <ycp/YCPString.h> +#include "YItem.h" + + +/** + * Tree item class with YCPValue IDs. + * + * Similar to YCPItem, but with YTreeItem as base class. There should be an + * elegant way to do this with templates, but the different constructor + * arguments make this difficult. + **/ +class YCPTreeItem: public YTreeItem +{ +public: + + /** + * Constructors + **/ + YCPTreeItem( const YCPString & label, + const YCPValue & id, + bool isOpen ) + : YTreeItem( label->value(), isOpen ) + , _id( id ) + {} + + YCPTreeItem( const YCPString & label, + const YCPValue & id, + const YCPString & iconName, + bool isOpen ) + : YTreeItem( label->value(), iconName->value(), isOpen ) + , _id( id ) + {} + + YCPTreeItem( YCPTreeItem * parent, + const YCPString & label, + const YCPValue & id, + bool isOpen ) + : YTreeItem( parent, label->value(), isOpen ) + , _id( id ) + {} + + YCPTreeItem( YCPTreeItem * parent, + const YCPString & label, + const YCPValue & id, + const YCPString & iconName, + bool isOpen ) + : YTreeItem( parent, label->value(), iconName->value(), isOpen ) + , _id( id ) + {} + + /** + * Destructor. + **/ + virtual ~YCPTreeItem() + {} + + /** + * Return 'true' if this item has an ID. + **/ + bool hasId() const { return ! _id.isNull() && ! _id->isVoid(); } + + /** + * Return this item's ID. + **/ + YCPValue id() const { return _id; } + + /** + * Set a new ID. + **/ + void setId( const YCPValue & newId ) { _id = newId; } + + /** + * Return this item's label as a YCPString. + **/ + YCPString label() const { return YCPString( YTreeItem::label() ); } + + /** + * Set this item's label with a YCPString. + **/ + void setLabel( const YCPString & newLabel ) + { YTreeItem::setLabel( newLabel->value() ); } + + /** + * Return this icon's icon name as a YCPString. + **/ + YCPString iconName() const { return YCPString( YTreeItem::iconName() ); } + + /** + * Set this icon's icon name with a YCPString. + **/ + void setIconName( const YCPString & newIconName ) + { YTreeItem::setIconName( newIconName->value() ); } + + +private: + + YCPValue _id; +}; + + +#endif // YCPTreeItem_h Added: 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=39223&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.cc Fri Jul 6 18:44:27 2007 @@ -0,0 +1,198 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPTreeItemParser.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + + +#include <ycp/YCPTerm.h> +#include <ycp/YCPBoolean.h> + +#define y2log_component "ui" +#include <ycp/y2log.h> + +#include "YCPTreeItemParser.h" +#include "YCP_UI_Exception.h" +#include "YUISymbols.h" + +#define VERBOSE_PARSER 0 + + +YItemCollection +YCPTreeItemParser::parseTreeItemList( const YCPList & itemList ) +{ + YItemCollection itemCollection; + itemCollection.reserve( itemList.size() ); + + try + { + for ( int i=0; i < itemList->size(); i++ ) + { + YCPTreeItem * item = parseTreeItem( 0, // parent item + itemList->value(i) ); + itemCollection.push_back( item ); + } + } + catch ( YUIException & exception ) + { + YItemIterator it = itemCollection.begin(); + + while ( it != itemCollection.end() ) + { + YItem * item = *it; + ++it; + delete item; + } + + itemCollection.clear(); + throw; + } + +#if VERBOSE_PARSER + y2debug( "%d items", itemCollection.size() ); +#endif + + return itemCollection; +} + + + +YCPTreeItem * +YCPTreeItemParser::parseTreeItem( YCPTreeItem * parent, const YCPValue & rawItem ) +{ + YCPTreeItem * item = 0; + +#if VERBOSE_PARSER + y2debug( "Parsing: %s", rawItem->toString().c_str() ); +#endif + + if ( rawItem->isString() ) // Simple case: just a string + { + YCPString label = rawItem->asString(); + item = new YCPTreeItem( parent, + label, // The real label + label, // Use the label as ID, too + false ); // Not initially selected + } + else // `item(...) + { + if ( rawItem->isTerm() && + rawItem->asTerm()->name() == YUISymbol_item ) // `item(...) + { + item = parseTreeItem( parent, rawItem->asTerm() ); + } + else // not `item(...) + { + YUI_THROW( YCPDialogSyntaxErrorException( "Expected `item(...)", rawItem ) ); + } + } + + return item; +} + + +YCPTreeItem * +YCPTreeItemParser::parseTreeItem( YCPTreeItem * parent, const YCPTerm & itemTerm ) +{ + YCPValue id = YCPNull(); + YCPString iconName = YCPNull(); + YCPString label = YCPNull(); + YCPBoolean isOpen = YCPNull(); + YCPList subItemList = YCPNull(); + + string usage = + "Expected: `item(`id(`myID), `icon(\"MyIcon.png\"), \"MyItemText\", boolean isOpen, list subItemList )"; + +#if VERBOSE_PARSER + y2debug( "Parsing: %s", itemTerm->toString().c_str() ); +#endif + + 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(), `icon() + { + YCPTerm term = arg->asTerm(); + + if ( term->size() != 1 ) // Both `id() and `icon() have 1 argument + YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) ); + + if ( term->name() == YUISymbol_id // `id(...) + && id.isNull() ) // and don't have an ID yet + { + id = term->value(0); + } + else if ( term->name() == YUISymbol_icon // `icon(...) + && term->value(0)->isString() // with a string argument + && iconName.isNull() ) // and don't have an icon name yet + { + iconName = term->value(0)->asString(); + } + else + { + YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) ); + } + } + else if ( arg->isString() // label (the user-visible text) + && label.isNull() ) // and don't have a label yet + { + label = arg->asString(); + } + else if ( arg->isBoolean() // "isOpen" flag + && isOpen.isNull() ) // and don't have an "isOpen" flag yet + { + isOpen = arg->asBoolean(); + } + else if( arg->isList() // sub item list + && subItemList.isNull() ) // and don't have a sub item list yet + { + subItemList = arg->asList(); + } + else + { + YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) ); + } + } + + if ( label.isNull() ) // the label is required + YUI_THROW( YCPDialogSyntaxErrorException( usage, itemTerm ) ); + + if ( iconName.isNull() ) + iconName = YCPString( "" ); + + if ( id.isNull() ) // no `id() ? + id = label; // use the label instead + + if ( isOpen.isNull() ) // "isOpen" not specified? + isOpen = YCPBoolean( false ); // use "not isOpen" (false) as default + + YCPTreeItem * item = new YCPTreeItem( parent, label, id, iconName, isOpen->value() ); + YUI_CHECK_NEW( item ); + + if ( ! subItemList.isNull() ) + { + for ( int i=0; i < subItemList->size(); i++ ) + { + parseTreeItem( item, subItemList->value(i) ); + } + } + + return item; +} Added: branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.h?rev=39223&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.h (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCPTreeItemParser.h Fri Jul 6 18:44:27 2007 @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YCPTreeItemParser.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YCPTreeItemParser_h +#define YCPTreeItemParser_h + +#include <ycp/YCPTerm.h> +#include "YCPTreeItem.h" + + +/** + * Parsers for SelectionBox, ComboBox, MultiSelectionBox item lists + **/ +class YCPTreeItemParser +{ +public: + + /** + * Parse a tree item list: + * + * [ + * `item(`id( `myID1 ), "Label1" ), + * `item(`id( `myID2 ), `icon( "icon2.png"), "Label2", true ), + * `item(`id( `myID3 ), `icon( "icon3.png"), "Label3", true, [ subItemList ] ), + * "Label4" + * ] + * + * Return a list of newly created YItem-derived objects. + * + * This function throws exceptions if there are syntax errors. + **/ + static YItemCollection parseTreeItemList( const YCPList & ycpItemList ); + + + /** + * Parse one item and create a YCPTreeItem from it. + * + * This function throws exceptions if there are syntax errors. + **/ + static YCPTreeItem * parseTreeItem( YCPTreeItem * parent, const YCPValue & item ); + +protected: + + /** + * Parse an item term: + * + * `item(`id( `myID1 ), "Label1" ) + * `item(`id( `myID2 ), `icon( "icon2.png"), "Label2", true ) + * `item(`id( `myID3 ), `icon( "icon3.png"), "Label3", true, [ subItemList ] ) + * "Label4" + * + * Everything except the label is optional. + * + * This function throws exceptions if there are syntax errors. + **/ + static YCPTreeItem * parseTreeItem( YCPTreeItem * parent, const YCPTerm & itemTerm ); + + +}; + + +#endif // YCPTreeItemParser_h Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCheckBox.cc Fri Jul 6 18:44:27 2007 @@ -105,7 +105,7 @@ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YCheckBoxFrame.cc Fri Jul 6 18:44:27 2007 @@ -139,7 +139,7 @@ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.cc Fri Jul 6 18:44:27 2007 @@ -153,13 +153,13 @@ } -YConstItemCollection +YItemCollection YComboBox::selectedItems() { - YConstItemCollection selectedItems; + YItemCollection selectedItems; // There can be no more than one selected item - const YItem * item = selectedItem(); + YItem * item = selectedItem(); if ( item ) selectedItems.push_back( item ); @@ -203,7 +203,7 @@ else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YComboBox.h Fri Jul 6 18:44:27 2007 @@ -123,7 +123,7 @@ * * Reimplemented from YSelectionWidget for better reliability. **/ - virtual YConstItemCollection selectedItems(); + virtual YItemCollection selectedItems(); /** * Select or deselect an item. See also setValue(). 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YDialog.cc Fri Jul 6 18:44:27 2007 @@ -97,7 +97,6 @@ } - void YDialog::setInitialSize() { // Trigger geometry management Modified: branches/tmp/sh/mod-ui/core/libyui/src/YFrame.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YFrame.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YFrame.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YFrame.cc Fri Jul 6 18:44:27 2007 @@ -69,7 +69,7 @@ if ( propSet.isEmpty() ) { /* - * @property string Label the label text on the frame + * @property string Label the text on the frame */ propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); @@ -88,7 +88,7 @@ if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YInputField.cc Fri Jul 6 18:44:27 2007 @@ -151,7 +151,7 @@ else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Added: branches/tmp/sh/mod-ui/core/libyui/src/YItem.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YItem.cc?rev=39223&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YItem.cc (added) +++ branches/tmp/sh/mod-ui/core/libyui/src/YItem.cc Fri Jul 6 18:44:27 2007 @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YItem.cc + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#include "YItem.h" + +/** + * Static children collection that is always empty so the children + * iterators of this base class have something valid to return. + * + * No item will ever be added to this collection. + **/ +YItemCollection YItem::_noChildren; + + + + +YTreeItem::YTreeItem( const string & label, + bool isOpen ) + : YItem( label ) + , _parent( 0 ) + , _isOpen( isOpen ) + , _data( 0 ) +{ +} + + +YTreeItem::YTreeItem( const string & label, + const string & iconName, + bool isOpen ) + : YItem( label, iconName ) + , _parent( 0 ) + , _isOpen( isOpen ) + , _data( 0 ) +{ +} + + +YTreeItem::YTreeItem( YTreeItem * parent, + const string & label, + bool isOpen ) + : YItem( label ) + , _parent( parent ) + , _isOpen( isOpen ) + , _data( 0 ) +{ + if ( parent ) + parent->addChild( this ); +} + + +YTreeItem::YTreeItem( YTreeItem * parent, + const string & label, + const string & iconName, + bool isOpen ) + : YItem( label, iconName ) + , _parent( parent ) + , _isOpen( isOpen ) + , _data( 0 ) +{ + if ( parent ) + parent->addChild( this ); +} + + +YTreeItem::~YTreeItem() +{ + deleteChildren(); +} + + +void YTreeItem::addChild( YItem * child ) +{ + _children.push_back( child ); +} + + +void YTreeItem::deleteChildren() +{ + YItemIterator it = childrenBegin(); + + while ( it != childrenEnd() ) + { + YItem * child = *it; + ++it; + delete child; + } + + _children.clear(); +} Modified: branches/tmp/sh/mod-ui/core/libyui/src/YItem.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YItem.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YItem.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YItem.h Fri Jul 6 18:44:27 2007 @@ -20,43 +20,53 @@ #define YItem_h #include <string> -#include <list> +#include <vector> using std::string; using std::vector; +class YItem; + +typedef vector<YItem *> YItemCollection; +typedef YItemCollection::iterator YItemIterator; +typedef YItemCollection::const_iterator YItemConstIterator; + +typedef vector<const YItem *> YConstItemCollection; +typedef YConstItemCollection::iterator YConstItemIterator; +typedef YConstItemCollection::const_iterator YConstItemConstIterator; + + + /** * Simple item class for SelectionBox, ComboBox, MultiSelectionBox etc. items. + * This class provides stubs for children management. **/ class YItem { public: - /** * Constructor with just the label and optionally the selected state. **/ - YItem( const string & label, bool sel = false ) + YItem( const string & label, bool selected = false ) : _label( label ) - , _selected( sel ) + , _selected( selected ) , _index( -1 ) {} /** * Constructor with label and icon name and optionally the selected state. **/ - YItem( const string & label, const string & iconName, bool sel = false ) + YItem( const string & label, const string & iconName, bool selected = false ) : _label( label ) , _iconName( iconName ) - , _selected( sel ) + , _selected( selected ) , _index( -1 ) {} /** - * Virtual Destructor. Only needed to enforce this class getting a VTable - * so RTTI and dynymic_cast will work. + * Destructor. **/ - virtual ~YItem() - {} + virtual ~YItem() {} /** * Return this item's label. This is what the user sees in a dialog, so @@ -106,22 +116,189 @@ **/ int index() const { return _index; } + // + // Children management stubs. + // + // Derived classes that can handle child items should reimplement those functions. + // The following default implementations don't do anything with children; + // they act as if this item didn't have any children. + // + + /** + * Return 'true' if this item has any child items. + **/ + virtual bool hasChildren() const { return false; } + + /** + * Return an iterator that points to the first child item of this item. + * + * This default implementation returns the 'end' iterator of the + * class-static always empty _noChildren YItemCollection. + * It is safe to use this iterator in classic iterator loops: + * + * for ( YItemIterator it = myItem->childrenBegin(); + * it != myItem->childrenEnd(); + * ++it ) + * { + * ... + * } + * + * The loop body will only ever be executed if this item is a derived class + * that actually manages child items. + **/ + virtual YItemIterator childrenBegin() { return _noChildren.end(); } + virtual YItemConstIterator childrenBegin() const { return _noChildren.end(); } + + /** + * Return an iterator that points after the last child item of this item. + * + * This default implementation returns the 'end' iterator of the + * class-static always empty _noChildren YItemCollection. + **/ + virtual YItemIterator childrenEnd() { return _noChildren.end(); } + virtual YItemConstIterator childrenEnd() const { return _noChildren.end(); } + private: + string _label; string _iconName; bool _selected; int _index; + + /** + * Static children collection that is always empty so the children + * iterators of this base class have something valid to return. + **/ + static YItemCollection _noChildren; }; -typedef vector<YItem *> YItemCollection; -typedef YItemCollection::iterator YItemIterator; -typedef YItemCollection::const_iterator YItemConstIterator; +/** + * Item class for tree items. + * + * This class implements children management. + **/ +class YTreeItem: public YItem +{ +public: + /** + * Constructors for toplevel items. + **/ + YTreeItem( const string & label, + bool isOpen ); -typedef vector<const YItem *> YConstItemCollection; -typedef YConstItemCollection::iterator YConstItemIterator; -typedef YConstItemCollection::const_iterator YConstItemConstIterator; + YTreeItem( const string & label, + const string & iconName, + bool isOpen ); + + /** + * Constructors for items that have a parent item. + * + * They will automatically register this item with the parent item. The + * parent assumes ownership of this item and will delete it in its (the + * parent's) destructor. + **/ + YTreeItem( YTreeItem * parent, + const string & label, + bool isOpen ); + + YTreeItem( YTreeItem * parent, + const string & label, + const string & iconName, + bool isOpen ); + + /** + * Destructor. + * + * This will delete all children. + **/ + virtual ~YTreeItem(); + + /** + * Return 'true' if this item has any child items. + * + * Reimplemented from YItem. + **/ + virtual bool hasChildren() const { return ! _children.empty(); } + + /** + * Return an iterator that points to the first child item of this item. + * + * Reimplemented from YItem. + **/ + virtual YItemIterator childrenBegin() { return _children.begin(); } + virtual YItemConstIterator childrenBegin() const { return _children.begin(); } + + /** + * Return an iterator that points after the last child item of this item. + * + * Reimplemented from YItem. + **/ + virtual YItemIterator childrenEnd() { return _children.end(); } + virtual YItemConstIterator childrenEnd() const { return _children.end(); } + + /** + * Add a child item to this item. + * + * Note that the constructors that accept a parent pointer will + * automatically add themselves to their parent, so applications will + * normally not have to call this function. + **/ + virtual void addChild( YItem * child ); + + /** + * Delete all child items. + **/ + virtual void deleteChildren(); + + /** + * Return 'true' if this tree item should be displayed open (with its + * children visible) by default. + **/ + bool isOpen() const { return _isOpen; } + + /** + * Change the 'isOpen' flag. + **/ + void setOpen( bool open ) { _isOpen = open; } + + /** + * Returns this item's parent item or 0 if it is a toplevel item. + **/ + YTreeItem * parent() const { return _parent; } + + /** + * Set the opaque data pointer for application use. + * + * Applications can use this to store the pointer to a counterpart of this + * tree item. It is the application's responsibility to watch for dangling + * pointers and possibliy deleting the data. All this class ever does with + * this pointer is to store it. + **/ + void setData( void * newData ) { _data = newData; } + + /** + * Return the opaque data pointer. + **/ + void * data() const { return _data; } + +private: + + YTreeItem * _parent; + YItemCollection _children; + bool _isOpen; + void * _data; +}; + + +typedef vector<YTreeItem *> YTreeItemCollection; +typedef YTreeItemCollection::iterator YTreeItemIterator; +typedef YTreeItemCollection::const_iterator YTreeItemConstIterator; + +typedef vector<const YTreeItem *> YConstTreeItemCollection; +typedef YConstTreeItemCollection::iterator YConstTreeItemIterator; +typedef YConstTreeItemCollection::const_iterator YConstTreeItemConstIterator; #endif // YItem_h Modified: branches/tmp/sh/mod-ui/core/libyui/src/YLabel.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YLabel.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YLabel.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YLabel.cc Fri Jul 6 18:44:27 2007 @@ -133,7 +133,7 @@ else if ( propertyName == YUIProperty_Text ) setText( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc Fri Jul 6 18:44:27 2007 @@ -127,7 +127,7 @@ else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMultiSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMultiSelectionBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YMultiSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YMultiSelectionBox.cc Fri Jul 6 18:44:27 2007 @@ -78,7 +78,7 @@ * @property itemList SelectedItems All currently selected items * @property itemList Items All items * @property itemID CurrentItem The current item (no matter if selected or not) - * @property string Label Caption above the input field + * @property string Label Caption above the MultiSelectionBox */ propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) ); propSet.add( YProperty( YUIProperty_SelectedItems, YOtherProperty ) ); @@ -102,7 +102,7 @@ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YProgressBar.cc Fri Jul 6 18:44:27 2007 @@ -107,7 +107,7 @@ { /* * @property integer Value the current progress - * @property string Label caption above the input field + * @property string Label caption above the progress bar */ propSet.add( YProperty( YUIProperty_Value, YIntegerProperty ) ); propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); @@ -127,7 +127,7 @@ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButton.cc Fri Jul 6 18:44:27 2007 @@ -134,7 +134,7 @@ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YRadioButtonGroup.cc Fri Jul 6 18:44:27 2007 @@ -149,7 +149,7 @@ propertyName == YUIProperty_Value ) return false; // Needs special handling else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YRichText.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YRichText.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YRichText.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YRichText.cc Fri Jul 6 18:44:27 2007 @@ -118,8 +118,8 @@ if ( propSet.isEmpty() ) { /* - * @property string Value the text content - * @property string Text the text content + * @property string Value the text content + * @property string Text the text content */ propSet.add( YProperty( YUIProperty_Value, YStringProperty ) ); propSet.add( YProperty( YUIProperty_Text, YStringProperty ) ); @@ -139,7 +139,7 @@ if ( propertyName == YUIProperty_Text ) setValue( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary Modified: branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionBox.cc Fri Jul 6 18:44:27 2007 @@ -94,13 +94,13 @@ if ( propSet.isEmpty() ) { /* - * @property itemID CurrentItem The currently selected item * @property itemID Value The currently selected item + * @property itemID CurrentItem The currently selected item * @property itemList Items All items - * @property string Label caption above the input field + * @property string Label caption above the selection box */ - propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) ); propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) ); propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) ); propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); propSet.add( YWidget::propertySet() ); @@ -121,7 +121,7 @@ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); else { - YWidget::setProperty( propertyName, val ); + return YWidget::setProperty( propertyName, val ); } return true; // success -- no special processing necessary 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.cc Fri Jul 6 18:44:27 2007 @@ -23,6 +23,7 @@ #include <algorithm> #include "YSelectionWidget.h" #include "YUIException.h" +#include "YApplication.h" struct YSelectionWidgetPrivate @@ -31,12 +32,10 @@ bool enforceSingleSelection ) : label( label ) , enforceSingleSelection( enforceSingleSelection ) - , hasIcons( false ) {} string label; bool enforceSingleSelection; - bool hasIcons; string iconBasePath; YItemCollection itemCollection; }; @@ -62,17 +61,20 @@ void YSelectionWidget::deleteAllItems() { - YItemIterator it = priv->itemCollection.begin(); + YItemIterator it = itemsBegin(); - while ( it != priv->itemCollection.end() ) + while ( it != itemsEnd() ) { YItem * item = *it; ++it; delete item; + + // No need to check for item->hasChildren() and iterate recursively + // over the children: The item will take care of its children in its + // destructor. } priv->itemCollection.clear(); - priv->hasIcons = false; } @@ -118,19 +120,11 @@ if ( item && ! item->iconName().empty() ) { - // FIXME - // FIXME - // FIXME -#if 0 if ( priv->iconBasePath.empty() || priv->iconBasePath[0] != '/' ) { - fullPath = YUI::qApp()->iconBasePath(); + fullPath = YUI::yApp()->iconBasePath(); } -#endif - // FIXME - // FIXME - // FIXME fullPath += priv->iconBasePath + "/" + item->iconName(); } @@ -144,17 +138,16 @@ YUI_CHECK_PTR( item ); // Add the new item to the item list - + priv->itemCollection.push_back( item ); item->setIndex( priv->itemCollection.size() - 1 ); - if ( item->hasIconName() ) - priv->hasIcons = true; + // y2debug( "Adding item \"%s\"", item->label().c_str() ); // // Enforce single selection (if applicable) // - + if ( priv->enforceSingleSelection ) { if ( item->selected() ) @@ -162,29 +155,28 @@ YItem * oldSelectedItem = selectedItem(); // This looks expensive, but it is not: Even though selectedItem() - // searches the complete item list until it finds a selected item, this - // happens only if a new item is to be inserted that has the "selected" - // flag on. In the normal case, this will only be one item. + // searches the complete item list until it finds a selected item, + // this happens only if a new item is to be inserted that has the + // "selected" flag on. In the normal case, this will only be one + // item. // - // Only if the calling application does this systematically wrong and - // sets the "selected" flag for ALL items it inserts this will be more - // expensive. But then, this is a bug in that application that needs to - // be fixed. + // Only if the calling application does this systematically wrong + // and sets the "selected" flag for ALL items it inserts this will + // be more expensive. But then, this is a bug in that application + // that needs to be fixed. - - if ( oldSelectedItem && oldSelectedItem != item ) { oldSelectedItem->setSelected( false ); } } - + // Make sure there is one item selected initially. // // If any other subsequently added items are to be selected, they will // override this initial selection. - + if ( priv->itemCollection.size() == 1 ) item->setSelected( true ); } @@ -217,10 +209,20 @@ ++it ) { addItem( *it ); + + // No need to check for (*it)->hasChildren() and iterate recursively + // over the children: Any children of this item simply remain in this + // item's YItemCollection. } } +YItemIterator +YSelectionWidget::itemsBegin() +{ + return priv->itemCollection.begin(); +} + YItemConstIterator YSelectionWidget::itemsBegin() const { @@ -228,6 +230,13 @@ } +YItemIterator +YSelectionWidget::itemsEnd() +{ + return priv->itemCollection.end(); +} + + YItemConstIterator YSelectionWidget::itemsEnd() const { @@ -248,6 +257,16 @@ YItem * +YSelectionWidget::firstItem() const +{ + if ( priv->itemCollection.empty() ) + return 0; + else + return priv->itemCollection.front(); +} + + +YItem * YSelectionWidget::itemAt( int index ) const { if ( index < 0 || index >= (int) priv->itemCollection.size() ) @@ -257,45 +276,73 @@ } -bool YSelectionWidget::hasIcons() const +YItem * +YSelectionWidget::selectedItem() { - return priv->hasIcons; + return findSelectedItem( itemsBegin(), itemsEnd() ); } YItem * -YSelectionWidget::selectedItem() +YSelectionWidget::findSelectedItem( YItemConstIterator begin, + YItemConstIterator end ) { - for ( YItemConstIterator it = itemsBegin(); - it != itemsEnd(); - ++it ) + for ( YItemConstIterator it = begin; it != end; ++it ) { - if ( (*it)->selected() ) + const YItem * item = *it; + + if ( item->selected() ) return *it; + + if ( item->hasChildren() ) + { + YItem * selectedItem = findSelectedItem( item->childrenBegin(), + item->childrenEnd() ); + if ( selectedItem ) + { + // y2debug( "Selected item: \"%s\"", selectedItem->label().c_str() ); + return selectedItem; + } + } } return 0; } -YConstItemCollection +YItemCollection YSelectionWidget::selectedItems() { - YConstItemCollection selectedItems; + YItemCollection selectedItems; + findSelectedItems( selectedItems, itemsBegin(), itemsEnd() ); - for ( YItemConstIterator it = itemsBegin(); - it != itemsEnd(); - ++it ) + return selectedItems; +} + + +void +YSelectionWidget::findSelectedItems( YItemCollection & selectedItems, + YItemConstIterator begin, + YItemConstIterator end ) +{ + for ( YItemConstIterator it = begin; it != end; ++it ) { - if ( (*it)->selected() ) - selectedItems.push_back( *it ); - } + YItem * item = *it; + + if ( item->selected() ) + selectedItems.push_back( item ); - return selectedItems; + if ( item->hasChildren() ) + { + findSelectedItems( selectedItems, + item->childrenBegin(), + item->childrenEnd() ); + } + } } -bool YSelectionWidget::hasSelectedItems() +bool YSelectionWidget::hasSelectedItem() { return selectedItem() != 0; } @@ -307,52 +354,102 @@ if ( ! itemsContain( item ) ) YUI_THROW( YUIException( "Item does not belong to this widget" ) ); - + if ( priv->enforceSingleSelection && selected ) { YItem * oldSelectedItem = selectedItem(); if ( oldSelectedItem ) - { - // Don't complain in the log etc. -- this is a perfectly legal case! oldSelectedItem->setSelected( false ); - } } item->setSelected( selected ); } -bool YSelectionWidget::itemsContain( YItem * item ) const +bool YSelectionWidget::itemsContain( YItem * wantedItem ) const { - return ( find( priv->itemCollection.begin(), priv->itemCollection.end(), item ) - != priv->itemCollection.end() ); + return itemsContain( wantedItem, itemsBegin(), itemsEnd() ); +} + + + +bool +YSelectionWidget::itemsContain( YItem * wantedItem, + YItemConstIterator begin, + YItemConstIterator end ) const +{ + for ( YItemConstIterator it = begin; it != end; ++it ) + { + const YItem * item = *it; + + if ( item == wantedItem ) + return true; + + if ( item->hasChildren() ) + { + if ( itemsContain( wantedItem, + item->childrenBegin(), + item->childrenEnd() ) ) + { + return true; + } + } + } + + return false; } void YSelectionWidget::deselectAllItems() { - for ( YItemIterator it = priv->itemCollection.begin(); - it != priv->itemCollection.end(); - ++it ) + deselectAllItems( itemsBegin(), itemsEnd() ); +} + + +void YSelectionWidget::deselectAllItems( YItemIterator begin, + YItemIterator end ) +{ + for ( YItemConstIterator it = begin; it != end; ++it ) { - (*it)->setSelected( false ); + YItem * item = *it; + + item->setSelected( false ); + + if ( item->hasChildren() ) + deselectAllItems( item->childrenBegin(), item->childrenEnd() ); } } +YItem * +YSelectionWidget::findItem( const string & wantedItemLabel ) const +{ + return findItem( wantedItemLabel, itemsBegin(), itemsEnd() ); +} + YItem * -YSelectionWidget::findItem( const string & wantedItemLabel ) +YSelectionWidget::findItem( const string & wantedItemLabel, + YItemConstIterator begin, + YItemConstIterator end ) const { - for ( YItemIterator it = priv->itemCollection.begin(); - it != priv->itemCollection.end(); - ++it ) + for ( YItemConstIterator it = begin; it != end; ++it ) { - if ( (*it)->label() == wantedItemLabel ) - return *it; + YItem * item = *it; + + if ( item->label() == wantedItemLabel ) + return item; + + if ( item->hasChildren() ) + { + YItem * wantedItem = findItem( wantedItemLabel, + item->childrenBegin(), + item->childrenEnd() ); + if ( wantedItem ) + return wantedItem; + } } return 0; } - 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YSelectionWidget.h Fri Jul 6 18:44:27 2007 @@ -128,12 +128,14 @@ * their "selected" state; that information might not always be up to * date. Use the dedicated functions for that. **/ - YItemConstIterator itemsBegin() const; + YItemIterator itemsBegin(); + YItemConstIterator itemsBegin() const; /** * Return an iterator that points behind the last item. **/ - YItemConstIterator itemsEnd() const; + YItemIterator itemsEnd(); + YItemConstIterator itemsEnd() const; /** * Return 'true' if this widget has any items. @@ -149,9 +151,9 @@ int itemsCount() const; /** - * Return 'true' if any of the items has an icon. + * Return the first item or 0 if there is none. **/ - bool hasIcons() const; + YItem * firstItem() const; /** * Return the (first) selected item or 0 if none is selected. @@ -165,12 +167,12 @@ * This function does not transfer ownership of those items to the caller, * so don't try to delete them! **/ - virtual YConstItemCollection selectedItems(); + virtual YItemCollection selectedItems(); /** * Return 'true' if any item is selected. **/ - bool hasSelectedItems(); + bool hasSelectedItem(); /** * Select or deselect an item. @@ -227,7 +229,7 @@ * Find the (first) item with the specified label. * Return 0 if there is no item with that label. **/ - YItem * findItem( const string & itemLabel ); + YItem * findItem( const string & itemLabel ) const; /** * Get the string of this widget that holds the keyboard shortcut. @@ -260,14 +262,49 @@ * Return 'true' if this base class should enforce single selection. **/ bool enforceSingleSelection() const; - + + /** + * Recursively try to find the first selected item between iterators + * 'begin' and 'end'. Return that item or 0 if there is none. + **/ + YItem * findSelectedItem( YItemConstIterator begin, + YItemConstIterator end ); + + /** + * Recursively find all selected items between iterators 'begin' and 'end' + * and add each of them to the 'selectedItems' YItemCollection. + **/ + void findSelectedItems( YItemCollection & selectedItems, + YItemConstIterator begin, + YItemConstIterator end ); + + /** + * Recursively deselect all items between iterators 'begin' and 'end'. + **/ + void deselectAllItems( YItemIterator begin, + YItemIterator end ); + /** + * Recursively try to find an item with label 'wantedItemLabel' between + * iterators 'begin' and 'end'. Return that item or 0 if there is none. + **/ + YItem * findItem ( const string & wantedItemLabel, + YItemConstIterator begin, + YItemConstIterator end ) const; + + /** + * Recursively check if 'wantedItem' is between iterators 'begin' and + * 'end'. + **/ + bool itemsContain ( YItem * wantedItem, + YItemConstIterator begin, + YItemConstIterator end ) const; /** * Return the item at index 'index' (from 0) - * or 0 if there is no such item. + * or 0 if there is no such item. **/ YItem * itemAt( int index ) const; - + private: ImplPtr<YSelectionWidgetPrivate> priv; Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTree.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTree.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YTree.cc (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YTree.cc Fri Jul 6 18:44:27 2007 @@ -17,10 +17,6 @@ /-*/ -#include <ycp/YCPSymbol.h> -#include <ycp/YCPBoolean.h> -#include <ycp/YCPVoid.h> -#include <ycp/YCPMap.h> #define y2log_component "ui" #include <ycp/y2log.h> @@ -28,15 +24,26 @@ #include "YSelectionWidget.h" #include "YMacroRecorder.h" #include "YTree.h" -#include "YUI.h" +#include "YItem.h" + +struct YTreePrivate +{ + YTreePrivate() + {} + + int dummy; +}; + -YTree::YTree( const YWidgetOpt & opt, YCPString newLabel ) - : YWidget( opt ) - , label( newLabel ) - , _hasIcons( false ) + +YTree::YTree( YWidget * parent, const string & label ) + : YSelectionWidget( parent, label, + true ) // enforceSingleSelection + , priv( new YTreePrivate() ) { - // y2debug( "YTree( %s )", newLabel->value_cstr() ); + YUI_CHECK_NEW( priv ); + setDefaultStretchable( YD_HORIZ, true ); setDefaultStretchable( YD_VERT, true ); } @@ -44,20 +51,113 @@ YTree::~YTree() { - // Get rid of all children. - // - // Unfortuanately, STL iterators are doo dumb to modify their - // container - so we really need to do this manually. + // NOP +} + + +void YTree::addItems( const YItemCollection & itemCollection ) +{ + YSelectionWidget::addItems( itemCollection ); + rebuildTree(); +} - for ( unsigned i=0; i < items.size(); i++ ) + +const YPropertySet & +YTree::propertySet() +{ + static YPropertySet propSet; + + if ( propSet.isEmpty() ) + { + /* + * @property itemID Value The currently selected item + * @property itemID CurrentItem The currently selected item + * @property list<itemID> CurrentBranch List of IDs of current branch from root to current item + * @property itemList Items All items + * @property map<ItemID> OpenItems Map of IDs of all open items - can only be queried, not set + * @property string Label caption above the tree + */ + propSet.add( YProperty( YUIProperty_Value, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_CurrentItem, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_CurrentBranch, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_Items, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_OpenItems, YOtherProperty ) ); + propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); + propSet.add( YWidget::propertySet() ); + } + + return propSet; +} + + +bool +YTree::setProperty( const string & propertyName, const YPropertyValue & val ) +{ + 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_CurrentBranch ) return false; // Needs special handling + else if ( propertyName == YUIProperty_Items ) return false; // Needs special handling + else if ( propertyName == YUIProperty_OpenItems ) return false; // Needs special handling + else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); + else + { + return YWidget::setProperty( propertyName, val ); + } + + return true; // success -- no special processing necessary +} + + +YPropertyValue +YTree::getProperty( const string & propertyName ) +{ + 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_CurrentBranch ) return YPropertyValue( YOtherProperty ); + else if ( propertyName == YUIProperty_Items ) return YPropertyValue( YOtherProperty ); + else if ( propertyName == YUIProperty_OpenItems ) return YPropertyValue( YOtherProperty ); + else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); + else { - delete items[i]; + return YWidget::getProperty( propertyName ); } +} - items.clear(); + +void YTree::saveUserInput( YMacroRecorder *macroRecorder ) +{ + macroRecorder->recordWidgetProperty( this, YUIProperty_CurrentItem ); } + + + + + + + + + + + + + + + + + + + + + + +#if 0 + YCPValue YTree::changeWidget( const YCPSymbol & property, const YCPValue & newvalue ) { @@ -146,10 +246,10 @@ else if ( s == YUIProperty_CurrentItem || s == YUIProperty_Value ) { - const YTreeItem *it = getCurrentItem(); + const YTreeItem * item = getCurrentItem(); - if ( it ) - return it->getId().isNull() ? it->getText() : it->getId(); + if ( item ) + return item->hasId() ? item->id() : item->label(); else return YCPVoid(); } @@ -193,10 +293,10 @@ if ( ! current ) return YCPVoid(); - + YCPList branchList; branchToList( branchList, current ); - + return branchList; } @@ -211,109 +311,12 @@ branchToList( branchList, item->parent() ); } - branchList->add( item->getId().isNull() ? item->getText() : item->getId() ); + branchList->add( item->hasId() ? item->id() : item->label() ) } } -void -YTree::setLabel( const YCPString & label ) -{ - this->label = label; -} - - -YCPString YTree::getLabel() -{ - return label; -} - - -YTreeItem * -YTree::addItem( YTreeItem * parentItem, - const YCPValue & id, - const YCPString & text, - const YCPString & iconName, - bool open ) -{ - YTreeItem *treeItem; - - if ( parentItem ) - treeItem = new YTreeItem( parentItem, id, text, iconName, open ); - else - treeItem = new YTreeItem( this, id, text, iconName, open ); - - return treeItem; -} - - -YTreeItem * -YTree::addItem( YTreeItem * parentItem, - const YCPString & text, - const YCPString & iconName, - void * data, - bool open ) -{ - YTreeItem *treeItem; - - if ( parentItem ) - treeItem = new YTreeItem( parentItem, text, iconName, data, open ); - else - treeItem = new YTreeItem( this, text, iconName, data, open ); - - return treeItem; -} - - -void -YTree::rebuildTree() -{ - // NOP -} - - -YCPList YTree::itemsTermList( YTreeItemList items ) -{ - YCPList list; - - for ( YTreeItemListIterator it = items.begin(); - it != items.end(); - ++it ) - { - YTreeItem * item = *it; - YCPTerm itemTerm( YUISymbol_item ); // `item() - YCPValue id = item->getId(); - - if ( ! id.isNull() ) - { - YCPTerm idTerm( YUISymbol_id ); // `id() - idTerm->add( id ); // `id(`something ) - itemTerm->add( idTerm ); // `item(`id(`something ) ) - } - - YCPString itemText = item->getText(); - itemTerm->add( itemText ); - - if ( item->isOpen() ) - { - // y2milestone( "Open item: %s", itemText->value().c_str() ); - itemTerm->add( YCPBoolean( true ) ); - } - - YCPList childrenList = itemsTermList( item->itemList() ); - - if ( childrenList->size() > 0 ) - itemTerm->add( childrenList ); - - list->add( itemTerm ); - } - - return list; -} - - - void YTree::findOpenItems( YCPMap & openItems, YTreeItemList items ) { for ( YTreeItemListIterator it = items.begin(); @@ -353,229 +356,6 @@ } -YTreeItem * -YTree::findItemWithText( const YCPString & text ) -{ - for ( unsigned i=0; i < items.size(); i++ ) - { - YTreeItem *it = items[i]->findItemWithText ( text ); - - if ( it ) - return it; - } - - return ( YTreeItem * ) 0; -} - - -void YTree::saveUserInput( YMacroRecorder *macroRecorder ) -{ - macroRecorder->recordWidgetProperty( this, YUIProperty_CurrentItem ); -} -bool YTree::parseItemList( const YCPList & itemList, - YTreeItem * parentItem ) -{ - // FIXME - // FIXME - // FIXME -#if 0 - for ( int i=0; i < itemList->size(); i++ ) - { - YCPValue item = itemList->value(i); - - if ( item->isString() ) - { - // The simplest case: just a string, nothing elsewas - ( void ) addItem ( parentItem, YCPNull(), item->asString(), YCPString( "" ), false ); - } - else if ( item->isTerm() - && item->asTerm()->name() == YUISymbol_item ) // `item(...) - { - YCPValue id = YCPNull(); - YCPString label = YCPNull(); - YCPString iconName = YCPNull(); - YCPBoolean isOpen = YCPNull(); - YCPList subItemList = YCPNull(); - - if ( YSelectionWidget::parseItem( item->asTerm(), // in - id, label, iconName, isOpen, subItemList) ) // out - { - if ( isOpen.isNull() ) - isOpen = YCPBoolean( false ); - - if ( ! iconName.isNull() ) - _hasIcons = true; - - YTreeItem * treeItem = addItem( parentItem, id, label, iconName, isOpen->value() ); - - if ( ! subItemList.isNull() ) - { - if ( ! parseItemList( subItemList, treeItem ) ) - return false; - } - } - else - { - return false; - } - } - else - { - y2error( "Invalid item %s: Tree items must be strings or specified with `" - YUISymbol_item "()", item->toString().c_str() ); - return false; - } - } #endif - // FIXME - // FIXME - // FIXME - - return true; -} - - -void YTree::deleteAllItems() -{ - _hasIcons = false; - items.clear(); -} - - - - - -/*==========================================================================*/ - - -YTreeItem::YTreeItem( YTree * parent, - const YCPValue & id, - const YCPString & text, - const YCPString & iconName, - bool open ) - : _id( id ) - , _data( 0 ) - , _text( text) - , _iconName( iconName ) - , _parentTree( parent ) - , _parentItem( ( YTreeItem * ) 0 ) - , _openByDefault( open ) - , _open( open ) -{ - parent->items.push_back ( this ); -} - - -YTreeItem::YTreeItem( YTreeItem * parent, - const YCPValue & id, - const YCPString & text, - const YCPString & iconName, - bool open ) - : _id( id ) - , _data(0) - , _text( text) - , _iconName( iconName ) - , _parentTree( ( YTree * ) 0 ) - , _parentItem( parent ) - , _openByDefault( open ) - , _open( open ) -{ - parent->_items.push_back ( this ); -} - - -YTreeItem::YTreeItem( YTree * parent, - const YCPString & text, - const YCPString & iconName, - void * data, - bool open ) - : _id( YCPNull() ) - , _data( data ) - , _text( text ) - , _iconName( iconName ) - , _parentTree( parent ) - , _parentItem( ( YTreeItem * ) 0 ) - , _openByDefault( open ) - , _open( open ) -{ - parent->items.push_back ( this ); -} - - -YTreeItem::YTreeItem( YTreeItem * parent, - const YCPString & text, - const YCPString & iconName, - void * data, - bool open ) - : _id( YCPNull() ) - , _data( data ) - , _text( text ) - , _iconName( iconName ) - , _parentTree( ( YTree * ) 0 ) - , _parentItem( parent ) - , _openByDefault( open ) - , _open( open ) -{ - parent->_items.push_back ( this ); -} - - -YTreeItem::~YTreeItem() -{ - // Get rid of all children. - // - // Unfortuanately, STL iterators are doo dumb to modify their - // container - so we really need to do this manually. - - for ( unsigned i=0; i < _items.size(); i++ ) - { - delete _items[i]; - } - - _items.clear(); -} - - -YTreeItem * -YTreeItem::findItemWithId( const YCPValue & id ) -{ - if ( ! getId().isNull() && getId()->equal( id ) ) - return this; - - for ( unsigned i=0; i < _items.size(); i++ ) - { - YTreeItem *it = _items[i]->findItemWithId ( id ); - - if ( it ) - return it; - } - - return ( YTreeItem * ) 0; -} - - -YTreeItem * -YTreeItem::findItemWithText( const YCPString & text ) -{ - if ( getText()->equal( text ) ) - return this; - - for ( unsigned i=0; i < _items.size(); i++ ) - { - YTreeItem *it = _items[i]->findItemWithText ( text ); - - if ( it ) - return it; - } - - return ( YTreeItem * ) 0; -} - - -YCPString -YTreeItem::iconName() const -{ - return _iconName.isNull() ? YCPString( "" ) : _iconName; -} Modified: branches/tmp/sh/mod-ui/core/libyui/src/YTree.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YTree.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YTree.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YTree.h Fri Jul 6 18:44:27 2007 @@ -19,196 +19,94 @@ #ifndef YTree_h #define YTree_h -#include "YWidget.h" -#include <ycp/YCPString.h> -#include <ycp/YCPList.h> - +#include "YSelectionWidget.h" class YMacroRecorder; class YTreeItem; - -typedef vector<YTreeItem *> YTreeItemList; -typedef vector<YTreeItem *>::iterator YTreeItemListIterator; -typedef vector<YTreeItem *>::const_iterator YTreeItemListConstIterator; +class YTreePrivate; -class YTree : public YWidget +class YTree : public YSelectionWidget { - friend class YTreeItem; - protected: /** - * Constructor - * @param opt the widget options - * @param text the initial text of the label + * Constructor. **/ - YTree( const YWidgetOpt & opt, YCPString label ); - + YTree( YWidget * parent, const string & label ); public: /** - * Destructor. Frees all tree items. + * Destructor. **/ virtual ~YTree(); - /** * Returns a descriptive name of this widget class for logging, * debugging etc. **/ virtual const char * widgetClass() { return "YTree"; } - /** - * Called once after items have been added. + * Rebuild the displayed tree from the internally stored YTreeItems. * - * Overload this to fill the ui specific widget with items. - **/ - virtual void rebuildTree(); - - /** - * Adds an item to the selection box. + * The application should call this (once) after all items have been added + * with addItem(). YTree::addItems() calls this automatically. + * + * Derived classes are required to implement this. **/ - YTreeItem * addItem ( YTreeItem * parentItem, - const YCPValue & id, - const YCPString & text, - const YCPString & iconName, - bool open ); + virtual void rebuildTree() = 0; /** - * Adds an item to the selection box. + * Add multiple items. For some UIs, this can be more efficient than + * calling addItem() multiple times. This function also automatically calls + * rebuildTree() at the end. + * + * Derived classes can overwrite this function, but they should call this + * base class function at the end of the new implementation. * - * Uses an opaque data pointer for application use. Use YTreeItem::data() - * to retrieve this kind of data. The application is responsible for - * the data contents - and of course for avoiding dangling pointers. + * Reimplemented from YSelectionWidget. **/ - YTreeItem * addItem ( YTreeItem * parentItem, - const YCPString & text, - const YCPString & iconName, - void * data, - bool open ); + virtual void addItems( const YItemCollection & itemCollection ); - /** - * Implements the ui command changeWidget. - **/ - YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue ); - /** - * Implements the ui command queryWidget. - **/ - YCPValue queryWidget( const YCPSymbol & property ); - /** - * Change the label text. Overload this, but call - * YTree::setLabel at the end of your own function. - **/ - virtual void setLabel( const YCPString & label ); + + /** - * Get the current label text. This method cannot be overidden. + * Set a property. + * Reimplemented from YWidget. + * + * This function may throw YUIPropertyExceptions. * - * The value of the label cannot be changed other than by calling - * setLabel, i.e. not by the ui. Therefore setLabel stores the - * current label in #label. + * 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). **/ - YCPString getLabel(); + virtual bool setProperty( const string & propertyName, + const YPropertyValue & val ); /** - * Get the string of this widget that holds the keyboard shortcut. - * + * Get a property. * Reimplemented from YWidget. + * + * This method may throw YUIPropertyExceptions. **/ - virtual string shortcutString() { return getLabel()->value(); } + virtual YPropertyValue getProperty( const string & propertyName ); /** - * Set the string of this widget that holds the keyboard shortcut. + * Return this class's property set. + * This also initializes the property upon the first call. * * Reimplemented from YWidget. **/ - virtual void setShortcutString( const string & str ) - { setLabel( YCPString( str ) ); } - + virtual const YPropertySet & propertySet(); + /** * The name of the widget property that will return user input. * Inherited from YWidget. **/ - const char *userInputProperty() { return YUIProperty_CurrentItem; } - - /** - * Parses a given item list and calls addItem(...) to insert entries. - * - * Returns 'true' on succes, 'false' on error. - **/ - bool parseItemList( const YCPList & itemList, YTreeItem *parentItem = 0); - - /** - * Returns 'true' if any item of this widget has an icon - **/ - bool hasIcons() const { return _hasIcons; } - - /** - * Returns a list of the current item and all its ancestors from the - * root item to the current item - either the respective IDs or, for items - * that don't have IDs, the item text. If no item is currently selected, - * YCPVoid ('nil') is returned. - **/ - YCPValue currentBranch() const; - - -protected: - - /** - * Returns the index of the currently - * selected item or NULL if no item is selected. - **/ - virtual const YTreeItem * getCurrentItem() const = 0; - - /** - * Selects an item. - **/ - virtual void setCurrentItem ( YTreeItem * it ) = 0; - - /** - * Recursively search for an item with a given ID. - * Returns 0 if not found. - **/ - YTreeItem *findItemWithId ( const YCPValue & id ); - - /** - * Recursively search for an item with a given text. - * Returns 0 if not found. - **/ - YTreeItem *findItemWithText ( const YCPString & text ); - - /** - * Returns a YCPList of items in the format needed for creating a tree - * widget. - **/ - YCPList itemsTermList( YTreeItemList items ); - - /** - * Recursively fills a map 'openItems' with items that are open. - **/ - void findOpenItems( YCPMap & openItems, YTreeItemList items ); - - /** - * Cleares the YTreeItemList. This function is - * calles out of the corresponding YQ classes. - **/ - virtual void deleteAllItems(); - - /** - * Recursively add items to list 'branchList' from 'item' up to the tree's root - **/ - static void branchToList( YCPList & branchList, const YTreeItem * item ); - - - // - // Data members - // - - YTreeItemList items; - + const char *userInputProperty() { return YUIProperty_CurrentItem; } private: @@ -220,143 +118,8 @@ virtual void saveUserInput( YMacroRecorder *macroRecorder ); - // - // Data members - // - - YCPString label; - bool _hasIcons; -}; - - -class YTreeItem -{ - friend class YTree; - -public: - - /** - * Regular constructor for root level items. - **/ - YTreeItem ( YTree * parent, - const YCPValue & id, - const YCPString & text, - const YCPString & iconName, - bool open = false ); - - /** - * Regular constructor for items in deeper tree levels. - **/ - YTreeItem ( YTreeItem * parent, - const YCPValue & id, - const YCPString & text, - const YCPString & iconName, - bool open = false ); - - - /** - * Special constructor for root items that take an opaque data pointer for - * application use: This kind of root item can be used to reference to - * external objects that are connected with this tree item. - * Use YTreeItem::data() to retrieve this pointer. Casting will be - * necessary to make any use of it. - **/ - YTreeItem ( YTree * parent, - const YCPString & text, - const YCPString & iconName, - void * data, - bool open = false ); - - - /** - * Special constructor for deeper level items that take an opaque data pointer for - * application use: This kind of root item can be used to reference to - * external objects that are connected with this tree item. - * Use YTreeItem::data() to retrieve this pointer. Casting will be - * necessary to make any use of it. - **/ - YTreeItem ( YTreeItem * parent, - const YCPString & text, - const YCPString & iconName, - void * data, - bool open = false ); - - - /** - * Destructor. - **/ - virtual ~YTreeItem(); - - YTreeItem * parent() const { return _parentItem; } - YTree * tree() const { return _parentTree; } - const YCPString & getText() const { return _text; } - const YCPValue & getId() const { return _id; } - const YTreeItemList & itemList() const { return _items; } - bool isOpenByDefault() const { return _openByDefault; } - - /** - * Recursively search for an item with a given ID. - * Returns 0 if not found. - **/ - YTreeItem *findItemWithId ( const YCPValue & id ); - - /** - * Recursively search for an item with a given text. - * Returns 0 if not found. - **/ - YTreeItem *findItemWithText ( const YCPString & text ); - - /** - * Set this item's "open" flag. The UI has to take care to set this each - * time the user opens or closes a branch. - **/ - void setOpen( bool open ) { _open = open; } - - /** - * Returns this item's "open" flag. - **/ - bool isOpen() const { return _open; } - - /** - * Returns the opaque data pointer for applicaton use. - **/ - void * data() const { return _data; } - - /** - * Set the opaque data pointer. The application may choose to store - * internal data here. Watch for dangling pointers! - **/ - void setData( void * data ) { _data = data; } - - /** - * Returns the name of this item's icon or an empty string if it doesn't have one. - **/ - YCPString iconName() const; - - /** - * Sets this item's icon name. - **/ - void setIconName( const YCPString & icon ) { _iconName = icon; } - - -protected: - - // - // Data members - // - - YCPValue _id; - void * _data; - YCPString _text; - YCPString _iconName; - YTree * _parentTree; - YTreeItem * _parentItem; - bool _openByDefault; - bool _open; - - YTreeItemList _items; + ImplPtr<YTreePrivate> priv; }; - #endif // YTree_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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original) +++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Fri Jul 6 18:44:27 2007 @@ -448,7 +448,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 *createTree( 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 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=39223&r1=39222&r2=39223&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 Jul 6 18:44:27 2007 @@ -777,18 +777,29 @@ if ( dialog ) { - YWidget * child = YCPDialogParser::parseWidgetTreeTerm( dialog, dialog_term ); - - if ( child ) + try { - dialog->setInitialSize(); - dialog->checkShortcuts(); - showDialog( dialog ); + YWidget * child = YCPDialogParser::parseWidgetTreeTerm( dialog, dialog_term ); + + if ( child ) + { + dialog->setInitialSize(); + dialog->checkShortcuts(); + showDialog( dialog ); - unblockEvents(); - return YCPBoolean( true ); + unblockEvents(); + return YCPBoolean( true ); + } + else + { + YDialog::deleteTopmostDialog(); + } + } + catch ( YUIException & exception ) + { + YUI_CAUGHT( exception ); + ycperror( "UI::OpenDialog(): Dialog term parse error" ); } - else YDialog::deleteTopmostDialog(); } unblockEvents(); Modified: branches/tmp/sh/mod-ui/qt/src/Makefile.am URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/Makefile.am?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/Makefile.am (original) +++ branches/tmp/sh/mod-ui/qt/src/Makefile.am Fri Jul 6 18:44:27 2007 @@ -58,6 +58,7 @@ YQWidgetFactory.cc \ YQOptionalWidgetFactory.cc \ YQPackageSelectorPlugin.cc \ + YQSignalBlocker.cc \ \ YQIconPool.cc \ \ Modified: branches/tmp/sh/mod-ui/qt/src/YQApplication.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQApplication.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQApplication.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQApplication.cc Fri Jul 6 18:44:27 2007 @@ -22,7 +22,7 @@ YQApplication::YQApplication() { - + setIconBasePath( ICONDIR "/icons/22x22/apps/" ); } Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQComboBox.cc Fri Jul 6 18:44:27 2007 @@ -23,6 +23,7 @@ #include <qlabel.h> #include <qcombobox.h> #include <qlineedit.h> +#include <qpixmap.h> #define y2log_component "qt-ui" #include <ycp/y2log.h> @@ -31,6 +32,7 @@ #include "YEvent.h" #include "QY2CharValidator.h" #include "YQComboBox.h" +#include "YQSignalBlocker.h" @@ -51,18 +53,18 @@ if ( label.empty() ) _qt_label->hide(); - _qt_combo_box = new QComboBox( editable, this ); - _qt_label->setBuddy( _qt_combo_box ); + _qt_comboBox = new QComboBox( editable, this ); + _qt_label->setBuddy( _qt_comboBox ); #if SEND_SELECTION_CHANGED_EVENT - connect( _qt_combo_box, SIGNAL( highlighted (int) ), + connect( _qt_comboBox, SIGNAL( highlighted (int) ), this, SLOT ( slotSelected(int) ) ); #endif - connect( _qt_combo_box, SIGNAL( activated ( const QString & ) ), + connect( _qt_comboBox, SIGNAL( activated ( const QString & ) ), this, SLOT ( textChanged( const QString & ) ) ); - connect( _qt_combo_box, SIGNAL( textChanged( const QString & ) ), + connect( _qt_comboBox, SIGNAL( textChanged( const QString & ) ), this, SLOT ( textChanged( const QString & ) ) ); } @@ -75,7 +77,7 @@ string YQComboBox::text() { - return toUTF8( _qt_combo_box->currentText() ); + return toUTF8( _qt_comboBox->currentText() ); } @@ -85,9 +87,8 @@ if ( isValidText( text ) ) { - _qt_combo_box->blockSignals( true ); - _qt_combo_box->setCurrentText( text ); - _qt_combo_box->blockSignals( false ); + YQSignalBlocker sigBlocker( _qt_comboBox ); + _qt_comboBox->setCurrentText( text ); } else { @@ -100,19 +101,37 @@ void YQComboBox::addItem( YItem * item ) { YComboBox::addItem( item ); - _qt_combo_box->insertItem( fromUTF8( item->label() ) ); + QPixmap icon; + + if ( item->hasIconName() ) + { + string iconName = iconFullPath( item ); + icon = QPixmap( iconName.c_str() ); + + if ( icon.isNull() ) + y2error( "Can't load icon %s", iconName.c_str() ); + } + + if ( icon.isNull() ) + _qt_comboBox->insertItem( fromUTF8( item->label() ) ); + else + _qt_comboBox->insertItem( icon, fromUTF8( item->label() ) ); if ( item->selected() ) + { + + YQSignalBlocker sigBlocker( _qt_comboBox ); setText( item->label() ); + } } void YQComboBox::deleteAllItems() { - _qt_combo_box->blockSignals( true ); - _qt_combo_box->clear(); - YSelectionWidget::deleteAllItems(); - _qt_combo_box->blockSignals( false ); + YQSignalBlocker sigBlocker( _qt_comboBox ); + + _qt_comboBox->clear(); + YComboBox::deleteAllItems(); } @@ -137,7 +156,7 @@ void YQComboBox::setValidChars( const string & newValidChars ) { - if ( ! _qt_combo_box->editable() ) + if ( ! _qt_comboBox->editable() ) { y2warning( "Setting ValidChars is useless on a combo box that isn't editable! (%s)", debugLabel().c_str() ); @@ -151,19 +170,19 @@ else { _validator = new QY2CharValidator( fromUTF8( newValidChars ), this ); - _qt_combo_box->setValidator( _validator ); + _qt_comboBox->setValidator( _validator ); // No need to delete the validator in the destructor - Qt will take // care of that since it's a QObject with a parent! } - if ( ! isValidText( _qt_combo_box->currentText() ) ) + if ( ! isValidText( _qt_comboBox->currentText() ) ) { y2error( "Old value \"%s\" of %s \"%s\" invalid according to ValidChars \"%s\" - deleting", - (const char *) _qt_combo_box->currentText(), + (const char *) _qt_comboBox->currentText(), widgetClass(), debugLabel().c_str(), newValidChars.c_str() ); - _qt_combo_box->setCurrentText( "" ); + _qt_comboBox->setCurrentText( "" ); } YComboBox::setValidChars( newValidChars ); @@ -205,7 +224,7 @@ void YQComboBox::setInputMaxLength( int len ) { - _qt_combo_box->lineEdit()->setMaxLength( len ); + _qt_comboBox->lineEdit()->setMaxLength( len ); YComboBox::setInputMaxLength( len ); } @@ -231,14 +250,14 @@ void YQComboBox::setEnabled( bool enabled ) { _qt_label->setEnabled( enabled ); - _qt_combo_box->setEnabled( enabled ); + _qt_comboBox->setEnabled( enabled ); YWidget::setEnabled( enabled ); } bool YQComboBox::setKeyboardFocus() { - _qt_combo_box->setFocus(); + _qt_comboBox->setFocus(); return true; } Modified: branches/tmp/sh/mod-ui/qt/src/YQComboBox.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQComboBox.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQComboBox.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQComboBox.h Fri Jul 6 18:44:27 2007 @@ -165,7 +165,7 @@ // QLabel * _qt_label; - QComboBox * _qt_combo_box; + QComboBox * _qt_comboBox; QY2CharValidator * _validator; }; Modified: branches/tmp/sh/mod-ui/qt/src/YQInputField.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQInputField.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQInputField.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQInputField.cc Fri Jul 6 18:44:27 2007 @@ -32,6 +32,7 @@ #include "QY2CharValidator.h" #include "YQInputField.h" #include "YQi18n.h" +#include "YQSignalBlocker.h" // Include low-level X headers AFTER Qt headers: // X.h pollutes the global namespace (!!!) with pretty useless #defines @@ -95,9 +96,8 @@ if ( isValidText( text ) ) { - _qt_lineEdit->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_lineEdit ); _qt_lineEdit->setText( text ); - _qt_lineEdit->blockSignals( false ); } else { Modified: branches/tmp/sh/mod-ui/qt/src/YQIntField.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQIntField.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQIntField.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQIntField.cc Fri Jul 6 18:44:27 2007 @@ -24,6 +24,7 @@ #include "YQUI.h" #include "YEvent.h" #include "YQIntField.h" +#include "YQSignalBlocker.h" YQIntField::YQIntField( QWidget * parent, @@ -108,10 +109,10 @@ void YQIntField::setValue( int newValue ) { - _qt_spinbox->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_spinbox ); + _qt_spinbox->setValue( newValue ); YIntField::setValue( newValue ); - _qt_spinbox->blockSignals( false ); } int YQIntField::value() Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc Fri Jul 6 18:44:27 2007 @@ -28,6 +28,7 @@ #include "YQUI.h" #include "YEvent.h" #include "YQMultiLineEdit.h" +#include "YQSignalBlocker.h" YQMultiLineEdit::YQMultiLineEdit( YWidget * parent, const string & label ) @@ -69,9 +70,9 @@ void YQMultiLineEdit::setValue( const string & text ) { - _qt_textEdit->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_textEdit ); + _qt_textEdit->setText( fromUTF8( text ) ); - _qt_textEdit->blockSignals( false ); } Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc Fri Jul 6 18:44:27 2007 @@ -30,6 +30,7 @@ #include "YQUI.h" #include "YEvent.h" #include "YQMultiSelectionBox.h" +#include "YQSignalBlocker.h" #define DEFAULT_VISIBLE_LINES 5 #define SHRINKABLE_VISIBLE_LINES 2 @@ -97,10 +98,9 @@ void YQMultiSelectionBox::addItem( YItem * yItem ) { + YQSignalBlocker sigBlocker( _qt_listView ); YMultiSelectionBox::addItem( yItem ); // will also check for NULL - _qt_listView->blockSignals( true ); - YQMultiSelectionBoxItem * msbItem = new YQMultiSelectionBoxItem( this, _qt_listView, yItem ); @@ -108,8 +108,6 @@ if ( yItem->selected() ) msbItem->setOn( true ); - - _qt_listView->blockSignals( false ); } void YQMultiSelectionBox::selectItem( YItem * yItem, bool selected ) @@ -125,9 +123,8 @@ void YQMultiSelectionBox::deselectAllItems() { + YQSignalBlocker sigBlocker( _qt_listView ); YMultiSelectionBox::deselectAllItems(); - - _qt_listView->blockSignals( true ); QListViewItemIterator it( _qt_listView ); @@ -140,19 +137,16 @@ ++it; } - - _qt_listView->blockSignals( false ); } void YQMultiSelectionBox::deleteAllItems() { - YMultiSelectionBox::deleteAllItems(); + YQSignalBlocker sigBlocker( _qt_listView ); - _qt_listView->blockSignals( true ); + YMultiSelectionBox::deleteAllItems(); _qt_listView->clear(); - _qt_listView->blockSignals( false ); } @@ -176,15 +170,12 @@ void YQMultiSelectionBox::setCurrentItem( YItem * yItem ) { - + YQSignalBlocker sigBlocker( _qt_listView ); + YQMultiSelectionBoxItem * msbItem = findItem( yItem ); if ( msbItem ) - { - _qt_listView->blockSignals( true ); _qt_listView->setCurrentItem( msbItem ); - _qt_listView->blockSignals( false ); - } } Modified: branches/tmp/sh/mod-ui/qt/src/YQPartitionSplitter.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQPartitionSplitter.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQPartitionSplitter.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQPartitionSplitter.cc Fri Jul 6 18:44:27 2007 @@ -24,6 +24,7 @@ #include "YQUI.h" #include "YEvent.h" #include "YQPartitionSplitter.h" +#include "YQSignalBlocker.h" YQPartitionSplitter::YQPartitionSplitter( QWidget * parent, @@ -174,24 +175,19 @@ if ( ! _barGraph ) return; - _barGraph->blockSignals( true ); - _qt_freeSizeField->blockSignals( true ); - _qt_freeSizeSlider->blockSignals( true ); - _qt_newPartSizeField->blockSignals( true ); + YQSignalBlocker sigBlocker1( _barGraph ); + YQSignalBlocker sigBlocker2( _qt_freeSizeField ); + YQSignalBlocker sigBlocker3( _qt_freeSizeSlider ); + YQSignalBlocker sigBlocker4( _qt_newPartSizeField ); _barGraph->setValue( 0, usedSize() ); _barGraph->setValue( 1, remainingFreeSize() ); _barGraph->setValue( 2, newPartSize() ); _barGraph->update(); + _qt_freeSizeField->setValue ( remainingFreeSize() ); _qt_freeSizeSlider->setValue( remainingFreeSize() ); _qt_newPartSizeField->setValue( newPartSize() ); - - _barGraph->blockSignals( false ); - _qt_freeSizeField->blockSignals( false ); - _qt_freeSizeSlider->blockSignals( false ); - _qt_newPartSizeField->blockSignals( false ); - } Modified: branches/tmp/sh/mod-ui/qt/src/YQRadioButton.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQRadioButton.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQRadioButton.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQRadioButton.cc Fri Jul 6 18:44:27 2007 @@ -27,6 +27,7 @@ #include "YEvent.h" #include "YQRadioButton.h" #include "YRadioButtonGroup.h" +#include "YQSignalBlocker.h" using std::string; @@ -100,7 +101,8 @@ void YQRadioButton::setValue( bool newValue ) { - _qt_radioButton->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_radioButton ); + _qt_radioButton->setChecked( newValue ); if ( newValue ) @@ -110,8 +112,6 @@ if ( group ) group->uncheckOtherButtons( this ); } - - _qt_radioButton->blockSignals( false ); } Modified: branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQSelectionBox.cc Fri Jul 6 18:44:27 2007 @@ -30,6 +30,7 @@ #include "YEvent.h" #include "YQUI.h" #include "YQSelectionBox.h" +#include "YQSignalBlocker.h" #include "YQDialog.h" #include "YUIException.h" @@ -38,8 +39,6 @@ #define DEFAULT_VISIBLE_LINES 5 #define SHRINKABLE_VISIBLE_LINES 2 -#define ICON_DIR ICONDIR "/icons/22x22/apps/" - YQSelectionBox::YQSelectionBox( YWidget * parent, const string & label ) : QVBox( (QWidget *) parent->widgetRep() ) @@ -105,60 +104,44 @@ void YQSelectionBox::addItem( YItem * item ) { - YSelectionWidget::addItem( item ); + YSelectionBox::addItem( item ); QPixmap icon; - if ( hasIcons() && ! item->iconName().empty() ) + if ( item->hasIconName() ) { - QString iconName( fromUTF8( item->iconName() ) ); - iconName.stripWhiteSpace(); - - if ( ! iconName.isEmpty() ) - { - if ( ! iconName.startsWith( "/" ) ) - iconName.prepend( ICON_DIR ); - - icon = QPixmap( iconName ); - - if ( icon.isNull() ) - y2error( "Can't load icon %s", (const char *) iconName ); - } + string iconName = iconFullPath( item ); + icon = QPixmap( iconName.c_str() ); + if ( icon.isNull() ) + y2error( "Can't load icon %s", iconName.c_str() ); } if ( icon.isNull() ) - { _qt_listBox->insertItem( fromUTF8( item->label() ) ); - } else - { _qt_listBox->insertItem( icon, fromUTF8( item->label() ) ); - } if ( item->selected() ) { - _qt_listBox->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_listBox ); _qt_listBox->setCurrentItem( item->index() ); - _qt_listBox->blockSignals( false ); } } void YQSelectionBox::selectItem( YItem * item, bool selected ) { - YSelectionWidget::selectItem( item, selected ); - - _qt_listBox->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_listBox ); + + YSelectionBox::selectItem( item, selected ); _qt_listBox->setCurrentItem( selected ? item->index() : -1 ); - _qt_listBox->blockSignals( false ); } void YQSelectionBox::selectItem( int index ) { - YSelectionWidget::deselectAllItems(); - - YItem * item = YSelectionWidget::itemAt( index ); + YSelectionBox::deselectAllItems(); + YItem * item = YSelectionBox::itemAt( index ); if ( item ) { @@ -168,7 +151,7 @@ debugLabel().c_str(), item->label().c_str() ); #endif - + item->setSelected( true ); } else @@ -178,7 +161,7 @@ void YQSelectionBox::deselectAllItems() { - YSelectionWidget::deselectAllItems(); + YSelectionBox::deselectAllItems(); _qt_listBox->clearSelection(); if ( _qt_listBox->currentItem() > -1 ) @@ -186,10 +169,10 @@ // Some item is selected after all; the Qt documtation says this // happens if the QListBox is in single selection mode (which it is) // and has the keyboard focus. - + // // Synchronize internal "selected" flags with what the QListBox // displays. This has a small performance penalty because it calls - // YSelectionWidget::deselectAllItems() again which again iterates over + // YSelectionBox::deselectAllItems() again which again iterates over // all items. selectItem( _qt_listBox->currentItem() ); } @@ -198,10 +181,10 @@ void YQSelectionBox::deleteAllItems() { - _qt_listBox->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_listBox ); + _qt_listBox->clear(); - YSelectionWidget::deleteAllItems(); - _qt_listBox->blockSignals( false ); + YSelectionBox::deleteAllItems(); } @@ -296,13 +279,13 @@ // Delayed event delivery - only if events are to be delivered // right now. // - // An event block that is in effect right now may or may not affect - // events after the timer delay is expired. + // An event block that is in effect right now may or may not + // affect events after the timer delay is expired. // - // This may create nasty side effects such as bug #32510: When an - // item is initially selected, that initial selection event gets - // through even though (!) events are blocked during widget - // creation. + // This may create nasty side effects such as bug #32510: When + // an item is initially selected, that initial selection event + // gets through even though (!) events are blocked during + // widget creation. returnDelayed(); } Added: branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.cc?rev=39223&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.cc (added) +++ branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.cc Fri Jul 6 18:44:27 2007 @@ -0,0 +1,39 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YQSignalBlocker.cc + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#include "YQSignalBlocker.h" +#include <qobject.h> + + +YQSignalBlocker::YQSignalBlocker( QObject * qobject ) + : _qobject( qobject ) +{ + if ( _qobject ) + { + _oldBlockedState = _qobject->signalsBlocked(); + _qobject->blockSignals( true ); + } +} + + +YQSignalBlocker::~YQSignalBlocker() +{ + if ( _qobject ) + _qobject->blockSignals( _oldBlockedState ); +} + Added: branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.h?rev=39223&view=auto ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.h (added) +++ branches/tmp/sh/mod-ui/qt/src/YQSignalBlocker.h Fri Jul 6 18:44:27 2007 @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------\ +| | +| __ __ ____ _____ ____ | +| \ \ / /_ _/ ___|_ _|___ \ | +| \ V / _` \___ \ | | __) | | +| | | (_| |___) || | / __/ | +| |_|\__,_|____/ |_| |_____| | +| | +| core system | +| (C) SuSE GmbH | +\----------------------------------------------------------------------/ + + File: YQSignalBlocker.h + + Author: Stefan Hundhammer <sh@suse.de> + +/-*/ + +#ifndef YQSignalBlocker_h +#define YQSignalBlocker_h + +class QObject; + +/** + * Helper class to block Qt signals for QWidgets or QObjects as long as this +Y * object exists. + * + * This object will restore the old blocked state when it goes out of scope. + **/ +class YQSignalBlocker +{ +public: + + /** + * Constructor. + * + * Qt signals for 'qobject' will be blocked as long as this object exists. + * Remember that a QWidget is also a QObject. + **/ + YQSignalBlocker( QObject * qobject ); + + /** + * Destructor. + * + * This will restore the old signal state. + **/ + ~YQSignalBlocker(); + + +private: + + QObject * _qobject; + bool _oldBlockedState; +}; + + +#endif // ifndef YQSignalBlocker_h Modified: branches/tmp/sh/mod-ui/qt/src/YQSlider.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQSlider.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQSlider.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQSlider.cc Fri Jul 6 18:44:27 2007 @@ -24,6 +24,7 @@ #include "YQUI.h" #include "YEvent.h" #include "YQSlider.h" +#include "YQSignalBlocker.h" YQSlider::YQSlider( QWidget * parent, @@ -124,9 +125,9 @@ void YQSlider::setValue( int newValue ) { - _qt_slider->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_slider ); + _qt_slider->setValue( newValue ); - _qt_slider->blockSignals( false ); YSlider::setValue( newValue ); } 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQTable.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQTable.cc Fri Jul 6 18:44:27 2007 @@ -26,6 +26,7 @@ #include "YQUI.h" #include "YEvent.h" #include "YQTable.h" +#include "YQSignalBlocker.h" @@ -201,17 +202,15 @@ if ( ! _qt_listview->selectedItem() ) { - _qt_listview->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_listview ); item->setSelected( true ); - _qt_listview->blockSignals( false ); } } void YQTable::itemsCleared() { - _qt_listview->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_listview ); _qt_listview->clear(); - _qt_listview->blockSignals( false ); } @@ -236,10 +235,10 @@ if ( item ) // should be always true { - _qt_listview->blockSignals( true ); + YQSignalBlocker sigBlocker( _qt_listview ); + _qt_listview->setCurrentItem( item ); _qt_listview->ensureItemVisible( item ); - _qt_listview->blockSignals( false ); } } 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQTree.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQTree.cc Fri Jul 6 18:44:27 2007 @@ -32,53 +32,57 @@ #include "YEvent.h" #include "utf8.h" #include "YQTree.h" +#include "YItem.h" +#include "YQSignalBlocker.h" -#define ICON_DIR ICONDIR "/icons/22x22/apps/" +#define VERBOSE_TREE_ITEMS 0 - -YQTree::YQTree( QWidget * parent, - const YWidgetOpt & opt, - const YCPString & label ) - : QVBox( parent ) - , YTree ( opt, label ) +YQTree::YQTree( YWidget * parent, const string & label ) + : QVBox( (QWidget *) parent->widgetRep() ) + , YTree( parent, label ) { setWidgetRep( this ); setSpacing( YQWidgetSpacing ); - setMargin( YQWidgetMargin ); + setMargin ( YQWidgetMargin ); _nextSerialNo = 0; - _qt_label = new QLabel( fromUTF8( label->value() ), this ); + _qt_label = new QLabel( fromUTF8( label ), this ); _qt_label->setTextFormat( QLabel::PlainText ); if ( _qt_label->text().isEmpty() ) _qt_label->hide(); - _listView = new QListView( this ); - _listView->addColumn( "" ); - _listView->header()->hide(); - _listView->setRootIsDecorated ( true ); + _qt_listView = new QListView( this ); + _qt_listView->addColumn( "" ); + _qt_listView->header()->hide(); + _qt_listView->setRootIsDecorated ( true ); - _qt_label->setBuddy ( _listView ); + _qt_label->setBuddy ( _qt_listView ); - connect( _listView, SIGNAL( selectionChanged ( void ) ), - this, SLOT ( slotSelected ( void ) ) ); + connect( _qt_listView, SIGNAL( selectionChanged ( QListViewItem * ) ), + this, SLOT ( slotSelected ( QListViewItem * ) ) ); - connect( _listView, SIGNAL( spacePressed ( QListViewItem * ) ), - this, SLOT ( slotActivated ( void ) ) ); + connect( _qt_listView, SIGNAL( spacePressed ( QListViewItem * ) ), + this, SLOT ( slotActivated ( QListViewItem * ) ) ); - connect( _listView, SIGNAL( doubleClicked ( QListViewItem * ) ), - this, SLOT ( slotActivated ( void ) ) ); + connect( _qt_listView, SIGNAL( doubleClicked ( QListViewItem * ) ), + this, SLOT ( slotActivated ( QListViewItem * ) ) ); } -void -YQTree::setLabel( const YCPString & label ) +YQTree::~YQTree() { - _qt_label->setText( fromUTF8( label->value() ) ); - + // NOP +} + + +void YQTree::setLabel( const string & label ) +{ + _qt_label->setText( fromUTF8( label ) ); + if ( _qt_label->text().isEmpty() ) { if ( _qt_label->isVisible() ) @@ -94,147 +98,158 @@ } -int YQTree::preferredWidth() +void YQTree::rebuildTree() { - return max( 200, _qt_label->sizeHint().width() ); + // y2debug( "Rebuilding tree" ); + + YQSignalBlocker sigBlocker( _qt_listView ); + _qt_listView->clear(); + + buildDisplayTree( 0, itemsBegin(), itemsEnd() ); } -int YQTree::preferredHeight() +void YQTree::buildDisplayTree( YQTreeItem * parentItem, YItemIterator begin, YItemIterator end ) { - // 300 is an arbitrary value. Use a MinSize or MinHeight widget to set a - // size that is useful for the application. + for ( YItemIterator it = begin; it < end; ++it ) + { + YTreeItem * orig = dynamic_cast<YTreeItem *> (*it); + YUI_CHECK_PTR( orig ); - return 300 + _qt_label->sizeHint().height(); -} + YQTreeItem * clone; + if ( parentItem ) + clone = new YQTreeItem( this, parentItem, orig, _nextSerialNo++ ); + else + clone = new YQTreeItem( this, _qt_listView, orig, _nextSerialNo++ ); -void -YQTree::setSize( int newWidth, int newHeight ) -{ - resize( newWidth, newHeight ); + YUI_CHECK_NEW( clone ); + + if ( orig->hasChildren() ) + buildDisplayTree( clone, orig->childrenBegin(), orig->childrenEnd() ); + } } -void -YQTree::setEnabled( bool enabled ) +void YQTree::selectItem( YItem * yItem, bool selected ) { - _qt_label->setEnabled( enabled ); - _listView->setEnabled( enabled ); - YWidget::setEnabled( enabled ); -} + YQSignalBlocker sigBlocker( _qt_listView ); + YTreeItem * treeItem = dynamic_cast<YTreeItem *> (yItem); + YUI_CHECK_PTR( treeItem ); -void -YQTree::rebuildTree() -{ - _listView->blockSignals( true ); - _listView->clear(); + YQTreeItem * yqTreeItem = (YQTreeItem *) treeItem->data(); + YUI_CHECK_PTR( yqTreeItem ); - for ( YTreeItemListIterator it = items.begin(); it < items.end(); ++it ) + if ( ! selected && yqTreeItem == _qt_listView->selectedItem() ) { - YQTreeItem * item = new YQTreeItem( this, - _listView, - *it, - _nextSerialNo++ ); - YTreeItemList itemList = ( *it)->itemList(); - - if ( itemList.size() > 0 ) - { - item->buildSubTree( itemList, _nextSerialNo ); - } + _qt_listView->clearSelection(); + YTree::deselectAllItems(); + } + else + { + _qt_listView->setSelected( yqTreeItem, true ); + openBranch( yqTreeItem ); + YTree::selectItem( treeItem, selected ); } - - _listView->blockSignals( false ); } -const YTreeItem * -YQTree::getCurrentItem() const +void YQTree::selectItem( YQTreeItem * item ) { - YQTreeItem * it = ( YQTreeItem * ) _listView->selectedItem(); + if ( item ) + { + YQSignalBlocker sigBlocker( _qt_listView ); - return it ? it->origItem() : 0; + _qt_listView->setSelected( item, true ); + openBranch( item ); + YTree::selectItem( item->origItem(), true ); + + y2debug( "selected item: \"%s\"", item->origItem()->label().c_str() ); + } } -void -YQTree::setCurrentItem( YTreeItem * yit ) +void YQTree::openBranch( QListViewItem * item ) { - _listView->blockSignals( true ); - - YQTreeItem * it = findYQTreeItem( yit ); - - if ( it ) + while ( item ) { - // Select this item + item->setOpen( true ); // Takes care of origItem()->setOpen() + item = item->parent(); + } +} - _listView->setSelected( it, true ); +void YQTree::deselectAllItems() +{ + YQSignalBlocker sigBlocker( _qt_listView ); - // Open all parent items so the selected item isn't obscured - // somewhere deep within the tree + YTree::deselectAllItems(); + _qt_listView->clearSelection(); +} - while ( ( it = ( YQTreeItem * ) it->parent() ) ) - { - if ( ! it->isOpen() ) - { - it->setOpen( true ); - } - } - _listView->ensureItemVisible( it ); - } - else - _listView->clearSelection(); +void YQTree::deleteAllItems() +{ + YQSignalBlocker sigBlocker( _qt_listView ); - _listView->blockSignals( false ); + _qt_listView->clear(); + YTree::deleteAllItems(); } -void -YQTree::registerItem( const YTreeItem * orig, - const YQTreeItem * clone ) +void YQTree::slotSelected( QListViewItem * qItem ) { - _yTreeItemToYQTreeItem.insert( ( void * ) orig, clone ); + selectItem( dynamic_cast<YQTreeItem *> (qItem) ); + + if ( notify() && ! YQUI::ui()->eventPendingFor( this ) ) + YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) ); } -YQTreeItem * -YQTree::findYQTreeItem( const YTreeItem * orig ) const +void YQTree::slotActivated( QListViewItem * qItem ) { - return _yTreeItemToYQTreeItem[ ( void * ) orig ]; + selectItem( dynamic_cast<YQTreeItem *> (qItem) ); + + if ( notify() ) + YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) ); } -void YQTree::slotSelected( void ) +int YQTree::preferredWidth() { - if ( notify() && ! YQUI::ui()->eventPendingFor( this ) ) - YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::SelectionChanged ) ); + return max( 200, _qt_label->sizeHint().width() ); } -void YQTree::slotActivated( void ) + +int YQTree::preferredHeight() { - if ( notify() ) - YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::Activated ) ); + // 300 is an arbitrary value. Use a MinSize or MinHeight widget to set a + // size that is useful for the application. + + return 300 + _qt_label->sizeHint().height(); } -bool -YQTree::setKeyboardFocus() +void YQTree::setSize( int newWidth, int newHeight ) { - _listView->setFocus(); + resize( newWidth, newHeight ); +} - return true; + +void YQTree::setEnabled( bool enabled ) +{ + _qt_label->setEnabled( enabled ); + _qt_listView->setEnabled( enabled ); + YWidget::setEnabled( enabled ); } -void YQTree::deleteAllItems() +bool YQTree::setKeyboardFocus() { - _listView->blockSignals( true ); - _listView->clear(); - YTree::deleteAllItems(); - _listView->blockSignals( false ); + _qt_listView->setFocus(); + + return true; } @@ -243,74 +258,60 @@ YQTreeItem::YQTreeItem( YQTree * tree, - QListView * parent, - YTreeItem * yTreeItem, + QListView * listView, + YTreeItem * orig, int serial ) - : QListViewItem( parent ) + : QListViewItem( listView ) { - init( tree, yTreeItem, serial ); + init( tree, orig, serial ); + +#if VERBOSE_TREE_ITEMS + y2debug( "Creating toplevel tree item \"%s\"", orig->label().c_str() ); +#endif } YQTreeItem::YQTreeItem( YQTree * tree, - YQTreeItem * parent, - YTreeItem * yTreeItem, + YQTreeItem * parentItem, + YTreeItem * orig, int serial ) - : QListViewItem( parent ) + : QListViewItem( parentItem ) { - init( tree, yTreeItem, serial ); + init( tree, orig, serial ); + +#if VERBOSE_TREE_ITEMS + y2debug( "Creating tree item \"%s\" as child of \"%s\"", + orig->label().c_str(), + parentItem->origItem()->label().c_str() ); +#endif } -void -YQTreeItem::init( YQTree * tree, - YTreeItem * yTreeItem, - int serial ) -{ - _tree = tree; - _tree->registerItem ( yTreeItem, this ); - _origItem = yTreeItem; - _serialNo = serial; - setText( 0, fromUTF8 ( _origItem->getText()->value() ) ); - setOpen( _origItem->isOpenByDefault() ); +void YQTreeItem::init( YQTree * tree, + YTreeItem * orig, + int serial ) +{ + YUI_CHECK_PTR( tree ); + YUI_CHECK_PTR( orig ); - if ( tree->hasIcons() ) - { - QString iconName = _origItem->iconName()->value().c_str(); - iconName.stripWhiteSpace(); + _tree = tree; + _serialNo = serial; + _origItem = orig; - if ( ! iconName.isEmpty() ) - { - if ( ! iconName.startsWith( "/" ) ) - iconName.prepend( ICON_DIR ); - - QPixmap icon( iconName ); - - if ( icon.isNull() ) - y2error( "Can't load icon %s", (const char *) iconName ); - - else - setPixmap( 0, icon ); - } - } -} + _origItem->setData( this ); + setText( 0, fromUTF8 ( _origItem->label() ) ); + setOpen( _origItem->isOpen() ); -void -YQTreeItem::buildSubTree( YTreeItemList & items, int & nextSerialNo ) -{ - for ( YTreeItemListIterator it = items.begin(); it < items.end(); ++it ) + if ( _origItem->hasIconName() ) { - YQTreeItem * item = new YQTreeItem ( _tree, - this, - *it, - nextSerialNo++ ); - YTreeItemList itemList = ( *it)->itemList(); - - if ( itemList.size() > 0 ) - { - item->buildSubTree ( itemList, nextSerialNo ); - } + string iconName = _tree->iconFullPath( _origItem ); + QPixmap icon( iconName.c_str() ); + + if ( icon.isNull() ) + y2error( "Can't load icon %s", iconName.c_str() ); + else + setPixmap( 0, icon ); } } @@ -332,7 +333,7 @@ * * Always sort tree items by insertion order. The tree widget * cannot maintain a meaningful sorting order of its own: All it - * could do is sort by names ( ASCII sort ). Better let the ( YCP ) + * could do is sort by names (ASCII sort). Better let the (YCP) * application handle this. */ Modified: branches/tmp/sh/mod-ui/qt/src/YQTree.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQTree.h?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQTree.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQTree.h Fri Jul 6 18:44:27 2007 @@ -22,8 +22,6 @@ #include <qvbox.h> #include <qlistview.h> -#include <qptrdict.h> -#include <ycp/YCPString.h> #include "YTree.h" @@ -41,124 +39,130 @@ /** * Constructor. **/ - YQTree( QWidget * parent, const YWidgetOpt & opt, const YCPString & label ); + YQTree( YWidget * parent, const string & label ); /** - * 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 ~YQTree(); + /** - * Preferred width of the widget. + * Change the label text. * - * Reimplemented from YWidget. + * Reimplemented from YSelectionWidget. **/ - virtual int preferredWidth(); + virtual void setLabel( const string & label ); /** - * Preferred height of the widget. + * Rebuild the displayed tree from the internally stored YTreeItems. * - * Reimplemented from YWidget. - **/ - virtual int preferredHeight(); - - /** - * Set the new size of the widget. + * The application should call this (once) after all items have been added + * with addItem(). YTree::addItems() calls this automatically. * - * Reimplemented from YWidget. + * Implemented from YTree. **/ - virtual void setSize( int newWidth, int newHeight ); + virtual void rebuildTree(); /** - * Change the label text. + * Select or deselect an item. + * + * Reimplemented from YSelectionWidget. **/ - void setLabel( const YCPString & label ); + virtual void selectItem( YItem * item, bool selected = true ); /** - * Inherited fro YTree. Called once after items have been added. + * Deselect all items. + * + * Reimplemented from YSelectionWidget. **/ - void rebuildTree(); + virtual void deselectAllItems(); /** - * Inherited from YTree. Returns the the currently - * selected item or 0 if no item is selected. + * Delete all items. + * + * Reimplemented from YSelectionWidget. **/ - virtual const YTreeItem * getCurrentItem() const; + virtual void deleteAllItems(); /** - * Inherited from YTree. Selects an item. + * Set enabled/disbled state. + * + * Reimplemented from YWidget. **/ - virtual void setCurrentItem( YTreeItem * it ); + virtual void setEnabled( bool enabled ); /** - * Accept the keyboard focus. + * Preferred width of the widget. + * + * Reimplemented from YWidget. **/ - virtual bool setKeyboardFocus(); - + virtual int preferredWidth(); /** - * Register a newly created item. - * Calling this method is mandatory for all items. + * Preferred height of the widget. + * + * Reimplemented from YWidget. **/ - void registerItem( const YTreeItem * orig, - const YQTreeItem * clone ); - + virtual int preferredHeight(); /** - * Find the corresponding YQTreeItem for a given YTreeItem. - * Returns 0 if not found. + * Set the new size of the widget. + * + * Reimplemented from YWidget. **/ - YQTreeItem * findYQTreeItem( const YTreeItem * orig ) const; + virtual void setSize( int newWidth, int newHeight ); /** - * Delete all items. - * - * Reimplemented from YTree + * Accept the keyboard focus. **/ - virtual void deleteAllItems(); + virtual bool setKeyboardFocus(); protected slots: /** - * Triggers a SelectionChanged event if `opt(`notify) is set. + * Propagate a tree item selection. + * + * This will trigger a 'SelectionChanged' event if 'notify' is set. **/ - void slotSelected(); + void slotSelected( QListViewItem * item ); /** - * Triggers an Activated event if `opt(`notify) is set. + * Propagate a double click or pressing the space key on a tree item. + * + * This will trigger an 'Activated' event if 'notify' is set. **/ - void slotActivated(); + void slotActivated( QListViewItem * item); protected: /** - * Title label of the box. + * Select an item via the corresponding YQTreItem. **/ - QLabel * _qt_label; + void selectItem( YQTreeItem * item ); /** - * The real tree: The QListView widget. + * Open the branch of 'item' recursively to its toplevel item. **/ - QListView * _listView; - + void openBranch( QListViewItem * item ); + /** - * The next item serial number. + * Build a tree of items that will be displayed (YQTreeItems) from the + * original items between iterators 'begin' and 'end' as child items of + * 'parentItem' (or as toplevel items if 'parentItem' is 0). **/ - int _nextSerialNo; + void buildDisplayTree( YQTreeItem * parentItem, + YItemIterator begin, + YItemIterator end ); - /** - * Map from YTreeItem to the corresponding ( cloned ) YQTreeItem. - * A Qt collection class is used here rather than an STL class - * because the STL map requires an operator< to be defined which is - * not very natural for pointers to objects. - * - * registerItem() adds a pair to this map. - **/ - QPtrDict <YQTreeItem> _yTreeItemToYQTreeItem; + // + // Data members + // + + QLabel * _qt_label; + QListView * _qt_listView; + int _nextSerialNo; }; @@ -174,7 +178,6 @@ YTreeItem * origItem, int serial ); - /** * Constructor for a non-top level item. **/ @@ -184,11 +187,6 @@ int serial ); /** - * Recursively build the subtree corresponding to 'items'. - **/ - void buildSubTree( YTreeItemList & items, int & nextSerialNo ); - - /** * Returns the original YTreeItem of which this item is a clone. **/ YTreeItem * origItem() { return _origItem; } @@ -214,27 +212,22 @@ protected: /** - * The YQTree parent this item belongs to. - **/ - YQTree * _tree; - - /** - * The original YTreeItem of which this item is a clone. - **/ - YTreeItem * _origItem; - - /** - * The serial number of this item so the insertion sort order can - * be maintained at all times. - **/ - int _serialNo; - - /** - * Sort key of this item. Inherited by QListViewItem. + * Sort key of this item. + * + * Reimplemented from QListViewItem. **/ QString key( int column, bool ascending ) const; + + // + // Data members + // + + YQTree * _tree; + YTreeItem * _origItem; + int _serialNo; + }; -#endif // YQLabel_h +#endif // ifndef YQTree_h 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI.h (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI.h Fri Jul 6 18:44:27 2007 @@ -454,7 +454,6 @@ 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); - YWidget * createTree ( YWidget * parent, YWidgetOpt & opt, const YCPString & label); /*** Widget creation methods for optional widgets, all reimplemented from YUI ***/ Modified: branches/tmp/sh/mod-ui/qt/src/YQUI_builtins.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI_builtins.cc?rev=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI_builtins.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI_builtins.cc Fri Jul 6 18:44:27 2007 @@ -40,6 +40,7 @@ #include "YMacroRecorder.h" #include "YUISymbols.h" #include "YQDialog.h" +#include "YQSignalBlocker.h" #include "utf8.h" #include "YQi18n.h" @@ -185,9 +186,11 @@ fileName.sprintf( screenShotNameTemplate, baseName, no ); y2debug( "screenshot: %s", (const char *) fileName ); - _user_input_timer.blockSignals( true ); - fileName = askForSaveFileName( fileName, QString( "*.png" ) , _( "Save screen shot to..." ) ); - _user_input_timer.blockSignals( false ); + { + YQSignalBlocker sigBlocker( &_user_input_timer ); + + fileName = askForSaveFileName( fileName, QString( "*.png" ) , _( "Save screen shot to..." ) ); + } if ( fileName.isEmpty() ) { 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc Fri Jul 6 18:44:27 2007 @@ -108,13 +108,6 @@ } -YWidget * YQUI::createTree ( YWidget * parent, - YWidgetOpt & opt, - const YCPString & label ) -{ - return new YQTree( (QWidget *) ( parent->widgetRep() ), opt, label); -} - YWidget * YQUI::createTable ( YWidget * parent, YWidgetOpt & opt, vector<string> header ) 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc Fri Jul 6 18:44:27 2007 @@ -172,7 +172,10 @@ YQTree * YQWidgetFactory::createTree( YWidget * parent, const string & label ) { - return 0; // FIXME: TO DO + YQTree * tree = new YQTree( parent, label ); + YUI_CHECK_NEW( tree ); + + return tree; } 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=39223&r1=39222&r2=39223&view=diff ============================================================================== --- branches/tmp/sh/mod-ui/qt/src/YQWizard.cc (original) +++ branches/tmp/sh/mod-ui/qt/src/YQWizard.cc Fri Jul 6 18:44:27 2007 @@ -71,6 +71,7 @@ #include "YQWizardButton.h" #include "YQIconPool.h" #include "YQWidgetFactory.h" +#include "YQSignalBlocker.h" #include "QY2LayoutUtils.h" #include "YEvent.h" @@ -935,10 +936,10 @@ if ( item ) { - _tree->blockSignals( true ); + YQSignalBlocker sigBlocker( _tree ); + _tree->setSelected( item, true ); _tree->ensureItemVisible( item ); - _tree->blockSignals( false ); } } } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
sh-sh-sh@svn.opensuse.org