Cocoa Menu: Remove unnecessary retain, release/retain in the right order
Also, make sure platform menu item is deleted on ActionRemoved event. Change-Id: Ic07a81cb77833bdffd1464abf1c81ebdee4d16e9 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
This commit is contained in:
parent
8cbc7ef05c
commit
2bd846f8da
@ -218,8 +218,6 @@ NSMenuItem *QCocoaMenuItem::sync()
|
||||
mergeItem = [loader aboutMenuItem];
|
||||
else
|
||||
mergeItem = [loader aboutQtMenuItem];
|
||||
|
||||
m_merged = true;
|
||||
} else if (m_text.startsWith(tr("Config"), Qt::CaseInsensitive)
|
||||
|| m_text.startsWith(tr("Preference"), Qt::CaseInsensitive)
|
||||
|| m_text.startsWith(tr("Options"), Qt::CaseInsensitive)
|
||||
@ -240,9 +238,9 @@ NSMenuItem *QCocoaMenuItem::sync()
|
||||
|
||||
if (mergeItem) {
|
||||
m_merged = true;
|
||||
[mergeItem retain];
|
||||
[m_native release];
|
||||
m_native = mergeItem;
|
||||
[m_native retain]; // balance out release!
|
||||
[m_native setTag:reinterpret_cast<NSInteger>(this)];
|
||||
} else if (m_merged) {
|
||||
// was previously merged, but no longer
|
||||
@ -256,13 +254,12 @@ NSMenuItem *QCocoaMenuItem::sync()
|
||||
m_native = [[NSMenuItem alloc] initWithTitle:QCFString::toNSString(m_text)
|
||||
action:nil
|
||||
keyEquivalent:@""];
|
||||
[m_native retain];
|
||||
[m_native setTag:reinterpret_cast<NSInteger>(this)];
|
||||
}
|
||||
|
||||
// [m_native setHidden:YES];
|
||||
// [m_native setHidden:NO];
|
||||
[m_native setHidden: !m_isVisible];
|
||||
[m_native setHidden: !m_isVisible];
|
||||
[m_native setEnabled: m_enabled];
|
||||
QString text = m_text;
|
||||
QKeySequence accel = m_shortcut;
|
||||
|
@ -3004,6 +3004,7 @@ void QMenu::actionEvent(QActionEvent *e)
|
||||
} else if (e->type() == QEvent::ActionRemoved) {
|
||||
QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action()));
|
||||
d->platformMenu->removeMenuItem(menuItem);
|
||||
delete menuItem;
|
||||
} else if (e->type() == QEvent::ActionChanged) {
|
||||
QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action()));
|
||||
copyActionToPlatformItem(e->action(), menuItem);
|
||||
|
Loading…
Reference in New Issue
Block a user