File indexing completed on 2024-11-24 04:50:37
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 0011 class InfiniteCalendarViewModel : public QAbstractListModel 0012 { 0013 Q_OBJECT 0014 // Amount of dates to add each time the model adds more dates 0015 Q_PROPERTY(int datesToAdd READ datesToAdd WRITE setDatesToAdd NOTIFY datesToAddChanged) 0016 Q_PROPERTY(int scale READ scale WRITE setScale NOTIFY scaleChanged) 0017 0018 public: 0019 // The decade scale is designed to be used in a 4x3 grid, so shows 12 years at a time 0020 enum Scale { 0021 DayScale, 0022 ThreeDayScale, 0023 WeekScale, 0024 MonthScale, 0025 YearScale, 0026 DecadeScale, 0027 InvalidScale, 0028 }; 0029 Q_ENUM(Scale) 0030 0031 enum Roles { 0032 StartDateRole = Qt::UserRole + 1, 0033 FirstDayOfMonthRole, 0034 SelectedMonthRole, 0035 SelectedYearRole, 0036 }; 0037 Q_ENUM(Roles) 0038 0039 explicit InfiniteCalendarViewModel(QObject *parent = nullptr); 0040 ~InfiniteCalendarViewModel() override = default; 0041 0042 void setup(); 0043 QVariant data(const QModelIndex &idx, int role) const override; 0044 QHash<int, QByteArray> roleNames() const override; 0045 int rowCount(const QModelIndex &parent = {}) const override; 0046 0047 Q_INVOKABLE int moveToDate(const QDate &selectedDate, const QDate ¤tDate, const int currentIndex); 0048 Q_INVOKABLE void addDates(const bool atEnd, const QDate startFrom = QDate()); 0049 void addDayDates(const bool atEnd, const QDate &startFrom, int amount = 1); 0050 void addWeekDates(const bool atEnd, const QDate &startFrom); 0051 void addMonthDates(const bool atEnd, const QDate &startFrom); 0052 void addYearDates(const bool atEnd, const QDate &startFrom); 0053 void addDecadeDates(const bool atEnd, const QDate &startFrom); 0054 0055 int datesToAdd() const; 0056 void setDatesToAdd(const int datesToAdd); 0057 0058 int scale() const; 0059 void setScale(const int scale); 0060 0061 Q_SIGNALS: 0062 void datesToAddChanged(); 0063 void scaleChanged(); 0064 0065 private: 0066 QList<QDate> m_startDates; 0067 QList<QDate> m_firstDayOfMonthDates; 0068 QLocale m_locale; 0069 int m_datesToAdd = 10; 0070 int m_scale = InvalidScale; 0071 };