File indexing completed on 2024-11-10 04:32:27

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 <QAbstractListModel>
0010 
0011 #include "bannerinfo/bannerinfos.h"
0012 #include "libruqolacore_export.h"
0013 #include <QVector>
0014 
0015 class LIBRUQOLACORE_EXPORT BannerInfosModel : public QAbstractListModel
0016 {
0017     Q_OBJECT
0018 public:
0019     enum BannerInfosRoles {
0020         Title = Qt::UserRole + 1,
0021         Text,
0022         Link,
0023         Read,
0024         Identifier,
0025     };
0026 
0027     Q_ENUM(BannerInfosRoles)
0028 
0029     explicit BannerInfosModel(QObject *parent = nullptr);
0030     ~BannerInfosModel() override;
0031 
0032     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0033     [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
0034 
0035     void clear();
0036 
0037     void insertBannerInfos(const BannerInfos &infos);
0038 
0039 private:
0040     [[nodiscard]] LIBRUQOLACORE_NO_EXPORT QString text(const BannerInfo &info) const;
0041     BannerInfos mBannerInfos;
0042 };