1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_PIVOTTABLEBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_PIVOTTABLEBUFFER_HXX
23 #include "pivotcachebuffer.hxx"
24 #include "stylesbuffer.hxx"
26 namespace com
{ namespace sun
{ namespace star
{
27 namespace sheet
{ class XDataPilotDescriptor
; }
28 namespace sheet
{ class XDataPilotField
; }
38 struct PTFieldItemModel
40 sal_Int32 mnCacheItem
; /// Index to shared item in pivot cache.
41 sal_Int32 mnType
; /// Type of the item.
42 OUString msCaption
; /// User caption of the item
43 bool mbShowDetails
; /// True = show item details (items of child fields).
44 bool mbHidden
; /// True = item is hidden.
46 explicit PTFieldItemModel();
48 /** Sets item type for BIFF import. */
49 void setBiffType( sal_uInt16 nType
);
54 sal_Int32 mnAxis
; /// Axis this field is assigned to (none, row, column, page).
55 sal_Int32 mnNumFmtId
; /// Number format for field items.
56 sal_Int32 mnAutoShowItems
; /// Number of items (or percent/sum) to be shown in auto show filter.
57 sal_Int32 mnAutoShowRankBy
; /// Index of the data field auto show filter is based on.
58 sal_Int32 mnSortType
; /// Autosorting type.
59 sal_Int32 mnSortRefField
; /// Reference field for autosorting.
60 sal_Int32 mnSortRefItem
; /// Item in reference field for autosorting.
61 bool mbDataField
; /// True = field appears in data area.
62 bool mbDefaultSubtotal
; /// True = show default subtotals.
63 bool mbSumSubtotal
; /// True = show sum subtotals.
64 bool mbCountASubtotal
; /// True = show count all subtotals.
65 bool mbAverageSubtotal
; /// True = show average subtotals.
66 bool mbMaxSubtotal
; /// True = show maximum subtotals.
67 bool mbMinSubtotal
; /// True = show minimum subtotals.
68 bool mbProductSubtotal
; /// True = show product subtotals.
69 bool mbCountSubtotal
; /// True = show count numbers subtotals.
70 bool mbStdDevSubtotal
; /// True = show standard deviation subtotals.
71 bool mbStdDevPSubtotal
; /// True = show standard deviation of population subtotals.
72 bool mbVarSubtotal
; /// True = show variance subtotals.
73 bool mbVarPSubtotal
; /// True = show variance of population subtotals.
74 bool mbShowAll
; /// True = show items without data.
75 bool mbOutline
; /// True = show in outline view, false = show in tabular view.
76 bool mbSubtotalTop
; /// True = show subtotals on top of items in outline or compact mode.
77 bool mbInsertBlankRow
; /// True = insert blank rows after items.
78 bool mbInsertPageBreak
; /// True = insert page breaks after items.
79 bool mbAutoShow
; /// True = auto show (top 10) filter enabled.
80 bool mbTopAutoShow
; /// True = auto show filter shows top entries, false = bottom.
81 bool mbMultiPageItems
; /// True = multiple items selectable in page dimension.
83 explicit PTFieldModel();
85 /** Sets axis type for BIFF import. */
86 void setBiffAxis( sal_uInt8 nAxisFlags
);
89 struct PTPageFieldModel
91 OUString maName
; /// Unique name of the page field.
92 sal_Int32 mnField
; /// Base pivot field.
93 sal_Int32 mnItem
; /// Index of field item that is shown by the page field.
95 explicit PTPageFieldModel();
98 struct PTDataFieldModel
100 OUString maName
; /// Name of the data field.
101 sal_Int32 mnField
; /// Base pivot field.
102 sal_Int32 mnSubtotal
; /// Subtotal aggregation function.
103 sal_Int32 mnShowDataAs
; /// Show data as, based on another field.
104 sal_Int32 mnBaseField
; /// Base field for 'show data as'.
105 sal_Int32 mnBaseItem
; /// Base item for 'show data as'.
106 sal_Int32 mnNumFmtId
; /// Number format for the result.
108 explicit PTDataFieldModel();
110 /** Sets the subtotal aggregation function for BIFF import. */
111 void setBiffSubtotal( sal_Int32 nSubtotal
);
112 /** Sets the 'show data as' type for BIFF import. */
113 void setBiffShowDataAs( sal_Int32 nShowDataAs
);
116 class PivotTableField
: public WorkbookHelper
119 explicit PivotTableField( PivotTable
& rPivotTable
, sal_Int32 nFieldIndex
);
121 /** Imports pivot field settings from the pivotField element. */
122 void importPivotField( const AttributeList
& rAttribs
);
123 /** Imports settings of an item in this pivot field from the item element. */
124 void importItem( const AttributeList
& rAttribs
);
125 /** Imports pivot field reference settings from the reference element. */
126 void importReference( const AttributeList
& rAttribs
);
127 /** Imports pivot field item reference settings from the x element. */
128 void importReferenceItem( const AttributeList
& rAttribs
);
130 /** Imports pivot field settings from the PTFIELD record. */
131 void importPTField( SequenceInputStream
& rStrm
);
132 /** Imports settings of an item in this pivot field from the PTFITEM record. */
133 void importPTFItem( SequenceInputStream
& rStrm
);
134 /** Imports pivot field reference settings from the PTREFERENCE record. */
135 void importPTReference( SequenceInputStream
& rStrm
);
136 /** Imports pivot field item reference settings from the PTREFERENCEITEM record. */
137 void importPTReferenceItem( SequenceInputStream
& rStrm
);
139 /** Finalizes the field after import, creates grouping and other settings. */
141 const css::uno::Reference
< css::sheet::XDataPilotDescriptor
>& rxDPDesc
);
142 /** Finalizes the grouped date field after import. */
143 void finalizeDateGroupingImport(
144 const css::uno::Reference
< css::sheet::XDataPilotField
>& rxBaseDPField
,
145 sal_Int32 nBaseFieldIdx
);
146 /** Finalizes the grouped field after import. */
147 void finalizeParentGroupingImport(
148 const css::uno::Reference
< css::sheet::XDataPilotField
>& rxBaseDPField
,
149 const PivotCacheField
& rBaseCacheField
,
150 PivotCacheGroupItemVector
& orItemNames
);
151 void finalizeImportBasedOnCache(
152 const css::uno::Reference
< css::sheet::XDataPilotDescriptor
>& rxDPDesc
);
154 /** Returns the name of the DataPilot field in the fields collection. */
155 const OUString
& getDPFieldName() const { return maDPFieldName
; }
157 /** Converts dimension and other settings for a row field. */
158 void convertRowField();
159 /** Converts dimension and other settings for a column field. */
160 void convertColField();
161 /** Converts dimension and other settings for a hidden field. */
162 void convertHiddenField();
163 /** Converts dimension and other settings for a page field */
164 void convertPageField( const PTPageFieldModel
& rPageField
);
165 /** Converts dimension and other settings for a data field. */
166 void convertDataField( const PTDataFieldModel
& rDataField
);
169 /** Converts dimension and other settings for row, column, page, or hidden fields. */
170 css::uno::Reference
< css::sheet::XDataPilotField
>
171 convertRowColPageField( sal_Int32 nAxis
);
174 typedef ::std::vector
< PTFieldItemModel
> ItemModelVector
;
176 PivotTable
& mrPivotTable
; /// The parent pivot table object.
177 ItemModelVector maItems
; /// All items of this field.
178 PTFieldModel maModel
; /// Pivot field settings.
179 OUString maDPFieldName
; /// Name of the field in DataPilot field collection.
180 sal_Int32
const mnFieldIndex
; /// Zero-based index of this field.
185 OUString maName
; /// Name of the field filter.
186 OUString maDescription
; /// Description of the field filter.
187 OUString maStrValue1
; /// First string value for label filter.
188 OUString maStrValue2
; /// Second string value for label filter.
189 double mfValue
; /// Number of items or percent or sum to be shown.
190 sal_Int32 mnField
; /// Base pivot field.
191 sal_Int32 mnMemPropField
; /// Member property field.
192 sal_Int32 mnType
; /// Filter type.
193 sal_Int32 mnEvalOrder
; /// Evaluation order index.
194 sal_Int32 mnId
; /// Unique identifier.
195 sal_Int32 mnMeasureField
; /// Data field for filter calculation.
196 sal_Int32 mnMeasureHier
; /// Hierarchy for filter calculation.
197 bool mbTopFilter
; /// True = filter shows top entries, false = bottom.
199 explicit PTFilterModel();
202 class PivotTableFilter
: public WorkbookHelper
205 explicit PivotTableFilter( const PivotTable
& rPivotTable
);
207 /** Reads the settings of a field filter from the filter element. */
208 void importFilter( const AttributeList
& rAttribs
);
209 /** Reads additional settings of a field filter from the top10 element. */
210 void importTop10( const AttributeList
& rAttribs
);
212 /** Reads the settings of a field filter from the PTFILTER record. */
213 void importPTFilter( SequenceInputStream
& rStrm
);
214 /** Reads additional settings of a field filter from the TOP10FILTER record. */
215 void importTop10Filter( SequenceInputStream
& rStrm
);
217 /** Applies the filter to the associated pivot table field if possible. */
218 void finalizeImport();
221 const PivotTable
& mrPivotTable
;
222 PTFilterModel maModel
;
225 struct PTDefinitionModel
: public AutoFormatModel
228 OUString maDataCaption
;
229 OUString maGrandTotalCaption
;
230 OUString maRowHeaderCaption
;
231 OUString maColHeaderCaption
;
232 OUString maErrorCaption
;
233 OUString maMissingCaption
;
234 OUString maPageStyle
;
235 OUString maPivotTableStyle
;
236 OUString maVacatedStyle
;
239 sal_Int32 mnDataPosition
;
240 sal_Int32 mnPageWrap
;
242 sal_Int32 mnChartFormat
;
247 bool mbDisableFieldList
;
248 bool mbShowCalcMembers
;
253 bool mbPreserveFormatting
;
254 bool mbUseAutoFormat
;
255 bool mbPageOverThenDown
;
256 bool mbSubtotalHiddenItems
;
257 bool mbRowGrandTotals
;
258 bool mbColGrandTotals
;
259 bool mbFieldPrintTitles
;
260 bool mbItemPrintTitles
;
265 bool mbFieldListSortAsc
;
266 bool mbCustomListSort
;
268 explicit PTDefinitionModel();
271 struct PTLocationModel
273 ScRange maRange
; /// Target cell range for the pivot table.
274 sal_Int32 mnFirstHeaderRow
; /// First row of header cells (relative in pivot table).
275 sal_Int32 mnFirstDataRow
; /// First row of data cells (relative in pivot table).
276 sal_Int32 mnFirstDataCol
; /// First column of data cells (relative in pivot table).
277 sal_Int32 mnRowPageCount
; /// Number of rows in page filter area.
278 sal_Int32 mnColPageCount
; /// Number of columns in page filter area.
280 explicit PTLocationModel();
283 class PivotTable
: public WorkbookHelper
286 explicit PivotTable( const WorkbookHelper
& rHelper
);
288 /** Reads global pivot table settings from the pivotTableDefinition element. */
289 void importPivotTableDefinition( const AttributeList
& rAttribs
);
290 /** Reads the location of the pivot table from the location element. */
291 void importLocation( const AttributeList
& rAttribs
, sal_Int16 nSheet
);
292 /** Reads the index of a field located in the row dimension. */
293 void importRowField( const AttributeList
& rAttribs
);
294 /** Reads the index of a field located in the column dimension. */
295 void importColField( const AttributeList
& rAttribs
);
296 /** Reads the settings of a field located in the page dimension from the pageField element. */
297 void importPageField( const AttributeList
& rAttribs
);
298 /** Reads the settings of a field located in the data dimension from the dataField element. */
299 void importDataField( const AttributeList
& rAttribs
);
300 /** Puts the attributes to the named grab bag value. */
301 void putToInteropGrabBag(const OUString
& sName
, const AttributeList
& rAttribs
);
303 /** Reads global pivot table settings from the PTDEFINITION record. */
304 void importPTDefinition( SequenceInputStream
& rStrm
);
305 /** Reads the location of the pivot table from the PTLOCATION record. */
306 void importPTLocation( SequenceInputStream
& rStrm
, sal_Int16 nSheet
);
307 /** Reads the indexes of all fields located in the row dimension from a PTROWFIELDS record. */
308 void importPTRowFields( SequenceInputStream
& rStrm
);
309 /** Reads the indexes of all fields located in the column dimension from a PTCOLFIELDS record. */
310 void importPTColFields( SequenceInputStream
& rStrm
);
311 /** Reads the settings of a field located in the page dimension from the PTPAGEFIELD record. */
312 void importPTPageField( SequenceInputStream
& rStrm
);
313 /** Reads the settings of a field located in the data dimension from the PTDATAFIELD record. */
314 void importPTDataField( SequenceInputStream
& rStrm
);
316 /** Creates and returns a new pivot table field. */
317 PivotTableField
& createTableField();
318 /** Creates and returns a new pivot table filter. */
319 PivotTableFilter
& createTableFilter();
320 /** Inserts the pivot table into the sheet. */
321 void finalizeImport();
322 /** Finalizes all fields, finds field names and creates grouping fields. */
323 void finalizeFieldsImport();
324 /** Creates all date group fields for the specified cache field after import. */
325 void finalizeDateGroupingImport(
326 const css::uno::Reference
< css::sheet::XDataPilotField
>& rxBaseDPField
,
327 sal_Int32 nBaseFieldIdx
);
328 /** Creates all grouped fields for the specified cache field after import. */
329 void finalizeParentGroupingImport(
330 const css::uno::Reference
< css::sheet::XDataPilotField
>& rxBaseDPField
,
331 const PivotCacheField
& rBaseCacheField
,
332 PivotCacheGroupItemVector
& orItemNames
);
334 /** Returns the associated data pilot field for the specified pivot table field. */
335 css::uno::Reference
< css::sheet::XDataPilotField
>
336 getDataPilotField( const OUString
& rFieldName
) const;
337 /** Returns the associated data pilot field for the specified pivot table field. */
338 css::uno::Reference
< css::sheet::XDataPilotField
>
339 getDataPilotField( sal_Int32 nFieldIdx
) const;
340 /** Returns the data layout field used to store all data fields in row/col dimension. */
341 css::uno::Reference
< css::sheet::XDataPilotField
>
342 getDataLayoutField() const;
344 /** Returns the cache field with the specified index. */
345 PivotCacheField
* getCacheField( sal_Int32 nFieldIdx
);
346 const PivotCacheField
* getCacheField( sal_Int32 nFieldIdx
) const;
347 /** Returns the base cache field of the data field item with the specified index. */
348 const PivotCacheField
* getCacheFieldOfDataField( sal_Int32 nDataItemIdx
) const;
349 /** Returns the source column index of the pivot field with the passed index, or -1. */
350 sal_Int32
getCacheDatabaseIndex( sal_Int32 nFieldIdx
) const;
352 ScDPObject
* getDPObject() { return mpDPObject
; }
355 typedef RefVector
< PivotTableField
> PivotTableFieldVector
;
356 typedef RefVector
< PivotTableFilter
> PivotTableFilterVector
;
357 typedef ::std::vector
< sal_Int32
> IndexVector
;
358 typedef ::std::vector
< PTPageFieldModel
> PageFieldVector
;
359 typedef ::std::vector
< PTDataFieldModel
> DataFieldVector
;
362 /** Returns a pivot table field by its index. */
363 PivotTableField
* getTableField( sal_Int32 nFieldIdx
);
365 /** Reads a field index for the row or column dimension. */
366 static void importField( IndexVector
& orFields
, const AttributeList
& rAttribs
);
367 /** Reads an array of field indexes for the row or column dimension. */
368 static void importFields( IndexVector
& orFields
, SequenceInputStream
& rStrm
);
371 ScDPObject
* mpDPObject
;
372 PivotTableFieldVector maFields
; /// All pivot table fields.
373 PivotTableField maDataField
; /// Data layout field.
374 IndexVector maRowFields
; /// Indexes to fields in row dimension.
375 IndexVector maColFields
; /// Indexes to fields in column dimension.
376 PageFieldVector maPageFields
; /// Settings for all fields in page dimension.
377 DataFieldVector maDataFields
; /// Settings for all fields in data area.
378 PivotTableFilterVector maFilters
; /// All field filters.
379 PTDefinitionModel maDefModel
; /// Global pivot table settings.
380 PTLocationModel maLocationModel
; /// Location settings of the pivot table.
381 PivotCache
* mpPivotCache
; /// The pivot cache this table is based on.
382 css::uno::Reference
< css::sheet::XDataPilotDescriptor
>
383 mxDPDescriptor
; /// Descriptor of the DataPilot object.
384 std::map
<OUString
, css::uno::Any
> maInteropGrabBag
;
388 class PivotTableBuffer
: public WorkbookHelper
391 explicit PivotTableBuffer( const WorkbookHelper
& rHelper
);
393 /** Creates and returns a new pivot table. */
394 PivotTable
& createPivotTable();
396 /** Inserts all pivot tables into the sheet. */
397 void finalizeImport();
400 typedef RefVector
< PivotTable
> PivotTableVector
;
401 PivotTableVector maTables
;
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */