Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/calendar/daysmodel.cpp
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 92 | if (m_data->size() <= 0) { | |||
---|---|---|---|---|---|
93 | return; | 93 | return; | ||
94 | } | 94 | } | ||
95 | 95 | | |||
96 | m_eventsData.clear(); | 96 | m_eventsData.clear(); | ||
97 | 97 | | |||
98 | const QDate modelFirstDay(m_data->at(0).yearNumber, m_data->at(0).monthNumber, m_data->at(0).dayNumber); | 98 | const QDate modelFirstDay(m_data->at(0).yearNumber, m_data->at(0).monthNumber, m_data->at(0).dayNumber); | ||
99 | 99 | | |||
100 | if (m_pluginsManager) { | 100 | if (m_pluginsManager) { | ||
101 | Q_FOREACH (CalendarEvents::CalendarEventsPlugin *eventsPlugin, m_pluginsManager->plugins()) { | 101 | const auto plugins = m_pluginsManager->plugins(); | ||
102 | for (CalendarEvents::CalendarEventsPlugin *eventsPlugin : plugins) { | ||||
102 | eventsPlugin->loadEventsForDateRange(modelFirstDay, modelFirstDay.addDays(42)); | 103 | eventsPlugin->loadEventsForDateRange(modelFirstDay, modelFirstDay.addDays(42)); | ||
103 | } | 104 | } | ||
104 | } | 105 | } | ||
105 | 106 | | |||
106 | // We always have 42 items (or weeks * num of days in week) so we only have to tell the view that the data changed. | 107 | // We always have 42 items (or weeks * num of days in week) so we only have to tell the view that the data changed. | ||
107 | emit dataChanged(index(0, 0), index(m_data->count() - 1, 0)); | 108 | emit dataChanged(index(0, 0), index(m_data->count() - 1, 0)); | ||
108 | } | 109 | } | ||
109 | 110 | | |||
Show All 25 Lines | 131 | while (i != m_eventsData.end()) { | |||
135 | 136 | | |||
136 | ++i; | 137 | ++i; | ||
137 | } | 138 | } | ||
138 | 139 | | |||
139 | if (!updatesList.isEmpty()) { | 140 | if (!updatesList.isEmpty()) { | ||
140 | m_agendaNeedsUpdate = true; | 141 | m_agendaNeedsUpdate = true; | ||
141 | } | 142 | } | ||
142 | 143 | | |||
143 | Q_FOREACH (const QDate date, updatesList) { | 144 | for (const QDate date : qAsConst(updatesList)) { | ||
144 | const QModelIndex changedIndex = indexForDate(date); | 145 | const QModelIndex changedIndex = indexForDate(date); | ||
145 | if (changedIndex.isValid()) { | 146 | if (changedIndex.isValid()) { | ||
146 | Q_EMIT dataChanged(changedIndex, changedIndex, | 147 | Q_EMIT dataChanged(changedIndex, changedIndex, | ||
147 | {containsEventItems, containsMajorEventItems, containsMinorEventItems}); | 148 | {containsEventItems, containsMajorEventItems, containsMinorEventItems}); | ||
148 | } | 149 | } | ||
149 | Q_EMIT agendaUpdated(date); | 150 | Q_EMIT agendaUpdated(date); | ||
150 | } | 151 | } | ||
151 | } | 152 | } | ||
Show All 10 Lines | 162 | } else { | |||
162 | ++i; | 163 | ++i; | ||
163 | } | 164 | } | ||
164 | } | 165 | } | ||
165 | 166 | | |||
166 | if (!updatesList.isEmpty()) { | 167 | if (!updatesList.isEmpty()) { | ||
167 | m_agendaNeedsUpdate = true; | 168 | m_agendaNeedsUpdate = true; | ||
168 | } | 169 | } | ||
169 | 170 | | |||
170 | Q_FOREACH (const QDate date, updatesList) { | 171 | for (const QDate date : qAsConst(updatesList)) { | ||
broulik: While at it `const QDate &` | |||||
Actually better not, a QDate is just a wrapper for a qint64, with a generated copy constructor (so it's just "copying" a qint64) dfaure: Actually better not, a QDate is just a wrapper for a qint64, with a generated copy constructor… | |||||
171 | const QModelIndex changedIndex = indexForDate(date); | 172 | const QModelIndex changedIndex = indexForDate(date); | ||
172 | if (changedIndex.isValid()) { | 173 | if (changedIndex.isValid()) { | ||
173 | Q_EMIT dataChanged(changedIndex, changedIndex, | 174 | Q_EMIT dataChanged(changedIndex, changedIndex, | ||
174 | {containsEventItems, containsMajorEventItems, containsMinorEventItems}); | 175 | {containsEventItems, containsMajorEventItems, containsMinorEventItems}); | ||
175 | } | 176 | } | ||
176 | Q_EMIT agendaUpdated(date); | 177 | Q_EMIT agendaUpdated(date); | ||
177 | } | 178 | } | ||
178 | } | 179 | } | ||
Show All 11 Lines | 182 | { | |||
190 | QList<CalendarEvents::EventData> events = m_eventsData.values(date); | 191 | QList<CalendarEvents::EventData> events = m_eventsData.values(date); | ||
191 | m_qmlData.reserve(events.size()); | 192 | m_qmlData.reserve(events.size()); | ||
192 | 193 | | |||
193 | // sort events by their time and type | 194 | // sort events by their time and type | ||
194 | std::sort(events.begin(), events.end(), [](const CalendarEvents::EventData &a, const CalendarEvents::EventData &b) { | 195 | std::sort(events.begin(), events.end(), [](const CalendarEvents::EventData &a, const CalendarEvents::EventData &b) { | ||
195 | return b.type() > a.type() || b.startDateTime() > a.startDateTime(); | 196 | return b.type() > a.type() || b.startDateTime() > a.startDateTime(); | ||
196 | }); | 197 | }); | ||
197 | 198 | | |||
198 | Q_FOREACH (const CalendarEvents::EventData &event, events) { | 199 | for (const CalendarEvents::EventData &event : qAsConst(events)) { | ||
199 | m_qmlData << new EventDataDecorator(event, this); | 200 | m_qmlData << new EventDataDecorator(event, this); | ||
200 | } | 201 | } | ||
201 | 202 | | |||
202 | m_agendaNeedsUpdate = false; | 203 | m_agendaNeedsUpdate = false; | ||
203 | return m_qmlData; | 204 | return m_qmlData; | ||
204 | } | 205 | } | ||
205 | 206 | | |||
206 | QModelIndex DaysModel::indexForDate(const QDate &date) | 207 | QModelIndex DaysModel::indexForDate(const QDate &date) | ||
▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines |
While at it const QDate &