Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "pivottablebuffer.hxx"
21 :
22 : #include <set>
23 : #include <com/sun/star/container/XIndexAccess.hpp>
24 : #include <com/sun/star/container/XNameAccess.hpp>
25 : #include <com/sun/star/sheet/CellFlags.hpp>
26 : #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
27 : #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
28 : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
29 : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
30 : #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
31 : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
32 : #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
33 : #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
34 : #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
35 : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
36 : #include <com/sun/star/sheet/GeneralFunction.hpp>
37 : #include <com/sun/star/sheet/XDataPilotDataLayoutFieldSupplier.hpp>
38 : #include <com/sun/star/sheet/XDataPilotField.hpp>
39 : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
40 : #include <com/sun/star/sheet/XSheetOperation.hpp>
41 : #include "oox/helper/attributelist.hxx"
42 : #include "oox/helper/containerhelper.hxx"
43 : #include "oox/helper/propertyset.hxx"
44 : #include "oox/token/properties.hxx"
45 : #include "addressconverter.hxx"
46 : #include "biffinputstream.hxx"
47 :
48 : #include "dapiuno.hxx"
49 : #include "dpobject.hxx"
50 : #include "dpsave.hxx"
51 :
52 : namespace oox {
53 : namespace xls {
54 :
55 : // ============================================================================
56 :
57 : using namespace ::com::sun::star::container;
58 : using namespace ::com::sun::star::sheet;
59 : using namespace ::com::sun::star::table;
60 : using namespace ::com::sun::star::uno;
61 : using namespace com::sun::star;
62 :
63 :
64 : // ============================================================================
65 :
66 : namespace {
67 :
68 : const sal_Int32 OOX_PT_DATALAYOUTFIELD = -2; /// Placeholder index of data layout field.
69 :
70 : const sal_Int32 OOX_PT_PREVIOUS_ITEM = 0x001000FC; /// Calculation of data item result is based on previous item.
71 : const sal_Int32 OOX_PT_NEXT_ITEM = 0x001000FD; /// Calculation of data item result is based on next item.
72 :
73 : // ----------------------------------------------------------------------------
74 :
75 : const sal_uInt32 BIFF12_PTFIELD_DATAFIELD = 0x00000008;
76 : const sal_uInt32 BIFF12_PTFIELD_DEFAULT = 0x00000100;
77 : const sal_uInt32 BIFF12_PTFIELD_SUM = 0x00000200;
78 : const sal_uInt32 BIFF12_PTFIELD_COUNTA = 0x00000400;
79 : const sal_uInt32 BIFF12_PTFIELD_AVERAGE = 0x00000800;
80 : const sal_uInt32 BIFF12_PTFIELD_MAX = 0x00001000;
81 : const sal_uInt32 BIFF12_PTFIELD_MIN = 0x00002000;
82 : const sal_uInt32 BIFF12_PTFIELD_PRODUCT = 0x00004000;
83 : const sal_uInt32 BIFF12_PTFIELD_COUNT = 0x00008000;
84 : const sal_uInt32 BIFF12_PTFIELD_STDDEV = 0x00010000;
85 : const sal_uInt32 BIFF12_PTFIELD_STDDEVP = 0x00020000;
86 : const sal_uInt32 BIFF12_PTFIELD_VAR = 0x00040000;
87 : const sal_uInt32 BIFF12_PTFIELD_VARP = 0x00080000;
88 :
89 : const sal_uInt32 BIFF12_PTFIELD_SHOWALL = 0x00000020;
90 : const sal_uInt32 BIFF12_PTFIELD_OUTLINE = 0x00000040;
91 : const sal_uInt32 BIFF12_PTFIELD_INSERTBLANKROW = 0x00000080;
92 : const sal_uInt32 BIFF12_PTFIELD_SUBTOTALTOP = 0x00000100;
93 : const sal_uInt32 BIFF12_PTFIELD_INSERTPAGEBREAK = 0x00000800;
94 : const sal_uInt32 BIFF12_PTFIELD_AUTOSORT = 0x00001000;
95 : const sal_uInt32 BIFF12_PTFIELD_SORTASCENDING = 0x00002000;
96 : const sal_uInt32 BIFF12_PTFIELD_AUTOSHOW = 0x00004000;
97 : const sal_uInt32 BIFF12_PTFIELD_AUTOSHOWTOP = 0x00008000;
98 : const sal_uInt32 BIFF12_PTFIELD_MULTIPAGEITEMS = 0x00080000;
99 :
100 : const sal_uInt16 BIFF12_PTFITEM_HIDDEN = 0x0001;
101 : const sal_uInt16 BIFF12_PTFITEM_HIDEDETAILS = 0x0002;
102 :
103 : const sal_uInt8 BIFF12_PTPAGEFIELD_HASNAME = 0x01;
104 : const sal_uInt8 BIFF12_PTPAGEFIELD_HASOLAPCAPTION = 0x02;
105 : const sal_Int32 BIFF12_PTPAGEFIELD_MULTIITEMS = 0x001000FE;
106 :
107 : const sal_uInt16 BIFF12_PTFILTER_HASNAME = 0x0001;
108 : const sal_uInt16 BIFF12_PTFILTER_HASDESCRIPTION = 0x0002;
109 : const sal_uInt16 BIFF12_PTFILTER_HASSTRVALUE1 = 0x0004;
110 : const sal_uInt16 BIFF12_PTFILTER_HASSTRVALUE2 = 0x0008;
111 :
112 : const sal_uInt8 BIFF12_TOP10FILTER_TOP = 0x01;
113 : const sal_uInt8 BIFF12_TOP10FILTER_PERCENT = 0x02;
114 :
115 : const sal_uInt32 BIFF12_PTDEF_SHOWITEMS = 0x00000100;
116 : const sal_uInt32 BIFF12_PTDEF_DISABLEFIELDLIST = 0x00000400;
117 : const sal_uInt32 BIFF12_PTDEF_HIDECALCMEMBERS = 0x00001000;
118 : const sal_uInt32 BIFF12_PTDEF_WITHHIDDENTOTALS = 0x00002000;
119 : const sal_uInt32 BIFF12_PTDEF_HIDEDRILL = 0x00100000;
120 : const sal_uInt32 BIFF12_PTDEF_PRINTDRILL = 0x00200000;
121 : const sal_uInt32 BIFF12_PTDEF_HIDEHEADERS = 0x80000000;
122 :
123 : const sal_uInt32 BIFF12_PTDEF_SHOWEMPTYROW = 0x00000004;
124 : const sal_uInt32 BIFF12_PTDEF_SHOWEMPTYCOL = 0x00000008;
125 : const sal_uInt32 BIFF12_PTDEF_ENABLEDRILL = 0x00000020;
126 : const sal_uInt32 BIFF12_PTDEF_PRESERVEFORMATTING = 0x00000080;
127 : const sal_uInt32 BIFF12_PTDEF_USEAUTOFORMAT = 0x00000100;
128 : const sal_uInt32 BIFF12_PTDEF_SHOWERROR = 0x00000200;
129 : const sal_uInt32 BIFF12_PTDEF_SHOWMISSING = 0x00000400;
130 : const sal_uInt32 BIFF12_PTDEF_PAGEOVERTHENDOWN = 0x00000800;
131 : const sal_uInt32 BIFF12_PTDEF_SUBTOTALHIDDENITEMS = 0x00001000;
132 : const sal_uInt32 BIFF12_PTDEF_ROWGRANDTOTALS = 0x00002000;
133 : const sal_uInt32 BIFF12_PTDEF_COLGRANDTOTALS = 0x00004000;
134 : const sal_uInt32 BIFF12_PTDEF_FIELDPRINTTITLES = 0x00008000;
135 : const sal_uInt32 BIFF12_PTDEF_ITEMPRINTTITLES = 0x00020000;
136 : const sal_uInt32 BIFF12_PTDEF_MERGEITEM = 0x00040000;
137 : const sal_uInt32 BIFF12_PTDEF_HASDATACAPTION = 0x00080000;
138 : const sal_uInt32 BIFF12_PTDEF_HASGRANDTOTALCAPTION = 0x00100000;
139 : const sal_uInt32 BIFF12_PTDEF_HASPAGESTYLE = 0x00200000;
140 : const sal_uInt32 BIFF12_PTDEF_HASPIVOTTABLESTYLE = 0x00400000;
141 : const sal_uInt32 BIFF12_PTDEF_HASVACATEDSTYLE = 0x00800000;
142 : const sal_uInt32 BIFF12_PTDEF_APPLYNUMFMT = 0x01000000;
143 : const sal_uInt32 BIFF12_PTDEF_APPLYFONT = 0x02000000;
144 : const sal_uInt32 BIFF12_PTDEF_APPLYALIGNMENT = 0x04000000;
145 : const sal_uInt32 BIFF12_PTDEF_APPLYBORDER = 0x08000000;
146 : const sal_uInt32 BIFF12_PTDEF_APPLYFILL = 0x10000000;
147 : const sal_uInt32 BIFF12_PTDEF_APPLYPROTECTION = 0x20000000;
148 : const sal_uInt32 BIFF12_PTDEF_HASTAG = 0x40000000;
149 :
150 : const sal_uInt32 BIFF12_PTDEF_NOERRORCAPTION = 0x00000040;
151 : const sal_uInt32 BIFF12_PTDEF_NOMISSINGCAPTION = 0x00000080;
152 : const sal_uInt32 BIFF12_PTDEF_HASROWHEADERCAPTION = 0x00000400;
153 : const sal_uInt32 BIFF12_PTDEF_HASCOLHEADERCAPTION = 0x00000800;
154 : const sal_uInt32 BIFF12_PTDEF_FIELDLISTSORTASC = 0x00001000;
155 : const sal_uInt32 BIFF12_PTDEF_NOCUSTOMLISTSORT = 0x00004000;
156 :
157 : const sal_uInt8 BIFF12_PTDEF_ROWAXIS = 1;
158 : const sal_uInt8 BIFF12_PTDEF_COLAXIS = 2;
159 :
160 : // ----------------------------------------------------------------------------
161 :
162 : const sal_uInt16 BIFF_PT_NOSTRING = 0xFFFF;
163 :
164 : const sal_uInt16 BIFF_PTFIELD_DATAFIELD = 0x0008;
165 : const sal_uInt16 BIFF_PTFIELD_DEFAULT = 0x0001;
166 : const sal_uInt16 BIFF_PTFIELD_SUM = 0x0002;
167 : const sal_uInt16 BIFF_PTFIELD_COUNTA = 0x0004;
168 : const sal_uInt16 BIFF_PTFIELD_AVERAGE = 0x0008;
169 : const sal_uInt16 BIFF_PTFIELD_MAX = 0x0010;
170 : const sal_uInt16 BIFF_PTFIELD_MIN = 0x0020;
171 : const sal_uInt16 BIFF_PTFIELD_PRODUCT = 0x0040;
172 : const sal_uInt16 BIFF_PTFIELD_COUNT = 0x0080;
173 : const sal_uInt16 BIFF_PTFIELD_STDDEV = 0x0100;
174 : const sal_uInt16 BIFF_PTFIELD_STDDEVP = 0x0200;
175 : const sal_uInt16 BIFF_PTFIELD_VAR = 0x0400;
176 : const sal_uInt16 BIFF_PTFIELD_VARP = 0x0800;
177 :
178 : const sal_uInt32 BIFF_PTFIELD2_SHOWALL = 0x00000001;
179 : const sal_uInt32 BIFF_PTFIELD2_AUTOSORT = 0x00000200;
180 : const sal_uInt32 BIFF_PTFIELD2_SORTASCENDING = 0x00000400;
181 : const sal_uInt32 BIFF_PTFIELD2_AUTOSHOW = 0x00000800;
182 : const sal_uInt32 BIFF_PTFIELD2_AUTOSHOWTOP = 0x00001000;
183 : const sal_uInt32 BIFF_PTFIELD2_OUTLINE = 0x00200000;
184 : const sal_uInt32 BIFF_PTFIELD2_INSERTBLANKROW = 0x00400000;
185 : const sal_uInt32 BIFF_PTFIELD2_SUBTOTALTOP = 0x00800000;
186 :
187 : const sal_uInt16 BIFF_PTFITEM_HIDDEN = 0x0001;
188 : const sal_uInt16 BIFF_PTFITEM_HIDEDETAILS = 0x0002;
189 :
190 : const sal_uInt16 BIFF_PTDEF_ROWGRANDTOTALS = 0x0001;
191 : const sal_uInt16 BIFF_PTDEF_COLGRANDTOTALS = 0x0002;
192 :
193 : const sal_uInt8 BIFF_PTDEF_ROWAXIS = 1;
194 : const sal_uInt8 BIFF_PTDEF_COLAXIS = 2;
195 :
196 : const sal_uInt32 BIFF_PTDEF2_PAGEOVERTHENDOWN = 0x00000001;
197 : const sal_uInt32 BIFF_PTDE2F_ENABLEDRILL = 0x00020000;
198 : const sal_uInt32 BIFF_PTDEF2_PRESERVEFORMATTING = 0x00080000;
199 : const sal_uInt32 BIFF_PTDEF2_MERGEITEM = 0x00100000;
200 : const sal_uInt32 BIFF_PTDEF2_SHOWERROR = 0x00200000;
201 : const sal_uInt32 BIFF_PTDEF2_SHOWMISSING = 0x00400000;
202 : const sal_uInt32 BIFF_PTDEF2_SUBTOTALHIDDENITEMS = 0x00800000;
203 :
204 : const sal_Int16 BIFF_PTPAGEFIELDS_ALLITEMS = 0x7FFD;
205 :
206 : const sal_Int16 BIFF_PTDATAFIELD_PREVIOUS = 0x7FFB;
207 : const sal_Int16 BIFF_PTDATAFIELD_NEXT = 0x7FFC;
208 :
209 : } // namespace
210 :
211 : // ============================================================================
212 :
213 0 : PTFieldItemModel::PTFieldItemModel() :
214 : mnCacheItem( -1 ),
215 : mnType( XML_data ),
216 : mbShowDetails( true ),
217 0 : mbHidden( false )
218 : {
219 0 : }
220 :
221 0 : void PTFieldItemModel::setBiffType( sal_uInt16 nType )
222 : {
223 : static const sal_Int32 spnTypes[] = { XML_data, XML_default,
224 : XML_sum, XML_countA, XML_avg, XML_max, XML_min, XML_product, XML_count,
225 : XML_stdDev, XML_stdDevP, XML_var, XML_varP, XML_grand, XML_blank };
226 0 : mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_data );
227 0 : }
228 :
229 : // ----------------------------------------------------------------------------
230 :
231 0 : PTFieldModel::PTFieldModel() :
232 : mnAxis( XML_TOKEN_INVALID ),
233 : mnNumFmtId( 0 ),
234 : mnAutoShowItems( 10 ),
235 : mnAutoShowRankBy( -1 ),
236 : mnSortType( XML_manual ),
237 : mnSortRefField( -1 ),
238 : mnSortRefItem( -1 ),
239 : mbDataField( false ),
240 : mbDefaultSubtotal( true ),
241 : mbSumSubtotal( false ),
242 : mbCountASubtotal( false ),
243 : mbAverageSubtotal( false ),
244 : mbMaxSubtotal( false ),
245 : mbMinSubtotal( false ),
246 : mbProductSubtotal( false ),
247 : mbCountSubtotal( false ),
248 : mbStdDevSubtotal( false ),
249 : mbStdDevPSubtotal( false ),
250 : mbVarSubtotal( false ),
251 : mbVarPSubtotal( false ),
252 : mbShowAll( true ),
253 : mbOutline( true ),
254 : mbSubtotalTop( true ),
255 : mbInsertBlankRow( false ),
256 : mbInsertPageBreak( false ),
257 : mbAutoShow( false ),
258 : mbTopAutoShow( true ),
259 0 : mbMultiPageItems( false )
260 : {
261 0 : }
262 :
263 0 : void PTFieldModel::setBiffAxis( sal_uInt8 nAxis )
264 : {
265 : /* Weird. The axis field is organized as bit field, but only one of the
266 : row/col/page flags are allowed at the same time and refer to the values
267 : 'axisRow', 'axisCol', and 'axisPage' of the XML attribute
268 : 'pivotField@axis'. Additionally, the fourth bit determines if the field
269 : is a data field, which may appear combined with the row/col/page flags.
270 : Therefore, this bit is unrelated to the 'axisValues' value of the
271 : 'pivotField@axis' attribute, but refers to the 'pivotField@dataField'
272 : boolean attribute. */
273 : static const sal_Int32 spnAxisIds[] = { XML_TOKEN_INVALID, XML_axisRow, XML_axisCol, XML_TOKEN_INVALID, XML_axisPage };
274 0 : mnAxis = STATIC_ARRAY_SELECT( spnAxisIds, nAxis, XML_TOKEN_INVALID );
275 0 : }
276 :
277 : // ----------------------------------------------------------------------------
278 :
279 0 : PTPageFieldModel::PTPageFieldModel() :
280 : mnField( -1 ),
281 0 : mnItem( BIFF12_PTPAGEFIELD_MULTIITEMS )
282 : {
283 0 : }
284 :
285 : // ----------------------------------------------------------------------------
286 :
287 0 : PTDataFieldModel::PTDataFieldModel() :
288 : mnField( -1 ),
289 : mnSubtotal( XML_sum ),
290 : mnShowDataAs( XML_normal ),
291 : mnBaseField( -1 ),
292 : mnBaseItem( -1 ),
293 0 : mnNumFmtId( 0 )
294 : {
295 0 : }
296 :
297 0 : void PTDataFieldModel::setBiffSubtotal( sal_Int32 nSubtotal )
298 : {
299 : static sal_Int32 spnSubtotals[] = { XML_sum, XML_count, XML_average, XML_max, XML_min, XML_product, XML_countNums, XML_stdDev, XML_stdDevp, XML_var, XML_varp };
300 0 : mnSubtotal = STATIC_ARRAY_SELECT( spnSubtotals, nSubtotal, XML_TOKEN_INVALID );
301 0 : }
302 :
303 0 : void PTDataFieldModel::setBiffShowDataAs( sal_Int32 nShowDataAs )
304 : {
305 : static sal_Int32 spnShowDataAs[] = { XML_normal, XML_difference, XML_percent, XML_percentDiff, XML_runTotal, XML_percentOfRow, XML_percentOfCol, XML_percentOfTotal, XML_index };
306 0 : mnShowDataAs = STATIC_ARRAY_SELECT( spnShowDataAs, nShowDataAs, XML_TOKEN_INVALID );
307 0 : }
308 :
309 : // ----------------------------------------------------------------------------
310 :
311 0 : PivotTableField::PivotTableField( PivotTable& rPivotTable, sal_Int32 nFieldIndex ) :
312 : WorkbookHelper( rPivotTable ),
313 : mrPivotTable( rPivotTable ),
314 0 : mnFieldIndex( nFieldIndex )
315 : {
316 0 : }
317 :
318 0 : void PivotTableField::importPivotField( const AttributeList& rAttribs )
319 : {
320 : /* The documentation mentions a value 'axisValues' for the attribute
321 : 'pivotField@axis'. But this value is not used to mark a data field, as
322 : data fields may be inserted in one of the row/column/page dimensions at
323 : the same time. Therefore, the boolean attribute 'pivotField@dataField'
324 : is really used to mark data fields. */
325 0 : maModel.mnAxis = rAttribs.getToken( XML_axis, XML_TOKEN_INVALID );
326 0 : maModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, 0 );
327 0 : maModel.mnAutoShowItems = rAttribs.getInteger( XML_itemPageCount, 10 );
328 0 : maModel.mnAutoShowRankBy = rAttribs.getInteger( XML_rankBy, -1 );
329 0 : maModel.mnSortType = rAttribs.getToken( XML_sortType, XML_manual );
330 0 : maModel.mbDataField = rAttribs.getBool( XML_dataField, false );
331 0 : maModel.mbDefaultSubtotal = rAttribs.getBool( XML_defaultSubtotal, true );
332 0 : maModel.mbSumSubtotal = rAttribs.getBool( XML_sumSubtotal, false );
333 0 : maModel.mbCountASubtotal = rAttribs.getBool( XML_countASubtotal, false );
334 0 : maModel.mbAverageSubtotal = rAttribs.getBool( XML_avgSubtotal, false );
335 0 : maModel.mbMaxSubtotal = rAttribs.getBool( XML_maxSubtotal, false );
336 0 : maModel.mbMinSubtotal = rAttribs.getBool( XML_minSubtotal, false );
337 0 : maModel.mbProductSubtotal = rAttribs.getBool( XML_productSubtotal, false );
338 0 : maModel.mbCountSubtotal = rAttribs.getBool( XML_countSubtotal, false );
339 0 : maModel.mbStdDevSubtotal = rAttribs.getBool( XML_stdDevSubtotal, false );
340 0 : maModel.mbStdDevPSubtotal = rAttribs.getBool( XML_stdDevPSubtotal, false );
341 0 : maModel.mbVarSubtotal = rAttribs.getBool( XML_varSubtotal, false );
342 0 : maModel.mbVarPSubtotal = rAttribs.getBool( XML_varPSubtotal, false );
343 0 : maModel.mbShowAll = rAttribs.getBool( XML_showAll, true );
344 0 : maModel.mbOutline = rAttribs.getBool( XML_outline, true );
345 0 : maModel.mbSubtotalTop = rAttribs.getBool( XML_subtotalTop, true );
346 0 : maModel.mbInsertBlankRow = rAttribs.getBool( XML_insertBlankRow, false );
347 0 : maModel.mbInsertPageBreak = rAttribs.getBool( XML_insertPageBreak, false );
348 0 : maModel.mbAutoShow = rAttribs.getBool( XML_autoShow, false );
349 0 : maModel.mbTopAutoShow = rAttribs.getBool( XML_topAutoShow, true );
350 0 : maModel.mbMultiPageItems = rAttribs.getBool( XML_multipleItemSelectionAllowed, false );
351 0 : }
352 :
353 0 : void PivotTableField::importItem( const AttributeList& rAttribs )
354 : {
355 0 : PTFieldItemModel aModel;
356 0 : aModel.mnCacheItem = rAttribs.getInteger( XML_x, -1 );
357 0 : aModel.mnType = rAttribs.getToken( XML_t, XML_data );
358 0 : aModel.mbShowDetails = rAttribs.getBool( XML_sd, true );
359 0 : aModel.mbHidden = rAttribs.getBool( XML_h, false );
360 0 : aModel.msCaption = rAttribs.getXString( XML_n, OUString() );
361 0 : maItems.push_back( aModel );
362 0 : }
363 :
364 0 : void PivotTableField::importReference( const AttributeList& rAttribs )
365 : {
366 : // field index is stored as unsigned integer
367 0 : maModel.mnSortRefField = static_cast< sal_Int32 >( rAttribs.getUnsigned( XML_field, SAL_MAX_UINT32 ) );
368 0 : }
369 :
370 0 : void PivotTableField::importReferenceItem( const AttributeList& rAttribs )
371 : {
372 0 : maModel.mnSortRefItem = rAttribs.getInteger( XML_v, -1 );
373 0 : }
374 :
375 0 : void PivotTableField::importPTField( SequenceInputStream& rStrm )
376 : {
377 : sal_uInt32 nFlags1, nFlags2;
378 0 : rStrm >> nFlags1 >> maModel.mnNumFmtId >> nFlags2 >> maModel.mnAutoShowItems >> maModel.mnAutoShowRankBy;
379 :
380 0 : maModel.setBiffAxis( extractValue< sal_uInt8 >( nFlags1, 0, 3 ) );
381 0 : maModel.mbDataField = getFlag( nFlags1, BIFF12_PTFIELD_DATAFIELD );
382 0 : maModel.mbDefaultSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_DEFAULT );
383 0 : maModel.mbSumSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_SUM );
384 0 : maModel.mbCountASubtotal = getFlag( nFlags1, BIFF12_PTFIELD_COUNTA );
385 0 : maModel.mbAverageSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_AVERAGE );
386 0 : maModel.mbMaxSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_MAX );
387 0 : maModel.mbMinSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_MIN );
388 0 : maModel.mbProductSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_PRODUCT );
389 0 : maModel.mbCountSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_COUNT );
390 0 : maModel.mbStdDevSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_STDDEV );
391 0 : maModel.mbStdDevPSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_STDDEVP );
392 0 : maModel.mbVarSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_VAR );
393 0 : maModel.mbVarPSubtotal = getFlag( nFlags1, BIFF12_PTFIELD_VARP );
394 :
395 0 : maModel.mbShowAll = getFlag( nFlags2, BIFF12_PTFIELD_SHOWALL );
396 0 : maModel.mbOutline = getFlag( nFlags2, BIFF12_PTFIELD_OUTLINE );
397 0 : maModel.mbSubtotalTop = getFlag( nFlags2, BIFF12_PTFIELD_SUBTOTALTOP );
398 0 : maModel.mbInsertBlankRow = getFlag( nFlags2, BIFF12_PTFIELD_INSERTBLANKROW );
399 0 : maModel.mbInsertPageBreak = getFlag( nFlags2, BIFF12_PTFIELD_INSERTPAGEBREAK );
400 0 : maModel.mbAutoShow = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSHOW );
401 0 : maModel.mbTopAutoShow = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSHOWTOP );
402 0 : maModel.mbMultiPageItems = getFlag( nFlags2, BIFF12_PTFIELD_MULTIPAGEITEMS );
403 :
404 0 : bool bAutoSort = getFlag( nFlags2, BIFF12_PTFIELD_AUTOSORT );
405 0 : bool bAscending = getFlag( nFlags2, BIFF12_PTFIELD_SORTASCENDING );
406 0 : maModel.mnSortType = bAutoSort ? (bAscending ? XML_ascending : XML_descending) : XML_manual;
407 0 : }
408 :
409 0 : void PivotTableField::importPTFItem( SequenceInputStream& rStrm )
410 : {
411 0 : PTFieldItemModel aModel;
412 : sal_uInt8 nType;
413 : sal_uInt16 nFlags;
414 0 : rStrm >> nType >> nFlags >> aModel.mnCacheItem;
415 :
416 0 : aModel.setBiffType( nType );
417 0 : aModel.mbShowDetails = !getFlag( nFlags, BIFF12_PTFITEM_HIDEDETAILS );
418 0 : aModel.mbHidden = getFlag( nFlags, BIFF12_PTFITEM_HIDDEN );
419 :
420 0 : maItems.push_back( aModel );
421 0 : }
422 :
423 0 : void PivotTableField::importPTReference( SequenceInputStream& rStrm )
424 : {
425 0 : rStrm >> maModel.mnSortRefField;
426 0 : }
427 :
428 0 : void PivotTableField::importPTReferenceItem( SequenceInputStream& rStrm )
429 : {
430 0 : rStrm >> maModel.mnSortRefItem;
431 0 : }
432 :
433 0 : void PivotTableField::finalizeImport( const Reference< XDataPilotDescriptor >& rxDPDesc )
434 : {
435 : /* Process all fields based on source data, other fields (e.g. group
436 : fields) are processed from here. PivotCacahe::getDatabaseIndex()
437 : returns -1 for all fields not based on source data. */
438 0 : Reference< XDataPilotField > xDPField;
439 0 : sal_Int32 nDatabaseIdx = mrPivotTable.getCacheDatabaseIndex( mnFieldIndex );
440 0 : if( (nDatabaseIdx >= 0) && rxDPDesc.is() ) try
441 : {
442 : // try to get the source field and its name from passed DataPilot descriptor
443 0 : Reference< XIndexAccess > xDPFieldsIA( rxDPDesc->getDataPilotFields(), UNO_SET_THROW );
444 0 : xDPField.set( xDPFieldsIA->getByIndex( nDatabaseIdx ), UNO_QUERY_THROW );
445 0 : Reference< XNamed > xDPFieldName( xDPField, UNO_QUERY_THROW );
446 0 : maDPFieldName = xDPFieldName->getName();
447 : OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeImport - no field name in source data found" );
448 :
449 : // try to convert grouping settings
450 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
451 : {
452 : // numeric grouping is done inplace, no nested group fields will appear
453 0 : if( pCacheField->hasNumericGrouping() )
454 : {
455 0 : pCacheField->convertNumericGrouping( xDPField );
456 : }
457 0 : else if( pCacheField->hasDateGrouping() )
458 : {
459 : // first date group settings are inplace
460 0 : pCacheField->createDateGroupField( xDPField );
461 : // create all nested group fields (if any)
462 0 : mrPivotTable.finalizeDateGroupingImport( xDPField, mnFieldIndex );
463 : }
464 0 : else if( pCacheField->hasParentGrouping() )
465 : {
466 :
467 : // create a list of all item names, needed to map between original and group items
468 0 : ::std::vector< OUString > aItems;
469 0 : pCacheField->getCacheItemNames( aItems );
470 0 : PivotCacheGroupItemVector aItemNames;
471 0 : for( ::std::vector< OUString >::iterator aIt = aItems.begin(), aEnd = aItems.end(); aIt != aEnd; ++aIt )
472 0 : aItemNames.push_back( PivotCacheGroupItem( *aIt ) );
473 : // create all nested group fields (if any)
474 0 : mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, aItemNames );
475 : }
476 0 : }
477 : }
478 0 : catch( Exception& )
479 : {
480 0 : }
481 0 : }
482 :
483 0 : void PivotTableField::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx )
484 : {
485 0 : if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken
486 : {
487 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
488 : {
489 0 : if( !pCacheField->isDatabaseField() && pCacheField->hasDateGrouping() && (pCacheField->getGroupBaseField() == nBaseFieldIdx) )
490 : {
491 0 : maDPFieldName = pCacheField->createDateGroupField( rxBaseDPField );
492 : OSL_ENSURE( !maDPFieldName.isEmpty(), "PivotTableField::finalizeDateGroupingImport - cannot create date group field" );
493 : }
494 : }
495 : }
496 0 : }
497 :
498 0 : void PivotTableField::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
499 : {
500 0 : if( maDPFieldName.isEmpty() ) // prevent endless loops if file format is broken
501 : {
502 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
503 : {
504 : // data field can have user defined groupname captions, apply them
505 : // if they do
506 0 : IdCaptionPairList captionList;
507 0 : for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
508 : {
509 0 : if ( aIt->mnType == XML_data && aIt->msCaption.getLength() )
510 0 : captionList.push_back( IdCaptionPair( aIt->mnCacheItem, aIt->msCaption ) );
511 : }
512 : // #FIXME find another way out of this const nightmare prison
513 0 : if ( !captionList.empty() )
514 0 : const_cast<PivotCacheField*>( pCacheField )->applyItemCaptions( captionList );
515 0 : maDPFieldName = pCacheField->createParentGroupField( rxBaseDPField, rBaseCacheField, orItemNames );
516 : // on success, try to create nested group fields
517 0 : Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
518 0 : if( xDPField.is() )
519 0 : mrPivotTable.finalizeParentGroupingImport( xDPField, *pCacheField, orItemNames );
520 : }
521 : }
522 0 : }
523 :
524 0 : void PivotTableField::convertRowField()
525 : {
526 0 : convertRowColPageField( XML_axisRow );
527 0 : }
528 :
529 0 : void PivotTableField::convertColField()
530 : {
531 0 : convertRowColPageField( XML_axisCol );
532 0 : }
533 :
534 0 : void PivotTableField::convertHiddenField()
535 : {
536 0 : convertRowColPageField( XML_TOKEN_INVALID );
537 0 : }
538 :
539 0 : void PivotTableField::convertPageField( const PTPageFieldModel& rPageField )
540 : {
541 : OSL_ENSURE( rPageField.mnField == mnFieldIndex, "PivotTableField::convertPageField - wrong field index" );
542 : // convert all settings common for row/column/page fields
543 0 : Reference< XDataPilotField > xDPField = convertRowColPageField( XML_axisPage );
544 :
545 0 : if( xDPField.is() )
546 : {
547 0 : PropertySet aPropSet( xDPField );
548 : using namespace ::com::sun::star::sheet;
549 :
550 : // find cache item used as 'selected page'
551 0 : sal_Int32 nCacheItem = -1;
552 0 : if( maModel.mbMultiPageItems )
553 : {
554 : // multiple items may be selected
555 : OSL_ENSURE( rPageField.mnItem == BIFF12_PTPAGEFIELD_MULTIITEMS, "PivotTableField::convertPageField - unexpected cache item index" );
556 : // try to find a single visible item
557 0 : bool bHasMultiItems = false;
558 0 : for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); (aIt != aEnd) && !bHasMultiItems; ++aIt )
559 : {
560 0 : if( (aIt->mnType == XML_data) && !aIt->mbHidden )
561 : {
562 0 : bHasMultiItems = nCacheItem >= 0;
563 0 : nCacheItem = bHasMultiItems ? -1 : aIt->mnCacheItem;
564 : }
565 : }
566 : }
567 : else
568 : {
569 : // single item may be selected
570 0 : if( (0 <= rPageField.mnItem) && (rPageField.mnItem < static_cast< sal_Int32 >( maItems.size() )) )
571 0 : nCacheItem = maItems[ rPageField.mnItem ].mnCacheItem;
572 : }
573 :
574 0 : if( nCacheItem >= 0 )
575 : {
576 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( mnFieldIndex ) )
577 : {
578 0 : if( const PivotCacheItem* pSharedItem = pCacheField->getCacheItem( nCacheItem ) )
579 : {
580 0 : OUString aSelectedPage = pSharedItem->getName();
581 0 : aPropSet.setProperty( PROP_SelectedPage, aSelectedPage );
582 : }
583 : }
584 0 : }
585 0 : }
586 0 : }
587 :
588 0 : void PivotTableField::convertDataField( const PTDataFieldModel& rDataField )
589 : {
590 : OSL_ENSURE( rDataField.mnField == mnFieldIndex, "PivotTableField::convertDataField - wrong field index" );
591 : OSL_ENSURE( maModel.mbDataField, "PivotTableField::convertDataField - not a data field" );
592 0 : Reference< XDataPilotField > xDPField = mrPivotTable.getDataPilotField( maDPFieldName );
593 0 : if( xDPField.is() )
594 : {
595 0 : PropertySet aPropSet( xDPField );
596 : using namespace ::com::sun::star::sheet;
597 :
598 : // field orientation
599 0 : aPropSet.setProperty( PROP_Orientation, DataPilotFieldOrientation_DATA );
600 :
601 : /* Field aggregation function. Documentation is a little bit confused
602 : about which names to use for the count functions. The name 'count'
603 : means 'count all', and 'countNum' means 'count numbers'. On the
604 : other hand, for subtotals, 'countA' means 'count all', and 'count'
605 : means 'count numbers' (see above). */
606 0 : GeneralFunction eAggFunc = GeneralFunction_SUM;
607 0 : switch( rDataField.mnSubtotal )
608 : {
609 0 : case XML_sum: eAggFunc = GeneralFunction_SUM; break;
610 0 : case XML_count: eAggFunc = GeneralFunction_COUNT; break;
611 0 : case XML_average: eAggFunc = GeneralFunction_AVERAGE; break;
612 0 : case XML_max: eAggFunc = GeneralFunction_MAX; break;
613 0 : case XML_min: eAggFunc = GeneralFunction_MIN; break;
614 0 : case XML_product: eAggFunc = GeneralFunction_PRODUCT; break;
615 0 : case XML_countNums: eAggFunc = GeneralFunction_COUNTNUMS; break;
616 0 : case XML_stdDev: eAggFunc = GeneralFunction_STDEV; break;
617 0 : case XML_stdDevp: eAggFunc = GeneralFunction_STDEVP; break;
618 0 : case XML_var: eAggFunc = GeneralFunction_VAR; break;
619 0 : case XML_varp: eAggFunc = GeneralFunction_VARP; break;
620 : default: OSL_FAIL( "PivotTableField::convertDataField - unknown aggregation function" );
621 : }
622 0 : aPropSet.setProperty( PROP_Function, eAggFunc );
623 :
624 : // field reference ('show data as')
625 0 : DataPilotFieldReference aReference;
626 0 : aReference.ReferenceType = DataPilotFieldReferenceType::NONE;
627 0 : switch( rDataField.mnShowDataAs )
628 : {
629 0 : case XML_difference: aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_DIFFERENCE; break;
630 0 : case XML_percent: aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_PERCENTAGE; break;
631 0 : case XML_percentDiff: aReference.ReferenceType = DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE; break;
632 0 : case XML_runTotal: aReference.ReferenceType = DataPilotFieldReferenceType::RUNNING_TOTAL; break;
633 0 : case XML_percentOfRow: aReference.ReferenceType = DataPilotFieldReferenceType::ROW_PERCENTAGE; break;
634 0 : case XML_percentOfCol: aReference.ReferenceType = DataPilotFieldReferenceType::COLUMN_PERCENTAGE; break;
635 0 : case XML_percentOfTotal: aReference.ReferenceType = DataPilotFieldReferenceType::TOTAL_PERCENTAGE; break;
636 0 : case XML_index: aReference.ReferenceType = DataPilotFieldReferenceType::INDEX; break;
637 : }
638 0 : if( aReference.ReferenceType != DataPilotFieldReferenceType::NONE )
639 : {
640 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheField( rDataField.mnBaseField ) )
641 : {
642 0 : aReference.ReferenceField = pCacheField->getName();
643 0 : switch( rDataField.mnBaseItem )
644 : {
645 : case OOX_PT_PREVIOUS_ITEM:
646 0 : aReference.ReferenceItemType = DataPilotFieldReferenceItemType::PREVIOUS;
647 0 : break;
648 : case OOX_PT_NEXT_ITEM:
649 0 : aReference.ReferenceItemType = DataPilotFieldReferenceItemType::NEXT;
650 0 : break;
651 : default:
652 0 : aReference.ReferenceItemType = DataPilotFieldReferenceItemType::NAMED;
653 0 : if( const PivotCacheItem* pCacheItem = pCacheField->getCacheItem( rDataField.mnBaseItem ) )
654 0 : aReference.ReferenceItemName = pCacheItem->getName();
655 : }
656 0 : aPropSet.setProperty( PROP_Reference, aReference );
657 : }
658 0 : }
659 0 : }
660 0 : }
661 :
662 : // private --------------------------------------------------------------------
663 :
664 0 : Reference< XDataPilotField > PivotTableField::convertRowColPageField( sal_Int32 nAxis )
665 : {
666 0 : bool bDataLayout = mnFieldIndex == OOX_PT_DATALAYOUTFIELD;
667 0 : Reference< XDataPilotField > xDPField = bDataLayout ? mrPivotTable.getDataLayoutField() : mrPivotTable.getDataPilotField( maDPFieldName );
668 : OSL_ENSURE( bDataLayout || (nAxis == maModel.mnAxis), "PivotTableField::convertRowColPageField - field axis mismatch" );
669 :
670 0 : if( xDPField.is() )
671 : {
672 : // TODO: Use this to set properties directly, bypassing the slow uno layer.
673 0 : ScDPObject* pDPObj = mrPivotTable.getDPObject();
674 :
675 0 : PropertySet aPropSet( xDPField );
676 : using namespace ::com::sun::star::sheet;
677 :
678 : // field orientation
679 0 : DataPilotFieldOrientation eFieldOrient = DataPilotFieldOrientation_HIDDEN;
680 0 : switch( nAxis )
681 : {
682 0 : case XML_axisRow: eFieldOrient = DataPilotFieldOrientation_ROW; break;
683 0 : case XML_axisCol: eFieldOrient = DataPilotFieldOrientation_COLUMN; break;
684 0 : case XML_axisPage: eFieldOrient = DataPilotFieldOrientation_PAGE; break;
685 : }
686 0 : if( eFieldOrient != DataPilotFieldOrientation_HIDDEN )
687 0 : aPropSet.setProperty( PROP_Orientation, eFieldOrient );
688 :
689 : // all other settings not for the data layout field
690 0 : if( !bDataLayout )
691 : {
692 : /* Field subtotal functions. Ignore the 'defaultSubtotal' flag, if
693 : explicit functions are set. This is different behaviour between
694 : XML (where 'defaultSubtotal' is set regardless of other
695 : functions) and binary formats (where 'defaultSubtotal' is not
696 : set if other functions are set). */
697 0 : ::std::vector< GeneralFunction > aSubtotals;
698 : /* Order of subtotals is fixed in Excel. Documentation is a little
699 : bit confused about which names to use for the count functions.
700 : For subtotals, 'countA' means 'count all', and 'count' means
701 : 'count numbers'. On the other hand, for the data field
702 : aggregation function, 'count' means 'count all', and 'countNum'
703 : means 'count numbers' (see below). */
704 0 : if( maModel.mbSumSubtotal ) aSubtotals.push_back( GeneralFunction_SUM );
705 0 : if( maModel.mbCountASubtotal ) aSubtotals.push_back( GeneralFunction_COUNT );
706 0 : if( maModel.mbAverageSubtotal ) aSubtotals.push_back( GeneralFunction_AVERAGE );
707 0 : if( maModel.mbMaxSubtotal ) aSubtotals.push_back( GeneralFunction_MAX );
708 0 : if( maModel.mbMinSubtotal ) aSubtotals.push_back( GeneralFunction_MIN );
709 0 : if( maModel.mbProductSubtotal ) aSubtotals.push_back( GeneralFunction_PRODUCT );
710 0 : if( maModel.mbCountSubtotal ) aSubtotals.push_back( GeneralFunction_COUNTNUMS );
711 0 : if( maModel.mbStdDevSubtotal ) aSubtotals.push_back( GeneralFunction_STDEV );
712 0 : if( maModel.mbStdDevPSubtotal ) aSubtotals.push_back( GeneralFunction_STDEVP );
713 0 : if( maModel.mbVarSubtotal ) aSubtotals.push_back( GeneralFunction_VAR );
714 0 : if( maModel.mbVarPSubtotal ) aSubtotals.push_back( GeneralFunction_VARP );
715 : // if no function is set manually, check the 'defaultSubtotal' flag
716 0 : if( aSubtotals.empty() && maModel.mbDefaultSubtotal )
717 0 : aSubtotals.push_back( GeneralFunction_AUTO );
718 0 : aPropSet.setProperty( PROP_Subtotals, ContainerHelper::vectorToSequence( aSubtotals ) );
719 :
720 : // layout settings
721 0 : DataPilotFieldLayoutInfo aLayoutInfo;
722 : aLayoutInfo.LayoutMode = maModel.mbOutline ?
723 : (maModel.mbSubtotalTop ? DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP : DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM) :
724 0 : DataPilotFieldLayoutMode::TABULAR_LAYOUT;
725 0 : aLayoutInfo.AddEmptyLines = maModel.mbInsertBlankRow;
726 0 : aPropSet.setProperty( PROP_LayoutInfo, aLayoutInfo );
727 0 : aPropSet.setProperty( PROP_ShowEmpty, maModel.mbShowAll );
728 :
729 : // auto show (OOXML/BIFF12 only)
730 0 : if( maModel.mbAutoShow )
731 : {
732 0 : DataPilotFieldAutoShowInfo aAutoShowInfo;
733 0 : aAutoShowInfo.IsEnabled = sal_True;
734 0 : aAutoShowInfo.ShowItemsMode = maModel.mbTopAutoShow ? DataPilotFieldShowItemsMode::FROM_TOP : DataPilotFieldShowItemsMode::FROM_BOTTOM;
735 0 : aAutoShowInfo.ItemCount = maModel.mnAutoShowItems;
736 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheFieldOfDataField( maModel.mnAutoShowRankBy ) )
737 0 : aAutoShowInfo.DataField = pCacheField->getName();
738 0 : aPropSet.setProperty( PROP_AutoShowInfo, aAutoShowInfo );
739 : }
740 :
741 : // auto sort
742 0 : DataPilotFieldSortInfo aSortInfo;
743 0 : aSortInfo.IsAscending = maModel.mnSortType == XML_ascending;
744 0 : if( (maModel.mnSortType != XML_ascending) && (maModel.mnSortType != XML_descending) )
745 : {
746 0 : aSortInfo.Mode = DataPilotFieldSortMode::MANUAL;
747 : }
748 : else
749 : {
750 0 : const PivotCacheField* pCacheField = (maModel.mnSortRefField == OOX_PT_DATALAYOUTFIELD) ?
751 0 : mrPivotTable.getCacheFieldOfDataField( maModel.mnSortRefItem ) : 0;
752 0 : if( pCacheField )
753 : {
754 0 : aSortInfo.Mode = DataPilotFieldSortMode::DATA;
755 0 : aSortInfo.Field = pCacheField->getName();
756 : }
757 : else
758 : {
759 0 : aSortInfo.Mode = DataPilotFieldSortMode::NAME;
760 : }
761 : }
762 0 : aPropSet.setProperty( PROP_SortInfo, aSortInfo );
763 :
764 : // item settings
765 0 : if (const PivotCacheField* pCacheField = mrPivotTable.getCacheField(mnFieldIndex))
766 : {
767 0 : ScDPSaveData* pSaveData = pDPObj->GetSaveData();
768 0 : ScDPSaveDimension* pDim = pSaveData->GetDimensionByName(pCacheField->getName());
769 :
770 : try
771 : {
772 0 : for( ItemModelVector::iterator aIt = maItems.begin(), aEnd = maItems.end(); aIt != aEnd; ++aIt )
773 : {
774 0 : if (aIt->mnType != XML_data)
775 0 : continue;
776 :
777 0 : const PivotCacheItem* pSharedItem = pCacheField->getCacheItem(aIt->mnCacheItem);
778 0 : if (!pSharedItem)
779 0 : continue;
780 :
781 : try
782 : {
783 0 : ScDPSaveMember* pMem = pDim->GetMemberByName(pSharedItem->getName());
784 0 : pMem->SetShowDetails(aIt->mbShowDetails);
785 0 : pMem->SetIsVisible(!aIt->mbHidden);
786 : }
787 0 : catch( Exception& )
788 : {
789 : // catch every failed container access to be able to process following items
790 : }
791 : }
792 : }
793 0 : catch (const Exception&) {}
794 0 : }
795 0 : }
796 : }
797 0 : return xDPField;
798 : }
799 :
800 : // ============================================================================
801 :
802 0 : PTFilterModel::PTFilterModel() :
803 : mfValue( 0.0 ),
804 : mnField( -1 ),
805 : mnMemPropField( -1 ),
806 : mnType( XML_TOKEN_INVALID ),
807 : mnEvalOrder( 0 ),
808 : mnId( -1 ),
809 : mnMeasureField( -1 ),
810 : mnMeasureHier( -1 ),
811 0 : mbTopFilter( true )
812 : {
813 0 : }
814 :
815 : // ----------------------------------------------------------------------------
816 :
817 0 : PivotTableFilter::PivotTableFilter( const PivotTable& rPivotTable ) :
818 : WorkbookHelper( rPivotTable ),
819 0 : mrPivotTable( rPivotTable )
820 : {
821 0 : }
822 :
823 0 : void PivotTableFilter::importFilter( const AttributeList& rAttribs )
824 : {
825 0 : maModel.maName = rAttribs.getXString( XML_name, OUString() );
826 0 : maModel.maDescription = rAttribs.getXString( XML_description, OUString() );
827 0 : maModel.maStrValue1 = rAttribs.getXString( XML_stringValue1, OUString() );
828 0 : maModel.maStrValue2 = rAttribs.getXString( XML_stringValue2, OUString() );
829 0 : maModel.mnField = rAttribs.getInteger( XML_fld, -1 );
830 0 : maModel.mnMemPropField = rAttribs.getInteger( XML_mpFld, -1 );
831 0 : maModel.mnType = rAttribs.getToken( XML_type, XML_TOKEN_INVALID );
832 0 : maModel.mnEvalOrder = rAttribs.getInteger( XML_evalOrder, 0 );
833 0 : maModel.mnId = rAttribs.getInteger( XML_id, -1 );
834 0 : maModel.mnMeasureField = rAttribs.getInteger( XML_iMeasureFld, -1 );
835 0 : maModel.mnMeasureHier = rAttribs.getInteger( XML_iMeasureHier, -1 );
836 0 : }
837 :
838 0 : void PivotTableFilter::importTop10( const AttributeList& rAttribs )
839 : {
840 : OSL_ENSURE( rAttribs.getBool( XML_percent, false ) == (maModel.mnType == XML_percent),
841 : "PivotTableFilter::importTop10 - unexpected value of percent attribute" );
842 0 : maModel.mfValue = rAttribs.getDouble( XML_val, 0.0 );
843 0 : maModel.mbTopFilter = rAttribs.getBool( XML_top, true );
844 0 : }
845 :
846 0 : void PivotTableFilter::importPTFilter( SequenceInputStream& rStrm )
847 : {
848 : sal_Int32 nType;
849 : sal_uInt16 nFlags;
850 0 : rStrm >> maModel.mnField >> maModel.mnMemPropField >> nType;
851 0 : rStrm.skip( 4 ); // unused
852 0 : rStrm >> maModel.mnId >> maModel.mnMeasureField >> maModel.mnMeasureHier >> nFlags;
853 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASNAME ) )
854 0 : rStrm >> maModel.maName;
855 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASDESCRIPTION ) )
856 0 : rStrm >> maModel.maDescription;
857 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASSTRVALUE1 ) )
858 0 : rStrm >> maModel.maStrValue1;
859 0 : if( getFlag( nFlags, BIFF12_PTFILTER_HASSTRVALUE2 ) )
860 0 : rStrm >> maModel.maStrValue2;
861 :
862 : static sal_Int32 spnTypes[] =
863 : {
864 : XML_unknown,
865 : // data field top10 filter (1-3)
866 : XML_count, XML_percent, XML_sum,
867 : // caption filter (4-17)
868 : XML_captionEqual, XML_captionNotEqual,
869 : XML_captionBeginsWith, XML_captionNotBeginsWith, XML_captionEndsWith, XML_captionNotEndsWith,
870 : XML_captionContains, XML_captionNotContains, XML_captionGreaterThan, XML_captionGreaterThanOrEqual,
871 : XML_captionLessThan, XML_captionLessThanOrEqual, XML_captionBetween, XML_captionNotBetween,
872 : // value filter (18-25)
873 : XML_valueEqual, XML_valueNotEqual, XML_valueGreaterThan, XML_valueGreaterThanOrEqual,
874 : XML_valueLessThan, XML_valueLessThanOrEqual, XML_valueBetween, XML_valueNotBetween,
875 : // date filter (26-65)
876 : XML_dateEqual, XML_dateOlderThan, XML_dateNewerThan, XML_dateBetween,
877 : XML_tomorrow, XML_today, XML_yesterday, XML_nextWeek, XML_thisWeek, XML_lastWeek,
878 : XML_nextMonth, XML_thisMonth, XML_lastMonth, XML_nextQuarter, XML_thisQuarter, XML_lastQuarter,
879 : XML_nextYear, XML_thisYear, XML_lastYear, XML_yearToDate, XML_Q1, XML_Q2, XML_Q3, XML_Q4,
880 : XML_M1, XML_M2, XML_M3, XML_M4, XML_M5, XML_M6, XML_M7, XML_M8, XML_M9, XML_M10, XML_M11, XML_M12,
881 : XML_dateNotEqual, XML_dateOlderThanOrEqual, XML_dateNewerThanOrEqual, XML_dateNotBetween
882 : };
883 0 : maModel.mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
884 0 : }
885 :
886 0 : void PivotTableFilter::importTop10Filter( SequenceInputStream& rStrm )
887 : {
888 : sal_uInt8 nFlags;
889 0 : rStrm >> nFlags >> maModel.mfValue;
890 :
891 : OSL_ENSURE( getFlag( nFlags, BIFF12_TOP10FILTER_PERCENT ) == (maModel.mnType == XML_percent),
892 : "PivotTableFilter::importTop10 - unexpected value of percent attribute" );
893 0 : maModel.mbTopFilter = getFlag( nFlags, BIFF12_TOP10FILTER_TOP );
894 0 : }
895 :
896 0 : void PivotTableFilter::finalizeImport()
897 : {
898 : // only simple top10 filter supported
899 0 : if( maModel.mnType == XML_count )
900 : {
901 0 : PropertySet aPropSet( mrPivotTable.getDataPilotField( maModel.mnField ) );
902 0 : if( aPropSet.is() )
903 : {
904 : using namespace ::com::sun::star::sheet;
905 0 : DataPilotFieldAutoShowInfo aAutoShowInfo;
906 0 : aAutoShowInfo.IsEnabled = sal_True;
907 0 : aAutoShowInfo.ShowItemsMode = maModel.mbTopFilter ? DataPilotFieldShowItemsMode::FROM_TOP : DataPilotFieldShowItemsMode::FROM_BOTTOM;
908 0 : aAutoShowInfo.ItemCount = getLimitedValue< sal_Int32, double >( maModel.mfValue, 0, SAL_MAX_INT32 );
909 0 : if( const PivotCacheField* pCacheField = mrPivotTable.getCacheFieldOfDataField( maModel.mnMeasureField ) )
910 0 : aAutoShowInfo.DataField = pCacheField->getName();
911 0 : aPropSet.setProperty( PROP_AutoShowInfo, aAutoShowInfo );
912 0 : }
913 : }
914 0 : }
915 :
916 : // ============================================================================
917 :
918 0 : PTDefinitionModel::PTDefinitionModel() :
919 : mnCacheId( -1 ),
920 : mnDataPosition( 0 ),
921 : mnPageWrap( 0 ),
922 : mnIndent( 1 ),
923 : mnChartFormat( 0 ),
924 : mnRowFields( 0 ),
925 : mnColFields( 0 ),
926 : mbDataOnRows( false ),
927 : mbShowError( false ),
928 : mbShowMissing( true ),
929 : mbShowItems( true ),
930 : mbDisableFieldList( false ),
931 : mbShowCalcMembers( true ),
932 : mbVisualTotals( true ),
933 : mbShowDrill( true ),
934 : mbPrintDrill( false ),
935 : mbEnableDrill( true ),
936 : mbPreserveFormatting( true ),
937 : mbUseAutoFormat( false ),
938 : mbPageOverThenDown( false ),
939 : mbSubtotalHiddenItems( false ),
940 : mbRowGrandTotals( true ),
941 : mbColGrandTotals( true ),
942 : mbFieldPrintTitles( false ),
943 : mbItemPrintTitles( false ),
944 : mbMergeItem( false ),
945 : mbShowEmptyRow( false ),
946 : mbShowEmptyCol( false ),
947 : mbShowHeaders( true ),
948 : mbFieldListSortAsc( false ),
949 0 : mbCustomListSort( true )
950 : {
951 0 : }
952 :
953 : // ----------------------------------------------------------------------------
954 :
955 0 : PTLocationModel::PTLocationModel() :
956 : mnFirstHeaderRow( 0 ),
957 : mnFirstDataRow( 0 ),
958 : mnFirstDataCol( 0 ),
959 : mnRowPageCount( 0 ),
960 0 : mnColPageCount( 0 )
961 : {
962 0 : }
963 :
964 : // ----------------------------------------------------------------------------
965 :
966 0 : PivotTable::PivotTable( const WorkbookHelper& rHelper ) :
967 : WorkbookHelper( rHelper ),
968 : mpDPObject(NULL),
969 : maDataField( *this, OOX_PT_DATALAYOUTFIELD ),
970 0 : mpPivotCache( 0 )
971 : {
972 0 : }
973 :
974 0 : void PivotTable::importPivotTableDefinition( const AttributeList& rAttribs )
975 : {
976 0 : maDefModel.maName = rAttribs.getXString( XML_name, OUString() );
977 0 : maDefModel.maDataCaption = rAttribs.getXString( XML_dataCaption , OUString() );
978 0 : maDefModel.maGrandTotalCaption = rAttribs.getXString( XML_grandTotalCaption, OUString() );
979 0 : maDefModel.maRowHeaderCaption = rAttribs.getXString( XML_rowHeaderCaption, OUString() );
980 0 : maDefModel.maColHeaderCaption = rAttribs.getXString( XML_colHeaderCaption, OUString() );
981 0 : maDefModel.maErrorCaption = rAttribs.getXString( XML_errorCaption, OUString() );
982 0 : maDefModel.maMissingCaption = rAttribs.getXString( XML_missingCaption, OUString() );
983 0 : maDefModel.maPageStyle = rAttribs.getXString( XML_pageStyle, OUString() );
984 0 : maDefModel.maPivotTableStyle = rAttribs.getXString( XML_pivotTableStyle, OUString() );
985 0 : maDefModel.maVacatedStyle = rAttribs.getXString( XML_vacatedStyle, OUString() );
986 0 : maDefModel.maTag = rAttribs.getXString( XML_tag, OUString() );
987 0 : maDefModel.mnCacheId = rAttribs.getInteger( XML_cacheId, -1 );
988 0 : maDefModel.mnDataPosition = rAttribs.getInteger( XML_dataPosition, 0 );
989 0 : maDefModel.mnPageWrap = rAttribs.getInteger( XML_pageWrap, 0 );
990 0 : maDefModel.mnIndent = rAttribs.getInteger( XML_indent, 1 );
991 0 : maDefModel.mnChartFormat = rAttribs.getInteger( XML_chartFormat, 0 );
992 0 : maDefModel.mnAutoFormatId = rAttribs.getInteger( XML_autoFormatId, 0 );
993 0 : maDefModel.mbDataOnRows = rAttribs.getBool( XML_dataOnRows, false );
994 0 : maDefModel.mbShowError = rAttribs.getBool( XML_showError, false );
995 0 : maDefModel.mbShowMissing = rAttribs.getBool( XML_showMissing, true );
996 0 : maDefModel.mbShowItems = rAttribs.getBool( XML_showItems, true );
997 0 : maDefModel.mbDisableFieldList = rAttribs.getBool( XML_disableFieldList, false );
998 0 : maDefModel.mbShowCalcMembers = rAttribs.getBool( XML_showCalcMbrs, true );
999 0 : maDefModel.mbVisualTotals = rAttribs.getBool( XML_visualTotals, true );
1000 0 : maDefModel.mbShowDrill = rAttribs.getBool( XML_showDrill, true );
1001 0 : maDefModel.mbPrintDrill = rAttribs.getBool( XML_printDrill, false );
1002 0 : maDefModel.mbEnableDrill = rAttribs.getBool( XML_enableDrill, true );
1003 0 : maDefModel.mbPreserveFormatting = rAttribs.getBool( XML_preserveFormatting, true );
1004 0 : maDefModel.mbUseAutoFormat = rAttribs.getBool( XML_useAutoFormatting, false );
1005 0 : maDefModel.mbPageOverThenDown = rAttribs.getBool( XML_pageOverThenDown, false );
1006 0 : maDefModel.mbSubtotalHiddenItems = rAttribs.getBool( XML_subtotalHiddenItems, false );
1007 0 : maDefModel.mbRowGrandTotals = rAttribs.getBool( XML_rowGrandTotals, true );
1008 0 : maDefModel.mbColGrandTotals = rAttribs.getBool( XML_colGrandTotals, true );
1009 0 : maDefModel.mbFieldPrintTitles = rAttribs.getBool( XML_fieldPrintTitles, false );
1010 0 : maDefModel.mbItemPrintTitles = rAttribs.getBool( XML_itemPrintTitles, false );
1011 0 : maDefModel.mbMergeItem = rAttribs.getBool( XML_mergeItem, false );
1012 0 : maDefModel.mbShowEmptyRow = rAttribs.getBool( XML_showEmptyRow, false );
1013 0 : maDefModel.mbShowEmptyCol = rAttribs.getBool( XML_showEmptyCol, false );
1014 0 : maDefModel.mbShowHeaders = rAttribs.getBool( XML_showHeaders, true );
1015 0 : maDefModel.mbFieldListSortAsc = rAttribs.getBool( XML_fieldListSortAscending, false );
1016 0 : maDefModel.mbCustomListSort = rAttribs.getBool( XML_customListSort, true );
1017 0 : maDefModel.mbApplyNumFmt = rAttribs.getBool( XML_applyNumberFormats, false );
1018 0 : maDefModel.mbApplyFont = rAttribs.getBool( XML_applyFontFormats, false );
1019 0 : maDefModel.mbApplyAlignment = rAttribs.getBool( XML_applyAlignmentFormats, false );
1020 0 : maDefModel.mbApplyBorder = rAttribs.getBool( XML_applyBorderFormats, false );
1021 0 : maDefModel.mbApplyFill = rAttribs.getBool( XML_applyPatternFormats, false );
1022 : // OOXML and BIFF12 documentation differ: OOXML mentions width/height, BIFF12 mentions protection
1023 0 : maDefModel.mbApplyProtection = rAttribs.getBool( XML_applyWidthHeightFormats, false );
1024 0 : }
1025 :
1026 0 : void PivotTable::importLocation( const AttributeList& rAttribs, sal_Int16 nSheet )
1027 : {
1028 0 : getAddressConverter().convertToCellRangeUnchecked( maLocationModel.maRange, rAttribs.getString( XML_ref, OUString() ), nSheet );
1029 0 : maLocationModel.mnFirstHeaderRow = rAttribs.getInteger( XML_firstHeaderRow, 0 );
1030 0 : maLocationModel.mnFirstDataRow = rAttribs.getInteger( XML_firstDataRow, 0 );
1031 0 : maLocationModel.mnFirstDataCol = rAttribs.getInteger( XML_firstDataCol, 0 );
1032 0 : maLocationModel.mnRowPageCount = rAttribs.getInteger( XML_rowPageCount, 0 );
1033 0 : maLocationModel.mnColPageCount = rAttribs.getInteger( XML_colPageCount, 0 );
1034 0 : }
1035 :
1036 0 : void PivotTable::importRowField( const AttributeList& rAttribs )
1037 : {
1038 0 : importField( maRowFields, rAttribs );
1039 0 : }
1040 :
1041 0 : void PivotTable::importColField( const AttributeList& rAttribs )
1042 : {
1043 0 : importField( maColFields, rAttribs );
1044 0 : }
1045 :
1046 0 : void PivotTable::importPageField( const AttributeList& rAttribs )
1047 : {
1048 0 : PTPageFieldModel aModel;
1049 0 : aModel.maName = rAttribs.getXString( XML_name, OUString() );
1050 0 : aModel.mnField = rAttribs.getInteger( XML_fld, -1 );
1051 : // specification is wrong, XML_item is not the cache item, but the field item
1052 0 : aModel.mnItem = rAttribs.getInteger( XML_item, BIFF12_PTPAGEFIELD_MULTIITEMS );
1053 0 : maPageFields.push_back( aModel );
1054 0 : }
1055 :
1056 0 : void PivotTable::importDataField( const AttributeList& rAttribs )
1057 : {
1058 0 : PTDataFieldModel aModel;
1059 0 : aModel.maName = rAttribs.getXString( XML_name, OUString() );
1060 0 : aModel.mnField = rAttribs.getInteger( XML_fld, -1 );
1061 0 : aModel.mnSubtotal = rAttribs.getToken( XML_subtotal, XML_sum );
1062 0 : aModel.mnShowDataAs = rAttribs.getToken( XML_showDataAs, XML_normal );
1063 0 : aModel.mnBaseField = rAttribs.getInteger( XML_baseField, -1 );
1064 0 : aModel.mnBaseItem = rAttribs.getInteger( XML_baseItem, -1 );
1065 0 : aModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, 0 );
1066 0 : maDataFields.push_back( aModel );
1067 0 : }
1068 :
1069 0 : void PivotTable::importPTDefinition( SequenceInputStream& rStrm )
1070 : {
1071 : sal_uInt32 nFlags1, nFlags2, nFlags3;
1072 : sal_uInt8 nDataAxis;
1073 0 : rStrm >> nFlags1 >> nFlags2 >> nFlags3 >> nDataAxis;
1074 0 : maDefModel.mnPageWrap = rStrm.readuInt8();
1075 0 : rStrm.skip( 2 ); // refresh versions
1076 0 : rStrm >> maDefModel.mnDataPosition;
1077 0 : maDefModel.mnAutoFormatId = rStrm.readuInt16();
1078 0 : rStrm.skip( 2 ); // unused
1079 0 : rStrm >> maDefModel.mnChartFormat >> maDefModel.mnCacheId >> maDefModel.maName;
1080 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASDATACAPTION ) )
1081 0 : rStrm >> maDefModel.maDataCaption;
1082 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASGRANDTOTALCAPTION ) )
1083 0 : rStrm >> maDefModel.maGrandTotalCaption;
1084 0 : if( !getFlag( nFlags3, BIFF12_PTDEF_NOERRORCAPTION ) ) // missing flag indicates existing string
1085 0 : rStrm >> maDefModel.maErrorCaption;
1086 0 : if( !getFlag( nFlags3, BIFF12_PTDEF_NOMISSINGCAPTION ) ) // missing flag indicates existing string
1087 0 : rStrm >> maDefModel.maMissingCaption;
1088 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASPAGESTYLE ) )
1089 0 : rStrm >> maDefModel.maPageStyle;
1090 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASPIVOTTABLESTYLE ) )
1091 0 : rStrm >> maDefModel.maPivotTableStyle;
1092 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASVACATEDSTYLE ) )
1093 0 : rStrm >> maDefModel.maVacatedStyle;
1094 0 : if( getFlag( nFlags2, BIFF12_PTDEF_HASTAG ) )
1095 0 : rStrm >> maDefModel.maTag;
1096 0 : if( getFlag( nFlags3, BIFF12_PTDEF_HASCOLHEADERCAPTION ) ) // TODO: right order (col/row)? spec is unclear
1097 0 : rStrm >> maDefModel.maColHeaderCaption;
1098 0 : if( getFlag( nFlags3, BIFF12_PTDEF_HASROWHEADERCAPTION ) )
1099 0 : rStrm >> maDefModel.maRowHeaderCaption;
1100 :
1101 : OSL_ENSURE( (nDataAxis == BIFF12_PTDEF_ROWAXIS) || (nDataAxis == BIFF12_PTDEF_COLAXIS),
1102 : "PivotTable::importPTDefinition - unexpected axis position for data field" );
1103 :
1104 0 : maDefModel.mnIndent = extractValue< sal_uInt8 >( nFlags1, 24, 7 );
1105 0 : maDefModel.mbDataOnRows = nDataAxis == BIFF12_PTDEF_ROWAXIS;
1106 0 : maDefModel.mbShowError = getFlag( nFlags2, BIFF12_PTDEF_SHOWERROR );
1107 0 : maDefModel.mbShowMissing = getFlag( nFlags2, BIFF12_PTDEF_SHOWMISSING );
1108 0 : maDefModel.mbShowItems = getFlag( nFlags1, BIFF12_PTDEF_SHOWITEMS );
1109 0 : maDefModel.mbDisableFieldList = getFlag( nFlags1, BIFF12_PTDEF_DISABLEFIELDLIST );
1110 0 : maDefModel.mbShowCalcMembers = !getFlag( nFlags1, BIFF12_PTDEF_HIDECALCMEMBERS );
1111 0 : maDefModel.mbVisualTotals = !getFlag( nFlags1, BIFF12_PTDEF_WITHHIDDENTOTALS );
1112 0 : maDefModel.mbShowDrill = !getFlag( nFlags1, BIFF12_PTDEF_HIDEDRILL );
1113 0 : maDefModel.mbPrintDrill = getFlag( nFlags1, BIFF12_PTDEF_PRINTDRILL );
1114 0 : maDefModel.mbEnableDrill = getFlag( nFlags2, BIFF12_PTDEF_ENABLEDRILL );
1115 0 : maDefModel.mbPreserveFormatting = getFlag( nFlags2, BIFF12_PTDEF_PRESERVEFORMATTING );
1116 0 : maDefModel.mbUseAutoFormat = getFlag( nFlags2, BIFF12_PTDEF_USEAUTOFORMAT );
1117 0 : maDefModel.mbPageOverThenDown = getFlag( nFlags2, BIFF12_PTDEF_PAGEOVERTHENDOWN );
1118 0 : maDefModel.mbSubtotalHiddenItems = getFlag( nFlags2, BIFF12_PTDEF_SUBTOTALHIDDENITEMS );
1119 0 : maDefModel.mbRowGrandTotals = getFlag( nFlags2, BIFF12_PTDEF_ROWGRANDTOTALS );
1120 0 : maDefModel.mbColGrandTotals = getFlag( nFlags2, BIFF12_PTDEF_COLGRANDTOTALS );
1121 0 : maDefModel.mbFieldPrintTitles = getFlag( nFlags2, BIFF12_PTDEF_FIELDPRINTTITLES );
1122 0 : maDefModel.mbItemPrintTitles = getFlag( nFlags2, BIFF12_PTDEF_ITEMPRINTTITLES );
1123 0 : maDefModel.mbMergeItem = getFlag( nFlags2, BIFF12_PTDEF_MERGEITEM );
1124 0 : maDefModel.mbApplyNumFmt = getFlag( nFlags2, BIFF12_PTDEF_APPLYNUMFMT );
1125 0 : maDefModel.mbApplyFont = getFlag( nFlags2, BIFF12_PTDEF_APPLYFONT );
1126 0 : maDefModel.mbApplyAlignment = getFlag( nFlags2, BIFF12_PTDEF_APPLYALIGNMENT );
1127 0 : maDefModel.mbApplyBorder = getFlag( nFlags2, BIFF12_PTDEF_APPLYBORDER );
1128 0 : maDefModel.mbApplyFill = getFlag( nFlags2, BIFF12_PTDEF_APPLYFILL );
1129 0 : maDefModel.mbApplyProtection = getFlag( nFlags2, BIFF12_PTDEF_APPLYPROTECTION );
1130 0 : maDefModel.mbShowEmptyRow = getFlag( nFlags2, BIFF12_PTDEF_SHOWEMPTYROW );
1131 0 : maDefModel.mbShowEmptyCol = getFlag( nFlags2, BIFF12_PTDEF_SHOWEMPTYCOL );
1132 0 : maDefModel.mbShowHeaders = !getFlag( nFlags1, BIFF12_PTDEF_HIDEHEADERS );
1133 0 : maDefModel.mbFieldListSortAsc = getFlag( nFlags3, BIFF12_PTDEF_FIELDLISTSORTASC );
1134 0 : maDefModel.mbCustomListSort = !getFlag( nFlags3, BIFF12_PTDEF_NOCUSTOMLISTSORT );
1135 0 : }
1136 :
1137 0 : void PivotTable::importPTLocation( SequenceInputStream& rStrm, sal_Int16 nSheet )
1138 : {
1139 0 : BinRange aBinRange;
1140 0 : rStrm >> aBinRange >> maLocationModel.mnFirstHeaderRow
1141 0 : >> maLocationModel.mnFirstDataRow >> maLocationModel.mnFirstDataCol
1142 0 : >> maLocationModel.mnRowPageCount >> maLocationModel.mnColPageCount;
1143 0 : getAddressConverter().convertToCellRangeUnchecked( maLocationModel.maRange, aBinRange, nSheet );
1144 0 : }
1145 :
1146 0 : void PivotTable::importPTRowFields( SequenceInputStream& rStrm )
1147 : {
1148 0 : importFields( maRowFields, rStrm );
1149 0 : }
1150 :
1151 0 : void PivotTable::importPTColFields( SequenceInputStream& rStrm )
1152 : {
1153 0 : importFields( maColFields, rStrm );
1154 0 : }
1155 :
1156 0 : void PivotTable::importPTPageField( SequenceInputStream& rStrm )
1157 : {
1158 0 : PTPageFieldModel aModel;
1159 : sal_uInt8 nFlags;
1160 0 : rStrm >> aModel.mnField >> aModel.mnItem;
1161 0 : rStrm.skip( 4 ); // hierarchy
1162 0 : rStrm >> nFlags;
1163 0 : if( getFlag( nFlags, BIFF12_PTPAGEFIELD_HASNAME ) )
1164 0 : rStrm >> aModel.maName;
1165 0 : maPageFields.push_back( aModel );
1166 0 : }
1167 :
1168 0 : void PivotTable::importPTDataField( SequenceInputStream& rStrm )
1169 : {
1170 0 : PTDataFieldModel aModel;
1171 : sal_Int32 nSubtotal, nShowDataAs;
1172 : sal_uInt8 nHasName;
1173 0 : rStrm >> aModel.mnField >> nSubtotal >> nShowDataAs >> aModel.mnBaseField >> aModel.mnBaseItem >> aModel.mnNumFmtId >> nHasName;
1174 0 : if( nHasName == 1 )
1175 0 : rStrm >> aModel.maName;
1176 0 : aModel.setBiffSubtotal( nSubtotal );
1177 0 : aModel.setBiffShowDataAs( nShowDataAs );
1178 0 : maDataFields.push_back( aModel );
1179 0 : }
1180 :
1181 0 : PivotTableField& PivotTable::createTableField()
1182 : {
1183 0 : sal_Int32 nFieldIndex = static_cast< sal_Int32 >( maFields.size() );
1184 0 : PivotTableFieldVector::value_type xTableField( new PivotTableField( *this, nFieldIndex ) );
1185 0 : maFields.push_back( xTableField );
1186 0 : return *xTableField;
1187 : }
1188 :
1189 0 : PivotTableFilter& PivotTable::createTableFilter()
1190 : {
1191 0 : PivotTableFilterVector::value_type xTableFilter( new PivotTableFilter( *this ) );
1192 0 : maFilters.push_back( xTableFilter );
1193 0 : return *xTableFilter;
1194 : }
1195 :
1196 0 : void PivotTable::finalizeImport()
1197 : {
1198 0 : if( getAddressConverter().validateCellRange( maLocationModel.maRange, true, true ) )
1199 : {
1200 0 : mpPivotCache = getPivotCaches().importPivotCacheFragment( maDefModel.mnCacheId );
1201 0 : if( mpPivotCache && mpPivotCache->isValidDataSource() && !maDefModel.maName.isEmpty() )
1202 : {
1203 : // clear destination area of the original pivot table
1204 : try
1205 : {
1206 0 : Reference< XSheetOperation > xSheetOp( getCellRangeFromDoc( maLocationModel.maRange ), UNO_QUERY_THROW );
1207 : using namespace ::com::sun::star::sheet::CellFlags;
1208 0 : xSheetOp->clearContents( VALUE | DATETIME | STRING | FORMULA | HARDATTR | STYLES | EDITATTR | FORMATTED );
1209 : }
1210 0 : catch( Exception& )
1211 : {
1212 : }
1213 :
1214 : try
1215 : {
1216 : // create a new data pilot descriptor based on the source data
1217 0 : Reference< XDataPilotTablesSupplier > xDPTablesSupp( getSheetFromDoc( maLocationModel.maRange.Sheet ), UNO_QUERY_THROW );
1218 0 : Reference< XDataPilotTables > xDPTables( xDPTablesSupp->getDataPilotTables(), UNO_SET_THROW );
1219 0 : mxDPDescriptor.set( xDPTables->createDataPilotDescriptor(), UNO_SET_THROW );
1220 0 : mxDPDescriptor->setSourceRange( mpPivotCache->getSourceRange() );
1221 0 : mxDPDescriptor->setTag( maDefModel.maTag );
1222 :
1223 : // TODO: This is a hack. Eventually we need to convert the whole thing to the internal API.
1224 0 : ScDataPilotDescriptorBase* pImpl = ScDataPilotDescriptorBase::getImplementation(mxDPDescriptor);
1225 0 : if (!pImpl)
1226 0 : return;
1227 :
1228 0 : mpDPObject = pImpl->GetDPObject();
1229 0 : if (!mpDPObject)
1230 0 : return;
1231 :
1232 : // global data pilot properties
1233 0 : PropertySet aDescProp( mxDPDescriptor );
1234 0 : aDescProp.setProperty( PROP_ColumnGrand, maDefModel.mbColGrandTotals );
1235 0 : aDescProp.setProperty( PROP_RowGrand, maDefModel.mbRowGrandTotals );
1236 0 : aDescProp.setProperty( PROP_ShowFilterButton, false );
1237 0 : aDescProp.setProperty( PROP_DrillDownOnDoubleClick, maDefModel.mbEnableDrill );
1238 :
1239 : // finalize all fields, this finds field names and creates grouping fields
1240 0 : maFields.forEachMem( &PivotTableField::finalizeImport, ::boost::cref( mxDPDescriptor ) );
1241 :
1242 : // all row fields
1243 0 : for( IndexVector::iterator aIt = maRowFields.begin(), aEnd = maRowFields.end(); aIt != aEnd; ++aIt )
1244 0 : if( PivotTableField* pField = getTableField( *aIt ) )
1245 0 : pField->convertRowField();
1246 :
1247 : // all column fields
1248 0 : for( IndexVector::iterator aIt = maColFields.begin(), aEnd = maColFields.end(); aIt != aEnd; ++aIt )
1249 0 : if( PivotTableField* pField = getTableField( *aIt ) )
1250 0 : pField->convertColField();
1251 :
1252 : // all page fields
1253 0 : for( PageFieldVector::iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt )
1254 0 : if( PivotTableField* pField = getTableField( aIt->mnField ) )
1255 0 : pField->convertPageField( *aIt );
1256 :
1257 : // all hidden fields
1258 0 : ::std::set< sal_Int32 > aVisFields;
1259 0 : aVisFields.insert( maRowFields.begin(), maRowFields.end() );
1260 0 : aVisFields.insert( maColFields.begin(), maColFields.end() );
1261 0 : for( PageFieldVector::iterator aIt = maPageFields.begin(), aEnd = maPageFields.end(); aIt != aEnd; ++aIt )
1262 0 : aVisFields.insert( aIt->mnField );
1263 0 : for( PivotTableFieldVector::iterator aBeg = maFields.begin(), aIt = aBeg, aEnd = maFields.end(); aIt != aEnd; ++aIt )
1264 0 : if( aVisFields.count( static_cast< sal_Int32 >( aIt - aBeg ) ) == 0 )
1265 0 : (*aIt)->convertHiddenField();
1266 :
1267 : // all data fields
1268 0 : for( DataFieldVector::iterator aIt = maDataFields.begin(), aEnd = maDataFields.end(); aIt != aEnd; ++aIt )
1269 : {
1270 0 : if( const PivotCacheField* pCacheField = getCacheField( aIt->mnField ) )
1271 : {
1272 0 : if ( pCacheField-> getGroupBaseField() != -1 )
1273 0 : aIt->mnField = pCacheField-> getGroupBaseField();
1274 : }
1275 0 : if( PivotTableField* pField = getTableField( aIt->mnField ) )
1276 0 : pField->convertDataField( *aIt );
1277 : }
1278 :
1279 : // filters
1280 0 : maFilters.forEachMem( &PivotTableFilter::finalizeImport );
1281 :
1282 : // calculate base position of table
1283 0 : CellAddress aPos( maLocationModel.maRange.Sheet, maLocationModel.maRange.StartColumn, maLocationModel.maRange.StartRow );
1284 : /* If page fields exist, include them into the destination
1285 : area (they are excluded in Excel). Add an extra blank row. */
1286 0 : if( !maPageFields.empty() )
1287 0 : aPos.Row = ::std::max< sal_Int32 >( static_cast< sal_Int32 >( aPos.Row - maPageFields.size() - 1 ), 0 );
1288 :
1289 : // insert the DataPilot table into the sheet
1290 0 : xDPTables->insertNewByName( maDefModel.maName, aPos, mxDPDescriptor );
1291 : }
1292 0 : catch( Exception& )
1293 : {
1294 : OSL_FAIL( "PivotTable::finalizeImport - exception while creating the DataPilot table" );
1295 : }
1296 : }
1297 : }
1298 : }
1299 :
1300 0 : void PivotTable::finalizeDateGroupingImport( const Reference< XDataPilotField >& rxBaseDPField, sal_Int32 nBaseFieldIdx )
1301 : {
1302 : // process all fields, there is no chaining information in the cache fields
1303 0 : maFields.forEachMem( &PivotTableField::finalizeDateGroupingImport, ::boost::cref( rxBaseDPField ), nBaseFieldIdx );
1304 0 : }
1305 :
1306 0 : void PivotTable::finalizeParentGroupingImport( const Reference< XDataPilotField >& rxBaseDPField,
1307 : const PivotCacheField& rBaseCacheField, PivotCacheGroupItemVector& orItemNames )
1308 : {
1309 : // try to create parent group fields that group the items of the passed base field
1310 0 : if( PivotTableField* pParentTableField = maFields.get( rBaseCacheField.getParentGroupField() ).get() )
1311 0 : pParentTableField->finalizeParentGroupingImport( rxBaseDPField, rBaseCacheField, orItemNames );
1312 0 : }
1313 :
1314 0 : Reference< XDataPilotField > PivotTable::getDataPilotField( const OUString& rFieldName ) const
1315 : {
1316 0 : Reference< XDataPilotField > xDPField;
1317 0 : if( !rFieldName.isEmpty() && mxDPDescriptor.is() ) try
1318 : {
1319 0 : Reference< XNameAccess > xDPFieldsNA( mxDPDescriptor->getDataPilotFields(), UNO_QUERY_THROW );
1320 0 : xDPField.set( xDPFieldsNA->getByName( rFieldName ), UNO_QUERY );
1321 : }
1322 0 : catch( Exception& )
1323 : {
1324 : }
1325 0 : return xDPField;
1326 : }
1327 :
1328 0 : Reference< XDataPilotField > PivotTable::getDataPilotField( sal_Int32 nFieldIdx ) const
1329 : {
1330 0 : Reference< XDataPilotField > xDPField;
1331 0 : if( const PivotTableField* pTableField = maFields.get( nFieldIdx ).get() )
1332 0 : xDPField = getDataPilotField( pTableField->getDPFieldName() );
1333 0 : return xDPField;
1334 : }
1335 :
1336 0 : Reference< XDataPilotField > PivotTable::getDataLayoutField() const
1337 : {
1338 0 : Reference< XDataPilotField > xDPField;
1339 : try
1340 : {
1341 0 : Reference< XDataPilotDataLayoutFieldSupplier > xDPDataFieldSupp( mxDPDescriptor, UNO_QUERY_THROW );
1342 0 : xDPField = xDPDataFieldSupp->getDataLayoutField();
1343 : }
1344 0 : catch( Exception& )
1345 : {
1346 : }
1347 0 : return xDPField;
1348 : }
1349 :
1350 0 : const PivotCacheField* PivotTable::getCacheField( sal_Int32 nFieldIdx ) const
1351 : {
1352 0 : return mpPivotCache ? mpPivotCache->getCacheField( nFieldIdx ) : 0;
1353 : }
1354 :
1355 0 : const PivotCacheField* PivotTable::getCacheFieldOfDataField( sal_Int32 nDataItemIdx ) const
1356 : {
1357 0 : const PTDataFieldModel* pDataField = ContainerHelper::getVectorElement( maDataFields, nDataItemIdx );
1358 0 : return pDataField ? getCacheField( pDataField->mnField ) : 0;
1359 : }
1360 :
1361 0 : sal_Int32 PivotTable::getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const
1362 : {
1363 0 : return mpPivotCache ? mpPivotCache->getCacheDatabaseIndex( nFieldIdx ) : -1;
1364 : }
1365 :
1366 0 : ScDPObject* PivotTable::getDPObject()
1367 : {
1368 0 : return mpDPObject;
1369 : }
1370 :
1371 : // private --------------------------------------------------------------------
1372 :
1373 0 : PivotTableField* PivotTable::getTableField( sal_Int32 nFieldIdx )
1374 : {
1375 0 : return (nFieldIdx == OOX_PT_DATALAYOUTFIELD) ? &maDataField : maFields.get( nFieldIdx ).get();
1376 : }
1377 :
1378 0 : void PivotTable::importField( IndexVector& orFields, const AttributeList& rAttribs )
1379 : {
1380 0 : orFields.push_back( rAttribs.getInteger( XML_x, -1 ) );
1381 0 : }
1382 :
1383 0 : void PivotTable::importFields( IndexVector& orFields, SequenceInputStream& rStrm )
1384 : {
1385 : OSL_ENSURE( orFields.empty(), "PivotTable::importFields - multiple record instances" );
1386 0 : orFields.clear();
1387 0 : sal_Int32 nCount = rStrm.readInt32();
1388 : OSL_ENSURE( 4 * nCount == rStrm.getRemaining(), "PivotTable::importFields - invalid field count" );
1389 0 : nCount = static_cast< sal_Int32 >( rStrm.getRemaining() / 4 );
1390 0 : for( sal_Int32 nIdx = 0; nIdx < nCount; ++nIdx )
1391 0 : orFields.push_back( rStrm.readInt32() );
1392 0 : }
1393 :
1394 : // ============================================================================
1395 :
1396 21 : PivotTableBuffer::PivotTableBuffer( const WorkbookHelper& rHelper ) :
1397 21 : WorkbookHelper( rHelper )
1398 : {
1399 21 : }
1400 :
1401 0 : PivotTable& PivotTableBuffer::createPivotTable()
1402 : {
1403 0 : PivotTableVector::value_type xTable( new PivotTable( *this ) );
1404 0 : maTables.push_back( xTable );
1405 0 : return *xTable;
1406 : }
1407 :
1408 21 : void PivotTableBuffer::finalizeImport()
1409 : {
1410 21 : maTables.forEachMem( &PivotTable::finalizeImport );
1411 21 : }
1412 :
1413 : // ============================================================================
1414 :
1415 : } // namespace xls
1416 15 : } // namespace oox
1417 :
1418 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|