MauiKit Calendar

infinitecalendarviewmodel.h
1// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include "hourlyincidencemodel.h"
7#include "multidayincidencemodel.h"
8#include <Akonadi/ETMCalendar>
9#include <QLocale>
10#include <QQmlEngine>
11
12class InfiniteCalendarViewModel : public QAbstractListModel
13{
15 QML_ELEMENT
16 // Amount of dates to add each time the model adds more dates
17 Q_PROPERTY(int datesToAdd READ datesToAdd WRITE setDatesToAdd NOTIFY datesToAddChanged)
18 Q_PROPERTY(int scale READ scale WRITE setScale NOTIFY scaleChanged)
19 Q_PROPERTY(QStringList hourlyViewLocalisedHourLabels MEMBER m_hourlyViewLocalisedHourLabels CONSTANT)
20
21public:
22 // The decade scale is designed to be used in a 4x3 grid, so shows 12 years at a time
23 enum Scale { DayScale, ThreeDayScale, WeekScale, MonthScale, YearScale, DecadeScale };
24 Q_ENUM(Scale)
25
26 enum Roles {
27 StartDateRole = Qt::UserRole + 1,
28 FirstDayOfMonthRole,
29 SelectedMonthRole,
30 SelectedYearRole,
31 };
32 Q_ENUM(Roles)
33
34 explicit InfiniteCalendarViewModel(QObject *parent = nullptr);
35 ~InfiniteCalendarViewModel() override = default;
36
37 void setup();
38 QVariant data(const QModelIndex &idx, int role) const override;
39 QHash<int, QByteArray> roleNames() const override;
40 int rowCount(const QModelIndex &parent = {}) const override;
41
42 Q_INVOKABLE void addDates(bool atEnd, const QDate startFrom = QDate());
43 void addDayDates(bool atEnd, const QDate &startFrom, int amount = 1);
44 void addWeekDates(bool atEnd, const QDate &startFrom);
45 void addMonthDates(bool atEnd, const QDate &startFrom);
46 void addYearDates(bool atEnd, const QDate &startFrom);
47 void addDecadeDates(bool atEnd, const QDate &startFrom);
48
49 int datesToAdd() const;
50 void setDatesToAdd(int datesToAdd);
51
52 int scale() const;
53 void setScale(int scale);
54
56 void datesToAddChanged();
57 void scaleChanged();
58
59private:
60 QVector<QDate> m_startDates;
61 QVector<QDate> m_firstDayOfMonthDates;
62 QStringList m_hourlyViewLocalisedHourLabels;
63 QLocale m_locale;
64 int m_datesToAdd = 10;
65 int m_scale = MonthScale;
66};
Q_ENUM(...)
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
T qobject_cast(QObject *object)
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:50:31 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.