diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-01-12 13:21:56 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-01-15 10:31:22 +0000 |
commit | fa99c0caa212e02472c2facb1a104358f077aa08 (patch) | |
tree | e1f40101ee663965e5a196f7afd8cc14337d1b16 | |
parent | 589d52b3b64a4b5221738a28df08be2eae4d12b2 (diff) |
MenuItem: use deferred execution for the arrow
Task-number: QTBUG-50992
Change-Id: Ifb41a8caf6b406249d6da4783c546816d9b51581
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
8 files changed, 66 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp index f71b9c35..6693d4f8 100644 --- a/src/quicktemplates2/qquickmenuitem.cpp +++ b/src/quicktemplates2/qquickmenuitem.cpp @@ -37,6 +37,7 @@ #include "qquickmenuitem_p.h" #include "qquickmenuitem_p_p.h" #include "qquickmenu_p.h" +#include "qquickdeferredexecute_p_p.h" #include <QtGui/qpa/qplatformtheme.h> #include <QtQuick/private/qquickevents_p_p.h> @@ -134,6 +135,26 @@ void QQuickMenuItemPrivate::updateEnabled() q->setEnabled(subMenu && subMenu->isEnabled()); } +static inline QString arrowName() { return QStringLiteral("arrow"); } + +void QQuickMenuItemPrivate::cancelArrow() +{ + Q_Q(QQuickAbstractButton); + quickCancelDeferred(q, arrowName()); +} + +void QQuickMenuItemPrivate::executeArrow(bool complete) +{ + Q_Q(QQuickMenuItem); + if (arrow.wasExecuted()) + return; + + if (!arrow || complete) + quickBeginDeferred(q, arrowName(), arrow); + if (complete) + quickCompleteDeferred(q, arrowName(), arrow); +} + /*! \qmlsignal void QtQuick.Controls::MenuItem::triggered() @@ -183,7 +204,9 @@ void QQuickMenuItem::setHighlighted(bool highlighted) */ QQuickItem *QQuickMenuItem::arrow() const { - Q_D(const QQuickMenuItem); + QQuickMenuItemPrivate *d = const_cast<QQuickMenuItemPrivate *>(d_func()); + if (!d->arrow) + d->executeArrow(); return d->arrow; } @@ -193,11 +216,15 @@ void QQuickMenuItem::setArrow(QQuickItem *arrow) if (d->arrow == arrow) return; - QQuickControlPrivate::destroyDelegate(d->arrow, this); + if (!d->arrow.isExecuting()) + d->cancelArrow(); + + delete d->arrow; d->arrow = arrow; if (arrow && !arrow->parentItem()) arrow->setParentItem(this); - emit arrowChanged(); + if (!d->arrow.isExecuting()) + emit arrowChanged(); } /*! @@ -228,6 +255,13 @@ QQuickMenu *QQuickMenuItem::subMenu() const return d->subMenu; } +void QQuickMenuItem::componentComplete() +{ + Q_D(QQuickMenuItem); + d->executeArrow(true); + QQuickAbstractButton::componentComplete(); +} + QFont QQuickMenuItem::defaultFont() const { return QQuickControlPrivate::themeFont(QPlatformTheme::MenuItemFont); diff --git a/src/quicktemplates2/qquickmenuitem_p.h b/src/quicktemplates2/qquickmenuitem_p.h index 8af3cbd1..7cffd97b 100644 --- a/src/quicktemplates2/qquickmenuitem_p.h +++ b/src/quicktemplates2/qquickmenuitem_p.h @@ -63,6 +63,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuItem : public QQuickAbstractBut Q_PROPERTY(QQuickItem *arrow READ arrow WRITE setArrow NOTIFY arrowChanged FINAL REVISION 3) Q_PROPERTY(QQuickMenu *menu READ menu NOTIFY menuChanged FINAL REVISION 3) Q_PROPERTY(QQuickMenu *subMenu READ subMenu NOTIFY subMenuChanged FINAL REVISION 3) + Q_CLASSINFO("DeferredPropertyNames", "arrow,background,contentItem,indicator") public: explicit QQuickMenuItem(QQuickItem *parent = nullptr); @@ -86,6 +87,8 @@ Q_SIGNALS: Q_REVISION(3) void subMenuChanged(); protected: + void componentComplete() override; + QFont defaultFont() const override; QPalette defaultPalette() const override; diff --git a/src/quicktemplates2/qquickmenuitem_p_p.h b/src/quicktemplates2/qquickmenuitem_p_p.h index e0e90ff1..5deea6e3 100644 --- a/src/quicktemplates2/qquickmenuitem_p_p.h +++ b/src/quicktemplates2/qquickmenuitem_p_p.h @@ -72,8 +72,11 @@ public: void updateEnabled(); + void cancelArrow(); + void executeArrow(bool complete = false); + bool highlighted; - QQuickItem *arrow; + QQuickDeferredPointer<QQuickItem> arrow; QQuickMenu *menu; QQuickMenu *subMenu; }; diff --git a/tests/auto/customization/data/styles/identified/MenuItem.qml b/tests/auto/customization/data/styles/identified/MenuItem.qml index cd4d53fb..40c293cd 100644 --- a/tests/auto/customization/data/styles/identified/MenuItem.qml +++ b/tests/auto/customization/data/styles/identified/MenuItem.qml @@ -49,12 +49,17 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.MenuItem { id: control objectName: "menuitem-identified" + arrow: Item { + id: arrow + objectName: "menuitem-arrow-identified" + } + indicator: Item { id: indicator objectName: "menuitem-indicator-identified" diff --git a/tests/auto/customization/data/styles/incomplete/MenuItem.qml b/tests/auto/customization/data/styles/incomplete/MenuItem.qml index 10c43105..708ec628 100644 --- a/tests/auto/customization/data/styles/incomplete/MenuItem.qml +++ b/tests/auto/customization/data/styles/incomplete/MenuItem.qml @@ -49,12 +49,16 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.MenuItem { id: control objectName: "menuitem-incomplete" + arrow: Item { + objectName: "menuitem-arrow-incomplete" + } + indicator: Item { objectName: "menuitem-indicator-incomplete" } diff --git a/tests/auto/customization/data/styles/override/MenuItem.qml b/tests/auto/customization/data/styles/override/MenuItem.qml index 6a96376e..2259e739 100644 --- a/tests/auto/customization/data/styles/override/MenuItem.qml +++ b/tests/auto/customization/data/styles/override/MenuItem.qml @@ -55,6 +55,10 @@ Simple.MenuItem { id: control objectName: "menuitem-override" + arrow: Item { + objectName: "menuitem-arrow-override" + } + indicator: Item { objectName: "menuitem-indicator-override" } diff --git a/tests/auto/customization/data/styles/simple/MenuItem.qml b/tests/auto/customization/data/styles/simple/MenuItem.qml index 3a72081a..cb915170 100644 --- a/tests/auto/customization/data/styles/simple/MenuItem.qml +++ b/tests/auto/customization/data/styles/simple/MenuItem.qml @@ -49,7 +49,7 @@ ****************************************************************************/ import QtQuick 2.9 -import QtQuick.Templates 2.2 as T +import QtQuick.Templates 2.3 as T T.MenuItem { id: control @@ -58,6 +58,11 @@ T.MenuItem { implicitWidth: Math.max(contentItem.implicitWidth + indicator.implicitWidth, background.implicitWidth) implicitHeight: Math.max(contentItem.implicitHeight, indicator.implicitHeight, background.implicitHeight) + arrow: Text { + objectName: "menuitem-arrow-simple" + text: control.mirrored ? "<" : ">" + } + indicator: Text { objectName: "menuitem-indicator-simple" text: control.checked ? "V" : "" diff --git a/tests/auto/customization/tst_customization.cpp b/tests/auto/customization/tst_customization.cpp index 3608a710..cd939bcc 100644 --- a/tests/auto/customization/tst_customization.cpp +++ b/tests/auto/customization/tst_customization.cpp @@ -74,7 +74,7 @@ static const ControlInfo ControlInfos[] = { { "Menu", QStringList() << "background" << "contentItem" }, { "MenuBar", QStringList() << "background" << "contentItem" }, { "MenuBarItem", QStringList() << "background" << "contentItem" }, - { "MenuItem", QStringList() << "background" << "contentItem" << "indicator" }, + { "MenuItem", QStringList() << "arrow" << "background" << "contentItem" << "indicator" }, { "MenuSeparator", QStringList() << "background" << "contentItem" }, { "Page", QStringList() << "background" << "contentItem" }, { "PageIndicator", QStringList() << "background" << "contentItem" }, |