File indexing completed on 2024-06-23 04:42:35

0001 // SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include "hourlyincidencemodel.h"
0007 #include "multidayincidencemodel.h"
0008 #include <Akonadi/ETMCalendar>
0009 #include <QLocale>
0010 #include <QQmlEngine>
0011 
0012 class InfiniteCalendarViewModel : public QAbstractListModel
0013 {
0014     Q_OBJECT
0015     QML_ELEMENT
0016     // Amount of dates to add each time the model adds more dates
0017     Q_PROPERTY(int datesToAdd READ datesToAdd WRITE setDatesToAdd NOTIFY datesToAddChanged)
0018     Q_PROPERTY(int scale READ scale WRITE setScale NOTIFY scaleChanged)
0019     Q_PROPERTY(QStringList hourlyViewLocalisedHourLabels MEMBER m_hourlyViewLocalisedHourLabels CONSTANT)
0020 
0021 public:
0022     // The decade scale is designed to be used in a 4x3 grid, so shows 12 years at a time
0023     enum Scale { DayScale, ThreeDayScale, WeekScale, MonthScale, YearScale, DecadeScale };
0024     Q_ENUM(Scale)
0025 
0026     enum Roles {
0027         StartDateRole = Qt::UserRole + 1,
0028         FirstDayOfMonthRole,
0029         SelectedMonthRole,
0030         SelectedYearRole,
0031     };
0032     Q_ENUM(Roles)
0033 
0034     explicit InfiniteCalendarViewModel(QObject *parent = nullptr);
0035     ~InfiniteCalendarViewModel() override = default;
0036 
0037     void setup();
0038     QVariant data(const QModelIndex &idx, int role) const override;
0039     QHash<int, QByteArray> roleNames() const override;
0040     int rowCount(const QModelIndex &parent = {}) const override;
0041 
0042     Q_INVOKABLE void addDates(bool atEnd, const QDate startFrom = QDate());
0043     void addDayDates(bool atEnd, const QDate &startFrom, int amount = 1);
0044     void addWeekDates(bool atEnd, const QDate &startFrom);
0045     void addMonthDates(bool atEnd, const QDate &startFrom);
0046     void addYearDates(bool atEnd, const QDate &startFrom);
0047     void addDecadeDates(bool atEnd, const QDate &startFrom);
0048 
0049     int datesToAdd() const;
0050     void setDatesToAdd(int datesToAdd);
0051 
0052     int scale() const;
0053     void setScale(int scale);
0054 
0055 Q_SIGNALS:
0056     void datesToAddChanged();
0057     void scaleChanged();
0058 
0059 private:
0060     QVector<QDate> m_startDates;
0061     QVector<QDate> m_firstDayOfMonthDates;
0062     QStringList m_hourlyViewLocalisedHourLabels;
0063     QLocale m_locale;
0064     int m_datesToAdd = 10;
0065     int m_scale = MonthScale;
0066 };