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 9696cce commit 309c831
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 151 deletions.
71 changes: 46 additions & 25 deletions src/odr/document_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,22 @@ TableDimensions Sheet::content(std::optional<TableDimensions> range) const {
return exists_() ? m_element->content(m_document, range) : TableDimensions();
}

ElementRange Sheet::cell_elements(std::uint32_t column,
std::uint32_t row) const {
return exists_() ? ElementRange(ElementIterator(m_document,
m_element->first_cell_element(
m_document, column, row)))
: ElementRange();
SheetColumn Sheet::column(std::uint32_t column) const {
return exists_() ? SheetColumn(m_document, m_element, column,
m_element->column(m_document, column))
: SheetColumn();
}

SheetRow Sheet::row(std::uint32_t row) const {
return exists_() ? SheetRow(m_document, m_element, row,
m_element->row(m_document, row))
: SheetRow();
}

SheetCell Sheet::cell(std::uint32_t column, std::uint32_t row) const {
return exists_() ? SheetCell(m_document, m_element, column, row,
m_element->cell(m_document, column, row))
: SheetCell();
}

ElementRange Sheet::shapes() const {
Expand All @@ -196,39 +206,50 @@ ElementRange Sheet::shapes() const {
: ElementRange();
}

TableStyle Sheet::style() const {
return exists_() ? m_element->style(m_document) : TableStyle();
}
SheetColumn::SheetColumn(const internal::abstract::Document *document,
internal::abstract::Sheet *sheet, std::uint32_t column,
internal::abstract::SheetColumn *element)
: TypedElement(document, element), m_sheet{sheet}, m_column{column} {}

TableColumnStyle Sheet::column_style(std::uint32_t column) const {
return exists_() ? m_element->column_style(m_document, column)
: TableColumnStyle();
TableColumnStyle SheetColumn::style() const {
return m_element->style(m_document, m_sheet, m_column);
}

TableRowStyle Sheet::row_style(std::uint32_t row) const {
return exists_() ? m_element->row_style(m_document, row) : TableRowStyle();
}
SheetRow::SheetRow(const internal::abstract::Document *document,
internal::abstract::Sheet *sheet, std::uint32_t row,
internal::abstract::SheetRow *element)
: TypedElement(document, element), m_sheet{sheet}, m_row{row} {}

TableCellStyle Sheet::cell_style(std::uint32_t column,
std::uint32_t row) const {
return exists_() ? m_element->cell_style(m_document, column, row)
: TableCellStyle();
TableRowStyle SheetRow::style() const {
return m_element->style(m_document, m_sheet, m_row);
}

bool Sheet::is_covered(std::uint32_t column, std::uint32_t row) const {
return exists_() ? m_element->is_covered(m_document, column, row) : false;
SheetCell::SheetCell(const internal::abstract::Document *document,
internal::abstract::Sheet *sheet, std::uint32_t column,
std::uint32_t row, internal::abstract::SheetCell *element)
: TypedElement(document, element), m_sheet{sheet}, m_column{column},
m_row{row} {}

bool SheetCell::is_covered() const {
return exists_() ? m_element->is_covered(m_document, m_sheet, m_column, m_row)
: false;
}

TableDimensions Sheet::span(std::uint32_t column, std::uint32_t row) const {
return exists_() ? m_element->span(m_document, column, row)
TableDimensions SheetCell::span() const {
return exists_() ? m_element->span(m_document, m_sheet, m_column, m_row)
: TableDimensions();
}

ValueType Sheet::value_type(std::uint32_t column, std::uint32_t row) const {
return exists_() ? m_element->value_type(m_document, column, row)
ValueType SheetCell::value_type() const {
return exists_() ? m_element->value_type(m_document, m_sheet, m_column, m_row)
: ValueType::unknown;
}

TableCellStyle SheetCell::style() const {
return exists_() ? m_element->style(m_document, m_sheet, m_column, m_row)
: TableCellStyle();
}

std::string Page::name() const {
return exists_() ? m_element->name(m_document) : "";
}
Expand Down
72 changes: 57 additions & 15 deletions src/odr/document_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Element;
class TextRoot;
class Slide;
class Sheet;
class SheetColumn;
class SheetRow;
class SheetCell;
class Page;
class MasterPage;
class LineBreak;
Expand Down Expand Up @@ -53,6 +56,9 @@ class ElementRange;
class TextRoot;
class Slide;
class Sheet;
class SheetColumn;
class SheetRow;
class SheetCell;
class Page;
class MasterPage;
class LineBreak;
Expand Down Expand Up @@ -216,6 +222,8 @@ class ElementRange {
template <typename T> class TypedElement : public Element {
public:
TypedElement() = default;
TypedElement(const internal::abstract::Document *document, T *element)
: Element(document, element), m_element{element} {}
TypedElement(const internal::abstract::Document *document,
internal::abstract::Element *element)
: Element(document, element), m_element{dynamic_cast<T *>(element)} {}
Expand Down Expand Up @@ -261,21 +269,58 @@ class Sheet final : public TypedElement<internal::abstract::Sheet> {
[[nodiscard]] TableDimensions
content(std::optional<TableDimensions> range) const;

[[nodiscard]] ElementRange cell_elements(std::uint32_t column,
std::uint32_t row) const;
[[nodiscard]] SheetColumn column(std::uint32_t column) const;
[[nodiscard]] SheetRow row(std::uint32_t row) const;
[[nodiscard]] SheetCell cell(std::uint32_t column, std::uint32_t row) const;

[[nodiscard]] ElementRange shapes() const;
};

[[nodiscard]] TableStyle style() const;
[[nodiscard]] TableColumnStyle column_style(std::uint32_t column) const;
[[nodiscard]] TableRowStyle row_style(std::uint32_t row) const;
[[nodiscard]] TableCellStyle cell_style(std::uint32_t column,
std::uint32_t row) const;
class SheetColumn final : public TypedElement<internal::abstract::SheetColumn> {
public:
SheetColumn() = default;
SheetColumn(const internal::abstract::Document *document,
internal::abstract::Sheet *sheet, std::uint32_t column,
internal::abstract::SheetColumn *element);

[[nodiscard]] TableColumnStyle style() const;

private:
internal::abstract::Sheet *m_sheet{};
std::uint32_t m_column{};
};

class SheetRow final : public TypedElement<internal::abstract::SheetRow> {
public:
SheetRow() = default;
SheetRow(const internal::abstract::Document *document,
internal::abstract::Sheet *sheet, std::uint32_t row,
internal::abstract::SheetRow *element);

[[nodiscard]] TableRowStyle style() const;

[[nodiscard]] bool is_covered(std::uint32_t column, std::uint32_t row) const;
[[nodiscard]] TableDimensions span(std::uint32_t column,
std::uint32_t row) const;
[[nodiscard]] ValueType value_type(std::uint32_t column,
std::uint32_t row) const;
private:
internal::abstract::Sheet *m_sheet{};
std::uint32_t m_row{};
};

class SheetCell final : public TypedElement<internal::abstract::SheetCell> {
public:
SheetCell() = default;
SheetCell(const internal::abstract::Document *document,
internal::abstract::Sheet *sheet, std::uint32_t column,
std::uint32_t row, internal::abstract::SheetCell *element);

[[nodiscard]] bool is_covered() const;
[[nodiscard]] TableDimensions span() const;
[[nodiscard]] ValueType value_type() const;

[[nodiscard]] TableCellStyle style() const;

private:
internal::abstract::Sheet *m_sheet{};
std::uint32_t m_column{};
std::uint32_t m_row{};
};

class Page final : public TypedElement<internal::abstract::Page> {
Expand Down Expand Up @@ -379,9 +424,6 @@ class TableCell final : public TypedElement<internal::abstract::TableCell> {
public:
using TypedElement::TypedElement;

[[nodiscard]] TableColumn column() const;
[[nodiscard]] TableRow row() const;

[[nodiscard]] bool is_covered() const;
[[nodiscard]] TableDimensions span() const;
[[nodiscard]] ValueType value_type() const;
Expand Down
18 changes: 11 additions & 7 deletions src/odr/internal/html/document_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ void html::translate_sheet(Element element, std::ostream &out,

for (std::uint32_t column_index = 0; column_index < end_column;
++column_index) {
auto table_column_style = sheet.column_style(column_index);
auto table_column = sheet.column(column_index);
auto table_column_style = table_column.style();

out << "<col";
out << optional_style_attribute(
Expand All @@ -127,7 +128,8 @@ void html::translate_sheet(Element element, std::ostream &out,
}

for (std::uint32_t row_index = 0; row_index < end_row; ++row_index) {
auto table_row_style = sheet.row_style(row_index);
auto table_row = sheet.row(row_index);
auto table_row_style = table_row.style();

out << "<tr";
out << optional_style_attribute(translate_table_row_style(table_row_style));
Expand All @@ -144,16 +146,18 @@ void html::translate_sheet(Element element, std::ostream &out,

for (std::uint32_t column_index = 0; column_index < end_column;
++column_index) {
if (sheet.is_covered(column_index, row_index)) {
auto cell = sheet.cell(column_index, row_index);

if (cell.is_covered()) {
continue;
}

// TODO looks a bit odd to query the same (col, row) all the time. maybe
// there could be a struct to get all the info?
auto cell_style = sheet.cell_style(column_index, row_index);
auto cell_span = sheet.span(column_index, row_index);
auto cell_value_type = sheet.value_type(column_index, row_index);
auto cell_elements = sheet.cell_elements(column_index, row_index);
auto cell_style = cell.style();
auto cell_span = cell.span();
auto cell_value_type = cell.value_type();
auto cell_elements = cell.children();

out << "<td";
if (cell_span.rows > 1) {
Expand Down
26 changes: 2 additions & 24 deletions src/odr/internal/odf/odf_spreadsheet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ODR_INTERNAL_ODF_SPREADSHEET_H

#include <odr/internal/abstract/document.hpp>
#include <odr/internal/common/document_element.hpp>
#include <odr/internal/abstract/sheet_element.hpp>
#include <odr/internal/common/style.hpp>
#include <odr/internal/common/table_position.hpp>
#include <odr/internal/odf/odf_element.hpp>
Expand All @@ -24,7 +24,7 @@ class SpreadsheetRoot final : public Root {
using Root::Root;
};

class Sheet final : public Element, public common::Sheet {
class Sheet final : public Element, public abstract::Sheet {
public:
using Element::Element;

Expand All @@ -38,30 +38,8 @@ class Sheet final : public Element, public common::Sheet {
const std::optional<TableDimensions> range) const final;

[[nodiscard]] abstract::Element *
first_cell_element(const abstract::Document *, std::uint32_t column,
std::uint32_t row) const final;
[[nodiscard]] abstract::Element *
first_shape(const abstract::Document *) const final;

[[nodiscard]] TableStyle style(const abstract::Document *) const final;
[[nodiscard]] TableColumnStyle column_style(const abstract::Document *,
std::uint32_t column) const final;
[[nodiscard]] TableRowStyle row_style(const abstract::Document *,
std::uint32_t row) const final;
[[nodiscard]] TableCellStyle cell_style(const abstract::Document *,
std::uint32_t column,
std::uint32_t row) const final;

[[nodiscard]] bool is_covered(const abstract::Document *,
std::uint32_t column,
std::uint32_t row) const final;
[[nodiscard]] TableDimensions span(const abstract::Document *,
std::uint32_t column,
std::uint32_t row) const final;
[[nodiscard]] ValueType value_type(const abstract::Document *,
std::uint32_t column,
std::uint32_t row) const final;

void init_column_(std::uint32_t column, std::uint32_t repeated,
Element *element);
void init_row_(std::uint32_t row, std::uint32_t repeated, Element *element);
Expand Down
Loading

0 comments on commit 309c831

Please sign in to comment.