summaryrefslogtreecommitdiff
path: root/sc/inc
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-11-27 21:37:06 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-11-28 05:36:59 +0100
commit669c839a61e2742a9128aabba30e2b55be517d21 (patch)
treeafd244e9f88908f1e71eee0c938c642a013767d9 /sc/inc
parent2310b7c8541a66fc4cbd243ca550cdc42e271cb3 (diff)
Simplify ScSubTotalParam
Change-Id: I4c1840e377711ad065c3042bddacb2028481b88d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177433 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/inc')
-rw-r--r--sc/inc/global.hxx2
-rw-r--r--sc/inc/subtotalparam.hxx77
2 files changed, 52 insertions, 27 deletions
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index fd51ff15808b..e37b2dbaef58 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -860,7 +860,7 @@ enum ScQueryConnect
SC_OR
};
-enum ScSubTotalFunc
+enum ScSubTotalFunc : sal_Int16
{
SUBTOTAL_FUNC_NONE = 0,
SUBTOTAL_FUNC_AVE = 1,
diff --git a/sc/inc/subtotalparam.hxx b/sc/inc/subtotalparam.hxx
index 3b379edb167d..df9f5ef390e3 100644
--- a/sc/inc/subtotalparam.hxx
+++ b/sc/inc/subtotalparam.hxx
@@ -11,35 +11,60 @@
#include "global.hxx"
#include <memory>
+#include <span>
+
+namespace com::sun::star::sheet { struct SubTotalColumn; }
+namespace com::sun::star::uno { template <class E> class Sequence; }
struct SC_DLLPUBLIC ScSubTotalParam
{
- SCCOL nCol1; ///< selected area
- SCROW nRow1;
- SCCOL nCol2;
- SCROW nRow2;
- sal_uInt16 nUserIndex; ///< index into list
- bool bRemoveOnly:1;
- bool bReplace:1; ///< replace existing results
- bool bPagebreak:1; ///< page break at change of group
- bool bCaseSens:1;
- bool bDoSort:1; ///< presort
- bool bSummaryBelow:1; ///< Summary below or above (default: below)
- bool bAscending:1; ///< sort ascending
- bool bUserDef:1; ///< sort user defined
- bool bIncludePattern:1; ///< sort formats
- bool bGroupActive[MAXSUBTOTAL]; ///< active groups
- SCCOL nField[MAXSUBTOTAL]; ///< associated field
- SCCOL nSubTotals[MAXSUBTOTAL]; ///< number of SubTotals
- std::unique_ptr<SCCOL[]> pSubTotals[MAXSUBTOTAL]; ///< array of columns to be calculated
- std::unique_ptr<ScSubTotalFunc[]> pFunctions[MAXSUBTOTAL]; ///< array of associated functions
-
- ScSubTotalParam();
- ScSubTotalParam( const ScSubTotalParam& r );
-
- ScSubTotalParam& operator= ( const ScSubTotalParam& r );
- bool operator== ( const ScSubTotalParam& r ) const;
- void Clear();
+ SCCOL nCol1 = 0; ///< selected area
+ SCROW nRow1 = 0;
+ SCCOL nCol2 = 0;
+ SCROW nRow2 = 0;
+ sal_uInt16 nUserIndex = 0; ///< index into list
+ bool bRemoveOnly:1 = false;
+ bool bReplace:1 = true; ///< replace existing results
+ bool bPagebreak:1 = false; ///< page break at change of group
+ bool bCaseSens:1 = false;
+ bool bDoSort:1 = true; ///< presort
+ bool bSummaryBelow:1 = true; ///< Summary below or above (default: below)
+ bool bAscending:1 = true; ///< sort ascending
+ bool bUserDef:1 = false; ///< sort user defined
+ bool bIncludePattern:1 = false; ///< sort formats
+
+ struct SubtotalGroup
+ {
+ bool bActive = false; ///< active groups
+ SCCOL nField = 0; ///< associated field
+ SCCOL nSubTotals = 0; ///< number of SubTotals
+
+ using Pair = std::pair<SCCOL, ScSubTotalFunc>;
+ // array of columns to be calculated, and associated functions
+ std::unique_ptr<Pair[]> pSubTotals;
+
+ SubtotalGroup() = default;
+ SubtotalGroup(const SubtotalGroup& r);
+
+ SubtotalGroup& operator=(const SubtotalGroup& r);
+ bool operator==(const SubtotalGroup& r) const;
+
+ void AllocSubTotals(SCCOL n);
+ void SetSubtotals(const css::uno::Sequence<css::sheet::SubTotalColumn>& seq);
+
+ std::span<Pair> subtotals() { return std::span(pSubTotals.get(), nSubTotals); }
+ std::span<const Pair> subtotals() const { return std::span(pSubTotals.get(), nSubTotals); }
+ SCCOL& col(SCCOL n) { return subtotals()[n].first; }
+ SCCOL col(SCCOL n) const { return subtotals()[n].first; }
+ ScSubTotalFunc func(SCCOL n) const { return subtotals()[n].second; }
+ };
+ SubtotalGroup aGroups[MAXSUBTOTAL];
+
+ ScSubTotalParam() = default;
+ ScSubTotalParam(const ScSubTotalParam&) = default;
+
+ ScSubTotalParam& operator=(const ScSubTotalParam&) = default;
+ inline bool operator==(const ScSubTotalParam&) const = default;
void SetSubTotals( sal_uInt16 nGroup,
const SCCOL* ptrSubTotals,
const ScSubTotalFunc* ptrFunctions,