From d3545dbdfdb30e310c6c962ba92f4fdf57354666 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 14 Nov 2018 11:13:15 +0100 Subject: Revert all Menu delegate patches This reverts the following commits: d5cb26bc56a3b6f6e99c88654d4f7a65f43551ac - Menu: ensure the correct delegates are used when created via Component d923dd467c1aeb3e195a09949b04862084002f88 - MenuBar: ensure the correct delegates are used when created via Component d56c193eb4ceb640611d66f22e1f26aae91cd7d1 - QQuickPopupPositioner: avoid adding duplicate item change listeners 567a2de8cd493aabe0055d6dbc367b39447e70dd - Stabilize tst_qquickmenubar 953fbac6131823e4fce0eb4707a854469c4c04ff - Fix Instantiator-created MenuItems disappearing 936d31179d44220571ded15840bedeccb581c83b - tst_qquickmenu: add a test for MenuItems before and after a Repeater fc1832810f6c09505d9413685ed0b2d6295bea4a - QQuickMenuBar: fix menu not opening The fix for QTBUG-67559 has caused lots of issues, with the latest being a crash right before the 5.12 release. The bug that they fix is a P2, so it's not worth the hassle. The patches might be able to be resubmitted to dev after the crash is fixed. Change-Id: Ic192c7a302176bcdb2503b636b3462b10898a2ba Fixes: QTBUG-71770 Reviewed-by: J-P Nurmi Reviewed-by: Shawn Rutledge --- src/quicktemplates2/qquickmenu.cpp | 99 +++++++------------------------------- 1 file changed, 17 insertions(+), 82 deletions(-) (limited to 'src/quicktemplates2/qquickmenu.cpp') diff --git a/src/quicktemplates2/qquickmenu.cpp b/src/quicktemplates2/qquickmenu.cpp index 42059e7f..f52405c9 100644 --- a/src/quicktemplates2/qquickmenu.cpp +++ b/src/quicktemplates2/qquickmenu.cpp @@ -43,7 +43,6 @@ #include "qquickpopuppositioner_p_p.h" #include "qquickaction_p.h" -#include #include #include #include @@ -55,8 +54,6 @@ #include #include #include -#include -#include #include #include #include @@ -68,8 +65,6 @@ QT_BEGIN_NAMESPACE // copied from qfusionstyle.cpp static const int SUBMENU_DELAY = 225; -Q_LOGGING_CATEGORY(qlcQQuickMenu, "qt.quick.controls.menu") - /*! \qmltype Menu \inherits Popup @@ -256,67 +251,6 @@ void QQuickMenuPrivate::removeItem(int index, QQuickItem *item) } } -void QQuickMenuPrivate::createAndAppendItem(QObject *object) -{ - Q_Q(QQuickMenu); - QQuickItem *item = qobject_cast(object); - if (!item) { - if (QQuickAction *action = qobject_cast(object)) - item = createItem(action); - else if (QQuickMenu *menu = qobject_cast(object)) - item = createItem(menu); - } - - if (item) { - if (QQuickItemPrivate::get(item)->isTransparentForPositioner()) { - QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::SiblingOrder); - item->setParentItem(contentItem); - } else if (contentModel->indexOf(item, nullptr) == -1) { - q->addItem(item); - } - } else { - contentData.append(object); - } -} - -void QQuickMenuPrivate::recreateItems() -{ - // removeItem() will remove stuff from contentData, so we have to make a copy of it. - const auto originalContentData = contentData; - - qCDebug(qlcQQuickMenu) << "removing items so that we can recreate them:"; - QSet instantiatedObjects; - for (int i = 0; i < contentModel->count(); ) { - QQuickItem *item = itemAt(i); - QQmlInstantiator *instantiator = qobject_cast(item->parent()); - if (instantiator) { - // Don't try to recreate items owned by an instantiator. - qCDebug(qlcQQuickMenu) << "- item" << item << "at index" << i << "with parent" - << item->parent() << "was instantiated by Instantiator; ignoring"; - instantiatedObjects.insert(item); - ++i; - } else { - qCDebug(qlcQQuickMenu) << "- removing item" << item << "at index" << i << "with parent" << item->parent(); - removeItem(0, item); - } - } - - qCDebug(qlcQQuickMenu) << "recreating items:"; - for (QObject *object : originalContentData) { - QQmlInstantiator *instantiator = qobject_cast(object); - // Instantiators are part of our contentData. If this particular object is an Instantiator, - // let it recreate its own items, otherwise strange things happen (the items are culled). - if (instantiator) { - qCDebug(qlcQQuickMenu) << "- contentData object" << object << "is an Instantiator;" - << "asking them to regenerate their own items"; - QQmlInstantiatorPrivate::get(instantiator)->regenerate(); - } else if (!instantiatedObjects.contains(object)) { - qCDebug(qlcQQuickMenu) << "- creating MenuItem for contentData object" << object; - createAndAppendItem(object); - } - } -} - QQuickItem *QQuickMenuPrivate::beginCreateItem() { Q_Q(QQuickMenu); @@ -389,7 +323,6 @@ void QQuickMenuPrivate::resizeItems() void QQuickMenuPrivate::itemChildAdded(QQuickItem *, QQuickItem *child) { // add dynamically reparented items (eg. by a Repeater) - qCDebug(qlcQQuickMenu) << "item child added" << child; if (!QQuickItemPrivate::get(child)->isTransparentForPositioner() && !contentData.contains(child)) insertItem(contentModel->count(), child); } @@ -397,7 +330,6 @@ void QQuickMenuPrivate::itemChildAdded(QQuickItem *, QQuickItem *child) void QQuickMenuPrivate::itemParentChanged(QQuickItem *item, QQuickItem *parent) { // remove dynamically unparented items (eg. by a Repeater) - qCDebug(qlcQQuickMenu) << "parent of item" << item << "changed to" << parent; if (!parent) removeItem(contentModel->indexOf(item, nullptr), item); } @@ -408,8 +340,6 @@ void QQuickMenuPrivate::itemSiblingOrderChanged(QQuickItem *) Q_Q(QQuickMenu); QList siblings = contentItem->childItems(); - qCDebug(qlcQQuickMenu) << "item sibling order changed"; - int to = 0; for (int i = 0; i < siblings.count(); ++i) { QQuickItem* sibling = siblings.at(i); @@ -422,7 +352,6 @@ void QQuickMenuPrivate::itemSiblingOrderChanged(QQuickItem *) void QQuickMenuPrivate::itemDestroyed(QQuickItem *item) { - qCDebug(qlcQQuickMenu) << "item child destroyed" << item; QQuickPopupPrivate::itemDestroyed(item); int index = contentModel->indexOf(item, nullptr); if (index != -1) @@ -697,18 +626,24 @@ void QQuickMenuPrivate::contentData_append(QQmlListProperty *prop, QObj QQuickMenu *q = qobject_cast(prop->object); QQuickMenuPrivate *p = QQuickMenuPrivate::get(q); - if (!p->complete) { - qCDebug(qlcQQuickMenu) << "appending object" << obj - << "to contentData, but delaying MenuItem creation (if necessary) until we're completed"; - // Don't add items until we're complete, as the delegate could change in the meantime. - // We'll add it to contentData and create it when we're complete. - p->contentData.append(obj); - return; + QQuickItem *item = qobject_cast(obj); + if (!item) { + if (QQuickAction *action = qobject_cast(obj)) + item = p->createItem(action); + else if (QQuickMenu *menu = qobject_cast(obj)) + item = p->createItem(menu); } - qCDebug(qlcQQuickMenu) << "appending object" << obj - << "to contentData and creating MenuItem for it if necessary"; - p->createAndAppendItem(obj); + if (item) { + if (QQuickItemPrivate::get(item)->isTransparentForPositioner()) { + QQuickItemPrivate::get(item)->addItemChangeListener(p, QQuickItemPrivate::SiblingOrder); + item->setParentItem(p->contentItem); + } else if (p->contentModel->indexOf(item, nullptr) == -1) { + q->addItem(item); + } + } else { + p->contentData.append(obj); + } } int QQuickMenuPrivate::contentData_count(QQmlListProperty *prop) @@ -1421,7 +1356,7 @@ void QQuickMenu::componentComplete() { Q_D(QQuickMenu); QQuickPopup::componentComplete(); - d->recreateItems(); + d->resizeItems(); } void QQuickMenu::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) -- cgit v1.2.3