forked from qt-creator/qt-creator
ActionContainer: Fix inconsistency in book keeping
It doesn't make sense to specify both a group ID and a menu to add another menu before. This most certainly leads to inconsistency in the internal book keeping in m_groups vs the actual menu insertion point. Change-Id: Ic30508f390885ddeb72eb94f26efb75456b469ec Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -263,20 +263,25 @@ void ActionContainerPrivate::addMenu(ActionContainer *menu, Id groupId)
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
void ActionContainerPrivate::addMenu(ActionContainer *before, ActionContainer *menu, Id groupId)
|
||||
void ActionContainerPrivate::addMenu(ActionContainer *before, ActionContainer *menu)
|
||||
{
|
||||
auto containerPrivate = static_cast<ActionContainerPrivate *>(menu);
|
||||
if (!containerPrivate->canBeAddedToMenu())
|
||||
return;
|
||||
|
||||
auto container = static_cast<MenuActionContainer *>(containerPrivate);
|
||||
const Id actualGroupId = groupId.isValid() ? groupId : Id(Constants::G_DEFAULT_TWO);
|
||||
QList<Group>::const_iterator groupIt = findGroup(actualGroupId);
|
||||
QTC_ASSERT(groupIt != m_groups.constEnd(), return);
|
||||
QAction *beforeAction = before->menu()->menuAction();
|
||||
m_groups[groupIt-m_groups.constBegin()].items.append(menu);
|
||||
QMutableListIterator<Group> it(m_groups);
|
||||
while (it.hasNext()) {
|
||||
Group &group = it.next();
|
||||
const int insertionPoint = group.items.indexOf(before);
|
||||
if (insertionPoint >= 0) {
|
||||
group.items.insert(insertionPoint, menu);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
connect(menu, &QObject::destroyed, this, &ActionContainerPrivate::itemDestroyed);
|
||||
auto container = static_cast<MenuActionContainer *>(containerPrivate);
|
||||
QAction *beforeAction = before->menu()->menuAction();
|
||||
insertMenu(beforeAction, container->menu());
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
@@ -64,7 +64,7 @@ public:
|
||||
virtual void insertGroup(Id before, Id group) = 0;
|
||||
virtual void addAction(Command *action, Id group = Id()) = 0;
|
||||
virtual void addMenu(ActionContainer *menu, Id group = Id()) = 0;
|
||||
virtual void addMenu(ActionContainer *before, ActionContainer *menu, Id group = Id()) = 0;
|
||||
virtual void addMenu(ActionContainer *before, ActionContainer *menu) = 0;
|
||||
Command *addSeparator(Id group = Id());
|
||||
virtual Command *addSeparator(const Context &context, Id group = Id(), QAction **outSeparator = nullptr) = 0;
|
||||
|
||||
|
@@ -56,7 +56,7 @@ public:
|
||||
void insertGroup(Id before, Id groupId) override;
|
||||
void addAction(Command *action, Id group = Id()) override;
|
||||
void addMenu(ActionContainer *menu, Id group = Id()) override;
|
||||
void addMenu(ActionContainer *before, ActionContainer *menu, Id group = Id()) override;
|
||||
void addMenu(ActionContainer *before, ActionContainer *menu) override;
|
||||
Command *addSeparator(const Context &context, Id group = Id(), QAction **outSeparator = nullptr) override;
|
||||
void clear() override;
|
||||
|
||||
|
Reference in New Issue
Block a user