File indexing completed on 2024-05-12 16:25:52

0001 /*
0002    SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractItemModel>
0010 
0011 #include "libruqolacore_export.h"
0012 #include "utils.h"
0013 
0014 class LIBRUQOLACORE_EXPORT SwitchChannelHistoryModel : public QAbstractListModel
0015 {
0016     Q_OBJECT
0017 public:
0018     enum SwitchChannelHistoryRoles {
0019         Name = Qt::UserRole + 1,
0020         Identifier,
0021         AvatarInfo,
0022     };
0023     Q_ENUM(SwitchChannelHistoryRoles)
0024 
0025     struct SwitchChannelInfo {
0026         SwitchChannelInfo() = default;
0027         SwitchChannelInfo(const QString &name, const QString &identifier, const Utils::AvatarInfo &info)
0028             : mName(name)
0029             , mIdentifier(identifier)
0030             , mAvatarInfo(info)
0031         {
0032         }
0033         [[nodiscard]] bool operator==(const SwitchChannelInfo &other) const;
0034         QString mName;
0035         QString mIdentifier;
0036         Utils::AvatarInfo mAvatarInfo;
0037     };
0038 
0039     explicit SwitchChannelHistoryModel(QObject *parent = nullptr);
0040     ~SwitchChannelHistoryModel() override;
0041 
0042     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0043     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0044 
0045     void addHistory(const SwitchChannelInfo &info);
0046 
0047 private:
0048     QVector<SwitchChannelInfo> mSwichChannelsInfo;
0049 };
0050 
0051 Q_DECLARE_METATYPE(SwitchChannelHistoryModel::SwitchChannelInfo)
0052 Q_DECLARE_TYPEINFO(SwitchChannelHistoryModel::SwitchChannelInfo, Q_MOVABLE_TYPE);