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