blob: 3920e384cb21ac02d9da306301634c2f0f1b0001 [file] [log] [blame]
swissChili4b3105a2022-02-22 16:34:39 -08001#pragma once
2
3#include <QAbstractListModel>
4#include <qqml.h>
5
6#include "Cell.h"
7
8class CellModel : public QAbstractListModel
9{
10 Q_OBJECT
11 QML_ELEMENT
12
13public:
14 explicit CellModel(QObject *parent = nullptr);
15 CellModel(const CellModel &model, QObject *parent = nullptr);
16
17 enum CellRoles
18 {
19 CodeRole = Qt::UserRole + 1,
20 ResultRole
21 };
22
23 // Basic functionality:
24 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
25
26 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
27
28 // Editable:
29 Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value,
30 int role = Qt::EditRole) override;
31
32 Qt::ItemFlags flags(const QModelIndex& index) const override;
33
34 // Add data:
35 Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
36
37 // Remove data:
38 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
39
40 QHash<int, QByteArray> roleNames() const override;
41
42 Q_INVOKABLE void addCell(const Cell &cell);
43 Q_INVOKABLE void addCell(QString code, QString result);
44
45private:
46 QList<Cell> _cells;
47};
48
49Q_DECLARE_METATYPE(CellModel)