diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-10-02 03:00:10 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-10-02 03:00:10 +0200 |
commit | c0ea6c87a07387792310746118d523d9541203c0 (patch) | |
tree | 4e19cd6db37b6f1e4adecae5000f6a2f530a6b11 /src | |
parent | 8d1de951f0993e1f4ed1a26a34f197acac7eef4c (diff) | |
parent | 352be75dec15cb333f58d0075d89b2ebc7a2e46b (diff) | |
download | qtquickcontrols-c0ea6c87a07387792310746118d523d9541203c0.tar.gz |
Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: Ibb1d26d59fb131e9fbdbcdd4a9009e96f0cb10a9
Diffstat (limited to 'src')
-rw-r--r-- | src/controls/Private/ScrollViewHelper.qml | 18 | ||||
-rw-r--r-- | src/controls/qquickmenu.cpp | 75 | ||||
-rw-r--r-- | src/controls/qquickmenu_p.h | 2 | ||||
-rw-r--r-- | src/widgets/qquickqfiledialog_p.h | 6 |
4 files changed, 67 insertions, 34 deletions
diff --git a/src/controls/Private/ScrollViewHelper.qml b/src/controls/Private/ScrollViewHelper.qml index 810de91d..53050108 100644 --- a/src/controls/Private/ScrollViewHelper.qml +++ b/src/controls/Private/ScrollViewHelper.qml @@ -68,31 +68,29 @@ Item { anchors.fill: parent - property bool recursionGuard: false - - function doLayout() { - if (!recursionGuard) { - recursionGuard = true + Timer { + id: layoutTimer + interval: 0; + onTriggered: { blockUpdates = true; scrollHelper.contentWidth = flickableItem !== null ? flickableItem.contentWidth : 0 scrollHelper.contentHeight = flickableItem !== null ? flickableItem.contentHeight : 0 scrollHelper.availableWidth = viewport.width scrollHelper.availableHeight = viewport.height blockUpdates = false; - recursionGuard = false } } Connections { target: viewport - onWidthChanged: doLayout() - onHeightChanged: doLayout() + onWidthChanged: layoutTimer.running = true + onHeightChanged: layoutTimer.running = true } Connections { target: flickableItem - onContentWidthChanged: doLayout() - onContentHeightChanged: doLayout() + onContentWidthChanged: layoutTimer.running = true + onContentHeightChanged: layoutTimer.running = true onContentXChanged: { hscrollbar.flash() vscrollbar.flash() diff --git a/src/controls/qquickmenu.cpp b/src/controls/qquickmenu.cpp index 3c6d91ef..bfa0f673 100644 --- a/src/controls/qquickmenu.cpp +++ b/src/controls/qquickmenu.cpp @@ -789,33 +789,41 @@ void QQuickMenu1::insertItem(int index, QQuickMenuBase1 *menuItem) void QQuickMenu1::removeItem(QQuickMenuBase1 *menuItem) { - if (!menuItem) - return; - menuItem->setParentMenu(0); - - QQuickMenuItemContainer1 *container = menuItem->parent() != this ? m_containers[menuItem->parent()] : 0; - if (container) - container->removeItem(menuItem); - else - m_menuItems.removeOne(menuItem); - - --m_itemsCount; - emit itemsChanged(); + // Removes the item, but if it's a container, the container is kept + if (menuItem) { + unparentItem(menuItem); + emit itemsChanged(); + } } void QQuickMenu1::clear() { - m_containers.clear(); - m_containersCount = 0; + if (m_itemsCount > 0) { + while (m_itemsCount > 0) + unparentItem(menuItemAtIndex(0)); - // QTBUG-48927: a proxy menu (ApplicationWindowStyle.qml) must not - // delete its items, because they are owned by the menubar - if (m_proxy) + // We can delete the containers now, as there cannot be any further items in them. + qDeleteAll(m_containers); + m_containers.clear(); + m_containersCount = 0; + + // The containers are also kept in m_menuItems, so we have to clear explicitly. m_menuItems.clear(); - while (!m_menuItems.empty()) - delete m_menuItems.takeFirst(); - m_itemsCount = 0; + emit itemsChanged(); + } +} + +void QQuickMenu1::unparentItem(QQuickMenuBase1 *menuItem) +{ + menuItem->setParentMenu(nullptr); + QQuickMenuItemContainer1 *container = (menuItem->parent() != this) + ? m_containers[menuItem->parent()] : nullptr; + if (container) + container->removeItem(menuItem); + else + m_menuItems.removeOne(menuItem); + --m_itemsCount; } void QQuickMenu1::setupMenuItem(QQuickMenuBase1 *item, int platformIndex) @@ -871,8 +879,31 @@ QObject *QQuickMenu1::at_menuItems(QQuickMenuItems *list, int index) void QQuickMenu1::clear_menuItems(QQuickMenuItems *list) { - if (QQuickMenu1 *menu = qobject_cast<QQuickMenu1 *>(list->object)) - menu->clear(); + if (QQuickMenu1 *menu = qobject_cast<QQuickMenu1 *>(list->object)) { + // There may be stray containers that don't appear in m_menuItems. This is because we may + // remove a container with removeItem(), which will only remove it from m_menuItems. + // Therefore, make sure that all containers are removed from m_menuItems first. + for (QQuickMenuItemContainer1 *container : menu->m_containers) + menu->m_menuItems.removeOne(container); + + // Delete or unparent the items first. They may have references to the containers. + // QTBUG-48927: a proxy menu (ApplicationWindowStyle.qml) must not + // delete its items, because they are owned by the menubar + // We still do own the containers, though. We create them on append_menuItems, after all. + while (!menu->m_menuItems.empty()) { + if (menu->m_proxy) + menu->unparentItem(menu->m_menuItems[0]); + else + delete menu->m_menuItems.takeFirst(); + } + menu->m_menuItems.clear(); + + qDeleteAll(menu->m_containers); + menu->m_containers.clear(); + menu->m_containersCount = 0; + + menu->m_itemsCount = 0; + } } QT_END_NAMESPACE diff --git a/src/controls/qquickmenu_p.h b/src/controls/qquickmenu_p.h index 800981dd..0594f391 100644 --- a/src/controls/qquickmenu_p.h +++ b/src/controls/qquickmenu_p.h @@ -190,6 +190,8 @@ private: static int count_menuItems(QQuickMenuItems *list); static QObject *at_menuItems(QQuickMenuItems *list, int index); static void clear_menuItems(QQuickMenuItems *list); + + void unparentItem(QQuickMenuBase1 *menuItem); void setupMenuItem(QQuickMenuBase1 *item, int platformIndex = -1); QPlatformMenu *m_platformMenu; diff --git a/src/widgets/qquickqfiledialog_p.h b/src/widgets/qquickqfiledialog_p.h index d977e345..4988c1e0 100644 --- a/src/widgets/qquickqfiledialog_p.h +++ b/src/widgets/qquickqfiledialog_p.h @@ -51,11 +51,13 @@ // We mean it. // -#include <QFileDialog> -#include "../dialogs/qquickabstractfiledialog_p.h" +#include <QtWidgets/qtwidgetsglobal.h> #if QT_CONFIG(filedialog) +#include <QFileDialog> +#include "../dialogs/qquickabstractfiledialog_p.h" + QT_BEGIN_NAMESPACE class QQuickQFileDialog : public QQuickAbstractFileDialog |