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

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 <QSharedPointer>
0027 #include <QDate>
0028 #include <QVariant>
0029 #include <QSet>
0030 #include <limits>
0031 #include "eventoccurrencemodel.h"
0032 
0033 /**
0034  * Each row represents a day.
0035  * For each day a date and a set of event occurences matching that day are exposed.
0036  */
0037 class KUBE_EXPORT PeriodDayEventModel : public QAbstractItemModel
0038 {
0039     Q_OBJECT
0040 
0041     Q_PROPERTY(EventOccurrenceModel* model WRITE setModel)
0042 
0043 public:
0044     PeriodDayEventModel(QObject *parent = nullptr);
0045     ~PeriodDayEventModel() = default;
0046 
0047     QModelIndex index(int row, int column, const QModelIndex &parent = {}) const override;
0048     QModelIndex parent(const QModelIndex &index) const override;
0049 
0050     int rowCount(const QModelIndex &parent) const override;
0051     int columnCount(const QModelIndex &parent) const override;
0052 
0053     QVariant data(const QModelIndex &index, int role) const override;
0054 
0055     QHash<int, QByteArray> roleNames() const override;
0056 
0057     void setModel(EventOccurrenceModel *model);
0058 
0059 private:
0060     QDateTime getStartTimeOfDay(const QDateTime &dateTime, const QDate &today) const;
0061     QDateTime getEndTimeOfDay(const QDateTime &dateTime, const QDate &today) const;
0062 
0063     EventOccurrenceModel *mSourceModel{nullptr};
0064 
0065     static const constexpr quintptr DAY_ID = std::numeric_limits<quintptr>::max();
0066 };