diff --git a/extenderitem.cpp b/extenderitem.cpp index 224e5169d..94db3aa55 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); @@ -1105,10 +1110,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;