1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:07:34 +00:00

Spreadsheet: Reorganise the sources a bit

This commit just moves some code around:
- Give Cell its own file
- Pull all forward-declared classes/structs into Forward.h
- Clean up the order of member functions a bit
This commit is contained in:
AnotherTest 2020-08-28 16:20:23 +04:30 committed by Andreas Kling
parent b6c34c0521
commit 5715ed3dd6
8 changed files with 250 additions and 146 deletions

View file

@ -26,6 +26,8 @@
#pragma once
#include "Cell.h"
#include "Forward.h"
#include <AK/HashMap.h>
#include <AK/HashTable.h>
#include <AK/String.h>
@ -39,9 +41,6 @@
namespace Spreadsheet {
class Workbook;
class SheetGlobalObject;
struct Position {
String column;
size_t row { 0 };
@ -57,83 +56,6 @@ struct Position {
}
};
class Sheet;
struct Cell : public Weakable<Cell> {
Cell(String data, WeakPtr<Sheet> sheet)
: dirty(false)
, data(move(data))
, kind(LiteralString)
, sheet(sheet)
{
}
Cell(String source, JS::Value&& cell_value, WeakPtr<Sheet> sheet)
: dirty(false)
, data(move(source))
, evaluated_data(move(cell_value))
, kind(Formula)
, sheet(sheet)
{
}
bool dirty { false };
bool evaluated_externally { false };
String data;
JS::Value evaluated_data;
enum Kind {
LiteralString,
Formula,
} kind { LiteralString };
WeakPtr<Sheet> sheet;
Vector<WeakPtr<Cell>> referencing_cells;
void reference_from(Cell*);
void set_data(String new_data)
{
if (data == new_data)
return;
if (new_data.starts_with("=")) {
new_data = new_data.substring(1, new_data.length() - 1);
kind = Formula;
} else {
kind = LiteralString;
}
data = move(new_data);
dirty = true;
evaluated_externally = false;
}
void set_data(JS::Value new_data)
{
dirty = true;
evaluated_externally = true;
StringBuilder builder;
builder.append("=");
builder.append(new_data.to_string_without_side_effects());
data = builder.build();
evaluated_data = move(new_data);
}
String source() const;
JS::Value js_data();
void update(Badge<Sheet>) { update_data(); }
void update();
private:
void update_data();
};
class Sheet : public Core::Object {
C_OBJECT(Sheet);