Add evaluator
diff --git a/ide/CellModel.cpp b/ide/CellModel.cpp
index 41acbe7..8271c87 100644
--- a/ide/CellModel.cpp
+++ b/ide/CellModel.cpp
@@ -29,9 +29,13 @@
switch (role)
{
case CodeRole:
- return _notebook->_cells[index.row()].code();
+ return _notebook->_cells[index.row()]->code();
case ResultRole:
- return _notebook->_cells[index.row()].result();
+ return _notebook->_cells[index.row()]->result();
+ case UuidRole:
+ return _notebook->_cells[index.row()]->uuid();
+ case StatusRole:
+ return _notebook->_cells[index.row()]->status();
default:
return QVariant();
}
@@ -44,10 +48,13 @@
switch (role)
{
case CodeRole:
- _notebook->_cells[index.row()].setCode(value.toString());
+ _notebook->_cells[index.row()]->setCode(value.toString());
break;
case ResultRole:
- _notebook->_cells[index.row()].setResult(value.toString());
+ _notebook->_cells[index.row()]->setResult(value.toString());
+ break;
+ case StatusRole:
+ _notebook->_cells[index.row()]->setStatus(value.toInt());
break;
default:
return false;
@@ -66,7 +73,7 @@
if (!index.isValid())
return Qt::NoItemFlags;
- return Qt::ItemIsEditable; // FIXME: Implement me!
+ return Qt::ItemIsEditable;
}
bool CellModel::insertRows(int row, int count, const QModelIndex &parent)
@@ -74,7 +81,26 @@
beginInsertRows(parent, row, row + count - 1);
for (int i = 0; i < count; i++)
- _notebook->_cells.insert(row, Cell());
+ {
+ Cell *cell = new Cell(this);
+
+ connect(cell, &Cell::codeChanged, this, [this, cell](QString)
+ {
+ announceCellChange(cell, CodeRole);
+ });
+
+ connect(cell, &Cell::resultChanged, this, [this, cell](QString)
+ {
+ announceCellChange(cell, ResultRole);
+ });
+
+ connect(cell, &Cell::statusChanged, this, [this, cell](int)
+ {
+ announceCellChange(cell, StatusRole);
+ });
+
+ _notebook->_cells.insert(row, cell);
+ }
endInsertRows();
@@ -86,7 +112,10 @@
beginRemoveRows(parent, row, row + count - 1);
for (int i = 0; i < count; i++)
+ {
+ delete _notebook->_cells[row];
_notebook->_cells.removeAt(row);
+ }
endRemoveRows();
@@ -98,6 +127,8 @@
return {
{CodeRole, "code"},
{ResultRole, "result"},
+ {UuidRole, "uuid"},
+ {StatusRole, "status"},
};
}
@@ -107,7 +138,7 @@
insertRows(i, 1, QModelIndex());
- _notebook->_cells[i] = cell;
+ *_notebook->_cells[i] = cell;
emit dataChanged(index(i), index(i), {CodeRole, ResultRole});
}
@@ -115,3 +146,17 @@
{
addCell(Cell(code, result));
}
+
+void CellModel::announceCellChange(Cell *cell, int role)
+{
+ // TODO: Optimize
+
+ for (int i = 0; i < rowCount(); i++)
+ {
+ if (_notebook->_cells[i] == cell)
+ {
+ emit dataChanged(index(i), index(i), QVector<int>() << role);
+ break;
+ }
+ }
+}