diff options
Diffstat (limited to 'core/src/Model/Template/TableTemplate.cpp')
-rw-r--r-- | core/src/Model/Template/TableTemplate.cpp | 114 |
1 files changed, 107 insertions, 7 deletions
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp index be61606..88980ae 100644 --- a/core/src/Model/Template/TableTemplate.cpp +++ b/core/src/Model/Template/TableTemplate.cpp @@ -34,26 +34,30 @@ int TableCellArrayGroup::GetCount() const return RightCell - LeftCell + 1; } -TableInstanciationParameters::TableInstanciationParameters(const TableTemplate& table) +Vec2i TableCellArrayGroup::FindCell(std::string_view name) +{ +} + +TableInstantiationParameters::TableInstantiationParameters(const TableTemplate& table) : mTable{ &table } { } -TableInstanciationParameters& TableInstanciationParameters::ResetTable(const TableTemplate& newTable) +TableInstantiationParameters& TableInstantiationParameters::ResetTable(const TableTemplate& newTable) { mTable = &newTable; return *this; } -TableInstanciationParameters TableInstanciationParameters::RebindTable(const TableTemplate& newTable) const +TableInstantiationParameters TableInstantiationParameters::RebindTable(const TableTemplate& newTable) const { - TableInstanciationParameters result(newTable); + TableInstantiationParameters result(newTable); result.SingularCells = this->SingularCells; result.ArrayGroups = this->ArrayGroups; return result; } -const TableTemplate& TableInstanciationParameters::GetTable() const +const TableTemplate& TableInstantiationParameters::GetTable() const { return *mTable; } @@ -142,6 +146,102 @@ TableCell& TableTemplate::GetCell(Vec2i pos) return const_cast<TableCell&>(const_cast<const TableTemplate*>(this)->GetCell(pos)); } +void TableTemplate::SetCellType(Vec2i pos, TableCell::CellType type) +{ + auto& cell = GetCell(pos); + if (cell.Type == type) { + return; + } + + switch (type) { + case TableCell::ConstantCell: { + // TODO + } break; + + case TableCell::SingularParametricCell: { + cell.Type = type; + } break; + + // Setting the cell to be a part of a group requires calling the overload that supplies the group + case TableCell::ArrayParametricCell: break; + } +} + +int TableTemplate::GetArrayGroupCount() const +{ + return mArrayGroups.size(); +} + +const TableCellArrayGroup& TableTemplate::GetArrayGroup(int id) const +{ + return mArrayGroups[id]; +} + +TableCellArrayGroup& TableTemplate::GetArrayGroup(int id) +{ + return mArrayGroups[id]; +} + +TableCellArrayGroup& TableTemplate::AddArrayGroup(int row, int left, int right) +{ + assert(row >= 0 && row < GetTableHeight()); + assert(left >= 0 && left < GetTableWidth()); + assert(right >= 0 && right < GetTableWidth()); + + // TODO check for overlap + + if (left > right) { + std::swap(left, right); + } + + mArrayGroups.push_back(TableCellArrayGroup{ + .Row = row, + .LeftCell = left, + .RightCell = right, + }); + return mArrayGroups.back(); +} + +bool TableTemplate::ExtendArrayGroupLeft(int id, int n) +{ + assert(n > 0); + + auto& ag = mArrayGroups[id]; + ag.LeftCell -= n; + + return false; +} + +bool TableTemplate::ExtendArrayGroupRight(int id, int n) +{ + assert(n > 0); + + auto& ag = mArrayGroups[id]; + ag.RightCell += n; + + return false; +} + +TableCell* TableTemplate::FindCell(std::string_view name) +{ + auto iter = mName2Parameters.find(name); + if (iter != mName2Parameters.end()) { + return &mCells[iter.value()]; + } else { + return nullptr; + } +} + +TableCellArrayGroup* TableTemplate::FindArrayGroup(std::string_view name) +{ + auto iter = mName2ArrayGroups.find(name); + if (iter != mName2ArrayGroups.end()) { + return &mArrayGroups[iter.value()]; + } else { + return nullptr; + } +} + TableTemplate::MergeCellsResult TableTemplate::MergeCells(Vec2i topLeft, Vec2i bottomRight) { auto SortTwo = [](int& a, int& b) { @@ -200,14 +300,14 @@ TableTemplate::BreakCellsResult TableTemplate::BreakCells(Vec2i topLeft) return BCR_Success; } -lxw_workbook* TableTemplate::InstantiateToExcelWorkbook(const TableInstanciationParameters& params) const +lxw_workbook* TableTemplate::InstantiateToExcelWorkbook(const TableInstantiationParameters& params) const { auto workbook = workbook_new("Table.xlsx"); InstantiateToExcelWorksheet(workbook, params); return workbook; } -lxw_worksheet* TableTemplate::InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const +lxw_worksheet* TableTemplate::InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstantiationParameters& params) const { auto worksheet = workbook_add_worksheet(workbook, "CpltExport.xlsx"); |