7#include <QtCore/private/qabstractitemmodel_p.h>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
38 Q_DECLARE_PUBLIC(QQuickCalendarModel)
48 void populate(QDate from, QDate to,
bool force =
false);
60 if (!from.isValid() || !to.isValid())
63 const QCalendar gregorian;
64 Q_ASSERT(gregorian.isGregorian());
65 const QCalendar::YearMonthDay &f = gregorian.partsFromDate(from);
66 const QCalendar::YearMonthDay &t = gregorian.partsFromDate(to);
67 Q_ASSERT(f.isValid() && t.isValid());
68 if (f.year > t.year || (f.year == t.year && f.month > t.month))
72 return 1 + t.month + 12 * (t.year - f.year) - f.month;
77 Q_Q(QQuickCalendarModel);
78 if (!force && f == from && t == to)
81 int c = getCount(from, to);
86 emit q->countChanged();
88 emit q->dataChanged(q->index(0, 0), q->index(c - 1, 0));
93 QAbstractListModel(*(
new QQuickCalendarModelPrivate), parent)
98
99
100
101
104 Q_D(
const QQuickCalendarModel);
110 Q_D(QQuickCalendarModel);
111 if (d->from != from) {
113 d->populate(from, d->to);
120
121
122
123
126 Q_D(
const QQuickCalendarModel);
132 Q_D(QQuickCalendarModel);
135 d->populate(d->from, to);
142
143
144
145
148 Q_D(
const QQuickCalendarModel);
149 return d->from.addMonths(index).month() - 1;
153
154
155
156
159 Q_D(
const QQuickCalendarModel);
160 return d->from.addMonths(index).year();
164
165
166
167
170 Q_D(
const QQuickCalendarModel);
171 return d->getCount(d->from, date) - 1;
175
176
177
178
181 return indexOf(QDate(year, month + 1, 1));
186 Q_D(
const QQuickCalendarModel);
187 if (index.isValid() && index.row() < d->count) {
190 return monthAt(index.row());
192 return yearAt(index.row());
202 Q_D(
const QQuickCalendarModel);
203 if (!parent.isValid())
210 QHash<
int, QByteArray> roles;
211 roles[
MonthRole] = QByteArrayLiteral(
"month");
212 roles[
YearRole] = QByteArrayLiteral(
"year");
222 Q_D(QQuickCalendarModel);
224 d->populate(d->from, d->to,
true);
229#include "moc_qquickcalendarmodel_p.cpp"
void populate(QDate from, QDate to, bool force=false)
Q_INVOKABLE int yearAt(int index) const
\qmlmethod int QtQuick.Controls::CalendarModel::yearAt(int index)
QDate to() const
\qmlproperty date QtQuick.Controls::CalendarModel::to
void classBegin() override
Invoked after class creation, but before any properties have been set.
Q_INVOKABLE int indexOf(int year, int month) const
\qmlmethod int QtQuick.Controls::CalendarModel::indexOf(int year, int month)
QDate from() const
\qmlproperty date QtQuick.Controls::CalendarModel::from
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QVariant data(const QModelIndex &index, int role) const override
Returns the data stored under the given role for the item referred to by the index.
Q_INVOKABLE int indexOf(QDate date) const
\qmlmethod int QtQuick.Controls::CalendarModel::indexOf(Date date)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
QHash< int, QByteArray > roleNames() const override
Q_INVOKABLE int monthAt(int index) const
\qmlmethod int QtQuick.Controls::CalendarModel::monthAt(int index)