File indexing completed on 2024-11-24 04:50:37
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #pragma once 0005 0006 #include <QAbstractListModel> 0007 #include <QDate> 0008 #include <QLocale> 0009 #include <memory> 0010 0011 /// Month model exposing month days and events to a QML view. 0012 class MonthModel : public QAbstractListModel 0013 { 0014 Q_OBJECT 0015 /// The year number of the month. 0016 Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged) 0017 /// The month number of the month. 0018 Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged) 0019 /// The translated week days. 0020 Q_PROPERTY(QStringList weekDays READ weekDays CONSTANT) 0021 /// Set the selected date. 0022 Q_PROPERTY(QDate selected READ selected WRITE setSelected NOTIFY selectedChanged) 0023 public: 0024 enum Roles { 0025 // Day roles 0026 DayNumber = Qt::UserRole, ///< Day numbers, usually from 1 to 31. 0027 SameMonth, ///< True iff this day is in the same month as the one displayed. 0028 Date, ///< Date of the day. 0029 IsSelected, ///< Date is equal the selected date. 0030 IsToday ///< Date is today. 0031 }; 0032 0033 public: 0034 explicit MonthModel(QObject *parent = nullptr); 0035 ~MonthModel() override; 0036 0037 int year() const; 0038 void setYear(int year); 0039 int month() const; 0040 void setMonth(int month); 0041 QDate selected() const; 0042 void setSelected(const QDate &selected); 0043 0044 QStringList weekDays() const; 0045 0046 /// Go to the next month. 0047 Q_INVOKABLE void next(); 0048 /// Go to the previous month. 0049 Q_INVOKABLE void previous(); 0050 /// Go to the currentDate. 0051 Q_INVOKABLE void goToday(); 0052 0053 // QAbstractItemModel overrides 0054 QHash<int, QByteArray> roleNames() const override; 0055 QVariant data(const QModelIndex &index, int role) const override; 0056 int rowCount(const QModelIndex &parent) const override; 0057 0058 Q_SIGNALS: 0059 void yearChanged(); 0060 void monthChanged(); 0061 void selectedChanged(); 0062 0063 private: 0064 struct Private; 0065 QLocale m_locale; 0066 std::unique_ptr<Private> d; 0067 };