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.
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};
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:32
@ Date
Date of the day.
Definition monthmodel.h:31
@ DayNumber
Day numbers, usually from 1 to 31.
Definition monthmodel.h:29
@ SameMonth
True iff this day is in the same month as the one displayed.
Definition monthmodel.h:30
@ IsToday
Date is today.
Definition monthmodel.h:33
Q_INVOKABLE void previous()
Go to the previous month.
QDate selected
Set the selected date.
Definition monthmodel.h:25
int month
The month number of the month.
Definition monthmodel.h:21
QStringList weekDays
The translated week days.
Definition monthmodel.h:23
Q_INVOKABLE void goToday()
Go to the currentDate.
QML_ELEMENTint year
The year number of the month.
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 Fri Oct 11 2024 12:08:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.