File indexing completed on 2024-11-24 04:50:38

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 <KCalendarCore/Calendar>
0007 #include <QAbstractListModel>
0008 
0009 class RecurrenceExceptionsModel : public QAbstractListModel
0010 {
0011     Q_OBJECT
0012     Q_PROPERTY(KCalendarCore::Incidence::Ptr incidencePtr READ incidencePtr WRITE setIncidencePtr NOTIFY incidencePtrChanged)
0013     Q_PROPERTY(QList<QDate> exceptions READ exceptions NOTIFY exceptionsChanged)
0014     Q_PROPERTY(QVariantMap dataroles READ dataroles CONSTANT)
0015 
0016 public:
0017     enum Roles {
0018         DateRole = Qt::UserRole + 1,
0019     };
0020     Q_ENUM(Roles)
0021 
0022     explicit RecurrenceExceptionsModel(QObject *parent = nullptr, KCalendarCore::Incidence::Ptr incidencePtr = nullptr);
0023     ~RecurrenceExceptionsModel() override = default;
0024 
0025     KCalendarCore::Incidence::Ptr incidencePtr();
0026     void setIncidencePtr(KCalendarCore::Incidence::Ptr incidence);
0027     QList<QDate> exceptions();
0028     void updateExceptions();
0029     QVariantMap dataroles();
0030 
0031     QVariant data(const QModelIndex &idx, int role) const override;
0032     QHash<int, QByteArray> roleNames() const override;
0033     int rowCount(const QModelIndex &parent = {}) const override;
0034 
0035     Q_INVOKABLE void addExceptionDateTime(QDateTime date);
0036     Q_INVOKABLE void deleteExceptionDateTime(QDateTime date);
0037 
0038 Q_SIGNALS:
0039     void incidencePtrChanged();
0040     void exceptionsChanged();
0041 
0042 private:
0043     KCalendarCore::Incidence::Ptr m_incidence;
0044     QList<QDate> m_exceptions;
0045     QVariantMap m_dataRoles;
0046 };