File indexing completed on 2024-05-12 05:04:14

0001 // SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
0002 // SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik <kde@privat.broulik.de>
0003 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
0004 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 
0006 #pragma once
0007 
0008 #include "notificationmodel.h"
0009 
0010 class NotificationGroupingModel : public QAbstractProxyModel
0011 {
0012     Q_OBJECT
0013     QML_ELEMENT
0014 
0015     Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
0016     Q_PROPERTY(NotificationModel *sourceModel WRITE setSourceModel READ getSourceModel NOTIFY sourceModelChanged)
0017 
0018 public:
0019     explicit NotificationGroupingModel(QObject *parent = nullptr);
0020 
0021     void setSourceModel(QAbstractItemModel *sourceModel) override;
0022 
0023     QModelIndex index(int row, int column, const QModelIndex &parent) const override;
0024     QModelIndex parent(const QModelIndex &child) const override;
0025 
0026     int rowCount(const QModelIndex &parent) const override;
0027     bool hasChildren(const QModelIndex &parent) const override;
0028     int columnCount(const QModelIndex &parent) const override;
0029 
0030     QVariant data(const QModelIndex &proxyIndex, int role) const override;
0031 
0032     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
0033     QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
0034 
0035     bool loading() const;
0036 
0037     void setSourceModel(NotificationModel *model);
0038     NotificationModel *getSourceModel();
0039 
0040 Q_SIGNALS:
0041     void loadingChanged();
0042     void sourceModelChanged();
0043 
0044 private:
0045     bool notificationsMatch(const QModelIndex &a, const QModelIndex &b);
0046     void rebuildMap();
0047     void checkGrouping(bool silent = false);
0048     bool isGroup(int row) const;
0049     bool tryToGroup(const QModelIndex &sourceIndex, bool silent = false);
0050     void adjustMap(int anchor, int delta);
0051 
0052     QList<QList<int> *> rowMap;
0053 };