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