From 4378dcd83d2387534f3b10276365d1003832fe81 Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 19 Jun 2021 22:41:05 -0700 Subject: Add cell type conversion mechanism --- core/src/Model/Template/TableTemplate.hpp | 39 +++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'core/src/Model/Template/TableTemplate.hpp') diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp index ed1a96f..754ebe1 100644 --- a/core/src/Model/Template/TableTemplate.hpp +++ b/core/src/Model/Template/TableTemplate.hpp @@ -5,8 +5,10 @@ #include "Utils/VectorHash.hpp" #include "cplt_fwd.hpp" +#include #include #include +#include #include class TableCell @@ -80,11 +82,13 @@ public: /// \endcode /// /// \see TableCell -/// \see TableInstanciationParameters +/// \see TableInstantiationParameters /// \see TableTemplate class TableCellArrayGroup { public: + /// Parameter name mapped to cell location (index from LeftCell). + tsl::array_map mName2Cell; int Row; /// Leftmost cell in this group int LeftCell; @@ -95,6 +99,9 @@ public: Vec2i GetLeftCell() const; Vec2i GetRightCell() const; int GetCount() const; + + /// Find the location of the cell within this array group that has the given name. + Vec2i FindCell(std::string_view name); }; // Forward declaration of libxlsxwriter structs @@ -103,7 +110,7 @@ struct lxw_worksheet; /// An object containing the necessary information to instanciate a table template. /// \see TableTemplate -class TableInstanciationParameters +class TableInstantiationParameters { private: const TableTemplate* mTable; @@ -116,10 +123,10 @@ public: std::vector ArrayGroups; public: - TableInstanciationParameters(const TableTemplate& table); + TableInstantiationParameters(const TableTemplate& table); - TableInstanciationParameters& ResetTable(const TableTemplate& newTable); - TableInstanciationParameters RebindTable(const TableTemplate& newTable) const; + TableInstantiationParameters& ResetTable(const TableTemplate& newTable); + TableInstantiationParameters RebindTable(const TableTemplate& newTable) const; const TableTemplate& GetTable() const; }; @@ -131,6 +138,10 @@ public: class TableTemplate : public Template { private: + /// Map from parameter name to index of the parameter cell (stored in mCells). + tsl::array_map mName2Parameters; + /// Map from array group name to the index of the array group (stored in mArrayGroups). + tsl::array_map mName2ArrayGroups; std::vector mCells; std::vector mArrayGroups; std::vector mRowHeights; @@ -151,6 +162,20 @@ public: const TableCell& GetCell(Vec2i pos) const; TableCell& GetCell(Vec2i pos); + void SetCellType(Vec2i pos, TableCell::CellType type); + + int GetArrayGroupCount() const; + const TableCellArrayGroup& GetArrayGroup(int id) const; + TableCellArrayGroup& GetArrayGroup(int id); + TableCellArrayGroup& AddArrayGroup(int row, int left, int right); + bool ExtendArrayGroupLeft(int id, int n); + bool ExtendArrayGroupRight(int id, int n); + + /// Find a singular parameter cell by its name. This does not include cells within an array group. + TableCell* FindCell(std::string_view name); + + /// Find an array group by its name. + TableCellArrayGroup* FindArrayGroup(std::string_view name); enum MergeCellsResult { @@ -166,8 +191,8 @@ public: }; BreakCellsResult BreakCells(Vec2i topLeft); - lxw_workbook* InstantiateToExcelWorkbook(const TableInstanciationParameters& params) const; - lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const; + lxw_workbook* InstantiateToExcelWorkbook(const TableInstantiationParameters& params) const; + lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstantiationParameters& params) const; virtual ReadResult ReadFrom(std::istream& stream) override; virtual void WriteTo(std::ostream& stream) const override; -- cgit v1.2.3-70-g09d2