MauiKit Calendar

monthmodel.h
1// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <QAbstractListModel>
7#include <QDate>
8#include <QLocale>
9#include <QQmlEngine>
10#include <memory>
11
12/// Month model exposing month days and events to a QML view.
13class MonthModel : public QAbstractListModel
14{
16 QML_ELEMENT
17
18 /// The year number of the month.
19 Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged)
20 /// The month number of the month.
21 Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged)
22 /// The translated week days.
24 /// Set the selected date.
25 Q_PROPERTY(QDate selected READ selected WRITE setSelected NOTIFY selectedChanged)
26public:
27 enum Roles {
28 // Day roles
29 DayNumber = Qt::UserRole, ///< Day numbers, usually from 1 to 31.
30 SameMonth, ///< True iff this day is in the same month as the one displayed.
31 Date, ///< Date of the day.
32 IsSelected, ///< Date is equal the selected date.
33 IsToday ///< Date is today.
34 };
35
36public:
37 explicit MonthModel(QObject *parent = nullptr);
38 ~MonthModel() override;
39
40 int year() const;
41 void setYear(int year);
42 int month() const;
43 void setMonth(int month);
44 QDate selected() const;
45 void setSelected(const QDate &selected);
46
47 QStringList weekDays() const;
48
49 /// Go to the next month.
50 Q_INVOKABLE void next();
51 /// Go to the previous month.
52 Q_INVOKABLE void previous();
53 /// Go to the currentDate.
54 Q_INVOKABLE void goToday();
55
56 // QAbstractItemModel overrides
57 QHash<int, QByteArray> roleNames() const override;
58 QVariant data(const QModelIndex &index, int role) const override;
59 int rowCount(const QModelIndex &parent) const override;
60
61 Q_INVOKABLE static QString monthName(int month);
62
64 void yearChanged();
65 void monthChanged();
66 void selectedChanged();
67
68private:
69 struct Private;
70 QLocale m_locale;
71 std::unique_ptr<Private> d;
72};
Q_INVOKABLE void next()
Q_INVOKABLE void previous()
QDate selected
Definition monthmodel.h:25
QStringList weekDays
Definition monthmodel.h:23
Q_INVOKABLE void goToday()
QML_ELEMENTint year
Definition monthmodel.h:19
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.