1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:37:44 +00:00

Spreadsheet: Add conditional formatting

Currently only supports setting the foregound and the background colours.
This patch also unifies `foreground_color' and `background_color' used
throughout to a `Format' struct, in hopes of getting more formatting
options one day :P
This commit is contained in:
AnotherTest 2020-09-25 22:31:39 +03:30 committed by Andreas Kling
parent 6902a09e47
commit 395df7b27d
13 changed files with 401 additions and 28 deletions

View file

@ -109,16 +109,37 @@ void Cell::update_data()
if (!dirty)
return;
dirty = false;
if (kind == Formula) {
if (!evaluated_externally)
evaluated_data = sheet->evaluate(data, this);
if (dirty) {
dirty = false;
if (kind == Formula) {
if (!evaluated_externally)
evaluated_data = sheet->evaluate(data, this);
}
for (auto& ref : referencing_cells) {
if (ref) {
ref->dirty = true;
ref->update();
}
}
}
for (auto& ref : referencing_cells) {
if (ref) {
ref->dirty = true;
ref->update();
m_evaluated_formats.background_color.clear();
m_evaluated_formats.foreground_color.clear();
StringBuilder builder;
for (auto& fmt : m_conditional_formats) {
if (!fmt.condition.is_empty()) {
builder.clear();
builder.append("return (");
builder.append(fmt.condition);
builder.append(')');
auto value = sheet->evaluate(builder.string_view(), this);
if (value.to_boolean()) {
if (fmt.background_color.has_value())
m_evaluated_formats.background_color = fmt.background_color;
if (fmt.foreground_color.has_value())
m_evaluated_formats.foreground_color = fmt.foreground_color;
}
}
}
}