LibreOffice Module sc (master) 1
subtotalparam.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <subtotalparam.hxx>
11
12#include <osl/diagnose.h>
13
15{
16 for ( sal_uInt16 i=0; i<MAXSUBTOTAL; i++ )
17 {
18 nSubTotals[i] = 0;
19 pSubTotals[i] = nullptr;
20 pFunctions[i] = nullptr;
21 }
22
23 Clear();
24}
25
27 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
28 bRemoveOnly(r.bRemoveOnly),bReplace(r.bReplace),bPagebreak(r.bPagebreak),bCaseSens(r.bCaseSens),
29 bDoSort(r.bDoSort),bAscending(r.bAscending),bUserDef(r.bUserDef),
30 bIncludePattern(r.bIncludePattern)
31{
32 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
33 {
35 nField[i] = r.nField[i];
36
37 if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
38 {
40 pSubTotals[i].reset(new SCCOL [r.nSubTotals[i]]);
41 pFunctions[i].reset(new ScSubTotalFunc [r.nSubTotals[i]]);
42
43 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
44 {
45 pSubTotals[i][j] = r.pSubTotals[i][j];
46 pFunctions[i][j] = r.pFunctions[i][j];
47 }
48 }
49 else
50 {
51 nSubTotals[i] = 0;
52 }
53 }
54}
55
57{
58 nCol1=nCol2= 0;
59 nRow1=nRow2 = 0;
60 nUserIndex = 0;
63
64 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
65 {
66 bGroupActive[i] = false;
67 nField[i] = 0;
68
69 if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
70 {
71 for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
72 pSubTotals[i][j] = 0;
74 }
75 }
76 }
77}
78
80{
81 if(this == &r)
82 return *this;
83
84 nCol1 = r.nCol1;
85 nRow1 = r.nRow1;
86 nCol2 = r.nCol2;
87 nRow2 = r.nRow2;
92 bDoSort = r.bDoSort;
97
98 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
99 {
101 nField[i] = r.nField[i];
102 nSubTotals[i] = r.nSubTotals[i];
103
104 pSubTotals[i].reset();
105 pFunctions[i].reset();
106
107 if ( r.nSubTotals[i] > 0 )
108 {
109 pSubTotals[i].reset(new SCCOL [r.nSubTotals[i]]);
110 pFunctions[i].reset(new ScSubTotalFunc [r.nSubTotals[i]]);
111
112 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
113 {
114 pSubTotals[i][j] = r.pSubTotals[i][j];
115 pFunctions[i][j] = r.pFunctions[i][j];
116 }
117 }
118 else
119 {
120 nSubTotals[i] = 0;
121 }
122 }
123
124 return *this;
125}
126
128{
129 bool bEqual = (nCol1 == rOther.nCol1)
130 && (nRow1 == rOther.nRow1)
131 && (nCol2 == rOther.nCol2)
132 && (nRow2 == rOther.nRow2)
133 && (nUserIndex == rOther.nUserIndex)
134 && (bRemoveOnly == rOther.bRemoveOnly)
135 && (bReplace == rOther.bReplace)
136 && (bPagebreak == rOther.bPagebreak)
137 && (bDoSort == rOther.bDoSort)
138 && (bCaseSens == rOther.bCaseSens)
139 && (bAscending == rOther.bAscending)
140 && (bUserDef == rOther.bUserDef)
141 && (bIncludePattern== rOther.bIncludePattern);
142
143 if ( bEqual )
144 {
145 bEqual = true;
146 for ( sal_uInt16 i=0; i<MAXSUBTOTAL && bEqual; i++ )
147 {
148 bEqual = (bGroupActive[i] == rOther.bGroupActive[i])
149 && (nField[i] == rOther.nField[i])
150 && (nSubTotals[i] == rOther.nSubTotals[i]);
151
152 if ( bEqual && (nSubTotals[i] > 0) )
153 {
154 for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
155 {
156 bEqual = bEqual
157 && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
158 && (pFunctions[i][j] == rOther.pFunctions[i][j]);
159 }
160 }
161 }
162 }
163
164 return bEqual;
165}
166
167void ScSubTotalParam::SetSubTotals( sal_uInt16 nGroup,
168 const SCCOL* ptrSubTotals,
169 const ScSubTotalFunc* ptrFunctions,
170 sal_uInt16 nCount )
171{
172 OSL_ENSURE( (nGroup <= MAXSUBTOTAL),
173 "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
174 OSL_ENSURE( ptrSubTotals,
175 "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
176 OSL_ENSURE( ptrFunctions,
177 "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
178 OSL_ENSURE( (nCount > 0),
179 "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
180
181 if ( !(ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL)) )
182 return;
183
184 // 0 is interpreted as 1, otherwise decrementing the array index
185 if (nGroup != 0)
186 nGroup--;
187
188 pSubTotals[nGroup].reset(new SCCOL[nCount]);
189 pFunctions[nGroup].reset(new ScSubTotalFunc[nCount]);
190 nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
191
192 for ( sal_uInt16 i=0; i<nCount; i++ )
193 {
194 pSubTotals[nGroup][i] = ptrSubTotals[i];
195 pFunctions[nGroup][i] = ptrFunctions[i];
196 }
197}
198
199/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int nCount
const SCSIZE MAXSUBTOTAL
Definition: global.hxx:82
ScSubTotalFunc
Definition: global.hxx:860
@ SUBTOTAL_FUNC_NONE
Definition: global.hxx:861
int i
bool bUserDef
sort user defined
bool bPagebreak
page break at change of group
bool operator==(const ScSubTotalParam &r) const
bool bAscending
sort ascending
bool bGroupActive[MAXSUBTOTAL]
active groups
sal_uInt16 nUserIndex
index into list
SCCOL nField[MAXSUBTOTAL]
associated field
SCCOL nSubTotals[MAXSUBTOTAL]
number of SubTotals
bool bDoSort
presort
std::unique_ptr< ScSubTotalFunc[]> pFunctions[MAXSUBTOTAL]
array of associated functions
std::unique_ptr< SCCOL[]> pSubTotals[MAXSUBTOTAL]
array of columns to be calculated
SCCOL nCol1
selected area
void SetSubTotals(sal_uInt16 nGroup, const SCCOL *ptrSubTotals, const ScSubTotalFunc *ptrFunctions, sal_uInt16 nCount)
ScSubTotalParam & operator=(const ScSubTotalParam &r)
bool bIncludePattern
sort formats
bool bReplace
replace existing results
sal_Int16 SCCOL
Definition: types.hxx:21