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  {
39  nSubTotals[i] = r.nSubTotals[i];
40  pSubTotals[i] = new SCCOL [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  pSubTotals[i] = nullptr;
53  pFunctions[i] = nullptr;
54  }
55  }
56 }
57 
59 {
60  nCol1=nCol2= 0;
61  nRow1=nRow2 = 0;
62  nUserIndex = 0;
65 
66  for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
67  {
68  bGroupActive[i] = false;
69  nField[i] = 0;
70 
71  if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
72  {
73  for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
74  pSubTotals[i][j] = 0;
76  }
77  }
78  }
79 }
80 
82 {
83  if(this == &r)
84  return *this;
85 
86  nCol1 = r.nCol1;
87  nRow1 = r.nRow1;
88  nCol2 = r.nCol2;
89  nRow2 = r.nRow2;
91  bReplace = r.bReplace;
93  bCaseSens = r.bCaseSens;
94  bDoSort = r.bDoSort;
96  bUserDef = r.bUserDef;
99 
100  for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
101  {
103  nField[i] = r.nField[i];
104  nSubTotals[i] = r.nSubTotals[i];
105 
106  if ( pSubTotals[i] ) delete [] pSubTotals[i];
107  if ( pFunctions[i] ) delete [] pFunctions[i];
108 
109  if ( r.nSubTotals[i] > 0 )
110  {
111  pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
112  pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
113 
114  for (SCCOL j=0; j<r.nSubTotals[i]; j++)
115  {
116  pSubTotals[i][j] = r.pSubTotals[i][j];
117  pFunctions[i][j] = r.pFunctions[i][j];
118  }
119  }
120  else
121  {
122  nSubTotals[i] = 0;
123  pSubTotals[i] = nullptr;
124  pFunctions[i] = nullptr;
125  }
126  }
127 
128  return *this;
129 }
130 
131 bool ScSubTotalParam::operator==( const ScSubTotalParam& rOther ) const
132 {
133  bool bEqual = (nCol1 == rOther.nCol1)
134  && (nRow1 == rOther.nRow1)
135  && (nCol2 == rOther.nCol2)
136  && (nRow2 == rOther.nRow2)
137  && (nUserIndex == rOther.nUserIndex)
138  && (bRemoveOnly == rOther.bRemoveOnly)
139  && (bReplace == rOther.bReplace)
140  && (bPagebreak == rOther.bPagebreak)
141  && (bDoSort == rOther.bDoSort)
142  && (bCaseSens == rOther.bCaseSens)
143  && (bAscending == rOther.bAscending)
144  && (bUserDef == rOther.bUserDef)
145  && (bIncludePattern== rOther.bIncludePattern);
146 
147  if ( bEqual )
148  {
149  bEqual = true;
150  for ( sal_uInt16 i=0; i<MAXSUBTOTAL && bEqual; i++ )
151  {
152  bEqual = (bGroupActive[i] == rOther.bGroupActive[i])
153  && (nField[i] == rOther.nField[i])
154  && (nSubTotals[i] == rOther.nSubTotals[i]);
155 
156  if ( bEqual && (nSubTotals[i] > 0) )
157  {
158  for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
159  {
160  bEqual = bEqual
161  && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
162  && (pFunctions[i][j] == rOther.pFunctions[i][j]);
163  }
164  }
165  }
166  }
167 
168  return bEqual;
169 }
170 
171 void ScSubTotalParam::SetSubTotals( sal_uInt16 nGroup,
172  const SCCOL* ptrSubTotals,
173  const ScSubTotalFunc* ptrFunctions,
174  sal_uInt16 nCount )
175 {
176  OSL_ENSURE( (nGroup <= MAXSUBTOTAL),
177  "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
178  OSL_ENSURE( ptrSubTotals,
179  "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
180  OSL_ENSURE( ptrFunctions,
181  "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
182  OSL_ENSURE( (nCount > 0),
183  "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
184 
185  if ( !(ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL)) )
186  return;
187 
188  // 0 is interpreted as 1, otherwise decrementing the array index
189  if (nGroup != 0)
190  nGroup--;
191 
192  delete [] pSubTotals[nGroup];
193  delete [] pFunctions[nGroup];
194 
195  pSubTotals[nGroup] = new SCCOL [nCount];
196  pFunctions[nGroup] = new ScSubTotalFunc [nCount];
197  nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
198 
199  for ( sal_uInt16 i=0; i<nCount; i++ )
200  {
201  pSubTotals[nGroup][i] = ptrSubTotals[i];
202  pFunctions[nGroup][i] = ptrFunctions[i];
203  }
204 }
205 
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool bGroupActive[MAXSUBTOTAL]
active groups
SCCOL nField[MAXSUBTOTAL]
associated field
bool bUserDef
sort user defined
SCCOL nCol1
selected area
bool bDoSort
presort
bool bPagebreak
page break at change of group
ScSubTotalParam & operator=(const ScSubTotalParam &r)
sal_uInt16 nUserIndex
index into list
SCCOL * pSubTotals[MAXSUBTOTAL]
array of columns to be calculated
ScSubTotalFunc * pFunctions[MAXSUBTOTAL]
array of associated functions
SCCOL nSubTotals[MAXSUBTOTAL]
number of SubTotals
int i
sal_Int16 SCCOL
Definition: types.hxx:22
void SetSubTotals(sal_uInt16 nGroup, const SCCOL *ptrSubTotals, const ScSubTotalFunc *ptrFunctions, sal_uInt16 nCount)
bool bReplace
replace existing results
bool operator==(const ScSubTotalParam &r) const
bool bIncludePattern
sort formats
ScSubTotalFunc
Definition: global.hxx:845
bool bAscending
sort ascending
const SCSIZE MAXSUBTOTAL
Definition: global.hxx:79