Spreadsheet: Display new value, or pending, when dirty

If recomputes are turned off, the old behavior was that a cell would
display its old property value in the SheetView. The new behavior is
that we check to see if the value is actually something that gets
computed: if so, show "#PENDING". If not, display the new value, but
format it specially to indicate that it's been changed and that
a recompute is (eventually) needed.
This commit is contained in:
Chris Hennes
2021-11-03 09:23:43 -05:00
parent 34fdcd1a61
commit bdd600ba6e

View File

@@ -277,18 +277,34 @@ QVariant SheetModel::data(const QModelIndex &index, int role) const
return QVariant::fromValue(f);
}
if (!prop) {
auto dirtyCells = sheet->getCells()->getDirty();
auto dirty = (dirtyCells.find(CellAddress(row,col)) != dirtyCells.end());
if (!prop || dirty) {
switch (role) {
case Qt::ForegroundRole: {
return QColor(0, 0, 255.0);
return QColor(0, 0, 255.0); // TODO: Remove this hardcoded color, replace with preference
}
case Qt::TextAlignmentRole: {
qtAlignment = Qt::AlignHCenter | Qt::AlignVCenter;
return QVariant::fromValue(qtAlignment);
}
case Qt::DisplayRole:
if(cell->getExpression())
return QVariant(QLatin1String("#PENDING"));
if(cell->getExpression()) {
std::string str;
if (cell->getStringContent(str))
if (str.size() > 0 && str[0] == '=')
// If this is a real computed value, indicate that a recompute is
// needed before we can display it
return QVariant(QLatin1String("#PENDING"));
else
// If it's just a simple value, display the new value, but still
// format it as a pending value to indicate to the user that
// a recompute is needed
return QVariant(QString::fromUtf8(str.c_str()));
else
return QVariant();
}
else
return QVariant();
default: