File indexing completed on 2025-01-05 04:55:00

0001 /*
0002     Copyright (c) 2018 Michael Bohlender <michael.bohlender@kdemail.net>
0003     Copyright (c) 2018 Christian Mollekopf <mollekopf@kolabsys.com>
0004     Copyright (c) 2018 RĂ©mi Nicole <minijackson@riseup.net>
0005 
0006     This library is free software; you can redistribute it and/or modify it
0007     under the terms of the GNU Library General Public License as published by
0008     the Free Software Foundation; either version 2 of the License, or (at your
0009     option) any later version.
0010 
0011     This library is distributed in the hope that it will be useful, but WITHOUT
0012     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0014     License for more details.
0015 
0016     You should have received a copy of the GNU Library General Public License
0017     along with this library; see the file COPYING.LIB.  If not, write to the
0018     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0019     02110-1301, USA.
0020 */
0021 
0022 #pragma once
0023 #include "kube_export.h"
0024 
0025 #include <QAbstractItemModel>
0026 #include <QList>
0027 #include <QSet>
0028 #include <QSharedPointer>
0029 #include <QDateTime>
0030 #include "eventoccurrencemodel.h"
0031 #include "debouncer.h"
0032 
0033 namespace KCalendarCore {
0034     class MemoryCalendar;
0035     class Incidence;
0036 }
0037 class EntityCacheInterface;
0038 
0039 /**
0040  * Each toplevel index represents a week.
0041  * The "events" roles provides a list of lists, where each list represents a visual line,
0042  * containing a number of events to display.
0043  */
0044 class KUBE_EXPORT MultiDayEventModel : public QAbstractItemModel
0045 {
0046     Q_OBJECT
0047 
0048     Q_PROPERTY(EventOccurrenceModel* model WRITE setModel)
0049 
0050 public:
0051     MultiDayEventModel(QObject *parent = nullptr);
0052     ~MultiDayEventModel() = default;
0053 
0054     QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
0055     QModelIndex parent(const QModelIndex &index) const override;
0056 
0057     int rowCount(const QModelIndex &parent) const override;
0058     int columnCount(const QModelIndex &parent) const override;
0059 
0060     QVariant data(const QModelIndex &index, int role) const override;
0061 
0062     QHash<int, QByteArray> roleNames() const override;
0063 
0064     void setModel(EventOccurrenceModel *model);
0065 private:
0066     QList<QModelIndex> sortedEventsFromSourceModel(const QDate &rowStart) const;
0067     QVariantList layoutLines(const QDate &rowStart) const;
0068     void reset();
0069 
0070     EventOccurrenceModel *mSourceModel{nullptr};
0071     int mPeriodLength{7};
0072     Debouncer mUpdateFromSourceDebouncer;
0073 };