Extend API to allow (re)positioning menu items during procedural insert.
REVIEW:127645
This commit is contained in:
parent
553a9bfe53
commit
70301e21b9
@ -167,10 +167,20 @@ void QMenuProxy::addMenuItem(const QString &text)
|
||||
m_items << item;
|
||||
}
|
||||
|
||||
void QMenuProxy::addMenuItem(QMenuItem *item)
|
||||
void QMenuProxy::addMenuItem(QMenuItem *item, QMenuItem *before)
|
||||
{
|
||||
m_menu->addAction(item->action());
|
||||
m_items << item;
|
||||
if (before) {
|
||||
if (m_items.contains(item)) {
|
||||
m_menu->removeAction(item->action());
|
||||
} else {
|
||||
m_items << item;
|
||||
}
|
||||
|
||||
m_menu->insertAction(before->action(), item->action());
|
||||
} else if (!m_items.contains(item)) {
|
||||
m_menu->addAction(item->action());
|
||||
m_items << item;
|
||||
}
|
||||
}
|
||||
|
||||
void QMenuProxy::addSection(const QString &text)
|
||||
|
@ -116,9 +116,13 @@ public:
|
||||
*/
|
||||
Q_INVOKABLE void addMenuItem(const QString &text);
|
||||
/**
|
||||
* This adds a menu item of type MenuItem
|
||||
* This adds MenuItem 'item' to the menu before MenuItem 'before'.
|
||||
* If MenuItem 'before' is 0 or does not exist in the menu, 'item'
|
||||
* is appended to the menu instead.
|
||||
* If MenuItem 'item' already exists in the menu, it is removed and
|
||||
* inserted at the new position.
|
||||
*/
|
||||
Q_INVOKABLE void addMenuItem(QMenuItem *item);
|
||||
Q_INVOKABLE void addMenuItem(QMenuItem *item, QMenuItem *before = nullptr);
|
||||
/**
|
||||
* This adds a section header with a string used as name for the section
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user