aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Template/TableTemplate.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-19 22:41:05 -0700
committerrtk0c <[email protected]>2021-06-19 22:41:05 -0700
commit4378dcd83d2387534f3b10276365d1003832fe81 (patch)
tree6bc055a1bd81d5a27c9066f05e28e5115f5de944 /core/src/Model/Template/TableTemplate.hpp
parenteec8dfd8a21b8bb37f6acac1da84cde8fbf7ace7 (diff)
Add cell type conversion mechanism
Diffstat (limited to 'core/src/Model/Template/TableTemplate.hpp')
-rw-r--r--core/src/Model/Template/TableTemplate.hpp39
1 files changed, 32 insertions, 7 deletions
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 <tsl/array_map.h>
#include <tsl/robin_map.h>
#include <string>
+#include <string_view>
#include <vector>
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<char, int> 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<ArrayGroupData> 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<char, int> mName2Parameters;
+ /// Map from array group name to the index of the array group (stored in mArrayGroups).
+ tsl::array_map<char, int> mName2ArrayGroups;
std::vector<TableCell> mCells;
std::vector<TableCellArrayGroup> mArrayGroups;
std::vector<int> 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;