diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-10-20 03:00:24 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-10-20 03:00:24 +0200 |
commit | b86d6b0b06db0eb978e2559745c48edb2ca876a7 (patch) | |
tree | 99d2d1a99421af4f018d6172f646f8dc2ebe423d /tests | |
parent | 607cabb999bb8eed58afb09a166d20e7e497196b (diff) | |
parent | 2876332ad911b3c0402006ca9116af66cecdb8eb (diff) |
Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: I9ab9a8c931ebcd20f7f7e73c428b7adb83e4b28b
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qquickmenubar/data/delegateFromSeparateComponent.qml | 79 | ||||
-rw-r--r-- | tests/auto/qquickmenubar/tst_qquickmenubar.cpp | 35 |
2 files changed, 114 insertions, 0 deletions
diff --git a/tests/auto/qquickmenubar/data/delegateFromSeparateComponent.qml b/tests/auto/qquickmenubar/data/delegateFromSeparateComponent.qml new file mode 100644 index 00000000..9d58e8c6 --- /dev/null +++ b/tests/auto/qquickmenubar/data/delegateFromSeparateComponent.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.11 +import QtQuick.Controls 2.4 + +ApplicationWindow { + width: 800 + height: 800 + + Component { + id: menuBarItemComponent + + MenuBarItem { + contentItem: Text { + text: parent.text + color: "blue" + } + background: Rectangle { + color: "#00ff00" + } + } + } + + menuBar: MenuBar { + delegate: menuBarItemComponent + + Menu { + title: "Menu" + } + } +} diff --git a/tests/auto/qquickmenubar/tst_qquickmenubar.cpp b/tests/auto/qquickmenubar/tst_qquickmenubar.cpp index 754e915b..cfcdee5e 100644 --- a/tests/auto/qquickmenubar/tst_qquickmenubar.cpp +++ b/tests/auto/qquickmenubar/tst_qquickmenubar.cpp @@ -45,6 +45,7 @@ #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickmenu_p.h> #include <QtQuickTemplates2/private/qquickmenubar_p.h> +#include <QtQuickTemplates2/private/qquickmenubar_p_p.h> #include <QtQuickTemplates2/private/qquickmenubaritem_p.h> #include <QtQuickTemplates2/private/qquickmenuitem_p.h> @@ -62,6 +63,7 @@ private slots: void keys(); void mnemonics(); void addRemove(); + void delegateFromSeparateComponent(); }; void tst_qquickmenubar::delegate() @@ -106,6 +108,13 @@ void tst_qquickmenubar::mouse() QQuickMenuBarItem *viewMenuBarItem = qobject_cast<QQuickMenuBarItem *>(viewMenuBarMenu->parentItem()); QQuickMenuBarItem *helpMenuBarItem = qobject_cast<QQuickMenuBarItem *>(helpMenuBarMenu->parentItem()); QVERIFY(fileMenuBarItem && editMenuBarItem && viewMenuBarItem && helpMenuBarItem); + // Something about postponing delegate creation to component completion + // means that the fileMenuBarItem->isHighlighted() check below fails occasionally. + // Give it a chance to sort itself out before sending move events. + QQuickMenuBarPrivate *menuBarPrivate = QQuickMenuBarPrivate::get(menuBar); + menuBar->polish(); + QVERIFY(menuBarPrivate->polishScheduled); + QTRY_VERIFY(!menuBarPrivate->polishScheduled); // highlight a menubar item QTest::mouseMove(window.data(), fileMenuBarItem->mapToScene(QPointF(fileMenuBarItem->width() / 2, fileMenuBarItem->height() / 2)).toPoint()); @@ -570,6 +579,32 @@ void tst_qquickmenubar::addRemove() QVERIFY(menuBarItem1.isNull()); } +// QTBUG-67559 +// Test that Menus declared as children of a MenuBar have the +// correct delegate when it is declared outside of the MenuBar as a Component. +void tst_qquickmenubar::delegateFromSeparateComponent() +{ + QQuickApplicationHelper helper(this, QLatin1String("delegateFromSeparateComponent.qml")); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + const QColor green = QColor::fromRgb(0x00ff00); + + QQuickMenuBar *menuBar = window->property("menuBar").value<QQuickMenuBar*>(); + QVERIFY(menuBar); + + QQuickMenu *menu = qobject_cast<QQuickMenu*>(menuBar->menuAt(0)); + QVERIFY(menu); + + QQuickMenuBarItem *menuBarItem = qobject_cast<QQuickMenuBarItem *>(menu->parentItem()); + QVERIFY(menuBarItem); + + QQuickItem *menuBarItemBg = menuBarItem->property("background").value<QQuickItem*>(); + QVERIFY(menuBarItemBg); + QCOMPARE(menuBarItemBg->property("color").value<QColor>(), green); +} + QTEST_QUICKCONTROLS_MAIN(tst_qquickmenubar) #include "tst_qquickmenubar.moc" |