MauiKit Calendar

remindersmodel.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 <KCalendarCore/Calendar>
7#include <QAbstractItemModel>
8#include <QDebug>
9
10/**
11 * This class provides a QAbstractItemModel for an incidences' reminders/alarms.
12 * This can be useful for letting users add, modify, or delete incidences on new or pre-existing incidences.
13 * It treats the incidence's list of alarms as the single source of truth (and it should be kept this way!)
14 *
15 * The data for the model comes from m_incidence, which is set in the constructor. This is a pointer to the
16 * incidence this model is getting the alarm info from. All alarm pointers are then added to m_alarms, which
17 * is a list. Elements in this model are therefore accessed through row numbers, as the list is a one-
18 * dimensional data structure.
19 */
20
22{
24 Q_PROPERTY(KCalendarCore::Incidence::Ptr incidencePtr READ incidencePtr WRITE setIncidencePtr NOTIFY incidencePtrChanged)
25 Q_PROPERTY(KCalendarCore::Alarm::List alarms READ alarms NOTIFY alarmsChanged)
26 Q_PROPERTY(QVariantMap dataroles READ dataroles CONSTANT)
27
28public:
29 enum Roles {
30 TypeRole = Qt::UserRole + 1,
31 TimeRole,
32 StartOffsetRole,
33 EndOffsetRole,
34 };
35 Q_ENUM(Roles);
36
37 explicit RemindersModel(QObject *parent = nullptr, KCalendarCore::Incidence::Ptr incidencePtr = nullptr);
38 ~RemindersModel() override = default;
39
40 KCalendarCore::Incidence::Ptr incidencePtr();
41 void setIncidencePtr(KCalendarCore::Incidence::Ptr incidence);
43 QVariantMap dataroles();
44
45 QVariant data(const QModelIndex &idx, int role) const override;
46 bool setData(const QModelIndex &idx, const QVariant &value, int role) override;
47 QHash<int, QByteArray> roleNames() const override;
48 int rowCount(const QModelIndex &parent = {}) const override;
49
50 Q_INVOKABLE void addAlarm();
51 Q_INVOKABLE void deleteAlarm(int row);
52
54 void incidencePtrChanged();
55 void alarmsChanged();
56
57private:
59 QVariantMap m_dataRoles;
60};
This class provides a QAbstractItemModel for an incidences' reminders/alarms.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
UserRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.