From 669c839a61e2742a9128aabba30e2b55be517d21 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 27 Nov 2024 21:37:06 +0500 Subject: Simplify ScSubTotalParam Change-Id: I4c1840e377711ad065c3042bddacb2028481b88d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177433 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sc/inc/subtotalparam.hxx | 77 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 26 deletions(-) (limited to 'sc/inc/subtotalparam.hxx') 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 +#include + +namespace com::sun::star::sheet { struct SubTotalColumn; } +namespace com::sun::star::uno { template 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 pSubTotals[MAXSUBTOTAL]; ///< array of columns to be calculated - std::unique_ptr 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; + // array of columns to be calculated, and associated functions + std::unique_ptr 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& seq); + + std::span subtotals() { return std::span(pSubTotals.get(), nSubTotals); } + std::span 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, -- cgit