MauiKit Calendar

hourlyincidencemodel.h
1// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4#pragma once
5
6#include "incidenceoccurrencemodel.h"
7#include <QAbstractItemModel>
8#include <QDateTime>
9#include <QList>
10#include <QSharedPointer>
11#include <QTimer>
12#include <QQmlEngine>
13
14namespace KCalendarCore
15{
16class Incidence;
17}
18
19/**
20 * Each toplevel index represents a day.
21 * The "incidences" roles provides a list of lists, where each list represents a visual line,
22 * containing a number of events to display.
23 */
25{
27 QML_ELEMENT
28 Q_PROPERTY(int periodLength READ periodLength WRITE setPeriodLength NOTIFY periodLengthChanged)
29 Q_PROPERTY(HourlyIncidenceModel::Filters filters READ filters WRITE setFilters NOTIFY filtersChanged)
30 Q_PROPERTY(IncidenceOccurrenceModel *model READ model WRITE setModel NOTIFY modelChanged)
31
32public:
33 enum Filter {
34 NoAllDay = 0x1,
35 NoMultiDay = 0x2,
36 };
37 Q_DECLARE_FLAGS(Filters, Filter)
40
41 enum Roles {
42 Incidences = IncidenceOccurrenceModel::LastRole,
43 PeriodStartDateTime,
44 };
45
46 explicit HourlyIncidenceModel(QObject *parent = nullptr);
47 ~HourlyIncidenceModel() override = default;
48
49 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
50 QModelIndex parent(const QModelIndex &index) const override;
51
52 int rowCount(const QModelIndex &parent) const override;
53 int columnCount(const QModelIndex &parent) const override;
54
55 QVariant data(const QModelIndex &index, int role) const override;
56
57 QHash<int, QByteArray> roleNames() const override;
58
60 void setModel(IncidenceOccurrenceModel *model);
61 int periodLength();
62 void setPeriodLength(int periodLength);
64 void setFilters(HourlyIncidenceModel::Filters filters);
65
67 void periodLengthChanged();
68 void filtersChanged();
69 void modelChanged();
70
71private:
72 QTimer mRefreshTimer;
73 QList<QModelIndex> sortedIncidencesFromSourceModel(const QDateTime &rowStart) const;
74 QVariantList layoutLines(const QDateTime &rowStart) const;
75 IncidenceOccurrenceModel *mSourceModel{nullptr};
76 int mPeriodLength{15}; // In minutes
78};
79
80Q_DECLARE_OPERATORS_FOR_FLAGS(HourlyIncidenceModel::Filters)
Each toplevel index represents a day.
Loads all event occurrences within the given period and matching the given filter.
Q_FLAGS(...)
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.