From c40486acc352d49398186fa32d1ccabdd5fc83c6 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 19 Dec 2017 13:38:40 +0100 Subject: Fix deferred execution If the QML engine refuses to defer execution of a delegate (it contains an ID), we must make sure to cancel any pending deferred execution for the same delegate. Otherwise, we may end up overriding a custom (non- deferred) delegate with a default (deferred) delegate. This patch adds a new test style "identified" to tst_customization. This style contains delegates with IDs so we can test the behavior with IDs in base styles. Furthermore, overriding delegates is now tested in various ways (with and without IDs in the base and custom styles) in a separate test method. This is done by generating QML code to override delegates with dummy Item instances with appropriate IDs and names. Task-number: QTBUG-65341 Change-Id: Ie6dca287cb74672004d9d8f599760b9d32c3a380 Reviewed-by: Mitch Curtis --- tests/auto/customization/tst_customization.cpp | 131 +++++++++++++++++++++++-- 1 file changed, 125 insertions(+), 6 deletions(-) (limited to 'tests/auto/customization/tst_customization.cpp') diff --git a/tests/auto/customization/tst_customization.cpp b/tests/auto/customization/tst_customization.cpp index 4c8ea72b..48dd4048 100644 --- a/tests/auto/customization/tst_customization.cpp +++ b/tests/auto/customization/tst_customization.cpp @@ -115,6 +115,9 @@ private slots: void creation_data(); void creation(); + void override_data(); + void override(); + void comboPopup(); private: @@ -122,7 +125,7 @@ private: void addHooks(); void removeHooks(); - QObject* createControl(const QString &type, QString *error); + QObject* createControl(const QString &type, const QString &qml, QString *error); QQmlEngine *engine = nullptr; }; @@ -190,10 +193,10 @@ void tst_customization::reset() qt_destroyedParentQObjects()->clear(); } -QObject* tst_customization::createControl(const QString &name, QString *error) +QObject* tst_customization::createControl(const QString &name, const QString &qml, QString *error) { QQmlComponent component(engine); - component.setData("import QtQuick.Controls 2.2; " + name.toUtf8() + " { }", QUrl()); + component.setData("import QtQuick 2.9; import QtQuick.Controls 2.2; " + name.toUtf8() + " { " + qml.toUtf8() + " }", QUrl()); QObject *obj = component.create(); if (!obj) *error = component.errorString(); @@ -214,6 +217,10 @@ void tst_customization::creation_data() for (const ControlInfo &control : ControlInfos) QTest::newRow(qPrintable("incomplete:" + control.type)) << "incomplete" << control.type << control.delegates; + // the "identified" style has IDs in the delegates (prevents deferred execution) + for (const ControlInfo &control : ControlInfos) + QTest::newRow(qPrintable("identified:" + control.type)) << "identified" << control.type << control.delegates; + // the "simple" style simulates a proper style and contains bindings to/in delegates for (const ControlInfo &control : ControlInfos) QTest::newRow(qPrintable("simple:" + control.type)) << "simple" << control.type << control.delegates; @@ -235,23 +242,38 @@ void tst_customization::creation() QQuickStyle::setStyle(testFile("styles/" + style)); QString error; - QScopedPointer control(createControl(type, &error)); + QScopedPointer control(createControl(type, "", &error)); QVERIFY2(control, qPrintable(error)); QByteArray templateType = "QQuick" + type.toUtf8(); QVERIFY2(control->inherits(templateType), qPrintable(type + " does not inherit " + templateType + " (" + control->metaObject()->className() + ")")); + // -