summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoamenuitem.mm
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2016-03-18 13:22:19 -0700
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2016-03-22 05:56:57 +0000
commit56384a854aeaa5d3275c158c80a07082949468da (patch)
tree2eb29e4462c7ef956d22d763088d65d91b1a5a9d /src/plugins/platforms/cocoa/qcocoamenuitem.mm
parentc228e01e1212a2ecd64d475980be04fc7b825bea (diff)
QCocoaMenus: Use mix-in pattern to implement menu hierarchy
To solve menu item roles from their text, we need to find its depth in the menubar hierarchy. Unfortunately, there's no trivial way to access that hierarchy from the QPA side, so we need to come with an ad-hoc solution. Previously, we were using a dynamic proprety to keep track of the 'parent' object. However, as the life span of the different objects has changed since 09acf326dbc6b7b67f21a36, we need a way to keep track of the parent's existence. This is what we do in this patch by having both QCocoaMenu and QCocoaMenuItem also inherit QCocoaMenuObject. This class' sole role is to store the menu hierarchy's parent object and wrap it in a QPointer. Change-Id: Ia18d95171af76d26f6325eef04c77b40d99c4285 Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com> Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoamenuitem.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenuitem.mm16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm
index e274448620..0f422843e0 100644
--- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm
@@ -105,8 +105,8 @@ QCocoaMenuItem::~QCocoaMenuItem()
{
QMacAutoReleasePool pool;
- if (m_menu && COCOA_MENU_ANCESTOR(m_menu) == this)
- SET_COCOA_MENU_ANCESTOR(m_menu, 0);
+ if (m_menu && m_menu->menuParent() == this)
+ m_menu->setMenuParent(0);
if (m_merged) {
[m_native setHidden:YES];
} else {
@@ -132,14 +132,14 @@ void QCocoaMenuItem::setMenu(QPlatformMenu *menu)
return;
if (m_menu) {
- if (COCOA_MENU_ANCESTOR(m_menu) == this)
- SET_COCOA_MENU_ANCESTOR(m_menu, 0);
+ if (m_menu->menuParent() == this)
+ m_menu->setMenuParent(0);
}
QMacAutoReleasePool pool;
m_menu = static_cast<QCocoaMenu *>(menu);
if (m_menu) {
- SET_COCOA_MENU_ANCESTOR(m_menu, this);
+ m_menu->setMenuParent(this);
} else {
// we previously had a menu, but no longer
// clear out our item so the nexy sync() call builds a new one
@@ -229,12 +229,14 @@ NSMenuItem *QCocoaMenuItem::sync()
mergeItem = [loader preferencesMenuItem];
break;
case TextHeuristicRole: {
- QObject *p = COCOA_MENU_ANCESTOR(this);
+ QObject *p = menuParent();
int depth = 1;
QCocoaMenuBar *menubar = 0;
while (depth < 3 && p && !(menubar = qobject_cast<QCocoaMenuBar *>(p))) {
++depth;
- p = COCOA_MENU_ANCESTOR(p);
+ QCocoaMenuObject *menuObject = dynamic_cast<QCocoaMenuObject *>(p);
+ Q_ASSERT(menuObject);
+ p = menuObject->menuParent();
}
if (depth == 3 || !menubar)
break; // Menu item too deep in the hierarchy, or not connected to any menubar