macOS: Add logging category for menu machinery
The machinery is quit fragile, so any logging will help here. Pick-to: 6.5 Change-Id: I1906c0e33b4afbf649a20bfe2aa7210b6822087e Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
6a66554d3b
commit
391491c8b3
@ -335,6 +335,8 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem*)item
|
||||
{
|
||||
qCDebug(lcQpaMenus) << "Validating" << item << "for" << self;
|
||||
|
||||
auto *nativeItem = qt_objc_cast<QCocoaNSMenuItem *>(item);
|
||||
if (!nativeItem)
|
||||
return item.enabled; // FIXME Test with with Qt as plugin or embedded QWindow.
|
||||
@ -356,6 +358,8 @@ QT_USE_NAMESPACE
|
||||
|
||||
- (void)qt_itemFired:(QCocoaNSMenuItem *)item
|
||||
{
|
||||
qCDebug(lcQpaMenus) << "Activating" << item;
|
||||
|
||||
if (item.hasSubmenu)
|
||||
return;
|
||||
|
||||
|
@ -42,6 +42,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaApplication)
|
||||
Q_DECLARE_LOGGING_CATEGORY(lcQpaClipboard)
|
||||
Q_DECLARE_LOGGING_CATEGORY(lcInputDevices)
|
||||
Q_DECLARE_LOGGING_CATEGORY(lcQpaDialogs)
|
||||
Q_DECLARE_LOGGING_CATEGORY(lcQpaMenus)
|
||||
|
||||
class QPixmap;
|
||||
class QString;
|
||||
|
@ -29,6 +29,7 @@ Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application");
|
||||
Q_LOGGING_CATEGORY(lcQpaClipboard, "qt.qpa.clipboard")
|
||||
Q_LOGGING_CATEGORY(lcInputDevices, "qt.qpa.input.devices")
|
||||
Q_LOGGING_CATEGORY(lcQpaDialogs, "qt.qpa.dialogs")
|
||||
Q_LOGGING_CATEGORY(lcQpaMenus, "qt.qpa.menus")
|
||||
|
||||
//
|
||||
// Conversion Functions
|
||||
|
@ -88,7 +88,7 @@ void QCocoaMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *
|
||||
int index = m_menuItems.indexOf(beforeItem);
|
||||
// if a before item is supplied, it should be in the menu
|
||||
if (index < 0) {
|
||||
qWarning("Before menu item not found");
|
||||
qCWarning(lcQpaMenus) << beforeItem << "not in" << m_menuItems;
|
||||
return;
|
||||
}
|
||||
m_menuItems.insert(index, cocoaItem);
|
||||
@ -126,13 +126,13 @@ void QCocoaMenu::insertNative(QCocoaMenuItem *item, QCocoaMenuItem *beforeItem)
|
||||
}
|
||||
|
||||
if (nativeItem.menu) {
|
||||
qWarning() << "Menu item" << item->text() << "already in menu" << QString::fromNSString(nativeItem.menu.title);
|
||||
qCWarning(lcQpaMenus) << "Menu item" << item->text() << "already in menu" << QString::fromNSString(nativeItem.menu.title);
|
||||
return;
|
||||
}
|
||||
|
||||
if (beforeItem) {
|
||||
if (beforeItem->isMerged()) {
|
||||
qWarning("No non-merged before menu item found");
|
||||
qCWarning(lcQpaMenus, "No non-merged before menu item found");
|
||||
return;
|
||||
}
|
||||
const NSInteger nativeIndex = [m_nativeMenu indexOfItem:beforeItem->nsItem()];
|
||||
@ -168,7 +168,7 @@ void QCocoaMenu::removeMenuItem(QPlatformMenuItem *menuItem)
|
||||
QMacAutoReleasePool pool;
|
||||
QCocoaMenuItem *cocoaItem = static_cast<QCocoaMenuItem *>(menuItem);
|
||||
if (!m_menuItems.contains(cocoaItem)) {
|
||||
qWarning("Menu does not contain the item to be removed");
|
||||
qCWarning(lcQpaMenus) << m_menuItems << "does not contain" << cocoaItem;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ void QCocoaMenu::removeMenuItem(QPlatformMenuItem *menuItem)
|
||||
m_menuItems.removeOne(cocoaItem);
|
||||
if (!cocoaItem->isMerged()) {
|
||||
if (m_nativeMenu != cocoaItem->nsItem().menu) {
|
||||
qWarning("Item to remove does not belong to this menu");
|
||||
qCWarning(lcQpaMenus) << cocoaItem << "does not belong to" << m_nativeMenu;
|
||||
return;
|
||||
}
|
||||
[m_nativeMenu removeItem:cocoaItem->nsItem()];
|
||||
@ -221,7 +221,7 @@ void QCocoaMenu::syncMenuItem_helper(QPlatformMenuItem *menuItem, bool menubarUp
|
||||
QMacAutoReleasePool pool;
|
||||
QCocoaMenuItem *cocoaItem = static_cast<QCocoaMenuItem *>(menuItem);
|
||||
if (!m_menuItems.contains(cocoaItem)) {
|
||||
qWarning("Item does not belong to this menu");
|
||||
qCWarning(lcQpaMenus) << cocoaItem << "does not belong to" << this;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "qcocoamenuloader.h"
|
||||
#include "qcocoaapplication.h" // for custom application category
|
||||
#include "qcocoaapplicationdelegate.h"
|
||||
#include "qcocoahelpers.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtCore/QDebug>
|
||||
@ -30,16 +31,12 @@ QCocoaMenuBar::QCocoaMenuBar()
|
||||
});
|
||||
|
||||
m_nativeMenu = [[NSMenu alloc] init];
|
||||
#ifdef QT_COCOA_ENABLE_MENU_DEBUG
|
||||
qDebug() << "Construct QCocoaMenuBar" << this << m_nativeMenu;
|
||||
#endif
|
||||
qCDebug(lcQpaMenus) << "Constructed" << this << "with" << m_nativeMenu;
|
||||
}
|
||||
|
||||
QCocoaMenuBar::~QCocoaMenuBar()
|
||||
{
|
||||
#ifdef QT_COCOA_ENABLE_MENU_DEBUG
|
||||
qDebug() << "~QCocoaMenuBar" << this;
|
||||
#endif
|
||||
qCDebug(lcQpaMenus) << "Destructing" << this << "with" << m_nativeMenu;;
|
||||
for (auto menu : std::as_const(m_menus)) {
|
||||
if (!menu)
|
||||
continue;
|
||||
@ -93,17 +90,16 @@ void QCocoaMenuBar::insertMenu(QPlatformMenu *platformMenu, QPlatformMenu *befor
|
||||
{
|
||||
QCocoaMenu *menu = static_cast<QCocoaMenu *>(platformMenu);
|
||||
QCocoaMenu *beforeMenu = static_cast<QCocoaMenu *>(before);
|
||||
#ifdef QT_COCOA_ENABLE_MENU_DEBUG
|
||||
qDebug() << "QCocoaMenuBar" << this << "insertMenu" << menu << "before" << before;
|
||||
#endif
|
||||
|
||||
qCDebug(lcQpaMenus) << "Inserting" << menu << "before" << before << "into" << this;
|
||||
|
||||
if (m_menus.contains(QPointer<QCocoaMenu>(menu))) {
|
||||
qWarning("This menu already belongs to the menubar, remove it first");
|
||||
qCWarning(lcQpaMenus, "This menu already belongs to the menubar, remove it first");
|
||||
return;
|
||||
}
|
||||
|
||||
if (beforeMenu && !m_menus.contains(QPointer<QCocoaMenu>(beforeMenu))) {
|
||||
qWarning("The before menu does not belong to the menubar");
|
||||
qCWarning(lcQpaMenus, "The before menu does not belong to the menubar");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -137,7 +133,7 @@ void QCocoaMenuBar::removeMenu(QPlatformMenu *platformMenu)
|
||||
{
|
||||
QCocoaMenu *menu = static_cast<QCocoaMenu *>(platformMenu);
|
||||
if (!m_menus.contains(menu)) {
|
||||
qWarning("Trying to remove a menu that does not belong to the menubar");
|
||||
qCWarning(lcQpaMenus) << "Trying to remove" << menu << "that does not belong to" << this;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -207,9 +203,7 @@ NSMenuItem *QCocoaMenuBar::nativeItemForMenu(QCocoaMenu *menu) const
|
||||
|
||||
void QCocoaMenuBar::handleReparent(QWindow *newParentWindow)
|
||||
{
|
||||
#ifdef QT_COCOA_ENABLE_MENU_DEBUG
|
||||
qDebug() << "QCocoaMenuBar" << this << "handleReparent" << newParentWindow;
|
||||
#endif
|
||||
qCDebug(lcQpaMenus) << "Reparenting" << this << "to" << newParentWindow;
|
||||
|
||||
if (!m_window.isNull())
|
||||
m_window->setMenubar(nullptr);
|
||||
@ -277,9 +271,8 @@ void QCocoaMenuBar::updateMenuBarImmediately()
|
||||
if (!mb)
|
||||
return;
|
||||
|
||||
#ifdef QT_COCOA_ENABLE_MENU_DEBUG
|
||||
qDebug() << "QCocoaMenuBar" << "updateMenuBarImmediately" << cw;
|
||||
#endif
|
||||
qCDebug(lcQpaMenus) << "Updating" << mb << "immediately for" << cw;
|
||||
|
||||
bool disableForModal = mb->shouldDisable(cw);
|
||||
|
||||
for (auto menu : std::as_const(mb->m_menus)) {
|
||||
|
@ -8,8 +8,6 @@
|
||||
#include <qpa/qplatformmenu.h>
|
||||
#include <QtGui/QImage>
|
||||
|
||||
//#define QT_COCOA_ENABLE_MENU_DEBUG
|
||||
|
||||
Q_FORWARD_DECLARE_OBJC_CLASS(NSMenuItem);
|
||||
Q_FORWARD_DECLARE_OBJC_CLASS(NSMenu);
|
||||
Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
|
||||
|
@ -383,7 +383,7 @@ QKeySequence QCocoaMenuItem::mergeAccel()
|
||||
void QCocoaMenuItem::syncMerged()
|
||||
{
|
||||
if (!m_merged) {
|
||||
qWarning("Trying to sync a non-merged item");
|
||||
qCWarning(lcQpaMenus) << "Trying to sync non-merged" << this;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ static bool selectorIsCutCopyPaste(SEL selector)
|
||||
|
||||
- (BOOL)validateMenuItem:(NSMenuItem*)item
|
||||
{
|
||||
qCDebug(lcQpaMenus) << "Validating" << item << "for" << self;
|
||||
|
||||
auto *nativeItem = qt_objc_cast<QCocoaNSMenuItem *>(item);
|
||||
if (!nativeItem)
|
||||
return item.enabled; // FIXME Test with with Qt as plugin or embedded QWindow.
|
||||
@ -88,6 +90,7 @@ static bool selectorIsCutCopyPaste(SEL selector)
|
||||
if (selectorIsCutCopyPaste(invocation.selector)) {
|
||||
NSObject *sender;
|
||||
[invocation getArgument:&sender atIndex:2];
|
||||
qCDebug(lcQpaMenus) << "Forwarding" << invocation.selector << "from" << sender;
|
||||
if (auto *nativeItem = qt_objc_cast<QCocoaNSMenuItem *>(sender)) {
|
||||
[self qt_itemFired:nativeItem];
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user