Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / pivottablebuffer.hxx
blob7b7f22320fb714ec637676eb992473a9310ae599
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include "pivotcachebuffer.hxx"
23 #include "stylesbuffer.hxx"
25 namespace com::sun::star {
26 namespace sheet { class XDataPilotDescriptor; }
27 namespace sheet { class XDataPilotField; }
30 class ScDPObject;
32 namespace oox::xls {
34 class PivotTable;
36 struct PTFieldItemModel
38 sal_Int32 mnCacheItem; /// Index to shared item in pivot cache.
39 sal_Int32 mnType; /// Type of the item.
40 OUString msCaption; /// User caption of the item
41 bool mbShowDetails; /// True = show item details (items of child fields).
42 bool mbHidden; /// True = item is hidden.
44 explicit PTFieldItemModel();
46 /** Sets item type for BIFF import. */
47 void setBiffType( sal_uInt16 nType );
50 struct PTFieldModel
52 sal_Int32 mnAxis; /// Axis this field is assigned to (none, row, column, page).
53 sal_Int32 mnNumFmtId; /// Number format for field items.
54 sal_Int32 mnAutoShowItems; /// Number of items (or percent/sum) to be shown in auto show filter.
55 sal_Int32 mnAutoShowRankBy; /// Index of the data field auto show filter is based on.
56 sal_Int32 mnSortType; /// Autosorting type.
57 sal_Int32 mnSortRefField; /// Reference field for autosorting.
58 sal_Int32 mnSortRefItem; /// Item in reference field for autosorting.
59 bool mbDataField; /// True = field appears in data area.
60 bool mbDefaultSubtotal; /// True = show default subtotals.
61 bool mbSumSubtotal; /// True = show sum subtotals.
62 bool mbCountASubtotal; /// True = show count all subtotals.
63 bool mbAverageSubtotal; /// True = show average subtotals.
64 bool mbMaxSubtotal; /// True = show maximum subtotals.
65 bool mbMinSubtotal; /// True = show minimum subtotals.
66 bool mbProductSubtotal; /// True = show product subtotals.
67 bool mbCountSubtotal; /// True = show count numbers subtotals.
68 bool mbStdDevSubtotal; /// True = show standard deviation subtotals.
69 bool mbStdDevPSubtotal; /// True = show standard deviation of population subtotals.
70 bool mbVarSubtotal; /// True = show variance subtotals.
71 bool mbVarPSubtotal; /// True = show variance of population subtotals.
72 bool mbShowAll; /// True = show items without data.
73 bool mbOutline; /// True = show in outline view, false = show in tabular view.
74 bool mbSubtotalTop; /// True = show subtotals on top of items in outline or compact mode.
75 bool mbInsertBlankRow; /// True = insert blank rows after items.
76 bool mbInsertPageBreak; /// True = insert page breaks after items.
77 bool mbAutoShow; /// True = auto show (top 10) filter enabled.
78 bool mbTopAutoShow; /// True = auto show filter shows top entries, false = bottom.
79 bool mbMultiPageItems; /// True = multiple items selectable in page dimension.
81 explicit PTFieldModel();
83 /** Sets axis type for BIFF import. */
84 void setBiffAxis( sal_uInt8 nAxisFlags );
87 struct PTPageFieldModel
89 OUString maName; /// Unique name of the page field.
90 sal_Int32 mnField; /// Base pivot field.
91 sal_Int32 mnItem; /// Index of field item that is shown by the page field.
93 explicit PTPageFieldModel();
96 struct PTDataFieldModel
98 OUString maName; /// Name of the data field.
99 sal_Int32 mnField; /// Base pivot field.
100 sal_Int32 mnSubtotal; /// Subtotal aggregation function.
101 sal_Int32 mnShowDataAs; /// Show data as, based on another field.
102 sal_Int32 mnBaseField; /// Base field for 'show data as'.
103 sal_Int32 mnBaseItem; /// Base item for 'show data as'.
104 sal_Int32 mnNumFmtId; /// Number format for the result.
106 explicit PTDataFieldModel();
108 /** Sets the subtotal aggregation function for BIFF import. */
109 void setBiffSubtotal( sal_Int32 nSubtotal );
110 /** Sets the 'show data as' type for BIFF import. */
111 void setBiffShowDataAs( sal_Int32 nShowDataAs );
114 class PivotTableField : public WorkbookHelper
116 public:
117 explicit PivotTableField( PivotTable& rPivotTable, sal_Int32 nFieldIndex );
119 /** Imports pivot field settings from the pivotField element. */
120 void importPivotField( const AttributeList& rAttribs );
121 /** Imports settings of an item in this pivot field from the item element. */
122 void importItem( const AttributeList& rAttribs );
123 /** Imports pivot field reference settings from the reference element. */
124 void importReference( const AttributeList& rAttribs );
125 /** Imports pivot field item reference settings from the x element. */
126 void importReferenceItem( const AttributeList& rAttribs );
128 /** Imports pivot field settings from the PTFIELD record. */
129 void importPTField( SequenceInputStream& rStrm );
130 /** Imports settings of an item in this pivot field from the PTFITEM record. */
131 void importPTFItem( SequenceInputStream& rStrm );
132 /** Imports pivot field reference settings from the PTREFERENCE record. */
133 void importPTReference( SequenceInputStream& rStrm );
134 /** Imports pivot field item reference settings from the PTREFERENCEITEM record. */
135 void importPTReferenceItem( SequenceInputStream& rStrm );
137 /** Finalizes the field after import, creates grouping and other settings. */
138 void finalizeImport(
139 const css::uno::Reference< css::sheet::XDataPilotDescriptor >& rxDPDesc );
140 /** Finalizes the grouped date field after import. */
141 void finalizeDateGroupingImport(
142 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
143 sal_Int32 nBaseFieldIdx );
144 /** Finalizes the grouped field after import. */
145 void finalizeParentGroupingImport(
146 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
147 const PivotCacheField& rBaseCacheField,
148 PivotCacheGroupItemVector& orItemNames );
149 void finalizeImportBasedOnCache(
150 const css::uno::Reference< css::sheet::XDataPilotDescriptor >& rxDPDesc);
152 /** Returns the name of the DataPilot field in the fields collection. */
153 const OUString& getDPFieldName() const { return maDPFieldName; }
155 /** Converts dimension and other settings for a row field. */
156 void convertRowField();
157 /** Converts dimension and other settings for a column field. */
158 void convertColField();
159 /** Converts dimension and other settings for a hidden field. */
160 void convertHiddenField();
161 /** Converts dimension and other settings for a page field */
162 void convertPageField( const PTPageFieldModel& rPageField );
163 /** Converts dimension and other settings for a data field. */
164 void convertDataField( const PTDataFieldModel& rDataField );
166 private:
167 /** Converts dimension and other settings for row, column, page, or hidden fields. */
168 css::uno::Reference< css::sheet::XDataPilotField >
169 convertRowColPageField( sal_Int32 nAxis );
171 private:
172 typedef ::std::vector< PTFieldItemModel > ItemModelVector;
174 PivotTable& mrPivotTable; /// The parent pivot table object.
175 ItemModelVector maItems; /// All items of this field.
176 PTFieldModel maModel; /// Pivot field settings.
177 OUString maDPFieldName; /// Name of the field in DataPilot field collection.
178 sal_Int32 mnFieldIndex; /// Zero-based index of this field.
181 struct PTFilterModel
183 OUString maName; /// Name of the field filter.
184 OUString maDescription; /// Description of the field filter.
185 OUString maStrValue1; /// First string value for label filter.
186 OUString maStrValue2; /// Second string value for label filter.
187 double mfValue; /// Number of items or percent or sum to be shown.
188 sal_Int32 mnField; /// Base pivot field.
189 sal_Int32 mnMemPropField; /// Member property field.
190 sal_Int32 mnType; /// Filter type.
191 sal_Int32 mnEvalOrder; /// Evaluation order index.
192 sal_Int32 mnId; /// Unique identifier.
193 sal_Int32 mnMeasureField; /// Data field for filter calculation.
194 sal_Int32 mnMeasureHier; /// Hierarchy for filter calculation.
195 bool mbTopFilter; /// True = filter shows top entries, false = bottom.
197 explicit PTFilterModel();
200 class PivotTableFilter : public WorkbookHelper
202 public:
203 explicit PivotTableFilter( const PivotTable& rPivotTable );
205 /** Reads the settings of a field filter from the filter element. */
206 void importFilter( const AttributeList& rAttribs );
207 /** Reads additional settings of a field filter from the top10 element. */
208 void importTop10( const AttributeList& rAttribs );
210 /** Reads the settings of a field filter from the PTFILTER record. */
211 void importPTFilter( SequenceInputStream& rStrm );
212 /** Reads additional settings of a field filter from the TOP10FILTER record. */
213 void importTop10Filter( SequenceInputStream& rStrm );
215 /** Applies the filter to the associated pivot table field if possible. */
216 void finalizeImport();
218 private:
219 const PivotTable& mrPivotTable;
220 PTFilterModel maModel;
223 struct PTDefinitionModel : public AutoFormatModel
225 OUString maName;
226 OUString maDataCaption;
227 OUString maGrandTotalCaption;
228 OUString maRowHeaderCaption;
229 OUString maColHeaderCaption;
230 OUString maErrorCaption;
231 OUString maMissingCaption;
232 OUString maPageStyle;
233 OUString maPivotTableStyle;
234 OUString maVacatedStyle;
235 OUString maTag;
236 sal_Int32 mnCacheId;
237 sal_Int32 mnDataPosition;
238 sal_Int32 mnPageWrap;
239 sal_Int32 mnIndent;
240 sal_Int32 mnChartFormat;
241 bool mbDataOnRows;
242 bool mbShowError;
243 bool mbShowMissing;
244 bool mbShowItems;
245 bool mbDisableFieldList;
246 bool mbShowCalcMembers;
247 bool mbVisualTotals;
248 bool mbShowDrill;
249 bool mbPrintDrill;
250 bool mbEnableDrill;
251 bool mbPreserveFormatting;
252 bool mbUseAutoFormat;
253 bool mbPageOverThenDown;
254 bool mbSubtotalHiddenItems;
255 bool mbRowGrandTotals;
256 bool mbColGrandTotals;
257 bool mbFieldPrintTitles;
258 bool mbItemPrintTitles;
259 bool mbMergeItem;
260 bool mbShowEmptyRow;
261 bool mbShowEmptyCol;
262 bool mbShowHeaders;
263 bool mbFieldListSortAsc;
264 bool mbCustomListSort;
266 explicit PTDefinitionModel();
269 struct PTLocationModel
271 ScRange maRange; /// Target cell range for the pivot table.
272 sal_Int32 mnFirstHeaderRow; /// First row of header cells (relative in pivot table).
273 sal_Int32 mnFirstDataRow; /// First row of data cells (relative in pivot table).
274 sal_Int32 mnFirstDataCol; /// First column of data cells (relative in pivot table).
275 sal_Int32 mnRowPageCount; /// Number of rows in page filter area.
276 sal_Int32 mnColPageCount; /// Number of columns in page filter area.
278 explicit PTLocationModel();
281 class PivotTable : public WorkbookHelper
283 public:
284 explicit PivotTable( const WorkbookHelper& rHelper );
286 /** Reads global pivot table settings from the pivotTableDefinition element. */
287 void importPivotTableDefinition( const AttributeList& rAttribs );
288 /** Reads the location of the pivot table from the location element. */
289 void importLocation( const AttributeList& rAttribs, sal_Int16 nSheet );
290 /** Reads the index of a field located in the row dimension. */
291 void importRowField( const AttributeList& rAttribs );
292 /** Reads the index of a field located in the column dimension. */
293 void importColField( const AttributeList& rAttribs );
294 /** Reads the settings of a field located in the page dimension from the pageField element. */
295 void importPageField( const AttributeList& rAttribs );
296 /** Reads the settings of a field located in the data dimension from the dataField element. */
297 void importDataField( const AttributeList& rAttribs );
298 /** Puts the attributes to the named grab bag value. */
299 void putToInteropGrabBag(const OUString& sName, const AttributeList& rAttribs);
301 /** Reads global pivot table settings from the PTDEFINITION record. */
302 void importPTDefinition( SequenceInputStream& rStrm );
303 /** Reads the location of the pivot table from the PTLOCATION record. */
304 void importPTLocation( SequenceInputStream& rStrm, sal_Int16 nSheet );
305 /** Reads the indexes of all fields located in the row dimension from a PTROWFIELDS record. */
306 void importPTRowFields( SequenceInputStream& rStrm );
307 /** Reads the indexes of all fields located in the column dimension from a PTCOLFIELDS record. */
308 void importPTColFields( SequenceInputStream& rStrm );
309 /** Reads the settings of a field located in the page dimension from the PTPAGEFIELD record. */
310 void importPTPageField( SequenceInputStream& rStrm );
311 /** Reads the settings of a field located in the data dimension from the PTDATAFIELD record. */
312 void importPTDataField( SequenceInputStream& rStrm );
314 /** Creates and returns a new pivot table field. */
315 PivotTableField& createTableField();
316 /** Creates and returns a new pivot table filter. */
317 PivotTableFilter& createTableFilter();
318 /** Inserts the pivot table into the sheet. */
319 void finalizeImport();
320 /** Finalizes all fields, finds field names and creates grouping fields. */
321 void finalizeFieldsImport();
322 /** Creates all date group fields for the specified cache field after import. */
323 void finalizeDateGroupingImport(
324 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
325 sal_Int32 nBaseFieldIdx );
326 /** Creates all grouped fields for the specified cache field after import. */
327 void finalizeParentGroupingImport(
328 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
329 const PivotCacheField& rBaseCacheField,
330 PivotCacheGroupItemVector& orItemNames );
332 /** Returns the associated data pilot field for the specified pivot table field. */
333 css::uno::Reference< css::sheet::XDataPilotField >
334 getDataPilotField( const OUString& rFieldName ) const;
335 /** Returns the associated data pilot field for the specified pivot table field. */
336 css::uno::Reference< css::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 css::uno::Reference< css::sheet::XDataPilotField >
340 getDataLayoutField() const;
342 /** Returns the cache field with the specified index. */
343 PivotCacheField* getCacheField( sal_Int32 nFieldIdx );
344 const PivotCacheField* getCacheField( sal_Int32 nFieldIdx ) const;
345 /** Returns the base cache field of the data field item with the specified index. */
346 const PivotCacheField* getCacheFieldOfDataField( sal_Int32 nDataItemIdx ) const;
347 /** Returns the source column index of the pivot field with the passed index, or -1. */
348 sal_Int32 getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const;
350 ScDPObject* getDPObject() { return mpDPObject; }
352 private:
353 typedef RefVector< PivotTableField > PivotTableFieldVector;
354 typedef RefVector< PivotTableFilter > PivotTableFilterVector;
355 typedef ::std::vector< sal_Int32 > IndexVector;
356 typedef ::std::vector< PTPageFieldModel > PageFieldVector;
357 typedef ::std::vector< PTDataFieldModel > DataFieldVector;
359 private:
360 /** Returns a pivot table field by its index. */
361 PivotTableField* getTableField( sal_Int32 nFieldIdx );
363 /** Reads a field index for the row or column dimension. */
364 static void importField( IndexVector& orFields, const AttributeList& rAttribs );
365 /** Reads an array of field indexes for the row or column dimension. */
366 static void importFields( IndexVector& orFields, SequenceInputStream& rStrm );
368 private:
369 ScDPObject* mpDPObject;
370 PivotTableFieldVector maFields; /// All pivot table fields.
371 PivotTableField maDataField; /// Data layout field.
372 IndexVector maRowFields; /// Indexes to fields in row dimension.
373 IndexVector maColFields; /// Indexes to fields in column dimension.
374 PageFieldVector maPageFields; /// Settings for all fields in page dimension.
375 DataFieldVector maDataFields; /// Settings for all fields in data area.
376 PivotTableFilterVector maFilters; /// All field filters.
377 PTDefinitionModel maDefModel; /// Global pivot table settings.
378 PTLocationModel maLocationModel; /// Location settings of the pivot table.
379 PivotCache* mpPivotCache; /// The pivot cache this table is based on.
380 css::uno::Reference< css::sheet::XDataPilotDescriptor >
381 mxDPDescriptor; /// Descriptor of the DataPilot object.
382 std::map<OUString, css::uno::Any> maInteropGrabBag;
386 class PivotTableBuffer : public WorkbookHelper
388 public:
389 explicit PivotTableBuffer( const WorkbookHelper& rHelper );
391 /** Creates and returns a new pivot table. */
392 PivotTable& createPivotTable();
394 /** Inserts all pivot tables into the sheet. */
395 void finalizeImport();
397 private:
398 typedef RefVector< PivotTable > PivotTableVector;
399 PivotTableVector maTables;
402 } // namespace oox::xls
404 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */