Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "dptabdat.hxx"
30 : :
31 : : #include "global.hxx"
32 : : #include "dpcachetable.hxx"
33 : : #include "dptabres.hxx"
34 : : #include "document.hxx"
35 : : #include "dpobject.hxx"
36 : :
37 : : #include <stdio.h>
38 : : #include <rtl/math.hxx>
39 : : #include <tools/date.hxx>
40 : : #include <unotools/transliterationwrapper.hxx>
41 : : #include <unotools/collatorwrapper.hxx>
42 : :
43 : : #include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
44 : :
45 : : using namespace ::com::sun::star;
46 : : using ::com::sun::star::uno::Sequence;
47 : : using ::com::sun::star::uno::Any;
48 : : using ::std::vector;
49 : :
50 : : // ---------------------------------------------------------------------------
51 : :
52 : 140 : ScDPTableData::CalcInfo::CalcInfo() :
53 [ + - ][ + - ]: 140 : bRepeatIfEmpty(false)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
54 : : {
55 : 140 : }
56 : :
57 : : // ---------------------------------------------------------------------------
58 : :
59 : 137 : ScDPTableData::ScDPTableData(ScDocument* pDoc) :
60 : 137 : mpDoc(pDoc)
61 : : {
62 : 137 : nLastDateVal = nLastHier = nLastLevel = nLastRet = -1; // invalid
63 : :
64 : : //! reset before new calculation (in case the base date is changed)
65 : 137 : }
66 : :
67 : 137 : ScDPTableData::~ScDPTableData()
68 : : {
69 [ - + ]: 137 : }
70 : :
71 : 2256 : rtl::OUString ScDPTableData::GetFormattedString(long nDim, const ScDPItemData& rItem) const
72 : : {
73 : 2256 : const ScDPCache* pCache = GetCacheTable().getCache();
74 : 2256 : return pCache->GetFormattedString(nDim, rItem);
75 : : }
76 : :
77 : 0 : long ScDPTableData::GetDatePart( long nDateVal, long nHierarchy, long nLevel )
78 : : {
79 [ # # ][ # # ]: 0 : if ( nDateVal == nLastDateVal && nHierarchy == nLastHier && nLevel == nLastLevel )
[ # # ]
80 : 0 : return nLastRet;
81 : :
82 : 0 : Date aDate( 30,12,1899 ); //! get from source data (and cache here)
83 [ # # ]: 0 : aDate += nDateVal;
84 : :
85 : 0 : long nRet = 0;
86 [ # # # ]: 0 : switch (nHierarchy)
87 : : {
88 : : case SC_DAPI_HIERARCHY_QUARTER:
89 [ # # # # : 0 : switch (nLevel)
# ]
90 : : {
91 : 0 : case 0: nRet = aDate.GetYear(); break;
92 : 0 : case 1: nRet = (aDate.GetMonth()-1) / 3 + 1; break;
93 : 0 : case 2: nRet = aDate.GetMonth(); break;
94 : 0 : case 3: nRet = aDate.GetDay(); break;
95 : : default:
96 : : OSL_FAIL("GetDatePart: wrong level");
97 : : }
98 : 0 : break;
99 : : case SC_DAPI_HIERARCHY_WEEK:
100 [ # # # # ]: 0 : switch (nLevel)
101 : : {
102 : : //! use settings for different definitions
103 : 0 : case 0: nRet = aDate.GetYear(); break; //!...
104 [ # # ]: 0 : case 1: nRet = aDate.GetWeekOfYear(); break;
105 [ # # ]: 0 : case 2: nRet = (long)aDate.GetDayOfWeek(); break;
106 : : default:
107 : : OSL_FAIL("GetDatePart: wrong level");
108 : : }
109 : 0 : break;
110 : : default:
111 : : OSL_FAIL("GetDatePart: wrong hierarchy");
112 : : }
113 : :
114 : 0 : nLastDateVal = nDateVal;
115 : 0 : nLastHier = nHierarchy;
116 : 0 : nLastLevel = nLevel;
117 : 0 : nLastRet = nRet;
118 : :
119 : 0 : return nRet;
120 : : }
121 : :
122 : 0 : bool ScDPTableData::IsRepeatIfEmpty()
123 : : {
124 : 0 : return false;
125 : : }
126 : :
127 : 0 : sal_uLong ScDPTableData::GetNumberFormat(long)
128 : : {
129 : 0 : return 0; // default format
130 : : }
131 : :
132 : 226 : sal_Bool ScDPTableData::IsBaseForGroup(long) const
133 : : {
134 : 226 : return false; // always false
135 : : }
136 : :
137 : 226 : long ScDPTableData::GetGroupBase(long) const
138 : : {
139 : 226 : return -1; // always none
140 : : }
141 : :
142 : 516 : sal_Bool ScDPTableData::IsNumOrDateGroup(long) const
143 : : {
144 : 516 : return false; // always false
145 : : }
146 : :
147 : 0 : sal_Bool ScDPTableData::IsInGroup( const ScDPItemData&, long,
148 : : const ScDPItemData&, long ) const
149 : : {
150 : : OSL_FAIL("IsInGroup shouldn't be called for non-group data");
151 : 0 : return false;
152 : : }
153 : :
154 : 0 : sal_Bool ScDPTableData::HasCommonElement( const ScDPItemData&, long,
155 : : const ScDPItemData&, long ) const
156 : : {
157 : : OSL_FAIL("HasCommonElement shouldn't be called for non-group data");
158 : 0 : return false;
159 : : }
160 : 760 : void ScDPTableData::FillRowDataFromCacheTable(sal_Int32 nRow, const ScDPCacheTable& rCacheTable,
161 : : const CalcInfo& rInfo, CalcRowData& rData)
162 : : {
163 : : // column dimensions
164 : 760 : GetItemData(rCacheTable, nRow, rInfo.aColLevelDims, rData.aColData);
165 : :
166 : : // row dimensions
167 : 760 : GetItemData(rCacheTable, nRow, rInfo.aRowLevelDims, rData.aRowData);
168 : :
169 : : // page dimensions
170 : 760 : GetItemData(rCacheTable, nRow, rInfo.aPageDims, rData.aPageData);
171 : :
172 : 760 : long nCacheColumnCount = rCacheTable.getCache()->GetColumnCount();
173 : 760 : sal_Int32 n = rInfo.aDataSrcCols.size();
174 [ + + ]: 1570 : for (sal_Int32 i = 0; i < n; ++i)
175 : : {
176 : 810 : long nDim = rInfo.aDataSrcCols[i];
177 [ + - ]: 810 : rData.aValues.push_back( ScDPValueData() );
178 : : // #i111435# GetItemData needs dimension indexes including groups,
179 : : // so the index must be checked here (groups aren't useful as data fields).
180 [ + - ]: 810 : if ( nDim < nCacheColumnCount )
181 : : {
182 : 810 : ScDPValueData& rVal = rData.aValues.back();
183 : 810 : rCacheTable.getValue( rVal, static_cast<SCCOL>(nDim), static_cast<SCROW>(nRow), false);
184 : : }
185 : : }
186 : 760 : }
187 : :
188 : 760 : void ScDPTableData::ProcessRowData(CalcInfo& rInfo, CalcRowData& rData, bool bAutoShow)
189 : : {
190 [ + + ]: 760 : if (!bAutoShow)
191 : : {
192 [ + - ]: 750 : LateInitParams aColParams(rInfo.aColDims, rInfo.aColLevels, false);
193 [ + - ]: 750 : LateInitParams aRowParams(rInfo.aRowDims, rInfo.aRowLevels, true);
194 : : // root always init child
195 : 750 : aColParams.SetInitChild(true);
196 : 750 : aColParams.SetInitAllChildren( false);
197 : 750 : aRowParams.SetInitChild(true);
198 : 750 : aRowParams.SetInitAllChildren( false);
199 : :
200 [ + - ]: 750 : rInfo.pColRoot->LateInitFrom(aColParams, rData.aColData, 0, *rInfo.pInitState);
201 [ + - ][ + - ]: 750 : rInfo.pRowRoot->LateInitFrom(aRowParams, rData.aRowData, 0, *rInfo.pInitState);
[ + - ]
202 : : }
203 : :
204 [ + + ][ + - : 2199 : if ( ( !rInfo.pColRoot->GetChildDimension() || rInfo.pColRoot->GetChildDimension()->IsValidEntry(rData.aColData) ) &&
+ + + + ]
[ + + ]
205 : 1439 : ( !rInfo.pRowRoot->GetChildDimension() || rInfo.pRowRoot->GetChildDimension()->IsValidEntry(rData.aRowData) ) )
206 : : {
207 : : //! single process method with ColMembers, RowMembers and data !!!
208 [ + + ]: 745 : if (rInfo.pColRoot->GetChildDimension())
209 : : {
210 [ + - ]: 400 : vector<SCROW> aEmptyData;
211 [ + - ]: 400 : rInfo.pColRoot->GetChildDimension()->ProcessData(rData.aColData, NULL, aEmptyData, rData.aValues);
212 : : }
213 : :
214 : 745 : rInfo.pRowRoot->ProcessData(rData.aRowData, rInfo.pColRoot->GetChildDimension(),
215 : 745 : rData.aColData, rData.aValues);
216 : : }
217 : 760 : }
218 : :
219 : 122 : void ScDPTableData::CalcResultsFromCacheTable(const ScDPCacheTable& rCacheTable, CalcInfo& rInfo, bool bAutoShow)
220 : : {
221 : 122 : sal_Int32 nRowSize = rCacheTable.getRowSize();
222 [ + + ]: 781 : for (sal_Int32 nRow = 0; nRow < nRowSize; ++nRow)
223 : : {
224 [ + - ][ + + ]: 659 : if (!rCacheTable.isRowActive(nRow))
225 : 68 : continue;
226 : :
227 [ + - ]: 591 : CalcRowData aData;
228 [ + - ]: 591 : FillRowDataFromCacheTable(nRow, rCacheTable, rInfo, aData);
229 [ + - ]: 591 : ProcessRowData(rInfo, aData, bAutoShow);
230 : 591 : }
231 : 122 : }
232 : :
233 : 2280 : void ScDPTableData::GetItemData(const ScDPCacheTable& rCacheTable, sal_Int32 nRow,
234 : : const vector<long>& rDims, vector<SCROW>& rItemData)
235 : : {
236 : 2280 : sal_Int32 nDimSize = rDims.size();
237 [ + + ]: 3797 : for (sal_Int32 i = 0; i < nDimSize; ++i)
238 : : {
239 [ + - ]: 1517 : long nDim = rDims[i];
240 : :
241 [ + - ][ + + ]: 1517 : if (getIsDataLayoutDimension(nDim))
242 : : {
243 [ + - ]: 102 : rItemData.push_back( -1 );
244 : 102 : continue;
245 : : }
246 : :
247 [ + - ]: 1415 : nDim = GetSourceDim( nDim );
248 [ + - ][ + - ]: 1415 : if ( nDim >= rCacheTable.getCache()->GetColumnCount() )
[ - + ]
249 : 0 : continue;
250 : :
251 [ + - ][ + - ]: 1415 : SCROW nId= rCacheTable.getCache()->GetItemDataId( static_cast<SCCOL>(nDim), static_cast<SCROW>(nRow), IsRepeatIfEmpty());
[ + - ]
252 [ + - ]: 1517 : rItemData.push_back( nId );
253 : : }
254 : 2280 : }
255 : :
256 : : // -----------------------------------------------------------------------
257 : :
258 : 235 : long ScDPTableData::GetMembersCount( long nDim )
259 : : {
260 [ - + ]: 235 : if ( nDim > MAXCOL )
261 : 0 : return 0;
262 : 235 : return GetCacheTable().getFieldEntries( nDim ).size();
263 : : }
264 : :
265 : 0 : const ScDPItemData* ScDPTableData::GetMemberByIndex( long nDim, long nIndex )
266 : : {
267 [ # # ]: 0 : if ( nIndex >= GetMembersCount( nDim ) )
268 : 0 : return NULL;
269 : :
270 : 0 : const ::std::vector<SCROW>& nMembers = GetCacheTable().getFieldEntries( nDim );
271 : :
272 : 0 : return GetCacheTable().getCache()->GetItemDataById( (SCCOL) nDim, (SCROW)nMembers[nIndex] );
273 : : }
274 : :
275 : 10390 : const ScDPItemData* ScDPTableData::GetMemberById( long nDim, long nId)
276 : : {
277 : :
278 : 10390 : return GetCacheTable().getCache()->GetItemDataById(nDim, static_cast<SCROW>(nId));
279 : : }
280 : :
281 : 0 : SCROW ScDPTableData::GetIdOfItemData( long nDim, const ScDPItemData& rData )
282 : : {
283 : 0 : return GetCacheTable().getCache()->GetIdByItemData((SCCOL) nDim, rData );
284 : : }
285 : :
286 : 1215 : const std::vector< SCROW >& ScDPTableData::GetColumnEntries( long nColumn )
287 : : {
288 : 1215 : return GetCacheTable().getFieldEntries( nColumn );
289 : : }
290 : :
291 : 1048 : long ScDPTableData::GetSourceDim( long nDim )
292 : : {
293 : 1048 : return nDim;
294 : :
295 : : }
296 : :
297 : 1594 : long ScDPTableData::Compare( long nDim, long nDataId1, long nDataId2)
298 : : {
299 [ + + ]: 1594 : if ( getIsDataLayoutDimension(nDim) )
300 : 30 : return 0;
301 : :
302 : 1564 : long n1 = GetCacheTable().getOrder(nDim, nDataId1);
303 : 1564 : long n2 = GetCacheTable().getOrder(nDim, nDataId2);
304 [ + - ]: 1564 : if ( n1 > n2 )
305 : 1564 : return 1;
306 [ # # ]: 0 : else if ( n1 == n2 )
307 : 0 : return 0;
308 : : else
309 : 1594 : return -1;
310 [ + - ][ + - ]: 153 : }
311 : :
312 : : #if DEBUG_PIVOT_TABLE
313 : : void ScDPTableData::Dump() const
314 : : {
315 : : }
316 : : #endif
317 : :
318 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|