File indexing completed on 2024-12-15 03:45:01

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KUSERFEEDBACK_CONSOLE_PRODUCTMODEL_H
0008 #define KUSERFEEDBACK_CONSOLE_PRODUCTMODEL_H
0009 
0010 #include <core/product.h>
0011 #include <rest/serverinfo.h>
0012 
0013 #include <QAbstractListModel>
0014 #include <QVector>
0015 
0016 namespace KUserFeedback {
0017 namespace Console {
0018 
0019 class RESTClient;
0020 
0021 /** Self-updating product model. */
0022 class ProductModel : public QAbstractListModel
0023 {
0024     Q_OBJECT
0025 public:
0026     explicit ProductModel(QObject *parent = nullptr);
0027     ~ProductModel() override;
0028 
0029     enum Roles {
0030         ProductRole = Qt::UserRole + 1
0031     };
0032 
0033     void setRESTClient(RESTClient *client);
0034     void clear();
0035     void reload();
0036 
0037     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0038     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0039     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0040 
0041 private:
0042     void mergeProducts(QVector<Product> &&products);
0043 
0044     RESTClient *m_restClient = nullptr;
0045     QVector<Product> m_products;
0046 };
0047 }
0048 }
0049 
0050 #endif // KUSERFEEDBACK_CONSOLE_PRODUCTMODEL_H