Commit 3b56cb4c authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Fix incidences disappearing off of certain weeks/months after scrolling

parent faacaf15
Pipeline #108093 passed with stage
in 5 minutes and 2 seconds
......@@ -200,6 +200,7 @@ Kirigami.Page {
root.daysToShow + 1
// As long as the date is even slightly larger, it will return 1; since we start from the startDate at 00:00, adjust
active: isNextOrCurrentItem
asynchronous: !isCurrentItem
visible: status === Loader.Ready
sourceComponent: Column {
......
......@@ -146,6 +146,7 @@ Kirigami.Page {
property bool isNextOrCurrentItem: index >= pathView.currentIndex -1 && index <= pathView.currentIndex + 1
property bool isCurrentItem: PathView.isCurrentItem
active: isNextOrCurrentItem
asynchronous: !isCurrentItem
visible: status === Loader.Ready
sourceComponent: MultiDayView {
......
......@@ -1108,7 +1108,6 @@ Kirigami.ApplicationWindow {
Loader {
id: monthScaleModelLoader
active: Config.lastOpenedView === Config.MonthView || Config.lastOpenedView === Config.ScheduleView
onStatusChanged: if(status === Loader.Ready) asynchronous = true
sourceComponent: InfiniteCalendarViewModel {
scale: InfiniteCalendarViewModel.MonthScale
calendar: CalendarManager.calendar
......@@ -1119,8 +1118,8 @@ Kirigami.ApplicationWindow {
Loader {
id: weekScaleModelLoader
active: Config.lastOpenedView === Config.WeekView
onStatusChanged: if(status === Loader.Ready) asynchronous = true
sourceComponent: InfiniteCalendarViewModel {
maxLiveModels: 20
scale: InfiniteCalendarViewModel.WeekScale
calendar: CalendarManager.calendar
filter: root.filter
......@@ -1130,7 +1129,6 @@ Kirigami.ApplicationWindow {
Loader {
id: threeDayScaleModelLoader
active: Config.lastOpenedView === Config.ThreeDayView
onStatusChanged: if(status === Loader.Ready) asynchronous = true
sourceComponent: InfiniteCalendarViewModel {
scale: InfiniteCalendarViewModel.ThreeDayScale
calendar: CalendarManager.calendar
......@@ -1141,7 +1139,6 @@ Kirigami.ApplicationWindow {
Loader {
id: dayScaleModelLoader
active: Config.lastOpenedView === Config.DayView
onStatusChanged: if(status === Loader.Ready) asynchronous = true
sourceComponent: InfiniteCalendarViewModel {
scale: InfiniteCalendarViewModel.DayScale
calendar: CalendarManager.calendar
......
......@@ -147,11 +147,6 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
}
}
} else if(m_models[i].modelType == m_lastAccessedModelType/* ||
((m_lastAccessedModelType == TypeWeek && m_models[i].modelType == TypeWeekMultiDay) ||
(m_lastAccessedModelType == TypeWeekMultiDay && m_models[i].modelType == TypeWeek))*/) {
continue;
} else if (m_models[i].liveKeysQueue->length() > 0) {
auto firstKey = m_models[i].liveKeysQueue->dequeue();
......@@ -165,6 +160,7 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
}
}
numLiveModels = m_liveMonthViewModelKeys.length() + m_liveScheduleViewModelKeys.length() + m_liveWeekViewModelKeys.length()
+ m_liveWeekViewMultiDayModelKeys.length() + m_liveThreeDayViewModelKeys.length() + m_liveThreeDayViewMultiDayModelKeys.length()
+ m_liveDayViewModelKeys.length() + m_liveDayViewMultiDayModelKeys.length();
......@@ -172,6 +168,15 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
}
};
auto requeue = [&, this](QQueue<QDate> &liveKeysQueue, const QDate &key) {
for (int i = 0; i < liveKeysQueue.length(); i++) {
if (liveKeysQueue[i] == key) {
liveKeysQueue.move(i, liveKeysQueue.length() - 1);
break;
}
}
};
if (m_scale == MonthScale && role != StartDateRole) {
const QDate firstDay = m_firstDayOfMonthDates[idx.row()];
......@@ -190,11 +195,13 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
// Unfortunately this gets called by the pathviews no matter what the currentIndex
// value is set to.
}
if (!m_monthViewModels.contains(startDate)) {
if (!m_liveMonthViewModelKeys.contains(startDate)) {
m_monthViewModels[startDate] = generateMultiDayIncidenceModel(startDate, 42, 7);
m_liveMonthViewModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveMonthViewModelKeys, startDate);
}
return QVariant::fromValue(m_monthViewModels[startDate]);
......@@ -211,6 +218,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveScheduleViewModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveScheduleViewModelKeys, startDate);
}
return QVariant::fromValue(m_scheduleViewModels[firstDay]);
......@@ -240,6 +249,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveWeekViewModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveWeekViewModelKeys, startDate);
}
return QVariant::fromValue(m_weekViewModels[startDate]);
......@@ -257,6 +268,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveWeekViewMultiDayModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveWeekViewMultiDayModelKeys, startDate);
}
return QVariant::fromValue(m_weekViewMultiDayModels[startDate]);
......@@ -273,6 +286,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveThreeDayViewModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveThreeDayViewModelKeys, startDate);
}
return QVariant::fromValue(m_threeDayViewModels[startDate]);
......@@ -290,6 +305,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveThreeDayViewMultiDayModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveThreeDayViewMultiDayModelKeys, startDate);
}
return QVariant::fromValue(m_threeDayViewMultiDayModels[startDate]);
......@@ -306,6 +323,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveDayViewModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveDayViewModelKeys, startDate);
}
return QVariant::fromValue(m_dayViewModels[startDate]);
......@@ -323,6 +342,8 @@ QVariant InfiniteCalendarViewModel::data(const QModelIndex &idx, int role) const
m_liveDayViewMultiDayModelKeys.enqueue(startDate);
cleanUpModels();
} else {
requeue(m_liveDayViewMultiDayModelKeys, startDate);
}
return QVariant::fromValue(m_dayViewMultiDayModels[startDate]);
......@@ -599,3 +620,14 @@ void InfiniteCalendarViewModel::setFilter(const QVariantMap &filter)
}
Q_EMIT filterChanged();
}
int InfiniteCalendarViewModel::maxLiveModels()
{
return m_maxLiveModels;
}
void InfiniteCalendarViewModel::setMaxLiveModels(int maxLiveModels)
{
m_maxLiveModels = maxLiveModels;
Q_EMIT maxLiveModelsChanged();
}
......@@ -18,6 +18,7 @@ class InfiniteCalendarViewModel : public QAbstractListModel
Q_PROPERTY(QStringList hourlyViewLocalisedHourLabels MEMBER m_hourlyViewLocalisedHourLabels CONSTANT)
Q_PROPERTY(Akonadi::ETMCalendar *calendar READ calendar WRITE setCalendar NOTIFY calendarChanged)
Q_PROPERTY(QVariantMap filter READ filter WRITE setFilter NOTIFY filterChanged)
Q_PROPERTY(int maxLiveModels READ maxLiveModels WRITE setMaxLiveModels NOTIFY maxLiveModelsChanged)
public:
// The decade scale is designed to be used in a 4x3 grid, so shows 12 years at a time
......@@ -70,6 +71,12 @@ public:
QVariantMap filter() const;
void setFilter(const QVariantMap &filter);
int maxLiveModels();
void setMaxLiveModels(int maxLiveModels);
QDateTime openDate();
void setOpenDate(QDateTime openDate);
void checkModels(const QDate &start, const QDate &end, KCalendarCore::Incidence::Ptr incidence);
void checkCalendarIndex(const QModelIndex &index);
void triggerAffectedModelUpdates();
......@@ -82,6 +89,8 @@ Q_SIGNALS:
void scaleChanged();
void calendarChanged();
void filterChanged();
void maxLiveModelsChanged();
void openDateChanged();
private:
QVector<QDate> m_startDates;
......@@ -118,7 +127,7 @@ private:
mutable QQueue<QDate> m_liveThreeDayViewMultiDayModelKeys;
mutable QQueue<QDate> m_liveDayViewModelKeys;
mutable QQueue<QDate> m_liveDayViewMultiDayModelKeys;
int m_maxLiveModels = 8;
int m_maxLiveModels = 10;
mutable int m_lastAccessedModelType = TypeMonth;
Akonadi::ETMCalendar *m_calendar;
QVariantMap mFilter;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment