1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICKCALENDARMODEL_P_H |
5 | #define QQUICKCALENDARMODEL_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtCore/qabstractitemmodel.h> |
19 | #include <QtCore/qdatetime.h> |
20 | #include <QtQml/qqmlparserstatus.h> |
21 | #include <QtQml/qqml.h> |
22 | #include <QtCore/private/qglobal_p.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class QQuickCalendarModelPrivate; |
27 | |
28 | class QQuickCalendarModel : public QAbstractListModel, public QQmlParserStatus |
29 | { |
30 | Q_OBJECT |
31 | Q_INTERFACES(QQmlParserStatus) |
32 | Q_PROPERTY(QDate from READ from WRITE setFrom NOTIFY fromChanged FINAL) |
33 | Q_PROPERTY(QDate to READ to WRITE setTo NOTIFY toChanged FINAL) |
34 | Q_PROPERTY(int count READ rowCount NOTIFY countChanged) |
35 | QML_NAMED_ELEMENT(CalendarModel) |
36 | QML_ADDED_IN_VERSION(6, 3) |
37 | |
38 | public: |
39 | explicit QQuickCalendarModel(QObject *parent = nullptr); |
40 | |
41 | QDate from() const; |
42 | void setFrom(const QDate &from); |
43 | |
44 | QDate to() const; |
45 | void setTo(const QDate &to); |
46 | |
47 | Q_INVOKABLE int monthAt(int index) const; |
48 | Q_INVOKABLE int yearAt(int index) const; |
49 | Q_INVOKABLE int indexOf(const QDate &date) const; |
50 | Q_INVOKABLE int indexOf(int year, int month) const; |
51 | |
52 | enum { |
53 | MonthRole, |
54 | YearRole |
55 | }; |
56 | |
57 | QHash<int, QByteArray> roleNames() const override; |
58 | QVariant data(const QModelIndex &index, int role) const override; |
59 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
60 | |
61 | Q_SIGNALS: |
62 | void fromChanged(); |
63 | void toChanged(); |
64 | void countChanged(); |
65 | |
66 | protected: |
67 | void classBegin() override; |
68 | void componentComplete() override; |
69 | |
70 | private: |
71 | Q_DISABLE_COPY(QQuickCalendarModel) |
72 | Q_DECLARE_PRIVATE(QQuickCalendarModel) |
73 | }; |
74 | |
75 | QT_END_NAMESPACE |
76 | |
77 | QML_DECLARE_TYPE(QQuickCalendarModel) |
78 | |
79 | #endif // QQUICKCALENDARMODEL_P_H |
80 |