From 98dbaecf7f9c16be82b895a75ff02e89ff1f3269 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Mon, 21 May 2012 15:33:42 +0200 Subject: [PATCH] Minor QPlatformMenu API cleanup. Make the QPlatformMenu* classes abstract with pure virtual functions. Delete qplatformmenu_qpa.cpp. QtGui no longer has to carry the empty implementations. Change the inheritance tree - Make QPlatformMenu and QPlatformMenuBar inherit QObject instead of QMenuItem. Add (now) missing virtual functions to QPlatformMenu. The effect of this change is to reduce the number of pure virtuals the platform has to implement. Change QPlatformMenuBar::syncMenu to take a QPlatformMenu pointer instead of a QPlatformMenuItem* pointer. Fix a couple of header/unused variable compiler warnings. Change-Id: I77450e40c6aae26f3e1aca204603acebd242c036 Reviewed-by: Friedemann Kleint Reviewed-by: Bradley T. Hughes --- src/gui/kernel/kernel.pri | 1 - src/gui/kernel/qplatformmenu.h | 56 +++--- src/gui/kernel/qplatformmenu_qpa.cpp | 161 ------------------ src/plugins/platforms/cocoa/qcocoamenubar.h | 2 +- src/plugins/platforms/cocoa/qcocoamenubar.mm | 4 +- .../platforms/cocoa/qcocoanativeinterface.mm | 1 + src/plugins/platforms/cocoa/qcocoatheme.mm | 4 +- 7 files changed, 37 insertions(+), 192 deletions(-) mode change 100644 => 100755 src/gui/kernel/qplatformmenu.h delete mode 100755 src/gui/kernel/qplatformmenu_qpa.cpp diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 0f46a8df52..9ea2d76aea 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -80,7 +80,6 @@ SOURCES += \ kernel/qplatformcursor_qpa.cpp \ kernel/qplatformclipboard_qpa.cpp \ kernel/qplatformnativeinterface_qpa.cpp \ - kernel/qplatformmenu_qpa.cpp \ kernel/qsessionmanager_qpa.cpp \ kernel/qsurfaceformat.cpp \ kernel/qguiapplication.cpp \ diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h old mode 100644 new mode 100755 index 4e36f5aee6..298dd5dd68 --- a/src/gui/kernel/qplatformmenu.h +++ b/src/gui/kernel/qplatformmenu.h @@ -69,50 +69,56 @@ public: enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole, AboutRole, PreferencesRole, QuitRole }; - virtual void setTag(quintptr tag); - virtual quintptr tag() const; + virtual void setTag(quintptr tag) = 0; + virtual quintptr tag()const = 0; - virtual void setText(const QString &text); - virtual void setIcon(const QImage &icon); - virtual void setMenu(QPlatformMenu *menu); - virtual void setVisible(bool isVisible); - virtual void setIsSeparator(bool isSeparator); - virtual void setFont(const QFont &font); - virtual void setRole(MenuRole role); - virtual void setChecked(bool isChecked); - virtual void setShortcut(const QKeySequence& shortcut); - virtual void setEnabled(bool enabled); + virtual void setText(const QString &text) = 0; + virtual void setIcon(const QImage &icon) = 0; + virtual void setMenu(QPlatformMenu *menu) = 0; + virtual void setVisible(bool isVisible) = 0; + virtual void setIsSeparator(bool isSeparator) = 0; + virtual void setFont(const QFont &font) = 0; + virtual void setRole(MenuRole role) = 0; + virtual void setChecked(bool isChecked) = 0; + virtual void setShortcut(const QKeySequence& shortcut) = 0; + virtual void setEnabled(bool enabled) = 0; Q_SIGNALS: void activated(); void hovered(); }; -class Q_GUI_EXPORT QPlatformMenu : public QPlatformMenuItem // Some (but not all) of the PlatformMenuItem API applies to QPlatformMenu as well. +class Q_GUI_EXPORT QPlatformMenu : public QObject { Q_OBJECT public: - virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before); - virtual void removeMenuItem(QPlatformMenuItem *menuItem); - virtual void syncMenuItem(QPlatformMenuItem *menuItem); - virtual void syncSeparatorsCollapsible(bool enable); + virtual void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) = 0; + virtual void removeMenuItem(QPlatformMenuItem *menuItem) = 0; + virtual void syncMenuItem(QPlatformMenuItem *menuItem) = 0; + virtual void syncSeparatorsCollapsible(bool enable) = 0; - virtual QPlatformMenuItem *menuItemAt(int position) const; - virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const; + virtual void setTag(quintptr tag) = 0; + virtual quintptr tag()const = 0; + + virtual void setText(const QString &text) = 0; + virtual void setEnabled(bool enabled) = 0; + + virtual QPlatformMenuItem *menuItemAt(int position) const = 0; + virtual QPlatformMenuItem *menuItemForTag(quintptr tag) const = 0; Q_SIGNALS: void aboutToShow(); void aboutToHide(); }; -class Q_GUI_EXPORT QPlatformMenuBar : public QPlatformMenu +class Q_GUI_EXPORT QPlatformMenuBar : public QObject { Q_OBJECT public: - virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before); - virtual void removeMenu(QPlatformMenu *menu); - virtual void syncMenu(QPlatformMenuItem *menuItem); - virtual void handleReparent(QWindow *newParentWindow); + virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) = 0; + virtual void removeMenu(QPlatformMenu *menu) = 0; + virtual void syncMenu(QPlatformMenu *menuItem) = 0; + virtual void handleReparent(QWindow *newParentWindow) = 0; - virtual QPlatformMenu *menuForTag(quintptr tag) const; + virtual QPlatformMenu *menuForTag(quintptr tag) const = 0; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformmenu_qpa.cpp b/src/gui/kernel/qplatformmenu_qpa.cpp deleted file mode 100755 index 050f11ec8d..0000000000 --- a/src/gui/kernel/qplatformmenu_qpa.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author James Turner -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformmenu.h" - -QT_BEGIN_NAMESPACE - -void QPlatformMenuItem::setText(const QString &text) -{ - -} - -void QPlatformMenuItem::setIcon(const QImage &icon) -{ - -} - -void QPlatformMenuItem::setMenu(QPlatformMenu *menu) -{ - -} - -void QPlatformMenuItem::setVisible(bool isVisible) -{ - -} - -void QPlatformMenuItem::setIsSeparator(bool isSeparator) -{ - -} - -void QPlatformMenuItem::setFont(const QFont &font) -{ - -} - -void QPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role) -{ - -} - -void QPlatformMenuItem::setChecked(bool isChecked) -{ - -} - -void QPlatformMenuItem::setShortcut(const QKeySequence& shortcut) -{ - -} - -void QPlatformMenuItem::setEnabled(bool enabled) -{ - -} - -void QPlatformMenuItem::setTag(quintptr tag) -{ -} - -quintptr QPlatformMenuItem::tag() const -{ - return 0; -} - -void QPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem* before) -{ - -} - -void QPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem) -{ - -} - -void QPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem) -{ - -} - -void QPlatformMenu::syncSeparatorsCollapsible(bool enable) -{ - -} - -QPlatformMenuItem* QPlatformMenu::menuItemAt(int position) const -{ - return 0; -} - -QPlatformMenuItem* QPlatformMenu::menuItemForTag(quintptr tag) const -{ - return 0; -} - -void QPlatformMenuBar::insertMenu(QPlatformMenu *menuItem, QPlatformMenu* before) -{ - -} - -void QPlatformMenuBar::removeMenu(QPlatformMenu *menuItem) -{ - -} - -void QPlatformMenuBar::syncMenu(QPlatformMenuItem *menuItem) -{ - -} - -void QPlatformMenuBar::handleReparent(QWindow *newParentWindow) -{ - -} - -QPlatformMenu *QPlatformMenuBar::menuForTag(quintptr tag) const -{ - Q_UNUSED(tag); - return 0; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h index 06e8eb6c9d..ef48c84712 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.h +++ b/src/plugins/platforms/cocoa/qcocoamenubar.h @@ -58,7 +58,7 @@ public: virtual void insertMenu(QPlatformMenu *menu, QPlatformMenu* before); virtual void removeMenu(QPlatformMenu *menu); - virtual void syncMenu(QPlatformMenuItem *menuItem); + virtual void syncMenu(QPlatformMenu *menuItem); virtual void handleReparent(QWindow *newParentWindow); virtual QPlatformMenu *menuForTag(quintptr tag) const; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index fc403ba504..dd22e61c45 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -113,9 +113,9 @@ void QCocoaMenuBar::removeMenu(QPlatformMenu *platformMenu) [m_nativeMenu removeItemAtIndex: realIndex]; } -void QCocoaMenuBar::syncMenu(QPlatformMenuItem *menuItem) +void QCocoaMenuBar::syncMenu(QPlatformMenu *menu) { - Q_UNUSED(menuItem); + Q_UNUSED(menu); } void QCocoaMenuBar::handleReparent(QWindow *newParentWindow) diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index 06d1f9ee0f..91461f279a 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -92,6 +92,7 @@ void *QCocoaNativeInterface::NSPrintInfoForPrintEngine(QPrintEngine *printEngine void QCocoaNativeInterface::onAppFocusWindowChanged(QWindow *window) { + Q_UNUSED(window); QCocoaMenuBar::updateMenuBarImmediately(); } diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 2f630c7763..0eb2136027 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -52,8 +52,8 @@ #include "qcocoamenubar.h" #include -#include -#include +#include +#include QT_BEGIN_NAMESPACE