From 97a3611c165b154211344336d99973391023c057 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Sun, 14 Aug 2016 11:48:11 +0200 Subject: [PATCH] [Calendar DaysModel] Don't call layoutChanged() and emit dataChanged() with roles LayoutChanged causes QML to destroy all delegates and re-create them. Since the number of days doesn't change but only the numbers, we can just call dataChanged on all roles. Furthermore, when agenda-related data changes, only the containsEventItems role might have changed, so only emit a change for it. CHANGELOG: Performance when changing months in the calendar has been greatly improved REVIEW: 128648 --- src/declarativeimports/calendar/daysmodel.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/declarativeimports/calendar/daysmodel.cpp b/src/declarativeimports/calendar/daysmodel.cpp index 169711e44..03dd3c22a 100644 --- a/src/declarativeimports/calendar/daysmodel.cpp +++ b/src/declarativeimports/calendar/daysmodel.cpp @@ -98,9 +98,6 @@ void DaysModel::update() m_eventsData.clear(); - // We always have 42 items (or weeks * num of days in week) so we only have to tell the view that the data changed. - layoutChanged(); - const QDate modelFirstDay(m_data->at(0).yearNumber, m_data->at(0).monthNumber, m_data->at(0).dayNumber); if (m_pluginsManager) { @@ -108,6 +105,9 @@ void DaysModel::update() eventsPlugin->loadEventsForDateRange(modelFirstDay, modelFirstDay.addDays(42)); } } + + // We always have 42 items (or weeks * num of days in week) so we only have to tell the view that the data changed. + emit dataChanged(index(0, 0), index(m_data->count() - 1, 0)); } void DaysModel::onDataReady(const QMultiHash &data) @@ -118,7 +118,10 @@ void DaysModel::onDataReady(const QMultiHash & if (data.contains(QDate::currentDate())) { m_agendaNeedsUpdate = true; } - layoutChanged(); + + // only the containsEventItems role may have changed + emit dataChanged(index(0, 0), index(m_data->count() - 1, 0), {containsEventItems}); + Q_EMIT agendaUpdated(QDate::currentDate()); } @@ -142,7 +145,7 @@ void DaysModel::onEventModified(const CalendarEvents::EventData &data) Q_FOREACH (const QDate date, updatesList) { const QModelIndex changedIndex = indexForDate(date); if (changedIndex.isValid()) { - Q_EMIT dataChanged(changedIndex, changedIndex); + Q_EMIT dataChanged(changedIndex, changedIndex, {containsEventItems}); } Q_EMIT agendaUpdated(date); } @@ -168,7 +171,7 @@ void DaysModel::onEventRemoved(const QString &uid) Q_FOREACH (const QDate date, updatesList) { const QModelIndex changedIndex = indexForDate(date); if (changedIndex.isValid()) { - Q_EMIT dataChanged(changedIndex, changedIndex); + Q_EMIT dataChanged(changedIndex, changedIndex, {containsEventItems}); } Q_EMIT agendaUpdated(date); }