-Action *ActionCollection::addAction(const QString &name, const QObject *receiver, const char *member) {
- Action *a = new Action(this);
- if(receiver && member)
- connect(a, SIGNAL(triggered(bool)), receiver, member);
- return addAction(name, a);
-}
+QAction* ActionCollection::addAction(const QString& name, QAction* action)
+{
+ if (!action)
+ return action;
+
+ const QString origName = action->objectName();
+ QString indexName = name;
+
+ if (indexName.isEmpty())
+ indexName = action->objectName();
+ else
+ action->setObjectName(indexName);
+ if (indexName.isEmpty())
+ indexName = indexName.asprintf("unnamed-%p", (void*)action);
+
+ // do we already have this action?
+ if (_actionByName.value(indexName, 0) == action)
+ return action;
+ // or maybe another action under this name?
+ if (QAction* oldAction = _actionByName.value(indexName))
+ takeAction(oldAction);
+
+ // do we already have this action under a different name?
+ int oldIndex = _actions.indexOf(action);
+ if (oldIndex != -1) {
+ _actionByName.remove(origName);
+ _actions.removeAt(oldIndex);
+ }