MauiKit Calendar

multidayincidencemodel.h
1// Copyright (c) 2018 Michael Bohlender <michael.bohlender@kdemail.net>
2// Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
3// Copyright (c) 2018 RĂ©mi Nicole <minijackson@riseup.net>
4// Copyright (c) 2021 Carl Schwan <carlschwan@kde.org>
5// SPDX-FileCopyrightText: 2021 Claudio Cambra <claudio.cambra@gmail.com>
6// SPDX-License-Identifier: LGPL-2.0-or-later
7
8#pragma once
9
10#include "incidenceoccurrencemodel.h"
11#include <QAbstractItemModel>
12#include <QList>
13#include <QSharedPointer>
14#include <QTimer>
15//#include <kalendarconfig.h>
16
17namespace KCalendarCore
18{
19class Incidence;
20}
21
22/**
23 * Each toplevel index represents a week.
24 * The "incidences" roles provides a list of lists, where each list represents a visual line,
25 * containing a number of events to display.
26 */
28{
30 Q_PROPERTY(int periodLength READ periodLength WRITE setPeriodLength NOTIFY periodLengthChanged)
31 Q_PROPERTY(MultiDayIncidenceModel::Filters filters READ filters WRITE setFilters NOTIFY filtersChanged)
32 Q_PROPERTY(int incidenceCount READ incidenceCount NOTIFY incidenceCountChanged)
33 Q_PROPERTY(IncidenceOccurrenceModel *model READ model WRITE setModel NOTIFY modelChanged)
34
35public:
36 enum Filter {
37 AllDayOnly = 0x1,
38 NoStartDateOnly = 0x2,
39 MultiDayOnly = 0x3,
40 };
41 Q_DECLARE_FLAGS(Filters, Filter)
44
45 enum Roles {
46 Incidences = IncidenceOccurrenceModel::LastRole,
47 PeriodStartDate,
48 };
49
50 explicit MultiDayIncidenceModel(QObject *parent = nullptr);
51 ~MultiDayIncidenceModel() override = default;
52
53 QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
54 QModelIndex parent(const QModelIndex &index) const override;
55
56 int rowCount(const QModelIndex &parent) const override;
57 int columnCount(const QModelIndex &parent) const override;
58
59 QVariant data(const QModelIndex &index, int role) const override;
60
61 QHash<int, QByteArray> roleNames() const override;
62
64 void setModel(IncidenceOccurrenceModel *model);
65 int periodLength();
66 void setPeriodLength(int periodLength);
68 void setFilters(MultiDayIncidenceModel::Filters filters);
69 bool incidencePassesFilter(const QModelIndex &idx) const;
70 Q_INVOKABLE int incidenceCount();
71
73 void periodLengthChanged();
74 void filtersChanged();
75 void incidenceCountChanged();
76 void modelChanged();
77
78protected:
79 void setIncidenceCount(int incidenceCount);
80
81private:
82 QTimer mRefreshTimer;
83 QList<QModelIndex> sortedIncidencesFromSourceModel(const QDate &rowStart) const;
84 QVariantList layoutLines(const QDate &rowStart) const;
85 IncidenceOccurrenceModel *mSourceModel{nullptr};
86 int mPeriodLength{7};
88// KalendarConfig *m_config = nullptr;
89};
90
91Q_DECLARE_OPERATORS_FOR_FLAGS(MultiDayIncidenceModel::Filters)
Loads all event occurrences within the given period and matching the given filter.
Each toplevel index represents a week.
Q_FLAGS(...)
Q_ENUM(...)
Q_INVOKABLEQ_INVOKABLE
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 Sat Dec 21 2024 17:02:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.