File indexing completed on 2025-02-02 05:02:37

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef TIMELINESECTIONDELEGATECONTROLLER_H
0008 #define TIMELINESECTIONDELEGATECONTROLLER_H
0009 
0010 #include <KHolidays/Holiday>
0011 
0012 #include <QDate>
0013 #include <QObject>
0014 
0015 class TimelineModel;
0016 
0017 /** Logic and data access for timeline section delegates.
0018  *  TODO this is still missing change notification for a few cases:
0019  *  - preceding location changes can change some or all subsequent day sections
0020  *  - isToday changes at midnight
0021  */
0022 class TimelineSectionDelegateController : public QObject
0023 {
0024     Q_OBJECT
0025     Q_PROPERTY(QString date READ dateString WRITE setDateString NOTIFY dateChanged)
0026     Q_PROPERTY(TimelineModel *timelineModel READ timelineModel WRITE setTimelineModel NOTIFY timelineModelChanged)
0027 
0028     Q_PROPERTY(QString title READ title NOTIFY dateChanged)
0029     Q_PROPERTY(bool isToday READ isToday NOTIFY dateChanged)
0030     Q_PROPERTY(QString subTitle READ subTitle NOTIFY dateChanged)
0031     Q_PROPERTY(bool isHoliday READ isHoliday NOTIFY dateChanged)
0032 
0033 public:
0034     explicit TimelineSectionDelegateController(QObject *parent = nullptr);
0035     ~TimelineSectionDelegateController();
0036 
0037     // limitation of what ListView can handle as a section value
0038     QString dateString() const;
0039     void setDateString(const QString &dtStr);
0040 
0041     TimelineModel *timelineModel() const;
0042     void setTimelineModel(TimelineModel *model);
0043 
0044     QString title() const;
0045     bool isToday() const;
0046     QString subTitle() const;
0047     bool isHoliday() const;
0048 
0049 Q_SIGNALS:
0050     void dateChanged();
0051     void timelineModelChanged();
0052 
0053 private:
0054     void recheckHoliday();
0055 
0056     TimelineModel *m_model = nullptr;
0057     QDate m_date;
0058     KHolidays::Holiday::List m_holidays;
0059 };
0060 
0061 #endif // TIMELINESECTIONDELEGATECONTROLLER_H