7struct MonthModel::Private {
14MonthModel::MonthModel(
QObject *parent)
22MonthModel::~MonthModel() =
default;
29void MonthModel::setYear(
int year)
31 if (d->year ==
year) {
37 setSelected(
QDate(
year, d->selected.month(), qMin(d->selected.day(), d->calendar.daysInMonth(d->selected.month(),
year))));
45void MonthModel::setMonth(
int month)
47 if (d->month ==
month) {
53 setSelected(
QDate(d->selected.year(), d->month, qMin(d->selected.day(), d->calendar.daysInMonth(d->month, d->selected.year()))));
61void MonthModel::setSelected(
const QDate &selected)
75 for (
int i = 0; i < 7; i++) {
92 setMonth(d->calendar.monthsInYear(d->year) - 1);
94 setMonth(d->month - 1);
100 if (d->calendar.monthsInYear(d->year) == d->month) {
102 setYear(d->year + 1);
104 setMonth(d->month + 1);
111 setMonth(today.month());
112 setYear(today.year());
125 int prefix = d->calendar.dayOfWeek(
QDate(d->year, d->month, 1)) - m_locale.
firstDayOfWeek();
129 }
else if (prefix > 7) {
140 int month = d->month;
142 const int daysInMonth = d->calendar.daysInMonth(d->month, d->year);
143 if (row >= prefix && row - prefix < daysInMonth) {
145 day = row - prefix + 1;
146 }
else if (row - prefix >= daysInMonth) {
148 month = d->calendar.monthsInYear(d->year) == d->month ? 1 : d->month + 1;
149 year = d->calendar.monthsInYear(d->year) == d->month ? d->year + 1 : d->year;
150 day = row - daysInMonth - prefix + 1;
153 year = d->month > 1 ? d->year : d->year - 1;
154 month = d->month > 1 ? d->month - 1 : d->calendar.monthsInYear(
year);
155 int daysInPreviousMonth = d->calendar.daysInMonth(
month,
year);
156 day = daysInPreviousMonth - prefix + row + 1;
164 return date.startOfDay();
169 return d->selected == date;
177 const int daysInMonth = d->calendar.daysInMonth(d->month, d->year);
178 return row >= prefix && row - prefix < daysInMonth;
185int MonthModel::rowCount(
const QModelIndex &parent)
const
191QString MonthModel::monthName(
int month)
Month model exposing month days and events to a QML view.
Q_INVOKABLE void next()
Go to the next month.
@ IsSelected
Date is equal the selected date.
@ DayNumber
Day numbers, usually from 1 to 31.
@ SameMonth
True iff this day is in the same month as the one displayed.
Q_INVOKABLE void previous()
Go to the previous month.
QDate selected
Set the selected date.
int month
The month number of the month.
QStringList weekDays
The translated week days.
Q_INVOKABLE void goToday()
Go to the currentDate.
QML_ELEMENTint year
The year number of the month.
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
void append(QList< T > &&value)
Qt::DayOfWeek firstDayOfWeek() const const
QString monthName(int month, FormatType type) const const
QString standaloneDayName(int day, FormatType type) const const
bool isValid() const const
QModelIndex parent() const const
QObject * parent() const const