From 31803eb51bb2dde55776317b678d48d76f0e27fe Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 23 Sep 2014 09:40:13 +0200 Subject: Fix asynchronous loading of Calendar. For some reason, adding the days of the week to the header model on component completion caused some (six) of the delegates to never be loaded. Instead, we assume that for most cases, the locale will be en_US, and only change the model via setProperty if this is not the case. This is enough to cause the delegates to be loaded properly. Change-Id: Ic399be4b3c9e252fec4eafac84bd9d44c61c1150 Task-number: QTBUG-41481 Reviewed-by: J-P Nurmi --- src/controls/Private/CalendarHeaderModel.qml | 29 ++++++++++++++-- tests/auto/controls/data/tst_calendar.qml | 51 ++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/src/controls/Private/CalendarHeaderModel.qml b/src/controls/Private/CalendarHeaderModel.qml index ef57e65b..8adfcc1a 100644 --- a/src/controls/Private/CalendarHeaderModel.qml +++ b/src/controls/Private/CalendarHeaderModel.qml @@ -68,6 +68,28 @@ ListModel { */ property var locale + ListElement { + dayOfWeek: Locale.Sunday + } + ListElement { + dayOfWeek: Locale.Monday + } + ListElement { + dayOfWeek: Locale.Tuesday + } + ListElement { + dayOfWeek: Locale.Wednesday + } + ListElement { + dayOfWeek: Locale.Thursday + } + ListElement { + dayOfWeek: Locale.Friday + } + ListElement { + dayOfWeek: Locale.Saturday + } + Component.onCompleted: { var daysOfWeek = [Locale.Sunday, Locale.Monday, Locale.Tuesday, Locale.Wednesday, Locale.Thursday, Locale.Friday, Locale.Saturday]; @@ -76,9 +98,10 @@ ListModel { var shifted = daysOfWeek.splice(firstDayOfWeek, daysOfWeek.length - firstDayOfWeek); daysOfWeek = shifted.concat(daysOfWeek) - for (var i = 0; i < daysOfWeek.length; ++i) { - var element = { dayOfWeek: daysOfWeek[i] } - root.append(element); + if (firstDayOfWeek !== Locale.Sunday) { + for (var i = 0; i < daysOfWeek.length; ++i) { + root.setProperty(i, "dayOfWeek", daysOfWeek[i]); + } } } } diff --git a/tests/auto/controls/data/tst_calendar.qml b/tests/auto/controls/data/tst_calendar.qml index a0035fcb..34ea6775 100644 --- a/tests/auto/controls/data/tst_calendar.qml +++ b/tests/auto/controls/data/tst_calendar.qml @@ -39,6 +39,8 @@ ****************************************************************************/ import QtQuick 2.2 +import QtQuick.Controls 1.3 +import QtQuick.Controls.Styles 1.3 import QtQuick.Controls.Private 1.0 import QtTest 1.0 @@ -51,8 +53,8 @@ Item { id: testcase name: "Tests_Calendar" when: windowShown - readonly property int navigationBarHeight: calendar !== undefined ? calendar.__panel.navigationBarItem.height : 0 - readonly property int dayOfWeekHeaderRowHeight: calendar !== undefined ? calendar.__panel.dayOfWeekHeaderRow.height : 0 + readonly property int navigationBarHeight: calendar ? calendar.__panel.navigationBarItem.height : 0 + readonly property int dayOfWeekHeaderRowHeight: calendar ? calendar.__panel.dayOfWeekHeaderRow.height : 0 readonly property int firstDateCellX: 0 readonly property int firstDateCellY: navigationBarHeight + dayOfWeekHeaderRowHeight readonly property int previousMonthButtonX: navigationBarHeight / 2 @@ -96,6 +98,9 @@ Item { clickedSignalSpy.clear(); releasedSignalSpy.clear(); pressAndHoldSignalSpy.clear(); + + if (calendar) + calendar.destroy(); } function toPixelsX(cellPosX) { @@ -894,5 +899,47 @@ Item { compare(releasedSignalSpy.count, 1); compare(pressAndHoldSignalSpy.count, 1); } + + property var aysncDelegatesConstructed: [] + property var aysncDelegatesDestructed: [] + + Loader { + id: asyncCalendarLoader + active: false + asynchronous: true + + sourceComponent: Calendar { + + style: CalendarStyle { + dayOfWeekDelegate: Component { + Text { + text: styleData.dayOfWeek + Component.onCompleted: testcase.aysncDelegatesConstructed[styleData.index] = true + Component.onDestruction: testcase.aysncDelegatesDestructed[styleData.index] = true + } + } + } + } + } + + function test_asynchronous() { + verify(!asyncCalendarLoader.item); + asyncCalendarLoader.active = true; + tryCompare(asyncCalendarLoader, "status", Component.Ready); + + var asyncCalendar = asyncCalendarLoader.item; + asyncCalendar.parent = container; + waitForRendering(asyncCalendar); + + for (var i = 0; i < testcase.aysncDelegatesConstructed.length; ++i) { + tryCompare(testcase.aysncDelegatesConstructed, i, true); + } + + asyncCalendarLoader.active = false; + + for (i = 0; i < testcase.aysncDelegatesDestructed.length; ++i) { + tryCompare(testcase.aysncDelegatesDestructed, i, true); + } + } } } -- cgit v1.2.1