From 4e7e5341031c5bec0d96e6c8324cb62113f65849 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 9 Jan 2009 02:15:23 +0000 Subject: [PATCH] * add actions in the order they are added, not alphabetically by name (?!) * remove actions if they get deleted CCBUG:30042 svn path=/trunk/KDE/kdelibs/; revision=907996 --- extenderitem.cpp | 28 ++++++++++++++++++++++++++-- extenderitem.h | 1 + private/extenderitem_p.h | 4 +++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/extenderitem.cpp b/extenderitem.cpp index bc226bae2..0bc1c5c15 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -331,9 +331,14 @@ bool ExtenderItem::isDetached() const void ExtenderItem::addAction(const QString &name, QAction *action) { Q_ASSERT(action); + if (d->actionsInOrder.contains(action)) { + return; + } d->actions.insert(name, action); + d->actionsInOrder.append(action); connect(action, SIGNAL(changed()), this, SLOT(updateToolBox())); + connect(action, SIGNAL(destroyed(QObject*)), this, SLOT(actionDestroyed(QObject*))); d->updateToolBox(); } @@ -907,7 +912,7 @@ void ExtenderItemPrivate::updateToolBox() } //add the actions that are actually set to visible. - foreach (QAction *action, actions) { + foreach (QAction *action, actionsInOrder) { if (action->isVisible()) { IconWidget *icon = new IconWidget(q); icon->setAction(action); @@ -1106,10 +1111,29 @@ void ExtenderItemPrivate::resizeContent(const QSizeF &newSize) void ExtenderItemPrivate::previousTargetExtenderDestroyed(QObject *o) { Q_UNUSED(o) - previousTargetExtender = 0; } +void ExtenderItemPrivate::actionDestroyed(QObject *o) +{ + QAction *action = static_cast(o); + QMutableHashIterator hit(actions); + while (hit.hasNext()) { + if (hit.next().value() == action) { + hit.remove(); + break; + } + } + + QMutableListIterator lit(actionsInOrder); + while (lit.hasNext()) { + if (lit.next() == action) { + lit.remove(); + break; + } + } +} + uint ExtenderItemPrivate::s_maxExtenderItemId = 0; } // namespace Plasma diff --git a/extenderitem.h b/extenderitem.h index 6d9718441..b68829a0a 100644 --- a/extenderitem.h +++ b/extenderitem.h @@ -249,6 +249,7 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget Q_PRIVATE_SLOT(d, void themeChanged()) Q_PRIVATE_SLOT(d, void sourceAppletRemoved()) Q_PRIVATE_SLOT(d, void previousTargetExtenderDestroyed(QObject*)) + Q_PRIVATE_SLOT(d, void actionDestroyed(QObject*)) ExtenderItemPrivate * const d; diff --git a/private/extenderitem_p.h b/private/extenderitem_p.h index e048b40f5..2a04ed879 100644 --- a/private/extenderitem_p.h +++ b/private/extenderitem_p.h @@ -59,6 +59,7 @@ class ExtenderItemPrivate qreal iconSize(); void resizeContent(const QSizeF &newSize); void previousTargetExtenderDestroyed(QObject *o); + void actionDestroyed(QObject *o); ExtenderItem *q; @@ -78,7 +79,8 @@ class ExtenderItemPrivate IconWidget *collapseIcon; - QMap actions; + QHash actions; + QList actionsInOrder; QString title; QString name;