Commit 3f0a4446 authored by con's avatar con
Browse files

Make action containers aware of deleted commands.

They need to remove them from their internal structure.
parent 06acd2cc
......@@ -245,6 +245,7 @@ void ActionContainerPrivate::addAction(Command *command, const QString &groupId)
m_groups[groupIt-m_groups.constBegin()].items.append(command);
connect(command, SIGNAL(activeStateChanged()), this, SLOT(scheduleUpdate()));
connect(command, SIGNAL(destroyed()), this, SLOT(itemDestroyed()));
insertAction(beforeAction, command->action());
scheduleUpdate();
}
......@@ -271,6 +272,17 @@ void ActionContainerPrivate::addMenu(ActionContainer *menu, const QString &group
scheduleUpdate();
}
void ActionContainerPrivate::itemDestroyed()
{
QObject *obj = sender();
QMutableListIterator<Group> it(m_groups);
while (it.hasNext()) {
Group &group = it.next();
if (group.items.removeAll(obj) > 0)
break;
}
}
int ActionContainerPrivate::id() const
{
return m_id;
......
......@@ -85,6 +85,7 @@ protected:
private slots:
void scheduleUpdate();
void update();
void itemDestroyed();
private:
QList<Group>::const_iterator findGroup(const QString &groupId) const;
......
......@@ -247,8 +247,9 @@ ActionManagerPrivate::ActionManagerPrivate(MainWindow *mainWnd)
ActionManagerPrivate::~ActionManagerPrivate()
{
qDeleteAll(m_idCmdMap.values());
// first delete containers to avoid them reacting to command deletion
qDeleteAll(m_idContainerMap.values());
qDeleteAll(m_idCmdMap.values());
}
ActionManagerPrivate *ActionManagerPrivate::instance()
......@@ -382,6 +383,7 @@ void ActionManagerPrivate::unregisterAction(QAction *action, const Id &id)
a->removeOverrideAction(action);
if (a->isEmpty()) {
// clean up
// ActionContainers listen to the commands' destroyed signals
m_mainWnd->removeAction(a->action());
delete a->action();
m_idCmdMap.remove(uid);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment