Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Dec 4, 2023
1 parent 309c831 commit eb6d4a4
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 147 deletions.
14 changes: 8 additions & 6 deletions src/odr/internal/abstract/sheet_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Sheet : public virtual Element {
std::uint32_t row) const = 0;

[[nodiscard]] virtual Element *first_shape(const Document *) const = 0;

[[nodiscard]] virtual TableStyle style(const Document *) const = 0;
};

class SheetColumn : public virtual Element {
Expand All @@ -36,7 +38,7 @@ class SheetColumn : public virtual Element {
return ElementType::table_column;
}

[[nodiscard]] virtual TableColumnStyle style(const Document *, const Sheet *,
[[nodiscard]] virtual TableColumnStyle style(const Document *, Sheet *,
std::uint32_t column) const = 0;
};

Expand All @@ -46,7 +48,7 @@ class SheetRow : public virtual Element {
return ElementType::table_row;
}

[[nodiscard]] virtual TableRowStyle style(const Document *, const Sheet *,
[[nodiscard]] virtual TableRowStyle style(const Document *, Sheet *,
std::uint32_t row) const = 0;
};

Expand All @@ -56,17 +58,17 @@ class SheetCell : public virtual Element {
return ElementType::table_cell;
}

[[nodiscard]] virtual bool is_covered(const Document *, const Sheet *,
[[nodiscard]] virtual bool is_covered(const Document *, Sheet *,
std::uint32_t column,
std::uint32_t row) const = 0;
[[nodiscard]] virtual TableDimensions span(const Document *, const Sheet *,
[[nodiscard]] virtual TableDimensions span(const Document *, Sheet *,
std::uint32_t column,
std::uint32_t row) const = 0;
[[nodiscard]] virtual ValueType value_type(const Document *, const Sheet *,
[[nodiscard]] virtual ValueType value_type(const Document *, Sheet *,
std::uint32_t column,
std::uint32_t row) const = 0;

[[nodiscard]] virtual TableCellStyle style(const Document *, const Sheet *,
[[nodiscard]] virtual TableCellStyle style(const Document *, Sheet *,
std::uint32_t column,
std::uint32_t row) const = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion src/odr/internal/odf/odf_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Element : public virtual common::Element {

bool is_editable(const abstract::Document *document) const override;

protected:
pugi::xml_node m_node;

protected:
virtual const char *style_name_(const abstract::Document *) const;

static const Document *document_(const abstract::Document *);
Expand Down
6 changes: 3 additions & 3 deletions src/odr/internal/odf/odf_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void odf::parse_element_children(Document &document, DrawingRoot *element,
}

template <>
std::tuple<odf::Element *, pugi::xml_node>
std::tuple<odf::Text *, pugi::xml_node>
odf::parse_element_tree<odf::Text>(Document &document, pugi::xml_node first) {
if (!first) {
return std::make_tuple(nullptr, pugi::xml_node());
Expand All @@ -96,7 +96,7 @@ odf::parse_element_tree<odf::Text>(Document &document, pugi::xml_node first) {
}

template <>
std::tuple<odf::Element *, pugi::xml_node>
std::tuple<odf::Table *, pugi::xml_node>
odf::parse_element_tree<odf::Table>(Document &document, pugi::xml_node node) {
if (!node) {
return std::make_tuple(nullptr, pugi::xml_node());
Expand Down Expand Up @@ -128,7 +128,7 @@ odf::parse_element_tree<odf::Table>(Document &document, pugi::xml_node node) {
}

template <>
std::tuple<odf::Element *, pugi::xml_node>
std::tuple<odf::TableRow *, pugi::xml_node>
odf::parse_element_tree<odf::TableRow>(Document &document,
pugi::xml_node node) {
if (!node) {
Expand Down
14 changes: 7 additions & 7 deletions src/odr/internal/odf/odf_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class TableRow;

Element *parse_tree(Document &document, pugi::xml_node node);

template <typename Derived>
std::tuple<Element *, pugi::xml_node> parse_element_tree(Document &document,
pugi::xml_node node) {
template <typename element_t>
std::tuple<element_t *, pugi::xml_node>
parse_element_tree(Document &document, pugi::xml_node node) {
if (!node) {
return std::make_tuple(nullptr, pugi::xml_node());
}

auto element_unique = std::make_unique<Derived>(node);
auto element_unique = std::make_unique<element_t>(node);
auto element = element_unique.get();
document.register_element_(std::move(element_unique));

Expand All @@ -36,13 +36,13 @@ std::tuple<Element *, pugi::xml_node> parse_element_tree(Document &document,
return std::make_tuple(element, node.next_sibling());
}
template <>
std::tuple<Element *, pugi::xml_node>
std::tuple<Text *, pugi::xml_node>
parse_element_tree<Text>(Document &document, pugi::xml_node first);
template <>
std::tuple<Element *, pugi::xml_node>
std::tuple<Table *, pugi::xml_node>
parse_element_tree<Table>(Document &document, pugi::xml_node node);
template <>
std::tuple<Element *, pugi::xml_node>
std::tuple<TableRow *, pugi::xml_node>
parse_element_tree<TableRow>(Document &document, pugi::xml_node node);

std::tuple<Element *, pugi::xml_node>
Expand Down
168 changes: 73 additions & 95 deletions src/odr/internal/odf/odf_spreadsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,76 @@

namespace odr::internal::odf {

namespace {

class SheetColumn final : public Element, public abstract::TableColumn {
class SheetColumn final : public Element, public abstract::SheetColumn {
public:
using Element::Element;

[[nodiscard]] TableColumnStyle
style(const abstract::Document *document) const final {
[[nodiscard]] TableColumnStyle style(const abstract::Document *document,
abstract::Sheet *,
std::uint32_t /*column*/) const final {
return partial_style(document).table_column_style;
}
};

class SheetRow final : public Element, public abstract::TableRow {
class SheetRow final : public Element, public abstract::SheetRow {
public:
using Element::Element;

[[nodiscard]] TableRowStyle
style(const abstract::Document *document) const final {
[[nodiscard]] TableRowStyle style(const abstract::Document *document,
abstract::Sheet *,
std::uint32_t /*column*/) const final {
return partial_style(document).table_row_style;
}
};

class SheetCell final : public Element, public abstract::TableCell {
class SheetCell final : public Element, public abstract::SheetCell {
public:
using Element::Element;

[[nodiscard]] bool is_covered(const abstract::Document *) const final {
[[nodiscard]] bool is_covered(const abstract::Document *, abstract::Sheet *,
std::uint32_t /*column*/,
std::uint32_t /*row*/) const final {
return std::strcmp(m_node.name(), "table:covered-table-cell") == 0;
}

[[nodiscard]] TableDimensions span(const abstract::Document *) const final {
[[nodiscard]] TableDimensions span(const abstract::Document *,
abstract::Sheet *,
std::uint32_t /*column*/,
std::uint32_t /*row*/) const final {
return {m_node.attribute("table:number-rows-spanned").as_uint(1),
m_node.attribute("table:number-columns-spanned").as_uint(1)};
}

[[nodiscard]] ValueType value_type(const abstract::Document *) const final {
[[nodiscard]] ValueType value_type(const abstract::Document *,
abstract::Sheet *,
std::uint32_t /*column*/,
std::uint32_t /*row*/) const final {
auto value_type = m_node.attribute("office:value-type").value();
if (std::strcmp("float", value_type) == 0) {
return ValueType::float_number;
}
return ValueType::string;
}

[[nodiscard]] TableCellStyle
style(const abstract::Document *document) const final {
return partial_style(document).table_cell_style;
[[nodiscard]] TableCellStyle style(const abstract::Document *document,
abstract::Sheet *sheet,
std::uint32_t column,
std::uint32_t /*row*/) const final {
auto style_name = style_name_(document);
if (style_name == nullptr) {
style_name = dynamic_cast<SheetColumn *>(sheet->column(document, column))
->m_node.attribute("table:default-cell-style-name")
.value();
}
if (style_name == nullptr) {
return {};
}
if (auto style = style_(document)->style(style_name)) {
return style->resolved().table_cell_style;
}
}
};

} // namespace

std::string Sheet::name(const abstract::Document *) const {
return m_node.attribute("table:name").value();
}
Expand Down Expand Up @@ -100,87 +119,16 @@ Sheet::content(const abstract::Document *,
return result;
}

abstract::Element *Sheet::first_cell_element(const abstract::Document *document,
std::uint32_t column,
std::uint32_t row) const {
auto cell = cell_(document, column, row);
if (cell == nullptr) {
return nullptr;
}
return cell->first_child(document);
}

abstract::Element *Sheet::first_shape(const abstract::Document *) const {
return m_first_shape;
}

TableStyle Sheet::style(const abstract::Document *document) const {
return partial_style(document).table_style;
}

TableColumnStyle Sheet::column_style(const abstract::Document *,
std::uint32_t /*column*/) const {
return TableColumnStyle(); // TODO
}

TableRowStyle Sheet::row_style(const abstract::Document *,
std::uint32_t /*row*/) const {
return TableRowStyle(); // TODO
}

TableCellStyle Sheet::cell_style(const abstract::Document *,
std::uint32_t /*column*/,
std::uint32_t /*row*/) const {
return TableCellStyle(); // TODO
}

bool Sheet::is_covered(const abstract::Document *, std::uint32_t /*column*/,
std::uint32_t /*row*/) const {
return false; // TODO
}

TableDimensions Sheet::span(const abstract::Document *,
std::uint32_t /*column*/,
std::uint32_t /*row*/) const {
return TableDimensions(); // TODO
}

ValueType Sheet::value_type(const abstract::Document *,
std::uint32_t /*column*/,
std::uint32_t /*row*/) const {
return ValueType::unknown; // TODO
}

void Sheet::init_column_(std::uint32_t column, std::uint32_t repeated,
Element *element) {
m_columns[column + repeated] = element;
}

void Sheet::init_row_(std::uint32_t row, std::uint32_t repeated,
Element *element) {
m_rows[row + repeated].element = element;
}

void Sheet::init_cell_(std::uint32_t column, std::uint32_t row,
std::uint32_t columns_repeated,
std::uint32_t rows_repeated, Element *element) {
m_rows[row + rows_repeated].cells[column + columns_repeated] = element;
}

void Sheet::init_dimensions_(TableDimensions dimensions) {
m_dimensions = dimensions;
}

abstract::Element *Sheet::column_(const abstract::Document *,
std::uint32_t column) const {
abstract::SheetColumn *Sheet::column(const abstract::Document *,
std::uint32_t column) const {
if (auto it = util::map::lookup_greater_than(m_columns, column);
it != std::end(m_columns)) {
return it->second;
return dynamic_cast<abstract::SheetColumn *>(it->second);
}
return nullptr;
}

abstract::Element *Sheet::row_(const abstract::Document *,
abstract::SheetRow *Sheet::row(const abstract::Document *,
std::uint32_t row) const {
if (auto it = util::map::lookup_greater_than(m_rows, row);
it != std::end(m_rows)) {
Expand All @@ -189,8 +137,9 @@ abstract::Element *Sheet::row_(const abstract::Document *,
return nullptr;
}

abstract::Element *Sheet::cell_(const abstract::Document *,
std::uint32_t column, std::uint32_t row) const {
abstract::SheetCell *Sheet::cell(const abstract::Document *,
std::uint32_t column,
std::uint32_t row) const {
if (auto row_it = util::map::lookup_greater_than(m_rows, row);
row_it != std::end(m_rows)) {
auto &cells = row_it->second.cells;
Expand All @@ -203,12 +152,41 @@ abstract::Element *Sheet::cell_(const abstract::Document *,
return nullptr;
}

abstract::Element *Sheet::first_shape(const abstract::Document *) const {
return m_first_shape;
}

TableStyle Sheet::style(const abstract::Document *document) const {
return partial_style(document).table_style;
}

void Sheet::init_column_(std::uint32_t column, std::uint32_t repeated,
SheetColumn *element) {
m_columns[column + repeated] = dynamic_cast<abstract::SheetColumn *>(element);
}

void Sheet::init_row_(std::uint32_t row, std::uint32_t repeated,
SheetRow *element) {
m_rows[row + repeated].element = dynamic_cast<abstract::SheetRow *>(element);
}

void Sheet::init_cell_(std::uint32_t column, std::uint32_t row,
std::uint32_t columns_repeated,
std::uint32_t rows_repeated, SheetCell *element) {
m_rows[row + rows_repeated].cells[column + columns_repeated] =
dynamic_cast<abstract::SheetCell *>(element);
}

void Sheet::init_dimensions_(TableDimensions dimensions) {
m_dimensions = dimensions;
}

} // namespace odr::internal::odf

namespace odr::internal {

template <>
std::tuple<odf::Element *, pugi::xml_node>
std::tuple<odf::Sheet *, pugi::xml_node>
odf::parse_element_tree<odf::Sheet>(Document &document, pugi::xml_node node) {
if (!node) {
return std::make_tuple(nullptr, pugi::xml_node());
Expand Down
Loading

0 comments on commit eb6d4a4

Please sign in to comment.