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_DATAMODEL_H 0008 #define KUSERFEEDBACK_CONSOLE_DATAMODEL_H 0009 0010 #include <core/product.h> 0011 #include <core/schemaentry.h> 0012 #include <core/schemaentryelement.h> 0013 0014 #include <QAbstractTableModel> 0015 0016 namespace KUserFeedback { 0017 namespace Console { 0018 0019 class RESTClient; 0020 class Sample; 0021 0022 /** Raw data model showing reported data of a product. */ 0023 class DataModel : public QAbstractTableModel 0024 { 0025 Q_OBJECT 0026 public: 0027 enum { 0028 SampleRole = Qt::UserRole + 1, 0029 AllSamplesRole 0030 }; 0031 0032 explicit DataModel(QObject *parent = nullptr); 0033 ~DataModel() override; 0034 0035 void setRESTClient(RESTClient *client); 0036 0037 Product product() const; 0038 void setProduct(const Product &product); 0039 0040 void setSamples(const QVector<Sample> &samples); 0041 void reload(); 0042 0043 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0044 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0045 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0046 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0047 0048 private: 0049 Product m_product; 0050 struct Column { 0051 SchemaEntry entry; 0052 SchemaEntryElement element; 0053 0054 QString name() const; 0055 }; 0056 QVector<Column> m_columns; 0057 RESTClient *m_restClient = nullptr; 0058 QVector<Sample> m_data; 0059 }; 0060 0061 } 0062 } 0063 0064 #endif // KUSERFEEDBACK_CONSOLE_DATAMODEL_H