Kirigami-addons

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 <QCalendar>
8#include <QDate>
9#include <QLocale>
10#include <memory>
11
12/// Month model exposing month days and events to a QML view.
14{
16 /// The year number of the month.
17 Q_PROPERTY(int year READ year WRITE setYear NOTIFY yearChanged)
18 /// The month number of the month.
19 Q_PROPERTY(int month READ month WRITE setMonth NOTIFY monthChanged)
20 /// The translated week days.
22 /// Set the selected date.
23 Q_PROPERTY(QDate selected READ selected WRITE setSelected NOTIFY selectedChanged)
24public:
25 enum Roles {
26 // Day roles
27 DayNumber = Qt::UserRole, ///< Day numbers, usually from 1 to 31.
28 SameMonth, ///< True iff this day is in the same month as the one displayed.
29 Date, ///< Date of the day.
30 IsSelected, ///< Date is equal the selected date.
31 IsToday ///< Date is today.
32 };
33
34public:
35 explicit MonthModel(QObject *parent = nullptr);
36 ~MonthModel() override;
37
38 int year() const;
39 void setYear(int year);
40 int month() const;
41 void setMonth(int month);
42 QDate selected() const;
43 void setSelected(const QDate &selected);
44
45 QStringList weekDays() const;
46
47 /// Go to the next month.
48 Q_INVOKABLE void next();
49 /// Go to the previous month.
50 Q_INVOKABLE void previous();
51 /// Go to the currentDate.
52 Q_INVOKABLE void goToday();
53
54 // QAbstractItemModel overrides
55 QHash<int, QByteArray> roleNames() const override;
56 QVariant data(const QModelIndex &index, int role) const override;
57 int rowCount(const QModelIndex &parent) const override;
58
60 void yearChanged();
61 void monthChanged();
62 void selectedChanged();
63
64private:
65 class Private;
66 QLocale m_locale;
67 std::unique_ptr<Private> d;
68};
Month model exposing month days and events to a QML view.
Definition monthmodel.h:14
Q_INVOKABLE void next()
Go to the next month.
@ IsSelected
Date is equal the selected date.
Definition monthmodel.h:30
@ Date
Date of the day.
Definition monthmodel.h:29
@ DayNumber
Day numbers, usually from 1 to 31.
Definition monthmodel.h:27
@ SameMonth
True iff this day is in the same month as the one displayed.
Definition monthmodel.h:28
@ IsToday
Date is today.
Definition monthmodel.h:31
Q_INVOKABLE void previous()
Go to the previous month.
QDate selected
Set the selected date.
Definition monthmodel.h:23
int month
The month number of the month.
Definition monthmodel.h:19
int year
The year number of the month.
Definition monthmodel.h:17
QStringList weekDays
The translated week days.
Definition monthmodel.h:21
Q_INVOKABLE void goToday()
Go to the currentDate.
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 Tue Mar 26 2024 11:16:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.