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

KDE's Doxygen guidelines are available online.