Make platform menu tag/setTag not be pure virtual
Reasons: * Tag means nothing to the platform, tag is something the Qt side code will store and then restore, but it's meaningless for the platform, since it can be either the pointer to an action (qmenu.cpp) or an item count (qcombobox.cpp) * Since it's meaningless to the platform you don't know what to do when trying to implement a platform, this shows in how the field was being initialized, some initialized to this, some initialized to 0 On a followup commit we will remove the virtual tag but first need to fix up other QPAs that don't live in the main repo Change-Id: I15ac83f3bf7e4c741153d31ac761dbbe6f4b1b52 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>bb10
parent
df252fc205
commit
6462f299ed
|
|
@ -45,6 +45,37 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QPlatformMenuItem::QPlatformMenuItem()
|
||||
{
|
||||
m_tag = reinterpret_cast<quintptr>(this);
|
||||
}
|
||||
|
||||
void QPlatformMenuItem::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
quintptr QPlatformMenuItem::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
QPlatformMenu::QPlatformMenu()
|
||||
{
|
||||
m_tag = reinterpret_cast<quintptr>(this);
|
||||
}
|
||||
|
||||
void QPlatformMenu::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
quintptr QPlatformMenu::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
|
||||
}
|
||||
|
||||
QPlatformMenuItem *QPlatformMenu::createMenuItem() const
|
||||
{
|
||||
return QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ class Q_GUI_EXPORT QPlatformMenuItem : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QPlatformMenuItem();
|
||||
|
||||
// copied from, and must stay in sync with, QAction menu roles.
|
||||
enum MenuRole { NoRole = 0, TextHeuristicRole, ApplicationSpecificRole, AboutQtRole,
|
||||
AboutRole, PreferencesRole, QuitRole,
|
||||
|
|
@ -71,8 +73,8 @@ public:
|
|||
RoleCount };
|
||||
Q_ENUM(MenuRole)
|
||||
|
||||
virtual void setTag(quintptr tag) = 0;
|
||||
virtual quintptr tag()const = 0;
|
||||
virtual void setTag(quintptr tag);
|
||||
virtual quintptr tag() const;
|
||||
|
||||
virtual void setText(const QString &text) = 0;
|
||||
virtual void setIcon(const QIcon &icon) = 0;
|
||||
|
|
@ -94,12 +96,17 @@ public:
|
|||
Q_SIGNALS:
|
||||
void activated();
|
||||
void hovered();
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
};
|
||||
|
||||
class Q_GUI_EXPORT QPlatformMenu : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QPlatformMenu();
|
||||
|
||||
enum MenuType { DefaultMenu = 0, EditMenu };
|
||||
Q_ENUM(MenuType)
|
||||
|
||||
|
|
@ -108,8 +115,8 @@ public:
|
|||
virtual void syncMenuItem(QPlatformMenuItem *menuItem) = 0;
|
||||
virtual void syncSeparatorsCollapsible(bool enable) = 0;
|
||||
|
||||
virtual void setTag(quintptr tag) = 0;
|
||||
virtual quintptr tag()const = 0;
|
||||
virtual void setTag(quintptr tag);
|
||||
virtual quintptr tag() const;
|
||||
|
||||
virtual void setText(const QString &text) = 0;
|
||||
virtual void setIcon(const QIcon &icon) = 0;
|
||||
|
|
@ -138,6 +145,9 @@ public:
|
|||
Q_SIGNALS:
|
||||
void aboutToShow();
|
||||
void aboutToHide();
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
};
|
||||
|
||||
class Q_GUI_EXPORT QPlatformMenuBar : public QObject
|
||||
|
|
|
|||
|
|
@ -50,9 +50,8 @@ Q_LOGGING_CATEGORY(qLcMenu, "qt.qpa.menu")
|
|||
static int nextDBusID = 1;
|
||||
QHash<int, QDBusPlatformMenuItem *> menuItemsByID;
|
||||
|
||||
QDBusPlatformMenuItem::QDBusPlatformMenuItem(quintptr tag)
|
||||
: m_tag(tag ? tag : reinterpret_cast<quintptr>(this)) // QMenu will overwrite this later
|
||||
, m_subMenu(Q_NULLPTR)
|
||||
QDBusPlatformMenuItem::QDBusPlatformMenuItem()
|
||||
: m_subMenu(nullptr)
|
||||
, m_role(NoRole)
|
||||
, m_isEnabled(true)
|
||||
, m_isVisible(true)
|
||||
|
|
@ -72,11 +71,6 @@ QDBusPlatformMenuItem::~QDBusPlatformMenuItem()
|
|||
static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR);
|
||||
}
|
||||
|
||||
void QDBusPlatformMenuItem::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
void QDBusPlatformMenuItem::setText(const QString &text)
|
||||
{
|
||||
qCDebug(qLcMenu) << m_dbusID << text;
|
||||
|
|
@ -167,9 +161,8 @@ QList<const QDBusPlatformMenuItem *> QDBusPlatformMenuItem::byIds(const QList<in
|
|||
}
|
||||
|
||||
|
||||
QDBusPlatformMenu::QDBusPlatformMenu(quintptr tag)
|
||||
: m_tag(tag ? tag : reinterpret_cast<quintptr>(this))
|
||||
, m_isEnabled(true)
|
||||
QDBusPlatformMenu::QDBusPlatformMenu()
|
||||
: m_isEnabled(true)
|
||||
, m_isVisible(true)
|
||||
, m_isSeparator(false)
|
||||
, m_revision(1)
|
||||
|
|
@ -253,11 +246,6 @@ void QDBusPlatformMenu::emitUpdated()
|
|||
emit updated(++m_revision, 0);
|
||||
}
|
||||
|
||||
void QDBusPlatformMenu::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
void QDBusPlatformMenu::setText(const QString &text)
|
||||
{
|
||||
m_text = text;
|
||||
|
|
|
|||
|
|
@ -73,12 +73,9 @@ class QDBusPlatformMenuItem : public QPlatformMenuItem
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QDBusPlatformMenuItem(quintptr tag = 0LL);
|
||||
QDBusPlatformMenuItem();
|
||||
~QDBusPlatformMenuItem();
|
||||
|
||||
quintptr tag()const Q_DECL_OVERRIDE { return m_tag; }
|
||||
void setTag(quintptr tag) Q_DECL_OVERRIDE;
|
||||
|
||||
const QString text() const { return m_text; }
|
||||
void setText(const QString &text) Q_DECL_OVERRIDE;
|
||||
QIcon icon() const { return m_icon; }
|
||||
|
|
@ -110,13 +107,10 @@ public:
|
|||
|
||||
void trigger();
|
||||
|
||||
bool operator==(const QDBusPlatformMenuItem& other) { return m_tag == other.m_tag; }
|
||||
|
||||
static QDBusPlatformMenuItem *byId(int id);
|
||||
static QList<const QDBusPlatformMenuItem *> byIds(const QList<int> &ids);
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
QString m_text;
|
||||
QIcon m_icon;
|
||||
QPlatformMenu *m_subMenu;
|
||||
|
|
@ -137,7 +131,7 @@ class QDBusPlatformMenu : public QPlatformMenu
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QDBusPlatformMenu(quintptr tag = 0LL);
|
||||
QDBusPlatformMenu();
|
||||
~QDBusPlatformMenu();
|
||||
void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) Q_DECL_OVERRIDE;
|
||||
void removeMenuItem(QPlatformMenuItem *menuItem) Q_DECL_OVERRIDE;
|
||||
|
|
@ -145,9 +139,6 @@ public:
|
|||
void syncMenuItem(QPlatformMenuItem *menuItem) Q_DECL_OVERRIDE;
|
||||
void syncSeparatorsCollapsible(bool enable) Q_DECL_OVERRIDE { Q_UNUSED(enable); }
|
||||
|
||||
quintptr tag()const Q_DECL_OVERRIDE { return m_tag; }
|
||||
void setTag(quintptr tag) Q_DECL_OVERRIDE;
|
||||
|
||||
const QString text() const { return m_text; }
|
||||
void setText(const QString &text) Q_DECL_OVERRIDE;
|
||||
QIcon icon() const { return m_icon; }
|
||||
|
|
@ -172,8 +163,6 @@ public:
|
|||
QPlatformMenuItem *createMenuItem() const Q_DECL_OVERRIDE;
|
||||
QPlatformMenu *createSubMenu() const Q_DECL_OVERRIDE;
|
||||
|
||||
bool operator==(const QDBusPlatformMenu& other) { return m_tag == other.m_tag; }
|
||||
|
||||
uint revision() const { return m_revision; }
|
||||
|
||||
void emitUpdated();
|
||||
|
|
@ -184,7 +173,6 @@ signals:
|
|||
void popupRequested(int id, uint timestamp);
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
QString m_text;
|
||||
QIcon m_icon;
|
||||
bool m_isEnabled;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
QAndroidPlatformMenu::QAndroidPlatformMenu()
|
||||
{
|
||||
m_tag = reinterpret_cast<quintptr>(this); // QMenu will overwrite this later, but we need a unique ID for QtQuick
|
||||
m_enabled = true;
|
||||
m_isVisible = true;
|
||||
}
|
||||
|
|
@ -92,16 +91,6 @@ void QAndroidPlatformMenu::syncSeparatorsCollapsible(bool enable)
|
|||
Q_UNUSED(enable)
|
||||
}
|
||||
|
||||
void QAndroidPlatformMenu::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
quintptr QAndroidPlatformMenu::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
void QAndroidPlatformMenu::setText(const QString &text)
|
||||
{
|
||||
m_text = text;
|
||||
|
|
|
|||
|
|
@ -61,8 +61,6 @@ public:
|
|||
void syncMenuItem(QPlatformMenuItem *menuItem) override;
|
||||
void syncSeparatorsCollapsible(bool enable) override;
|
||||
|
||||
void setTag(quintptr tag) override;
|
||||
quintptr tag() const override;
|
||||
void setText(const QString &text) override;
|
||||
QString text() const;
|
||||
void setIcon(const QIcon &icon) override;
|
||||
|
|
@ -81,7 +79,6 @@ public:
|
|||
|
||||
private:
|
||||
PlatformMenuItemsType m_menuItems;
|
||||
quintptr m_tag;
|
||||
QString m_text;
|
||||
QIcon m_icon;
|
||||
bool m_enabled;
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
QAndroidPlatformMenuItem::QAndroidPlatformMenuItem()
|
||||
{
|
||||
m_tag = reinterpret_cast<quintptr>(this); // QMenu will overwrite this later, but we need a unique ID for QtQuick
|
||||
m_menu = 0;
|
||||
m_isVisible = true;
|
||||
m_isSeparator = false;
|
||||
|
|
@ -54,16 +53,6 @@ QAndroidPlatformMenuItem::QAndroidPlatformMenuItem()
|
|||
m_isEnabled = true;
|
||||
}
|
||||
|
||||
void QAndroidPlatformMenuItem::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
quintptr QAndroidPlatformMenuItem::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
void QAndroidPlatformMenuItem::setText(const QString &text)
|
||||
{
|
||||
m_text = text;
|
||||
|
|
|
|||
|
|
@ -49,8 +49,6 @@ class QAndroidPlatformMenuItem: public QPlatformMenuItem
|
|||
{
|
||||
public:
|
||||
QAndroidPlatformMenuItem();
|
||||
void setTag(quintptr tag) override;
|
||||
quintptr tag() const override;
|
||||
|
||||
void setText(const QString &text) override;
|
||||
QString text() const;
|
||||
|
|
@ -86,7 +84,6 @@ public:
|
|||
void setIconSize(int size) override;
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
QString m_text;
|
||||
QIcon m_icon;
|
||||
QAndroidPlatformMenu *m_menu;
|
||||
|
|
|
|||
|
|
@ -55,11 +55,6 @@ public:
|
|||
QCocoaMenu();
|
||||
~QCocoaMenu();
|
||||
|
||||
void setTag(quintptr tag) Q_DECL_OVERRIDE
|
||||
{ m_tag = tag; }
|
||||
quintptr tag() const Q_DECL_OVERRIDE
|
||||
{ return m_tag; }
|
||||
|
||||
void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) Q_DECL_OVERRIDE;
|
||||
void removeMenuItem(QPlatformMenuItem *menuItem) Q_DECL_OVERRIDE;
|
||||
void syncMenuItem(QPlatformMenuItem *menuItem) Q_DECL_OVERRIDE;
|
||||
|
|
@ -103,7 +98,6 @@ private:
|
|||
QList<QCocoaMenuItem *> m_menuItems;
|
||||
NSMenu *m_nativeMenu;
|
||||
NSMenuItem *m_attachedItem;
|
||||
quintptr m_tag;
|
||||
bool m_enabled:1;
|
||||
bool m_parentEnabled:1;
|
||||
bool m_visible:1;
|
||||
|
|
|
|||
|
|
@ -259,7 +259,6 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
QCocoaMenu::QCocoaMenu() :
|
||||
m_attachedItem(0),
|
||||
m_tag(0),
|
||||
m_enabled(true),
|
||||
m_parentEnabled(true),
|
||||
m_visible(true),
|
||||
|
|
|
|||
|
|
@ -78,11 +78,6 @@ public:
|
|||
QCocoaMenuItem();
|
||||
~QCocoaMenuItem();
|
||||
|
||||
void setTag(quintptr tag) Q_DECL_OVERRIDE
|
||||
{ m_tag = tag; }
|
||||
quintptr tag() const Q_DECL_OVERRIDE
|
||||
{ return m_tag; }
|
||||
|
||||
void setText(const QString &text) Q_DECL_OVERRIDE;
|
||||
void setIcon(const QIcon &icon) Q_DECL_OVERRIDE;
|
||||
void setMenu(QPlatformMenu *menu) Q_DECL_OVERRIDE;
|
||||
|
|
@ -129,7 +124,6 @@ private:
|
|||
#ifndef QT_NO_SHORTCUT
|
||||
QKeySequence m_shortcut;
|
||||
#endif
|
||||
quintptr m_tag;
|
||||
int m_iconSize;
|
||||
bool m_textSynced:1;
|
||||
bool m_isVisible:1;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,6 @@ QCocoaMenuItem::QCocoaMenuItem() :
|
|||
m_itemView(nil),
|
||||
m_menu(NULL),
|
||||
m_role(NoRole),
|
||||
m_tag(0),
|
||||
m_iconSize(16),
|
||||
m_textSynced(false),
|
||||
m_isVisible(true),
|
||||
|
|
|
|||
|
|
@ -56,9 +56,6 @@ class QIOSMenuItem : public QPlatformMenuItem
|
|||
public:
|
||||
QIOSMenuItem();
|
||||
|
||||
void setTag(quintptr tag) Q_DECL_OVERRIDE;
|
||||
quintptr tag()const Q_DECL_OVERRIDE;
|
||||
|
||||
void setText(const QString &text) Q_DECL_OVERRIDE;
|
||||
void setIcon(const QIcon &) Q_DECL_OVERRIDE {}
|
||||
void setMenu(QPlatformMenu *) Q_DECL_OVERRIDE;
|
||||
|
|
@ -74,7 +71,6 @@ public:
|
|||
void setEnabled(bool enabled) Q_DECL_OVERRIDE;
|
||||
void setIconSize(int) Q_DECL_OVERRIDE {}
|
||||
|
||||
quintptr m_tag;
|
||||
bool m_visible;
|
||||
QString m_text;
|
||||
MenuRole m_role;
|
||||
|
|
@ -97,9 +93,6 @@ public:
|
|||
void syncMenuItem(QPlatformMenuItem *) Q_DECL_OVERRIDE;
|
||||
void syncSeparatorsCollapsible(bool) Q_DECL_OVERRIDE {}
|
||||
|
||||
void setTag(quintptr tag) Q_DECL_OVERRIDE;
|
||||
quintptr tag()const Q_DECL_OVERRIDE;
|
||||
|
||||
void setText(const QString &) Q_DECL_OVERRIDE;
|
||||
void setIcon(const QIcon &) Q_DECL_OVERRIDE {}
|
||||
void setEnabled(bool enabled) Q_DECL_OVERRIDE;
|
||||
|
|
@ -121,7 +114,6 @@ protected:
|
|||
bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
bool m_enabled;
|
||||
bool m_visible;
|
||||
QString m_text;
|
||||
|
|
|
|||
|
|
@ -259,7 +259,6 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_";
|
|||
|
||||
QIOSMenuItem::QIOSMenuItem()
|
||||
: QPlatformMenuItem()
|
||||
, m_tag(0)
|
||||
, m_visible(true)
|
||||
, m_text(QString())
|
||||
, m_role(MenuRole(0))
|
||||
|
|
@ -269,16 +268,6 @@ QIOSMenuItem::QIOSMenuItem()
|
|||
{
|
||||
}
|
||||
|
||||
void QIOSMenuItem::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
quintptr QIOSMenuItem::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
void QIOSMenuItem::setText(const QString &text)
|
||||
{
|
||||
m_text = QPlatformTheme::removeMnemonics(text);
|
||||
|
|
@ -319,7 +308,6 @@ void QIOSMenuItem::setEnabled(bool enabled)
|
|||
|
||||
QIOSMenu::QIOSMenu()
|
||||
: QPlatformMenu()
|
||||
, m_tag(0)
|
||||
, m_enabled(true)
|
||||
, m_visible(false)
|
||||
, m_text(QString())
|
||||
|
|
@ -371,16 +359,6 @@ void QIOSMenu::syncMenuItem(QPlatformMenuItem *)
|
|||
}
|
||||
}
|
||||
|
||||
void QIOSMenu::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
quintptr QIOSMenu::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
void QIOSMenu::setText(const QString &text)
|
||||
{
|
||||
m_text = text;
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ QGtk3MenuItem::QGtk3MenuItem()
|
|||
m_enabled(true),
|
||||
m_underline(false),
|
||||
m_invalid(true),
|
||||
m_tag(reinterpret_cast<quintptr>(this)),
|
||||
m_menu(nullptr),
|
||||
m_item(nullptr)
|
||||
{
|
||||
|
|
@ -145,16 +144,6 @@ GtkWidget *QGtk3MenuItem::handle() const
|
|||
return m_item;
|
||||
}
|
||||
|
||||
quintptr QGtk3MenuItem::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
void QGtk3MenuItem::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
QString QGtk3MenuItem::text() const
|
||||
{
|
||||
return m_text;
|
||||
|
|
@ -341,7 +330,6 @@ void QGtk3MenuItem::onToggle(GtkCheckMenuItem *check, void *data)
|
|||
}
|
||||
|
||||
QGtk3Menu::QGtk3Menu()
|
||||
: m_tag(reinterpret_cast<quintptr>(this))
|
||||
{
|
||||
m_menu = gtk_menu_new();
|
||||
|
||||
|
|
@ -402,16 +390,6 @@ void QGtk3Menu::syncSeparatorsCollapsible(bool enable)
|
|||
Q_UNUSED(enable);
|
||||
}
|
||||
|
||||
quintptr QGtk3Menu::tag() const
|
||||
{
|
||||
return m_tag;
|
||||
}
|
||||
|
||||
void QGtk3Menu::setTag(quintptr tag)
|
||||
{
|
||||
m_tag = tag;
|
||||
}
|
||||
|
||||
void QGtk3Menu::setEnabled(bool enabled)
|
||||
{
|
||||
gtk_widget_set_sensitive(m_menu, enabled);
|
||||
|
|
|
|||
|
|
@ -61,9 +61,6 @@ public:
|
|||
GtkWidget *create();
|
||||
GtkWidget *handle() const;
|
||||
|
||||
quintptr tag() const override;
|
||||
void setTag(quintptr tag) override;
|
||||
|
||||
QString text() const;
|
||||
void setText(const QString &text) override;
|
||||
|
||||
|
|
@ -110,7 +107,6 @@ private:
|
|||
bool m_exclusive;
|
||||
bool m_underline;
|
||||
bool m_invalid;
|
||||
quintptr m_tag;
|
||||
QGtk3Menu *m_menu;
|
||||
GtkWidget *m_item;
|
||||
QString m_text;
|
||||
|
|
@ -132,9 +128,6 @@ public:
|
|||
void syncMenuItem(QPlatformMenuItem *item) override;
|
||||
void syncSeparatorsCollapsible(bool enable) override;
|
||||
|
||||
quintptr tag() const override;
|
||||
void setTag(quintptr tag) override;
|
||||
|
||||
void setEnabled(bool enabled) override;
|
||||
void setVisible(bool visible) override;
|
||||
|
||||
|
|
@ -157,7 +150,6 @@ protected:
|
|||
static void onHide(GtkWidget *menu, void *data);
|
||||
|
||||
private:
|
||||
quintptr m_tag;
|
||||
GtkWidget *m_menu;
|
||||
QPoint m_targetPos;
|
||||
QVector<QGtk3MenuItem *> m_items;
|
||||
|
|
|
|||
Loading…
Reference in New Issue