Add Notebook
diff --git a/ide/CellModel.cpp b/ide/CellModel.cpp
index 911c9a9..41acbe7 100644
--- a/ide/CellModel.cpp
+++ b/ide/CellModel.cpp
@@ -1,14 +1,14 @@
#include "CellModel.h"
-CellModel::CellModel(QObject *parent)
+CellModel::CellModel(Notebook *parent)
: QAbstractListModel(parent)
+ , _notebook(parent)
{
}
-CellModel::CellModel(const CellModel &model, QObject *parent)
- : CellModel(parent)
+CellModel::CellModel(const CellModel &other)
+ : CellModel(other._notebook)
{
- _cells = model._cells;
}
int CellModel::rowCount(const QModelIndex &parent) const
@@ -18,7 +18,7 @@
if (parent.isValid())
return 0;
- return _cells.size();
+ return _notebook->_cells.size();
}
QVariant CellModel::data(const QModelIndex &index, int role) const
@@ -29,9 +29,9 @@
switch (role)
{
case CodeRole:
- return _cells[index.row()].code();
+ return _notebook->_cells[index.row()].code();
case ResultRole:
- return _cells[index.row()].result();
+ return _notebook->_cells[index.row()].result();
default:
return QVariant();
}
@@ -44,10 +44,10 @@
switch (role)
{
case CodeRole:
- _cells[index.row()].setCode(value.toString());
+ _notebook->_cells[index.row()].setCode(value.toString());
break;
case ResultRole:
- _cells[index.row()].setResult(value.toString());
+ _notebook->_cells[index.row()].setResult(value.toString());
break;
default:
return false;
@@ -74,7 +74,7 @@
beginInsertRows(parent, row, row + count - 1);
for (int i = 0; i < count; i++)
- _cells.insert(row, Cell());
+ _notebook->_cells.insert(row, Cell());
endInsertRows();
@@ -86,7 +86,7 @@
beginRemoveRows(parent, row, row + count - 1);
for (int i = 0; i < count; i++)
- _cells.removeAt(row);
+ _notebook->_cells.removeAt(row);
endRemoveRows();
@@ -103,11 +103,11 @@
void CellModel::addCell(const Cell &cell)
{
- int i = _cells.size();
+ int i = _notebook->_cells.size();
insertRows(i, 1, QModelIndex());
- _cells[i] = cell;
+ _notebook->_cells[i] = cell;
emit dataChanged(index(i), index(i), {CodeRole, ResultRole});
}