diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-12-30 18:08:56 +0600 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-12-30 14:43:38 +0100 |
commit | 7e5a345897e633083ce0194a34c4faac54d28371 (patch) | |
tree | 196c4ca2bd92c5ec6378c67f25b59589a533494e /sc/inc/table.hxx | |
parent | 020444ed98d7a31403787238cd753e112a6a56fb (diff) |
tdf#158254: generalize and use algorithm to apply with allocation
Commit 17bcf1073bf21088b9845e36fe735622d8f88fd7 (introduce ScColumnData
for ScColumn/ScTable code sharing, 2022-05-05) implemented an algorithm
to only allocate needed amount of columns, and/or apply to default data
when needed. It was done for ApplySelectionCache, ChangeSelectionIndent,
ClearSelectionItems. Yet, many other functions need the same approach.
This change introduces ScTable::ApplyWithAllocation template, which
allows to use this algorithm uniformly to any operation on a selection,
which ultimately applies to ScColumnData. The code in the functions
mentioned above is replaced with its use; and ApplySelectionStyle is
fixed using it.
Change-Id: Ic8890d9980fcb01b61bb111183b355c623f866a2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161441
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/inc/table.hxx')
-rw-r--r-- | sc/inc/table.hxx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 72e78b195986..8f749a273707 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -34,6 +34,7 @@ #include "drwlayer.hxx" #include "SparklineList.hxx" #include "SolverSettings.hxx" +#include "markdata.hxx" #include <algorithm> #include <atomic> @@ -1427,6 +1428,40 @@ private: SCROW mnUBound; }; + // Applies a function to the selected ranges; makes sure to only allocate + // as few columns as needed, and applies the rest to default column data. + // The function looks like + // ApplyDataFunc(ScColumnData& applyTo, SCROW nTop, SCROW nBottom) + template <typename ApplyDataFunc> + void ApplyWithAllocation(const ScMarkData&, ApplyDataFunc); }; +template <typename ApplyDataFunc> +void ScTable::ApplyWithAllocation(const ScMarkData& rMark, ApplyDataFunc apply) +{ + if (!rMark.GetTableSelect(nTab) || !(rMark.IsMultiMarked() || rMark.IsMarked())) + return; + SCCOL lastChangeCol; + if (rMark.GetArea().aEnd.Col() == GetDoc().MaxCol()) + { + // For the same unallocated columns until the end we can change just the default. + lastChangeCol = rMark.GetStartOfEqualColumns(GetDoc().MaxCol(), aCol.size()) - 1; + // Allocate needed different columns before changing the default. + if (lastChangeCol >= 0) + CreateColumnIfNotExists(lastChangeCol); + + aDefaultColData.Apply(rMark, GetDoc().MaxCol(), apply); + } + else // need to allocate all columns affected + { + lastChangeCol = rMark.GetArea().aEnd.Col(); + CreateColumnIfNotExists(lastChangeCol); + } + + // The loop should go not to lastChangeCol, but over all columns, to apply to already allocated + // in the "StartOfEqualColumns" range + for (SCCOL i = 0; i < aCol.size(); i++) + aCol[i].Apply(rMark, i, apply); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |