aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Template/TableTemplate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/Model/Template/TableTemplate.cpp')
-rw-r--r--core/src/Model/Template/TableTemplate.cpp63
1 files changed, 47 insertions, 16 deletions
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp
index 258bb37..0ad1cca 100644
--- a/core/src/Model/Template/TableTemplate.cpp
+++ b/core/src/Model/Template/TableTemplate.cpp
@@ -5,6 +5,7 @@
bool TableCell::IsDataHoldingCell() const
{
+ return IsPrimaryCell() || !IsMergedCell();
}
bool TableCell::IsPrimaryCell() const
@@ -58,12 +59,12 @@ const TableTemplate& TableInstanciationParameters::GetTable() const
int TableTemplate::GetTableWidth() const
{
- return mTableWidth;
+ return mColumnWidths.size();
}
int TableTemplate::GetTableHeight() const
{
- return mTableHeight;
+ return mRowHeights.size();
}
void TableTemplate::Resize(int newWidth, int newHeight)
@@ -73,10 +74,13 @@ void TableTemplate::Resize(int newWidth, int newHeight)
std::vector<TableCell> cells;
cells.reserve(newWidth * newHeight);
- int yEnd = std::min(mTableHeight, newHeight);
- int xEnd = std::min(mTableWidth, newWidth);
+ int tableWidth = GetTableWidth();
+ int tableHeight = GetTableHeight();
+
+ int yEnd = std::min(tableHeight, newHeight);
+ int xEnd = std::min(tableWidth, newWidth);
for (int y = 0; y < yEnd; ++y) {
- if (y >= mTableHeight) {
+ if (y >= tableHeight) {
for (int x = 0; x < xEnd; ++x) {
cells.push_back(TableCell{});
}
@@ -84,7 +88,7 @@ void TableTemplate::Resize(int newWidth, int newHeight)
}
for (int x = 0; x < xEnd; ++x) {
- if (x >= mTableWidth) {
+ if (x >= tableWidth) {
cells.push_back(TableCell{});
} else {
auto& cell = GetCell({ x, y });
@@ -96,9 +100,30 @@ void TableTemplate::Resize(int newWidth, int newHeight)
mCells = std::move(cells);
}
+int TableTemplate::GetRowHeight(int row) const
+{
+ return mRowHeights[row];
+}
+
+void TableTemplate::SetRowHeight(int row, int height)
+{
+ mRowHeights[row] = height;
+}
+
+int TableTemplate::GetColumnWidth(int column) const
+{
+ return mColumnWidths[column];
+}
+
+void TableTemplate::SetColumnWidth(int column, int width)
+{
+ mColumnWidths[column] = width;
+}
+
const TableCell& TableTemplate::GetCell(Vec2i pos) const
{
- return mCells[pos.y * mTableWidth + pos.x];
+ int tableWidth = GetTableWidth();
+ return mCells[pos.y * tableWidth + pos.x];
}
TableCell& TableTemplate::GetCell(Vec2i pos)
@@ -194,7 +219,7 @@ lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook
// Not enough space to fit in this array group, update (or insert) the appropriate amount of generated rows
int row = i;
int count = param.size();
- generatedRanges.insert(row, count);
+ generatedRanges.try_emplace(row, count);
}
auto GetOffset = [&](int y) -> int {
@@ -217,27 +242,33 @@ lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook
}
};
- // Write/instanciate all array groups
+ // Write/instantiate all array groups
for (size_t i = 0; i < mArrayGroups.size(); ++i) {
auto& groupInfo = mArrayGroups[i];
auto& groupParams = params.ArrayGroups[i];
int rowCellCount = groupInfo.GetCount();
- int row = groupInfo.Row + GetOffset(groupInfo.Row);
+ int rowCount = groupParams.size();
+ int baseRowIdx = groupInfo.Row + GetOffset(groupInfo.Row);
// For each row that would be generated
- for (auto& rowCells : groupParams) {
+ for (int rowIdx = 0; rowIdx < rowCount; ++rowIdx) {
+ auto& row = groupParams[rowIdx];
+
// For each cell in the row
- for (int i = 0; i < rowCellCount; ++i) {
- // TODO spport merged cells in array groups
- worksheet_write_string(worksheet, row + i, col, rowCells[i].c_str(), nullptr);
+ for (int rowCellIdx = 0; rowCellIdx < rowCellCount; ++rowCellIdx) {
+ // TODO support merged cells in array groups
+ worksheet_write_string(worksheet, baseRowIdx + rowIdx, rowCellIdx, row[rowCellIdx].c_str(), nullptr);
}
}
}
+ int tableWidth = GetTableWidth();
+ int tableHeight = GetTableHeight();
+
// Write all regular and singular parameter cells
- for (int y = 0; y < mTableHeight; ++y) {
- for (int x = 0; x < mTableWidth; ++x) {
+ for (int y = 0; y < tableHeight; ++y) {
+ for (int x = 0; x < tableWidth; ++x) {
auto& cell = GetCell({ x, y });
if (!cell.IsDataHoldingCell()) {