QCocoaMenu: Sync menubar menu when adding items

Empty menus on a menubar are hidden by default. If the menu gets
added to the menubar before it contains any item, we need to get
the menubar to sync the menu, which will update its native menu
item hidden property.

Menurama manual test's 'Add Many Items' button should now work.

Change-Id: I8ce1df21031c171789318fdf28ae495819458d71
Task-number: QTBUG-62260
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Gabriel de Dietrich 2017-08-10 10:30:56 +07:00
parent f27d1ccbb2
commit 306071e50e
2 changed files with 8 additions and 1 deletions

View File

@ -328,6 +328,13 @@ void QCocoaMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *
}
insertNative(cocoaItem, beforeItem);
// Empty menus on a menubar are hidden by default. If the menu gets
// added to the menubar before it contains any item, we need to sync.
if (isVisible() && attachedItem().hidden) {
if (auto *mb = qobject_cast<QCocoaMenuBar *>(menuParent()))
mb->syncMenu(this);
}
}
void QCocoaMenu::insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem)

View File

@ -370,7 +370,7 @@ void QCocoaMenuBar::updateMenuBarImmediately()
QCocoaMenuLoader *loader = [QCocoaMenuLoader sharedMenuLoader];
[loader ensureAppMenuInMenu:mb->nsMenu()];
NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:0] retain];
NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:mb->merged().count()] retain];
foreach (QCocoaMenuItem *m, mb->merged()) {
[mergedItems addObject:m->nsItem()];
m->syncMerged();