Author: sh-sh-sh
Date: Wed Oct 10 22:35:28 2007
New Revision: 41354
URL: http://svn.opensuse.org/viewcvs/yast?rev=41354&view=rev
Log:
Moved gory details to base class
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.cc
branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.h
branches/tmp/sh/mod-ui/qt/src/YQMenuButton.cc
branches/tmp/sh/mod-ui/qt/src/YQMenuButton.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.cc?rev=41354&r1=41353&r2=41354&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.cc Wed Oct 10 22:35:28 2007
@@ -28,9 +28,10 @@
struct YMenuButtonPrivate
{
YMenuButtonPrivate()
+ : nextSerialNo( 0 )
{}
- int dummy;
+ int nextSerialNo;
};
@@ -51,7 +52,8 @@
}
-void YMenuButton::addItems( const YItemCollection & itemCollection )
+void
+YMenuButton::addItems( const YItemCollection & itemCollection )
{
YSelectionWidget::addItems( itemCollection );
resolveShortcutConflicts();
@@ -60,6 +62,73 @@
void
+YMenuButton::addItem( YItem * item )
+{
+ YSelectionWidget::addItem( item );
+ item->setIndex( ++(priv->nextSerialNo) );
+
+ if ( item->hasChildren() )
+ assignUniqueIndex( item->childrenBegin(), item->childrenEnd() );
+}
+
+
+void
+YMenuButton::assignUniqueIndex( YItemIterator begin, YItemIterator end )
+{
+ for ( YItemIterator it = begin; it != end; ++it )
+ {
+ YItem * item = *it;
+
+ item->setIndex( ++(priv->nextSerialNo) );
+
+ if ( item->hasChildren() )
+ assignUniqueIndex( item->childrenBegin(), item->childrenEnd() );
+ }
+}
+
+
+void
+YMenuButton::deleteAllItems()
+{
+ YSelectionWidget::deleteAllItems();
+ priv->nextSerialNo = 0;
+}
+
+
+YMenuItem *
+YMenuButton::findMenuItem( int index )
+{
+ return findMenuItem( index, itemsBegin(), itemsEnd() );
+}
+
+
+YMenuItem *
+YMenuButton::findMenuItem( int wantedIndex, YItemConstIterator begin, YItemConstIterator end )
+{
+ for ( YItemConstIterator it = begin; it != end; ++it )
+ {
+ YMenuItem * item = dynamic_cast (*it);
+
+ if ( item )
+ {
+ if ( item->index() == wantedIndex )
+ return item;
+
+ if ( item->hasChildren() )
+ {
+ YMenuItem * result = findMenuItem( wantedIndex, item->childrenBegin(), item->childrenEnd() );
+
+ if ( result )
+ return result;
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+void
YMenuButton::resolveShortcutConflicts()
{
// TO DO
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.h?rev=41354&r1=41353&r2=41354&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YMenuButton.h Wed Oct 10 22:35:28 2007
@@ -20,6 +20,7 @@
#define YMenuButton_h
#include "YSelectionWidget.h"
+#include "YMenuItem.h"
class YMacroRecorder;
class YMenuItem;
@@ -85,6 +86,25 @@
virtual void addItems( const YItemCollection & itemCollection );
/**
+ * Add one item. This widget assumes ownership of the item object and will
+ * delete it in its destructor.
+ *
+ * This reimplementation will an index to the item that is unique for all
+ * items in this MenuButton. That index can be used later with
+ * findMenuItem() to find the item by that index.
+ *
+ * Reimplemented from YSelectionWidget.
+ **/
+ virtual void addItem( YItem * item );
+
+ /**
+ * Delete all items.
+ *
+ * Reimplemented from YSelectionWidget.
+ **/
+ virtual void deleteAllItems();
+
+ /**
* Resolve keyboard shortcut conflicts: Change shortcuts of menu items if
* there are duplicates in the respective menu level.
*
@@ -122,9 +142,37 @@
**/
virtual const YPropertySet & propertySet();
+protected:
+
+ /**
+ * Recursively find the first menu item with the specified index.
+ * Returns 0 if there is no such item.
+ **/
+ YMenuItem * findMenuItem( int index );
+
+ /**
+ * Recursively find the first menu item with the specified index
+ * from iterator 'begin' to iterator 'end'.
+ *
+ * Returns 0 if there is no such item.
+ **/
+ YMenuItem * findMenuItem( int index, YItemConstIterator begin, YItemConstIterator end );
+
+ /**
+ * Alias for findMenuItem(). Reimplemented to ensure consistent behaviour
+ * with YSelectionWidget::itemAt().
+ **/
+ YMenuItem * itemAt( int index )
+ { return findMenuItem( index ); }
private:
+ /**
+ * Assign a unique index to all items from iterator 'begin' to iterator 'end'.
+ **/
+ void assignUniqueIndex( YItemIterator begin, YItemIterator end );
+
+
ImplPtr<YMenuButtonPrivate> priv;
};
Modified: branches/tmp/sh/mod-ui/qt/src/YQMenuButton.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMenuButton.cc?rev=41354&r1=41353&r2=41354&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQMenuButton.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQMenuButton.cc Wed Oct 10 22:35:28 2007
@@ -28,7 +28,6 @@
#include "utf8.h"
#include "YQUI.h"
#include "YQMenuButton.h"
-#include "YMenuItem.h"
#include "YEvent.h"
@@ -37,7 +36,6 @@
const string & label )
: QWidget( (QWidget *) parent->widgetRep() )
, YMenuButton( parent, label )
- , _nextSerialNo( 0 )
, _selectedItem( 0 )
{
setWidgetRep( this );
@@ -89,7 +87,6 @@
// Recursively add Qt menu items from the YMenuItems
//
- _nextSerialNo = 0;
rebuildMenuTree( menu, itemsBegin(), itemsEnd() );
}
@@ -103,7 +100,7 @@
YUI_CHECK_PTR( item );
QPixmap icon;
-
+
if ( item->hasIconName() )
{
string iconName = iconFullPath( item );
@@ -130,47 +127,16 @@
}
else // No children - leaf entry
{
- item->setData( (void *) ++_nextSerialNo );
-
+ // item->index() is guaranteed to be unique within this YMenuButton's items,
+ // so it can easily be used as unique ID in all QPopupMenus that belong
+ // to this YQMenuButton.
+
if ( icon.isNull() )
- parentMenu->insertItem( fromUTF8( item->label() ), _nextSerialNo );
+ parentMenu->insertItem( fromUTF8( item->label() ), item->index() );
else
- parentMenu->insertItem( QIconSet( icon ), fromUTF8( item->label() ), _nextSerialNo );
- }
- }
-}
-
-
-YMenuItem *
-YQMenuButton::findMenuItem( int serialNo )
-{
- return findMenuItem( serialNo, itemsBegin(), itemsEnd() );
-}
-
-
-YMenuItem *
-YQMenuButton::findMenuItem( int serialNo, YItemConstIterator begin, YItemConstIterator end )
-{
- for ( YItemConstIterator it = begin; it != end; ++it )
- {
- YMenuItem * item = dynamic_cast (*it);
-
- if ( item )
- {
- if ( item->data() == (void *) serialNo )
- return item;
-
- if ( item->hasChildren() )
- {
- YMenuItem * result = findMenuItem( serialNo, item->childrenBegin(), item->childrenEnd() );
-
- if ( result )
- return result;
- }
+ parentMenu->insertItem( QIconSet( icon ), fromUTF8( item->label() ), item->index() );
}
}
-
- return 0;
}
Modified: branches/tmp/sh/mod-ui/qt/src/YQMenuButton.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMenuButton.h?rev=41354&r1=41353&r2=41354&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQMenuButton.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQMenuButton.h Wed Oct 10 22:35:28 2007
@@ -114,23 +114,11 @@
**/
void rebuildMenuTree( QPopupMenu * menu, YItemIterator begin, YItemIterator end );
- /**
- * Recursively find the first menu item with the specified serial no.
- **/
- YMenuItem * findMenuItem( int serialNo );
-
- /**
- * Recursively find the first menu item with the specified serial no
- * from iterator 'begin' to iterator 'end'.
- **/
- YMenuItem * findMenuItem( int serialNo, YItemConstIterator begin, YItemConstIterator end );
-
//
// Data members
//
- int _nextSerialNo;
YMenuItem * _selectedItem;
QPushButton * _qt_button;
};
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org