File indexing completed on 2024-05-05 16:58:36
0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include "messageeventmodel.h" 0007 #include <QSortFilterProxyModel> 0008 0009 /** 0010 * @class CollapseStateProxyModel 0011 * 0012 * This model aggregates multiple sequential state events into a single entry. 0013 * 0014 * Events are only aggregated if they happened on the same day. 0015 * 0016 * @sa MessageEventModel 0017 */ 0018 class CollapseStateProxyModel : public QSortFilterProxyModel 0019 { 0020 Q_OBJECT 0021 public: 0022 /** 0023 * @brief Defines the model roles. 0024 */ 0025 enum Roles { 0026 AggregateDisplayRole = MessageEventModel::LastRole + 1, /**< Single line aggregation of all the state events. */ 0027 StateEventsRole, /**< List of state events in the aggregated state. */ 0028 AuthorListRole, /**< List of the first 5 unique authors of the aggregated state event. */ 0029 ExcessAuthorsRole, /**< The number of unique authors beyond the first 5. */ 0030 LastRole, // Keep this last 0031 }; 0032 0033 /** 0034 * @brief Whether a row should be shown out or not. 0035 * 0036 * @sa QSortFilterProxyModel::filterAcceptsRow 0037 */ 0038 [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override; 0039 0040 /** 0041 * @brief Get the given role value at the given index. 0042 * 0043 * @sa QSortFilterProxyModel::data 0044 */ 0045 [[nodiscard]] QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override; 0046 0047 /** 0048 * @brief Returns a mapping from Role enum values to role names. 0049 * 0050 * @sa Roles, QAbstractProxyModel::roleNames() 0051 */ 0052 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0053 0054 private: 0055 /** 0056 * @brief Aggregation of the text of consecutive state events starting at row. 0057 * 0058 * If state events happen on different days they will be split into two aggregate 0059 * events. 0060 */ 0061 [[nodiscard]] QString aggregateEventToString(int row) const; 0062 0063 /** 0064 * @brief Return a list of consecutive state events starting at row. 0065 * 0066 * If state events happen on different days they will be split into two aggregate 0067 * events. 0068 */ 0069 [[nodiscard]] QVariantList stateEventsList(int row) const; 0070 0071 /** 0072 * @brief List of the first 5 unique authors for the aggregate state events starting at row. 0073 */ 0074 [[nodiscard]] QVariantList authorList(int row) const; 0075 0076 /** 0077 * @brief The number of unique authors beyond the first 5 for the aggregate state events starting at row. 0078 */ 0079 [[nodiscard]] QString excessAuthors(int row) const; 0080 };