4#include "incidenceoccurrencemodel.h"
5#include <Akonadi/EntityTreeModel>
8#include <models/infinitecalendarviewmodel.h>
10InfiniteCalendarViewModel::InfiniteCalendarViewModel(
QObject *parent)
16void InfiniteCalendarViewModel::setup()
21 if (!m_hourlyViewLocalisedHourLabels.
length()) {
22 m_hourlyViewLocalisedHourLabels.
clear();
23 for (
int i = 1; i < 24; i++) {
31 QDate firstDay = today;
32 firstDay = firstDay.
addDays(m_datesToAdd / 2);
34 addDayDates(
true, firstDay);
38 QDate firstDay = today;
39 firstDay = firstDay.
addDays((-m_datesToAdd * 3) / 2);
41 addDayDates(
true, firstDay, 3);
47 firstDay = firstDay.
addDays((-m_datesToAdd * 7) / 2);
49 addWeekDates(
true, firstDay);
54 firstDay = firstDay.
addMonths(-m_datesToAdd / 2);
56 addMonthDates(
true, firstDay);
61 firstDay = firstDay.
addYears(-m_datesToAdd / 2);
63 addYearDates(
true, firstDay);
67 const int firstYear = ((floor(today.
year() / 10)) * 10) - 1;
69 firstDay = firstDay.
addYears(((-m_datesToAdd * 12) / 2) + 10);
71 addDecadeDates(
true, firstDay);
83 const QDate startDate = m_startDates[idx.
row()];
85 if (m_scale == MonthScale && role != StartDateRole) {
86 const QDate firstDay = m_firstDayOfMonthDates[idx.
row()];
89 case FirstDayOfMonthRole:
91 case SelectedMonthRole:
92 return firstDay.
month();
93 case SelectedYearRole:
94 return firstDay.
year();
104 case SelectedMonthRole:
105 return startDate.
month();
106 case SelectedYearRole:
107 return startDate.
year();
114int InfiniteCalendarViewModel::rowCount(
const QModelIndex &parent)
const
117 return m_startDates.length();
123 {StartDateRole, QByteArrayLiteral(
"startDate")},
124 {FirstDayOfMonthRole, QByteArrayLiteral(
"firstDay")},
125 {SelectedMonthRole, QByteArrayLiteral(
"selectedMonth")},
126 {SelectedYearRole, QByteArrayLiteral(
"selectedYear")},
130void InfiniteCalendarViewModel::addDates(
bool atEnd,
const QDate startFrom)
134 addDayDates(atEnd, startFrom);
137 addDayDates(atEnd, startFrom, 3);
140 addWeekDates(atEnd, startFrom);
143 addMonthDates(atEnd, startFrom);
146 addYearDates(atEnd, startFrom);
149 addDecadeDates(atEnd, startFrom);
154void InfiniteCalendarViewModel::addDayDates(
bool atEnd,
const QDate &startFrom,
int amount)
156 const int newRow = atEnd ? rowCount() : 0;
160 for (
int i = 0; i < m_datesToAdd; i++) {
161 QDate startDate = startFrom.
isValid() && i == 0 ? startFrom : atEnd ? m_startDates[rowCount() - 1].addDays(amount) : m_startDates[0].addDays(-amount);
164 m_startDates.append(startDate);
166 m_startDates.insert(0, startDate);
173void InfiniteCalendarViewModel::addWeekDates(
bool atEnd,
const QDate &startFrom)
175 const int newRow = atEnd ? rowCount() : 0;
179 for (
int i = 0; i < m_datesToAdd; i++) {
180 QDate startDate = startFrom.
isValid() && i == 0 ? startFrom : atEnd ? m_startDates[rowCount() - 1].addDays(7) : m_startDates[0].addDays(-7);
187 m_startDates.append(startDate);
189 m_startDates.insert(0, startDate);
196void InfiniteCalendarViewModel::addMonthDates(
bool atEnd,
const QDate &startFrom)
198 const int newRow = atEnd ? rowCount() : 0;
202 for (
int i = 0; i < m_datesToAdd; i++) {
203 const QDate firstDay = startFrom.
isValid() && i == 0 ? startFrom
204 : atEnd ? m_firstDayOfMonthDates[rowCount() - 1].addMonths(1)
205 : m_firstDayOfMonthDates[0].addMonths(-1);
206 QDate startDate = firstDay;
209 if (startDate >= firstDay) {
210 startDate = startDate.
addDays(-7);
214 m_firstDayOfMonthDates.append(firstDay);
215 m_startDates.append(startDate);
217 m_firstDayOfMonthDates.insert(0, firstDay);
218 m_startDates.insert(0, startDate);
225void InfiniteCalendarViewModel::addYearDates(
bool atEnd,
const QDate &startFrom)
227 const int newRow = atEnd ? rowCount() : 0;
231 for (
int i = 0; i < m_datesToAdd; i++) {
232 QDate startDate = startFrom.
isValid() && i == 0 ? startFrom : atEnd ? m_startDates[rowCount() - 1].addYears(1) : m_startDates[0].addYears(-1);
235 m_startDates.append(startDate);
237 m_startDates.insert(0, startDate);
244void InfiniteCalendarViewModel::addDecadeDates(
bool atEnd,
const QDate &startFrom)
246 const int newRow = atEnd ? rowCount() : 0;
250 for (
int i = 0; i < m_datesToAdd; i++) {
251 QDate startDate = startFrom.
isValid() && i == 0 ? startFrom : atEnd ? m_startDates[rowCount() - 1].addYears(10) : m_startDates[0].addYears(-10);
254 m_startDates.append(startDate);
256 m_startDates.insert(0, startDate);
263int InfiniteCalendarViewModel::datesToAdd()
const
268void InfiniteCalendarViewModel::setDatesToAdd(
int datesToAdd)
270 m_datesToAdd = datesToAdd;
271 Q_EMIT datesToAddChanged();
274int InfiniteCalendarViewModel::scale()
const
279void InfiniteCalendarViewModel::setScale(
int scale)
283 m_startDates.clear();
284 m_firstDayOfMonthDates.clear();
293#include "infinitecalendarviewmodel.moc"
294#include "moc_infinitecalendarviewmodel.cpp"
char * toString(const EngineQuery &query)
void beginInsertRows(const QModelIndex &parent, int first, int last)
bool hasIndex(int row, int column, const QModelIndex &parent) const const
QDate addDays(qint64 ndays) const const
QDate addMonths(int nmonths) const const
QDate addYears(int nyears) const const
int dayOfWeek() const const
bool isValid(int year, int month, int day)
QDateTime startOfDay() const const
void append(QList< T > &&value)
qsizetype length() const const
Qt::DayOfWeek firstDayOfWeek() const const
QObject * parent() const const
QTestData & newRow(const char *dataTag)
bool setHMS(int h, int m, int s, int ms)