blob: 46f3628412b4271fb4232ad633112dc755ecfc34 [file] [log] [blame]
#pragma once
#include <QAbstractListModel>
#include <qqml.h>
#include "Cell.h"
class Notebook;
class CellModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit CellModel(Notebook *parent = nullptr);
CellModel(const CellModel &other);
enum CellRoles
{
CodeRole = Qt::UserRole + 1,
ResultRole,
UuidRole,
StatusRole,
};
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
// Add data:
Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
// Remove data:
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
QHash<int, QByteArray> roleNames() const override;
Q_INVOKABLE void addCell(const Cell &cell);
Q_INVOKABLE void addCell(QString code, QString result);
Q_INVOKABLE void insertCellBefore(int index);
Q_INVOKABLE void deleteCellAt(int index);
private:
Notebook *_notebook;
void announceCellChange(Cell *cell, int role);
};
Q_DECLARE_METATYPE(CellModel)
Q_DECLARE_METATYPE(CellModel *)