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 <com/sun/star/table/CellRangeAddress.hpp>
24 #include "pivotcachebuffer.hxx"
25 #include "stylesbuffer.hxx"
27 namespace com
{ namespace sun
{ namespace star
{
28 namespace sheet
{ class XDataPilotDescriptor
; }
29 namespace sheet
{ class XDataPilotField
; }
39 struct PTFieldItemModel
41 sal_Int32 mnCacheItem
; /// Index to shared item in pivot cache.
42 sal_Int32 mnType
; /// Type of the item.
43 OUString msCaption
; /// User caption of the item
44 bool mbShowDetails
; /// True = show item details (items of child fields).
45 bool mbHidden
; /// True = item is hidden.
47 explicit PTFieldItemModel();
49 /** Sets item type for BIFF import. */
50 void setBiffType( sal_uInt16 nType
);
55 sal_Int32 mnAxis
; /// Axis this field is assigned to (none, row, column, page).
56 sal_Int32 mnNumFmtId
; /// Number format for field items.
57 sal_Int32 mnAutoShowItems
; /// Number of items (or percent/sum) to be shown in auto show filter.
58 sal_Int32 mnAutoShowRankBy
; /// Index of the data field auto show filter is based on.
59 sal_Int32 mnSortType
; /// Autosorting type.
60 sal_Int32 mnSortRefField
; /// Reference field for autosorting.
61 sal_Int32 mnSortRefItem
; /// Item in reference field for autosorting.
62 bool mbDataField
; /// True = field appears in data area.
63 bool mbDefaultSubtotal
; /// True = show default subtotals.
64 bool mbSumSubtotal
; /// True = show sum subtotals.
65 bool mbCountASubtotal
; /// True = show count all subtotals.
66 bool mbAverageSubtotal
; /// True = show average subtotals.
67 bool mbMaxSubtotal
; /// True = show maximum subtotals.
68 bool mbMinSubtotal
; /// True = show minimum subtotals.
69 bool mbProductSubtotal
; /// True = show product subtotals.
70 bool mbCountSubtotal
; /// True = show count numbers subtotals.
71 bool mbStdDevSubtotal
; /// True = show standard deviation subtotals.
72 bool mbStdDevPSubtotal
; /// True = show standard deviation of population subtotals.
73 bool mbVarSubtotal
; /// True = show variance subtotals.
74 bool mbVarPSubtotal
; /// True = show variance of population subtotals.
75 bool mbShowAll
; /// True = show items without data.
76 bool mbOutline
; /// True = show in outline view, false = show in tabular view.
77 bool mbSubtotalTop
; /// True = show subtotals on top of items in outline or compact mode.
78 bool mbInsertBlankRow
; /// True = insert blank rows after items.
79 bool mbInsertPageBreak
; /// True = insert page breaks after items.
80 bool mbAutoShow
; /// True = auto show (top 10) filter enabled.
81 bool mbTopAutoShow
; /// True = auto show filter shows top entries, false = bottom.
82 bool mbMultiPageItems
; /// True = multiple items selectable in page diemsion.
84 explicit PTFieldModel();
86 /** Sets axis type for BIFF import. */
87 void setBiffAxis( sal_uInt8 nAxisFlags
);
90 struct PTPageFieldModel
92 OUString maName
; /// Unique name of the page field.
93 sal_Int32 mnField
; /// Base pivot field.
94 sal_Int32 mnItem
; /// Index of field item that is shown by the page field.
96 explicit PTPageFieldModel();
99 struct PTDataFieldModel
101 OUString maName
; /// Name of the data field.
102 sal_Int32 mnField
; /// Base pivot field.
103 sal_Int32 mnSubtotal
; /// Subtotal aggregation function.
104 sal_Int32 mnShowDataAs
; /// Show data as, based on another field.
105 sal_Int32 mnBaseField
; /// Base field for 'show data as'.
106 sal_Int32 mnBaseItem
; /// Base item for 'show data as'.
107 sal_Int32 mnNumFmtId
; /// Number format for the result.
109 explicit PTDataFieldModel();
111 /** Sets the subtotal aggregation function for BIFF import. */
112 void setBiffSubtotal( sal_Int32 nSubtotal
);
113 /** Sets the 'show data as' type for BIFF import. */
114 void setBiffShowDataAs( sal_Int32 nShowDataAs
);
117 class PivotTableField
: public WorkbookHelper
120 explicit PivotTableField( PivotTable
& rPivotTable
, sal_Int32 nFieldIndex
);
122 /** Imports pivot field settings from the pivotField element. */
123 void importPivotField( const AttributeList
& rAttribs
);
124 /** Imports settings of an item in this pivot field from the item element. */
125 void importItem( const AttributeList
& rAttribs
);
126 /** Imports pivot field reference settings from the reference element. */
127 void importReference( const AttributeList
& rAttribs
);
128 /** Imports pivot field item reference settings from the x element. */
129 void importReferenceItem( const AttributeList
& rAttribs
);
131 /** Imports pivot field settings from the PTFIELD record. */
132 void importPTField( SequenceInputStream
& rStrm
);
133 /** Imports settings of an item in this pivot field from the PTFITEM record. */
134 void importPTFItem( SequenceInputStream
& rStrm
);
135 /** Imports pivot field reference settings from the PTREFERENCE record. */
136 void importPTReference( SequenceInputStream
& rStrm
);
137 /** Imports pivot field item reference settings from the PTREFERENCEITEM record. */
138 void importPTReferenceItem( SequenceInputStream
& rStrm
);
140 /** Finalizes the field after import, creates grouping and other settings. */
142 const ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotDescriptor
>& rxDPDesc
);
143 /** Finalizes the grouped date field after import. */
144 void finalizeDateGroupingImport(
145 const ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>& rxBaseDPField
,
146 sal_Int32 nBaseFieldIdx
);
147 /** Finalizes the grouped field after import. */
148 void finalizeParentGroupingImport(
149 const ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>& rxBaseDPField
,
150 const PivotCacheField
& rBaseCacheField
,
151 PivotCacheGroupItemVector
& orItemNames
);
153 /** Returns the name of the DataPilot field in the fields collection. */
154 inline const OUString
& getDPFieldName() const { return maDPFieldName
; }
156 /** Converts dimension and other settings for a row field. */
157 void convertRowField();
158 /** Converts dimension and other settings for a column field. */
159 void convertColField();
160 /** Converts dimension and other settings for a hidden field. */
161 void convertHiddenField();
162 /** Converts dimension and other settings for a page field */
163 void convertPageField( const PTPageFieldModel
& rPageField
);
164 /** Converts dimension and other settings for a data field. */
165 void convertDataField( const PTDataFieldModel
& rDataField
);
168 /** Converts dimension and other settings for row, column, page, or hidden fields. */
169 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>
170 convertRowColPageField( sal_Int32 nAxis
);
173 typedef ::std::vector
< PTFieldItemModel
> ItemModelVector
;
175 PivotTable
& mrPivotTable
; /// The parent pivot table object.
176 ItemModelVector maItems
; /// All items of this field.
177 PTFieldModel maModel
; /// Pivot field settings.
178 OUString maDPFieldName
; /// Name of the field in DataPilot field collection.
179 sal_Int32 mnFieldIndex
; /// Zero-based index of this field.
184 OUString maName
; /// Name of the field filter.
185 OUString maDescription
; /// Description of the field filter.
186 OUString maStrValue1
; /// First string value for label filter.
187 OUString maStrValue2
; /// Second string value for label filter.
188 double mfValue
; /// Number of items or percent or sum to be shown.
189 sal_Int32 mnField
; /// Base pivot field.
190 sal_Int32 mnMemPropField
; /// Member property field.
191 sal_Int32 mnType
; /// Filter type.
192 sal_Int32 mnEvalOrder
; /// Evaluation order index.
193 sal_Int32 mnId
; /// Unique identifier.
194 sal_Int32 mnMeasureField
; /// Data field for filter calculation.
195 sal_Int32 mnMeasureHier
; /// Hierarchy for filter calculation.
196 bool mbTopFilter
; /// True = filter shows top entries, false = bottom.
198 explicit PTFilterModel();
201 class PivotTableFilter
: public WorkbookHelper
204 explicit PivotTableFilter( const PivotTable
& rPivotTable
);
206 /** Reads the settings of a field filter from the filter element. */
207 void importFilter( const AttributeList
& rAttribs
);
208 /** Reads additional settings of a field filter from the top10 element. */
209 void importTop10( const AttributeList
& rAttribs
);
211 /** Reads the settings of a field filter from the PTFILTER record. */
212 void importPTFilter( SequenceInputStream
& rStrm
);
213 /** Reads additional settings of a field filter from the TOP10FILTER record. */
214 void importTop10Filter( SequenceInputStream
& rStrm
);
216 /** Applies the filter to the associated pivot table field if possible. */
217 void finalizeImport();
220 const PivotTable
& mrPivotTable
;
221 PTFilterModel maModel
;
224 struct PTDefinitionModel
: public AutoFormatModel
227 OUString maDataCaption
;
228 OUString maGrandTotalCaption
;
229 OUString maRowHeaderCaption
;
230 OUString maColHeaderCaption
;
231 OUString maErrorCaption
;
232 OUString maMissingCaption
;
233 OUString maPageStyle
;
234 OUString maPivotTableStyle
;
235 OUString maVacatedStyle
;
238 sal_Int32 mnDataPosition
;
239 sal_Int32 mnPageWrap
;
241 sal_Int32 mnChartFormat
;
242 sal_uInt16 mnRowFields
;
243 sal_uInt16 mnColFields
;
248 bool mbDisableFieldList
;
249 bool mbShowCalcMembers
;
254 bool mbPreserveFormatting
;
255 bool mbUseAutoFormat
;
256 bool mbPageOverThenDown
;
257 bool mbSubtotalHiddenItems
;
258 bool mbRowGrandTotals
;
259 bool mbColGrandTotals
;
260 bool mbFieldPrintTitles
;
261 bool mbItemPrintTitles
;
266 bool mbFieldListSortAsc
;
267 bool mbCustomListSort
;
269 explicit PTDefinitionModel();
272 struct PTLocationModel
274 ::com::sun::star::table::CellRangeAddress
275 maRange
; /// Target cell range for the pivot table.
276 sal_Int32 mnFirstHeaderRow
; /// First row of header cells (relative in pivot table).
277 sal_Int32 mnFirstDataRow
; /// First row of data cells (relative in pivot table).
278 sal_Int32 mnFirstDataCol
; /// First column of data cells (relative in pivot table).
279 sal_Int32 mnRowPageCount
; /// Number of rows in page filter area.
280 sal_Int32 mnColPageCount
; /// Number of columns in page filter area.
282 explicit PTLocationModel();
285 class PivotTable
: public WorkbookHelper
288 explicit PivotTable( const WorkbookHelper
& rHelper
);
290 /** Reads global pivot table settings from the pivotTableDefinition element. */
291 void importPivotTableDefinition( const AttributeList
& rAttribs
);
292 /** Reads the location of the pivot table from the location element. */
293 void importLocation( const AttributeList
& rAttribs
, sal_Int16 nSheet
);
294 /** Reads the index of a field located in the row dimension. */
295 void importRowField( const AttributeList
& rAttribs
);
296 /** Reads the index of a field located in the column dimension. */
297 void importColField( const AttributeList
& rAttribs
);
298 /** Reads the settings of a field located in the page dimension from the pageField element. */
299 void importPageField( const AttributeList
& rAttribs
);
300 /** Reads the settings of a field located in the data dimension from the dataField element. */
301 void importDataField( 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 /** Creates all date group fields for the specified cache field after import. */
323 void finalizeDateGroupingImport(
324 const ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>& rxBaseDPField
,
325 sal_Int32 nBaseFieldIdx
);
326 /** Creates all grouped fields for the specified cache field after import. */
327 void finalizeParentGroupingImport(
328 const ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>& rxBaseDPField
,
329 const PivotCacheField
& rBaseCacheField
,
330 PivotCacheGroupItemVector
& orItemNames
);
332 /** Returns the associated data pilot field for the specified pivot table field. */
333 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>
334 getDataPilotField( const OUString
& rFieldName
) const;
335 /** Returns the associated data pilot field for the specified pivot table field. */
336 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>
337 getDataPilotField( sal_Int32 nFieldIdx
) const;
338 /** Returns the data layout field used to store all data fields in row/col dimension. */
339 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotField
>
340 getDataLayoutField() const;
342 /** Returns the cache field with the specified index. */
343 const PivotCacheField
* getCacheField( sal_Int32 nFieldIdx
) const;
344 /** Returns the base cache field of the data field item with the specified index. */
345 const PivotCacheField
* getCacheFieldOfDataField( sal_Int32 nDataItemIdx
) const;
346 /** Returns the source column index of the pivot field with the passed index, or -1. */
347 sal_Int32
getCacheDatabaseIndex( sal_Int32 nFieldIdx
) const;
349 ScDPObject
* getDPObject() { return mpDPObject
; }
352 typedef RefVector
< PivotTableField
> PivotTableFieldVector
;
353 typedef RefVector
< PivotTableFilter
> PivotTableFilterVector
;
354 typedef ::std::vector
< sal_Int32
> IndexVector
;
355 typedef ::std::vector
< PTPageFieldModel
> PageFieldVector
;
356 typedef ::std::vector
< PTDataFieldModel
> DataFieldVector
;
359 /** Returns a pivot table field by its index. */
360 PivotTableField
* getTableField( sal_Int32 nFieldIdx
);
362 /** Reads a field index for the row or column dimension. */
363 static void importField( IndexVector
& orFields
, const AttributeList
& rAttribs
);
364 /** Reads an array of field indexes for the row or column dimension. */
365 static void importFields( IndexVector
& orFields
, SequenceInputStream
& rStrm
);
368 ScDPObject
* mpDPObject
;
369 PivotTableFieldVector maFields
; /// All pivot table fields.
370 PivotTableField maDataField
; /// Data layout field.
371 IndexVector maRowFields
; /// Indexes to fields in row dimension.
372 IndexVector maColFields
; /// Indexes to fields in column dimension.
373 PageFieldVector maPageFields
; /// Settings for all fields in page dimension.
374 DataFieldVector maDataFields
; /// Settings for all fields in data area.
375 PivotTableFilterVector maFilters
; /// All field filters.
376 PTDefinitionModel maDefModel
; /// Global pivot table settings.
377 PTLocationModel maLocationModel
; /// Location settings of the pivot table.
378 const PivotCache
* mpPivotCache
; /// The pivot cache this table is based on.
379 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XDataPilotDescriptor
>
380 mxDPDescriptor
; /// Descriptor of the DataPilot object.
383 class PivotTableBuffer
: public WorkbookHelper
386 explicit PivotTableBuffer( const WorkbookHelper
& rHelper
);
388 /** Creates and returns a new pivot table. */
389 PivotTable
& createPivotTable();
391 /** Inserts all pivot tables into the sheet. */
392 void finalizeImport();
395 typedef RefVector
< PivotTable
> PivotTableVector
;
396 PivotTableVector maTables
;
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */