Get the style color and number just once
[LibreOffice.git] / sc / source / filter / inc / pivottablebuffer.hxx
blob2c032277e90e6d77a8deec227184881fdf7f3c2f
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 "PivotTableFormat.hxx"
24 #include "stylesbuffer.hxx"
25 #include <rtl/ref.hxx>
27 namespace com::sun::star {
28 namespace sheet { class XDataPilotDescriptor; }
29 namespace sheet { class XDataPilotField; }
32 class ScDPObject;
33 class ScDataPilotDescriptorBase;
35 namespace oox::xls {
37 class PivotTable;
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 );
53 struct PTFieldModel
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 mbCompact; /// True = show in compact view, false = show in either outline or tabular view.
79 bool mbInsertBlankRow; /// True = insert blank rows after items.
80 bool mbInsertPageBreak; /// True = insert page breaks after items.
81 bool mbAutoShow; /// True = auto show (top 10) filter enabled.
82 bool mbTopAutoShow; /// True = auto show filter shows top entries, false = bottom.
83 bool mbMultiPageItems; /// True = multiple items selectable in page dimension.
85 explicit PTFieldModel();
87 /** Sets axis type for BIFF import. */
88 void setBiffAxis( sal_uInt8 nAxisFlags );
91 struct PTPageFieldModel
93 OUString maName; /// Unique name of the page field.
94 sal_Int32 mnField; /// Base pivot field.
95 sal_Int32 mnItem; /// Index of field item that is shown by the page field.
97 explicit PTPageFieldModel();
100 struct PTDataFieldModel
102 OUString maName; /// Name of the data field.
103 sal_Int32 mnField; /// Base pivot field.
104 sal_Int32 mnSubtotal; /// Subtotal aggregation function.
105 sal_Int32 mnShowDataAs; /// Show data as, based on another field.
106 sal_Int32 mnBaseField; /// Base field for 'show data as'.
107 sal_Int32 mnBaseItem; /// Base item for 'show data as'.
108 sal_Int32 mnNumFmtId; /// Number format for the result.
110 explicit PTDataFieldModel();
112 /** Sets the subtotal aggregation function for BIFF import. */
113 void setBiffSubtotal( sal_Int32 nSubtotal );
114 /** Sets the 'show data as' type for BIFF import. */
115 void setBiffShowDataAs( sal_Int32 nShowDataAs );
118 class PivotTableField : public WorkbookHelper
120 public:
121 explicit PivotTableField( PivotTable& rPivotTable, sal_Int32 nFieldIndex );
123 /** Imports pivot field settings from the pivotField element. */
124 void importPivotField( const AttributeList& rAttribs );
125 /** Imports settings of an item in this pivot field from the item element. */
126 void importItem( const AttributeList& rAttribs );
127 /** Imports pivot field reference settings from the reference element. */
128 void importReference( const AttributeList& rAttribs );
129 /** Imports pivot field item reference settings from the x element. */
130 void importReferenceItem( const AttributeList& rAttribs );
132 /** Imports pivot field settings from the PTFIELD record. */
133 void importPTField( SequenceInputStream& rStrm );
134 /** Imports settings of an item in this pivot field from the PTFITEM record. */
135 void importPTFItem( SequenceInputStream& rStrm );
136 /** Imports pivot field reference settings from the PTREFERENCE record. */
137 void importPTReference( SequenceInputStream& rStrm );
138 /** Imports pivot field item reference settings from the PTREFERENCEITEM record. */
139 void importPTReferenceItem( SequenceInputStream& rStrm );
141 /** Finalizes the field after import, creates grouping and other settings. */
142 void finalizeImport(
143 const css::uno::Reference< css::sheet::XDataPilotDescriptor >& rxDPDesc );
144 /** Finalizes the grouped date field after import. */
145 void finalizeDateGroupingImport(
146 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
147 sal_Int32 nBaseFieldIdx );
148 /** Finalizes the grouped field after import. */
149 void finalizeParentGroupingImport(
150 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
151 const PivotCacheField& rBaseCacheField,
152 PivotCacheGroupItemVector& orItemNames );
153 void finalizeImportBasedOnCache(
154 const css::uno::Reference< css::sheet::XDataPilotDescriptor >& rxDPDesc);
156 /** Returns the name of the DataPilot field in the fields collection. */
157 const OUString& getDPFieldName() const { return maDPFieldName; }
159 /** Converts dimension and other settings for a row field. */
160 void convertRowField();
161 /** Converts dimension and other settings for a column field. */
162 void convertColField();
163 /** Converts dimension and other settings for a hidden field. */
164 void convertHiddenField();
165 /** Converts dimension and other settings for a page field */
166 void convertPageField( const PTPageFieldModel& rPageField );
167 /** Converts dimension and other settings for a data field. */
168 void convertDataField( const PTDataFieldModel& rDataField );
170 private:
171 /** Converts dimension and other settings for row, column, page, or hidden fields. */
172 css::uno::Reference< css::sheet::XDataPilotField >
173 convertRowColPageField( sal_Int32 nAxis );
175 private:
176 typedef ::std::vector< PTFieldItemModel > ItemModelVector;
178 PivotTable& mrPivotTable; /// The parent pivot table object.
179 ItemModelVector maItems; /// All items of this field.
180 PTFieldModel maModel; /// Pivot field settings.
181 OUString maDPFieldName; /// Name of the field in DataPilot field collection.
182 sal_Int32 mnFieldIndex; /// Zero-based index of this field.
185 struct PTFilterModel
187 OUString maName; /// Name of the field filter.
188 OUString maDescription; /// Description of the field filter.
189 OUString maStrValue1; /// First string value for label filter.
190 OUString maStrValue2; /// Second string value for label filter.
191 double mfValue; /// Number of items or percent or sum to be shown.
192 sal_Int32 mnField; /// Base pivot field.
193 sal_Int32 mnMemPropField; /// Member property field.
194 sal_Int32 mnType; /// Filter type.
195 sal_Int32 mnEvalOrder; /// Evaluation order index.
196 sal_Int32 mnId; /// Unique identifier.
197 sal_Int32 mnMeasureField; /// Data field for filter calculation.
198 sal_Int32 mnMeasureHier; /// Hierarchy for filter calculation.
199 bool mbTopFilter; /// True = filter shows top entries, false = bottom.
201 explicit PTFilterModel();
204 class PivotTableFilter : public WorkbookHelper
206 public:
207 explicit PivotTableFilter( const PivotTable& rPivotTable );
209 /** Reads the settings of a field filter from the filter element. */
210 void importFilter( const AttributeList& rAttribs );
211 /** Reads additional settings of a field filter from the top10 element. */
212 void importTop10( const AttributeList& rAttribs );
214 /** Reads the settings of a field filter from the PTFILTER record. */
215 void importPTFilter( SequenceInputStream& rStrm );
216 /** Reads additional settings of a field filter from the TOP10FILTER record. */
217 void importTop10Filter( SequenceInputStream& rStrm );
219 /** Applies the filter to the associated pivot table field if possible. */
220 void finalizeImport();
222 private:
223 const PivotTable& mrPivotTable;
224 PTFilterModel maModel;
227 struct PTDefinitionModel : public AutoFormatModel
229 OUString maName;
230 OUString maDataCaption;
231 OUString maGrandTotalCaption;
232 OUString maRowHeaderCaption;
233 OUString maColHeaderCaption;
234 OUString maErrorCaption;
235 OUString maMissingCaption;
236 OUString maPageStyle;
237 OUString maPivotTableStyle;
238 OUString maVacatedStyle;
239 OUString maTag;
240 sal_Int32 mnCacheId;
241 sal_Int32 mnDataPosition;
242 sal_Int32 mnPageWrap;
243 sal_Int32 mnIndent;
244 sal_Int32 mnChartFormat;
245 bool mbDataOnRows;
246 bool mbShowError;
247 bool mbShowMissing;
248 bool mbShowItems;
249 bool mbDisableFieldList;
250 bool mbShowCalcMembers;
251 bool mbVisualTotals;
252 bool mbShowDrill;
253 bool mbPrintDrill;
254 bool mbEnableDrill;
255 bool mbPreserveFormatting;
256 bool mbUseAutoFormat;
257 bool mbPageOverThenDown;
258 bool mbSubtotalHiddenItems;
259 bool mbRowGrandTotals;
260 bool mbColGrandTotals;
261 bool mbFieldPrintTitles;
262 bool mbItemPrintTitles;
263 bool mbMergeItem;
264 bool mbShowEmptyRow;
265 bool mbShowEmptyCol;
266 bool mbShowHeaders;
267 bool mbFieldListSortAsc;
268 bool mbCustomListSort;
270 explicit PTDefinitionModel();
273 struct PTLocationModel
275 ScRange 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
287 public:
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 );
302 /** Puts the attributes to the named grab bag value. */
303 void putToInteropGrabBag(const OUString& sName, const AttributeList& rAttribs);
305 /** Reads global pivot table settings from the PTDEFINITION record. */
306 void importPTDefinition( SequenceInputStream& rStrm );
307 /** Reads the location of the pivot table from the PTLOCATION record. */
308 void importPTLocation( SequenceInputStream& rStrm, sal_Int16 nSheet );
309 /** Reads the indexes of all fields located in the row dimension from a PTROWFIELDS record. */
310 void importPTRowFields( SequenceInputStream& rStrm );
311 /** Reads the indexes of all fields located in the column dimension from a PTCOLFIELDS record. */
312 void importPTColFields( SequenceInputStream& rStrm );
313 /** Reads the settings of a field located in the page dimension from the PTPAGEFIELD record. */
314 void importPTPageField( SequenceInputStream& rStrm );
315 /** Reads the settings of a field located in the data dimension from the PTDATAFIELD record. */
316 void importPTDataField( SequenceInputStream& rStrm );
318 /** Creates and returns a new pivot table field. */
319 PivotTableField& createTableField();
320 /** Creates and returns a new pivot table filter. */
321 PivotTableFilter& createTableFilter();
322 /** Creates and returns a new pivot table format. */
323 PivotTableFormat& createFormat();
324 /** Inserts the pivot table into the sheet. */
325 void finalizeImport();
326 /** Finalizes all fields, finds field names and creates grouping fields. */
327 void finalizeFieldsImport();
328 /** Creates all date group fields for the specified cache field after import. */
329 void finalizeDateGroupingImport(
330 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
331 sal_Int32 nBaseFieldIdx );
332 /** Creates all grouped fields for the specified cache field after import. */
333 void finalizeParentGroupingImport(
334 const css::uno::Reference< css::sheet::XDataPilotField >& rxBaseDPField,
335 const PivotCacheField& rBaseCacheField,
336 PivotCacheGroupItemVector& orItemNames );
338 /** Returns the associated data pilot field for the specified pivot table field. */
339 css::uno::Reference< css::sheet::XDataPilotField >
340 getDataPilotField( const OUString& rFieldName ) const;
341 /** Returns the associated data pilot field for the specified pivot table field. */
342 css::uno::Reference< css::sheet::XDataPilotField >
343 getDataPilotField( sal_Int32 nFieldIdx ) const;
344 /** Returns the data layout field used to store all data fields in row/col dimension. */
345 css::uno::Reference< css::sheet::XDataPilotField >
346 getDataLayoutField() const;
348 /** Returns the cache field with the specified index. */
349 PivotCacheField* getCacheField( sal_Int32 nFieldIdx );
350 const PivotCacheField* getCacheField( sal_Int32 nFieldIdx ) const;
351 /** Returns the base cache field of the data field item with the specified index. */
352 const PivotCacheField* getCacheFieldOfDataField( sal_Int32 nDataItemIdx ) const;
353 /** Returns the source column index of the pivot field with the passed index, or -1. */
354 sal_Int32 getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const;
356 ScDPObject* getDPObject() { return mpDPObject; }
358 private:
359 typedef RefVector< PivotTableField > PivotTableFieldVector;
360 typedef RefVector< PivotTableFilter > PivotTableFilterVector;
361 typedef ::std::vector< sal_Int32 > IndexVector;
362 typedef ::std::vector< PTPageFieldModel > PageFieldVector;
363 typedef ::std::vector< PTDataFieldModel > DataFieldVector;
365 private:
366 /** Returns a pivot table field by its index. */
367 PivotTableField* getTableField( sal_Int32 nFieldIdx );
369 /** Reads a field index for the row or column dimension. */
370 static void importField( IndexVector& orFields, const AttributeList& rAttribs );
371 /** Reads an array of field indexes for the row or column dimension. */
372 static void importFields( IndexVector& orFields, SequenceInputStream& rStrm );
374 private:
375 ScDPObject* mpDPObject;
376 PivotTableFieldVector maFields; /// All pivot table fields.
377 PivotTableField maDataField; /// Data layout field.
378 IndexVector maRowFields; /// Indexes to fields in row dimension.
379 IndexVector maColFields; /// Indexes to fields in column dimension.
380 PageFieldVector maPageFields; /// Settings for all fields in page dimension.
381 DataFieldVector maDataFields; /// Settings for all fields in data area.
382 PivotTableFilterVector maFilters; /// All field filters.
383 PivotTableFormatVector maFormats;
384 PTDefinitionModel maDefModel; /// Global pivot table settings.
385 PTLocationModel maLocationModel; /// Location settings of the pivot table.
386 PivotCache* mpPivotCache; /// The pivot cache this table is based on.
387 rtl::Reference< ScDataPilotDescriptorBase > // css::sheet::XDataPilotDescriptor
388 mxDPDescriptor; /// Descriptor of the DataPilot object.
389 std::map<OUString, css::uno::Any> maInteropGrabBag;
393 class PivotTableBuffer : public WorkbookHelper
395 public:
396 explicit PivotTableBuffer( const WorkbookHelper& rHelper );
398 /** Creates and returns a new pivot table. */
399 PivotTable& createPivotTable();
401 /** Inserts all pivot tables into the sheet. */
402 void finalizeImport();
404 private:
405 typedef RefVector< PivotTable > PivotTableVector;
406 PivotTableVector maTables;
409 } // namespace oox::xls
411 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */