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_PIVOTCACHEBUFFER_HXX
30 : : #define OOX_XLS_PIVOTCACHEBUFFER_HXX
31 : :
32 : : #include <com/sun/star/table/CellAddress.hpp>
33 : : #include <com/sun/star/table/CellRangeAddress.hpp>
34 : : #include <com/sun/star/util/DateTime.hpp>
35 : : #include "oox/helper/containerhelper.hxx"
36 : : #include "oox/helper/refvector.hxx"
37 : : #include "workbookhelper.hxx"
38 : :
39 : : namespace com { namespace sun { namespace star {
40 : : namespace sheet { class XDataPilotField; }
41 : : } } }
42 : :
43 : : namespace oox { namespace core { class Relations; } }
44 : :
45 : : namespace oox {
46 : : namespace xls {
47 : :
48 : : class WorksheetHelper;
49 : :
50 : : // ============================================================================
51 : :
52 : : typedef ::std::pair< sal_Int32, rtl::OUString > IdCaptionPair;
53 : : typedef ::std::vector< IdCaptionPair > IdCaptionPairList;
54 : :
55 : 0 : class PivotCacheItem
56 : : {
57 : : public:
58 : : explicit PivotCacheItem();
59 : :
60 : : /** Reads the string value from a pivot cache item. */
61 : : void readString( const AttributeList& rAttribs );
62 : : /** Reads the double value from a pivot cache item. */
63 : : void readNumeric( const AttributeList& rAttribs );
64 : : /** Reads the date/time value from a pivot cache item. */
65 : : void readDate( const AttributeList& rAttribs );
66 : : /** Reads the boolean value from a pivot cache item. */
67 : : void readBool( const AttributeList& rAttribs );
68 : : /** Reads the error code value from a pivot cache item. */
69 : : void readError( const AttributeList& rAttribs, const UnitConverter& rUnitConverter );
70 : : /** Reads the index of a shared item. */
71 : : void readIndex( const AttributeList& rAttribs );
72 : :
73 : : /** Reads the string value from a pivot cache item. */
74 : : void readString( SequenceInputStream& rStrm );
75 : : /** Reads the double value from a pivot cache item. */
76 : : void readDouble( SequenceInputStream& rStrm );
77 : : /** Reads the date/time value from a pivot cache item. */
78 : : void readDate( SequenceInputStream& rStrm );
79 : : /** Reads the boolean value from a pivot cache item. */
80 : : void readBool( SequenceInputStream& rStrm );
81 : : /** Reads the error code value from a pivot cache item. */
82 : : void readError( SequenceInputStream& rStrm );
83 : : /** Reads the index of a shared item. */
84 : : void readIndex( SequenceInputStream& rStrm );
85 : :
86 : : /** Reads the string value from a pivot cache item. */
87 : : void readString( BiffInputStream& rStrm, const WorkbookHelper& rHelper );
88 : : /** Reads the double value from a pivot cache item. */
89 : : void readDouble( BiffInputStream& rStrm );
90 : : /** Reads the integer value from a pivot cache item. */
91 : : void readInteger( BiffInputStream& rStrm );
92 : : /** Reads the date/time value from a pivot cache item. */
93 : : void readDate( BiffInputStream& rStrm );
94 : : /** Reads the boolean value from a pivot cache item. */
95 : : void readBool( BiffInputStream& rStrm );
96 : : /** Reads the error code value from a pivot cache item. */
97 : : void readError( BiffInputStream& rStrm );
98 : :
99 : : /** Returns the type of the item. */
100 : 0 : inline sal_Int32 getType() const { return mnType; }
101 : : /** Returns the value of the item. */
102 : 0 : inline const ::com::sun::star::uno::Any& getValue() const { return maValue; }
103 : : /** Returns the string representation of the item. */
104 : : ::rtl::OUString getName() const;
105 : : /** Returns true if the item is unused. */
106 : 0 : inline bool isUnused() const { return mbUnused; }
107 : :
108 : : private:
109 : : friend class PivotCacheItemList;
110 : : // #FIXME hack Sets the value of this item to the given string ( and overwrites type if necessary
111 : : void setStringValue( const rtl::OUString& sName );
112 : : ::com::sun::star::uno::Any maValue; /// Value of the item.
113 : : sal_Int32 mnType; /// Value type (OOXML token identifier).
114 : : bool mbUnused;
115 : : };
116 : :
117 : : // ----------------------------------------------------------------------------
118 : :
119 [ # # ][ # # ]: 0 : class PivotCacheItemList : public WorkbookHelper
120 : : {
121 : : public:
122 : : explicit PivotCacheItemList( const WorkbookHelper& rHelper );
123 : :
124 : : /** Imports the item from the passed attribute list. */
125 : : void importItem( sal_Int32 nElement, const AttributeList& rAttribs );
126 : : /** Imports the item from the passed stream and record. */
127 : : void importItem( sal_Int32 nRecId, SequenceInputStream& rStrm );
128 : : /** Imports a complete item list from the passed stream. */
129 : : void importItemList( BiffInputStream& rStrm, sal_uInt16 nCount );
130 : :
131 : : /** Returns true, if this item list is empty. */
132 : 0 : inline bool empty() const { return maItems.empty(); }
133 : : /** Returns the size of the item list. */
134 : 0 : inline size_t size() const { return maItems.size(); }
135 : :
136 : : /** Returns the specified item. */
137 : : const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const;
138 : : /** Returns the names of all items. */
139 : : void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const;
140 : : void applyItemCaptions( const IdCaptionPairList& vCaptions );
141 : :
142 : : private:
143 : : /** Creates and returns a new item at the end of the items list. */
144 : : PivotCacheItem& createItem();
145 : : /** Imports an array of items from the PCITEM_ARRAY record */
146 : : void importArray( SequenceInputStream& rStrm );
147 : :
148 : : private:
149 : : typedef ::std::vector< PivotCacheItem > CacheItemVector;
150 : : CacheItemVector maItems; /// All items of this list.
151 : : };
152 : :
153 : : // ============================================================================
154 : :
155 : 0 : struct PCFieldModel
156 : : {
157 : : ::rtl::OUString maName; /// Fixed name of the cache field.
158 : : ::rtl::OUString maCaption; /// Caption of the ccahe field.
159 : : ::rtl::OUString maPropertyName; /// OLAP property name.
160 : : ::rtl::OUString maFormula; /// Formula of a calculated field.
161 : : sal_Int32 mnNumFmtId; /// Number format for all items.
162 : : sal_Int32 mnSqlType; /// Data type from ODBC data source.
163 : : sal_Int32 mnHierarchy; /// Hierarchy this field is part of.
164 : : sal_Int32 mnLevel; /// Hierarchy level this field is part of.
165 : : sal_Int32 mnMappingCount; /// Number of property mappings.
166 : : bool mbDatabaseField; /// True = field from source data; false = calculated field.
167 : : bool mbServerField; /// True = ODBC server-based page field.
168 : : bool mbUniqueList; /// True = list of unique ODBC items exists.
169 : : bool mbMemberPropField; /// True = contains OLAP member properties.
170 : :
171 : : explicit PCFieldModel();
172 : : };
173 : :
174 : : // ----------------------------------------------------------------------------
175 : :
176 : : struct PCSharedItemsModel
177 : : {
178 : : bool mbHasSemiMixed; /// True = has (blank|string|bool|error) item(s), maybe other types.
179 : : bool mbHasNonDate; /// True = has non-date item(s), maybe date items.
180 : : bool mbHasDate; /// True = has date item(s), maybe other types.
181 : : bool mbHasString; /// True = has (string|bool|error) item(s), maybe other types.
182 : : bool mbHasBlank; /// True = has blank item(s), maybe other types.
183 : : bool mbHasMixed; /// True = has [(string|bool|error) and (number|date)] or (number and date).
184 : : bool mbIsNumeric; /// True = has numeric item(s), maybe other types except date.
185 : : bool mbIsInteger; /// True = has numeric item(s) with only integers, maybe other types except date.
186 : : bool mbHasLongText; /// True = contains strings with >255 charascters.
187 : : bool mbHasLongIndexes; /// True = indexes to shared items are 16-bit (BIFF only).
188 : :
189 : : explicit PCSharedItemsModel();
190 : : };
191 : :
192 : : // ----------------------------------------------------------------------------
193 : :
194 : : struct PCFieldGroupModel
195 : : {
196 : : ::com::sun::star::util::DateTime maStartDate; /// Manual or calculated start date for range grouping.
197 : : ::com::sun::star::util::DateTime maEndDate; /// Manual or calculated end date for range grouping.
198 : : double mfStartValue; /// Manual or calculated start value for range grouping.
199 : : double mfEndValue; /// Manual or calculated end value for range grouping.
200 : : double mfInterval; /// Interval for numeric range grouping.
201 : : sal_Int32 mnParentField; /// Index of cache field that contains item groups based on this field.
202 : : sal_Int32 mnBaseField; /// Index of cache field this grouped field is based on.
203 : : sal_Int32 mnGroupBy; /// Type of numeric or date range grouping.
204 : : bool mbRangeGroup; /// True = items are grouped by numeric ranges or date ranges.
205 : : bool mbDateGroup; /// True = items are grouped by date ranges or by item names.
206 : : bool mbAutoStart; /// True = start value for range groups is calculated from source data.
207 : : bool mbAutoEnd; /// True = end value for range groups is calculated from source data.
208 : :
209 : : explicit PCFieldGroupModel();
210 : :
211 : : /** Sets the group-by value for BIFF import. */
212 : : void setBiffGroupBy( sal_uInt8 nGroupBy );
213 : : };
214 : :
215 : : // ----------------------------------------------------------------------------
216 : :
217 : : /** Helper struct for mapping original item names from/to group item names. */
218 : 0 : struct PivotCacheGroupItem
219 : : {
220 : : ::rtl::OUString maOrigName;
221 : : ::rtl::OUString maGroupName;
222 : :
223 : 0 : inline explicit PivotCacheGroupItem( const ::rtl::OUString& rItemName ) :
224 : 0 : maOrigName( rItemName ), maGroupName( rItemName ) {}
225 : : };
226 : :
227 : : typedef ::std::vector< PivotCacheGroupItem > PivotCacheGroupItemVector;
228 : :
229 : : // ----------------------------------------------------------------------------
230 : :
231 [ # # ][ # # ]: 0 : class PivotCacheField : public WorkbookHelper
[ # # ]
232 : : {
233 : : public:
234 : : explicit PivotCacheField( const WorkbookHelper& rHelper, bool bIsDatabaseField );
235 : :
236 : : /** Imports pivot cache field settings from the cacheField element. */
237 : : void importCacheField( const AttributeList& rAttribs );
238 : : /** Imports shared items settings from the sharedItems element. */
239 : : void importSharedItems( const AttributeList& rAttribs );
240 : : /** Imports a shared item from the passed element. */
241 : : void importSharedItem( sal_Int32 nElement, const AttributeList& rAttribs );
242 : : /** Imports grouping settings from the fieldGroup element. */
243 : : void importFieldGroup( const AttributeList& rAttribs );
244 : : /** Imports numeric grouping settings from the rangePr element. */
245 : : void importRangePr( const AttributeList& rAttribs );
246 : : /** Imports an item of the mapping between group items and base items from the passed element. */
247 : : void importDiscretePrItem( sal_Int32 nElement, const AttributeList& rAttribs );
248 : : /** Imports a group item from the passed element. */
249 : : void importGroupItem( sal_Int32 nElement, const AttributeList& rAttribs );
250 : :
251 : : /** Imports pivot cache field settings from the PCDFIELD record. */
252 : : void importPCDField( SequenceInputStream& rStrm );
253 : : /** Imports shared items settings from the PCDFSHAREDITEMS record. */
254 : : void importPCDFSharedItems( SequenceInputStream& rStrm );
255 : : /** Imports one or more shared items from the passed record. */
256 : : void importPCDFSharedItem( sal_Int32 nRecId, SequenceInputStream& rStrm );
257 : : /** Imports grouping settings from the PCDFIELDGROUP record. */
258 : : void importPCDFieldGroup( SequenceInputStream& rStrm );
259 : : /** Imports numeric grouping settings from the PCDFRANGEPR record. */
260 : : void importPCDFRangePr( SequenceInputStream& rStrm );
261 : : /** Imports an item of the mapping between group items and base items from the passed record. */
262 : : void importPCDFDiscretePrItem( sal_Int32 nRecId, SequenceInputStream& rStrm );
263 : : /** Imports one or more group items from the passed record. */
264 : : void importPCDFGroupItem( sal_Int32 nRecId, SequenceInputStream& rStrm );
265 : :
266 : : /** Imports pivot cache field settings from the PCDFIELD record. */
267 : : void importPCDField( BiffInputStream& rStrm );
268 : : /** Imports numeric grouping settings from the PCDFRANGEPR record. */
269 : : void importPCDFRangePr( BiffInputStream& rStrm );
270 : : /** Imports the mapping between group items and base items from the PCDFDISCRETEPR record. */
271 : : void importPCDFDiscretePr( BiffInputStream& rStrm );
272 : : /** Apply user Captions to imported group data */
273 : : void applyItemCaptions( const IdCaptionPairList& vCaptions );
274 : :
275 : : /** Returns true, if the field is based on source data, or false if it is grouped or calculated. */
276 : 0 : inline bool isDatabaseField() const { return maFieldModel.mbDatabaseField; }
277 : :
278 : : /** Returns true, if the field contains a list of shared items. */
279 : 0 : inline bool hasSharedItems() const { return !maSharedItems.empty(); }
280 : : /** Returns true, if the field contains a list of grouping items. */
281 : 0 : inline bool hasGroupItems() const { return !maGroupItems.empty(); }
282 : : /** Returns true, if the field has inplace numeric grouping settings. */
283 [ # # ][ # # ]: 0 : inline bool hasNumericGrouping() const { return maFieldGroupModel.mbRangeGroup && !maFieldGroupModel.mbDateGroup; }
284 : : /** Returns true, if the field has inplace date grouping settings. */
285 [ # # ][ # # ]: 0 : inline bool hasDateGrouping() const { return maFieldGroupModel.mbRangeGroup && maFieldGroupModel.mbDateGroup; }
286 : : /** Returns true, if the field has a parent group field that groups the items of this field. */
287 : 0 : inline bool hasParentGrouping() const { return maFieldGroupModel.mnParentField >= 0; }
288 : :
289 : : /** Returns the name of the cache field. */
290 : 0 : inline const ::rtl::OUString& getName() const { return maFieldModel.maName; }
291 : : /** Returns the index of the parent group field that groups the items of this field. */
292 : 0 : inline sal_Int32 getParentGroupField() const { return maFieldGroupModel.mnParentField; }
293 : : /** Returns the index of the base field grouping is based on. */
294 : 0 : inline sal_Int32 getGroupBaseField() const { return maFieldGroupModel.mnBaseField; }
295 : :
296 : : /** Returns the shared or group item with the specified index. */
297 : : const PivotCacheItem* getCacheItem( sal_Int32 nItemIdx ) const;
298 : : /** Returns the names of all shared or group items. */
299 : : void getCacheItemNames( ::std::vector< ::rtl::OUString >& orItemNames ) const;
300 : : /** Returns shared or group items. */
301 : : PivotCacheItemList getCacheItems() const;
302 : :
303 : : /** Creates inplace numeric grouping settings. */
304 : : void convertNumericGrouping(
305 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxDPField ) const;
306 : : /** Creates inplace date grouping settings or a new date group field. */
307 : : ::rtl::OUString createDateGroupField(
308 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField ) const;
309 : : /** Creates a new grouped DataPilot field and returns its name. */
310 : : ::rtl::OUString createParentGroupField(
311 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDataPilotField >& rxBaseDPField,
312 : : const PivotCacheField& rBaseCacheField,
313 : : PivotCacheGroupItemVector& orItemNames ) const;
314 : :
315 : : /** Writes the title of the field into the passed sheet at the passed address. */
316 : : void writeSourceHeaderCell( WorksheetHelper& rSheetHelper,
317 : : sal_Int32 nCol, sal_Int32 nRow ) const;
318 : : /** Writes a source field item value into the passed sheet. */
319 : : void writeSourceDataCell( WorksheetHelper& rSheetHelper,
320 : : sal_Int32 nCol, sal_Int32 nRow,
321 : : const PivotCacheItem& rItem ) const;
322 : :
323 : : /** Reads an item from the PCRECORD record and writes it to the passed sheet. */
324 : : void importPCRecordItem( SequenceInputStream& rStrm,
325 : : WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const;
326 : : /** Reads an item index from the PCITEM_INDEXLIST record and writes the item to the passed sheet. */
327 : : void importPCItemIndex( BiffInputStream& rStrm,
328 : : WorksheetHelper& rSheetHelper, sal_Int32 nCol, sal_Int32 nRow ) const;
329 : :
330 : : private:
331 : : /** Tries to write the passed value to the passed sheet position. */
332 : : void writeItemToSourceDataCell( WorksheetHelper& rSheetHelper,
333 : : sal_Int32 nCol, sal_Int32 nRow, const PivotCacheItem& rItem ) const;
334 : : /** Tries to write the value of a shared item to the passed sheet position. */
335 : : void writeSharedItemToSourceDataCell( WorksheetHelper& rSheetHelper,
336 : : sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nItemIdx ) const;
337 : :
338 : : private:
339 : : typedef ::std::vector< sal_Int32 > IndexVector;
340 : :
341 : : PivotCacheItemList maSharedItems; /// All shared items of this field.
342 : : PivotCacheItemList maGroupItems; /// All group items of this field.
343 : : IndexVector maDiscreteItems; /// Mapping between group and base items.
344 : : PCFieldModel maFieldModel; /// Settings for this cache field.
345 : : PCSharedItemsModel maSharedItemsModel; /// Settings for shared items.
346 : : PCFieldGroupModel maFieldGroupModel; /// Settings for item grouping.
347 : : };
348 : :
349 : : // ============================================================================
350 : :
351 : 0 : struct PCDefinitionModel
352 : : {
353 : : ::rtl::OUString maRelId; /// Relation identifier for cache records fragment.
354 : : ::rtl::OUString maRefreshedBy; /// Name of user who last refreshed the cache.
355 : : double mfRefreshedDate; /// Date/time of last refresh.
356 : : sal_Int32 mnRecords; /// Number of data records in the cache.
357 : : sal_Int32 mnMissItemsLimit; /// Limit for discarding unused items.
358 : : sal_uInt16 mnDatabaseFields; /// Number of database (source data) fields (BIFF only).
359 : : bool mbInvalid; /// True = cache needs refresh.
360 : : bool mbSaveData; /// True = cached item values are present.
361 : : bool mbRefreshOnLoad; /// True = try to refresh cache on load.
362 : : bool mbOptimizeMemory; /// True = application may optimize memory usage.
363 : : bool mbEnableRefresh; /// True = refreshing cache is enabled in UI.
364 : : bool mbBackgroundQuery; /// True = application queries data asynchonously.
365 : : bool mbUpgradeOnRefresh; /// True = application may upgrade cache version.
366 : : bool mbTupleCache; /// True = cache stores OLAP functions.
367 : : bool mbSupportSubquery; /// True = data source supports subqueries.
368 : : bool mbSupportDrill; /// True = data source supports drilldown.
369 : :
370 : : explicit PCDefinitionModel();
371 : : };
372 : :
373 : : // ----------------------------------------------------------------------------
374 : :
375 : : struct PCSourceModel
376 : : {
377 : : sal_Int32 mnSourceType; /// Type of the source data (sheet, consolidation, scenario, external).
378 : : sal_Int32 mnConnectionId; /// Connection identifier for external data source.
379 : :
380 : : explicit PCSourceModel();
381 : : };
382 : :
383 : : // ----------------------------------------------------------------------------
384 : :
385 : 0 : struct PCWorksheetSourceModel
386 : : {
387 : : ::rtl::OUString maRelId; /// Relation identifier for an external document URL.
388 : : ::rtl::OUString maSheet; /// Sheet name for cell range or sheet-local defined names.
389 : : ::rtl::OUString maDefName; /// Defined name containing a cell range if present.
390 : : ::com::sun::star::table::CellRangeAddress
391 : : maRange; /// Source cell range of the data.
392 : :
393 : : explicit PCWorksheetSourceModel();
394 : : };
395 : :
396 : : // ----------------------------------------------------------------------------
397 : :
398 [ # # ]: 0 : class PivotCache : public WorkbookHelper
399 : : {
400 : : public:
401 : : explicit PivotCache( const WorkbookHelper& rHelper );
402 : :
403 : : /** Reads pivot cache global settings from the pivotCacheDefinition element. */
404 : : void importPivotCacheDefinition( const AttributeList& rAttribs );
405 : : /** Reads cache source settings from the cacheSource element. */
406 : : void importCacheSource( const AttributeList& rAttribs );
407 : : /** Reads sheet source settings from the worksheetSource element. */
408 : : void importWorksheetSource( const AttributeList& rAttribs, const ::oox::core::Relations& rRelations );
409 : :
410 : : /** Reads pivot cache global settings from the PCDEFINITION record. */
411 : : void importPCDefinition( SequenceInputStream& rStrm );
412 : : /** Reads cache source settings from the PCDSOURCE record. */
413 : : void importPCDSource( SequenceInputStream& rStrm );
414 : : /** Reads sheet source settings from the PCDSHEETSOURCE record. */
415 : : void importPCDSheetSource( SequenceInputStream& rStrm, const ::oox::core::Relations& rRelations );
416 : :
417 : : /** Reads pivot cache global settings from the PCDEFINITION record. */
418 : : void importPCDefinition( BiffInputStream& rStrm );
419 : :
420 : : /** Creates and returns a new pivot cache field. */
421 : : PivotCacheField& createCacheField( bool bInitDatabaseField = false );
422 : : /** Checks validity of source data and creates a dummy data sheet for external sheet sources. */
423 : : void finalizeImport();
424 : :
425 : : /** Returns true, if the pivot cache is based on a valid data source, so
426 : : that pivot tables can be created based on this pivot cache. */
427 : 0 : inline bool isValidDataSource() const { return mbValidSource; }
428 : : /** Returns true, if the pivot cache is based on a dummy sheet created in finalizeImport. */
429 : 0 : inline bool isBasedOnDummySheet() const { return mbDummySheet; }
430 : : /** Returns the internal cell range the cache is based on. */
431 : : inline const ::com::sun::star::table::CellRangeAddress&
432 : 0 : getSourceRange() const { return maSheetSrcModel.maRange; }
433 : : /** Returns the relation identifier of the pivot cache records fragment. */
434 : 0 : inline const ::rtl::OUString& getRecordsRelId() const { return maDefModel.maRelId; }
435 : :
436 : : /** Returns the number of pivot cache fields. */
437 : : sal_Int32 getCacheFieldCount() const;
438 : : /** Returns the cache field with the specified index. */
439 : : const PivotCacheField* getCacheField( sal_Int32 nFieldIdx ) const;
440 : : /** Returns the source column index of the field with the passed index. */
441 : : sal_Int32 getCacheDatabaseIndex( sal_Int32 nFieldIdx ) const;
442 : :
443 : : /** Writes the titles of all source fields into the passed sheet. */
444 : : void writeSourceHeaderCells( WorksheetHelper& rSheetHelper ) const;
445 : : /** Writes a source field item value into the passed sheet. */
446 : : void writeSourceDataCell( WorksheetHelper& rSheetHelper,
447 : : sal_Int32 nColIdx, sal_Int32 nRowIdx,
448 : : const PivotCacheItem& rItem ) const;
449 : :
450 : : /** Reads a PCRECORD record and writes all item values to the passed sheet. */
451 : : void importPCRecord( SequenceInputStream& rStrm,
452 : : WorksheetHelper& rSheetHelper, sal_Int32 nRowIdx ) const;
453 : : /** Reads a PCITEM_INDEXLIST record and writes all item values to the passed sheet. */
454 : : void importPCItemIndexList( BiffInputStream& rStrm,
455 : : WorksheetHelper& rSheetHelper, sal_Int32 nRowIdx ) const;
456 : :
457 : : private:
458 : :
459 : : /** Finalizes the pivot cache if it is based on internal sheet data. */
460 : : void finalizeInternalSheetSource();
461 : : /** Finalizes the pivot cache if it is based on sheet data of an external spreadsheet document. */
462 : : void finalizeExternalSheetSource();
463 : : /** Creates a dummy sheet that will be filled with the pivot cache data. */
464 : : void prepareSourceDataSheet();
465 : : /** Checks, if the row index has changed since last call, and initializes the sheet data buffer. */
466 : : void updateSourceDataRow( WorksheetHelper& rSheetHelper, sal_Int32 nRow ) const;
467 : :
468 : : private:
469 : : typedef RefVector< PivotCacheField > PivotCacheFieldVector;
470 : : typedef ::std::vector< sal_Int32 > IndexVector;
471 : :
472 : : PivotCacheFieldVector maFields; /// All pivot cache fields.
473 : : PivotCacheFieldVector maDatabaseFields; /// All cache fields that are based on source data.
474 : : IndexVector maDatabaseIndexes; /// Database field index for all fields.
475 : : PCDefinitionModel maDefModel; /// Global pivot cache settings.
476 : : PCSourceModel maSourceModel; /// Pivot cache source settings.
477 : : PCWorksheetSourceModel maSheetSrcModel; /// Sheet source data if cache type is sheet.
478 : : ValueRangeSet maColSpans; /// Column spans used by SheetDataBuffer for optimized cell import.
479 : : ::rtl::OUString maTargetUrl; /// URL of an external source document.
480 : : mutable sal_Int32 mnCurrRow; /// Current row index in dummy sheet.
481 : : bool mbValidSource; /// True = pivot cache is based on supported data source.
482 : : bool mbDummySheet; /// True = pivot cache is based on a dummy sheet.
483 : : };
484 : :
485 : : // ============================================================================
486 : :
487 [ - + ]: 48 : class PivotCacheBuffer : public WorkbookHelper
488 : : {
489 : : public:
490 : : explicit PivotCacheBuffer( const WorkbookHelper& rHelper );
491 : :
492 : : /** Registers a pivot cache definition fragment. The fragment will be loaded on demand (OOXML/BIFF12 only). */
493 : : void registerPivotCacheFragment( sal_Int32 nCacheId, const ::rtl::OUString& rFragmentPath );
494 : :
495 : : /** Imports and stores a pivot cache definition fragment on first call,
496 : : returns the imported cache on subsequent calls with the same identifier. */
497 : : PivotCache* importPivotCacheFragment( sal_Int32 nCacheId );
498 : :
499 : : private:
500 : : /** Creates and returns a new pivot cache object with the passed identifier. */
501 : : PivotCache& createPivotCache( sal_Int32 nCacheId );
502 : :
503 : : private:
504 : : typedef ::std::map< sal_Int32, ::rtl::OUString > FragmentPathMap;
505 : : typedef RefMap< sal_Int32, PivotCache > PivotCacheMap;
506 : : typedef ::std::vector< sal_Int32 > PivotCacheIdVector;
507 : :
508 : : FragmentPathMap maFragmentPaths;
509 : : PivotCacheMap maCaches;
510 : : PivotCacheIdVector maCacheIds;
511 : : };
512 : :
513 : : // ============================================================================
514 : :
515 : : } // namespace xls
516 : : } // namespace oox
517 : :
518 : : #endif
519 : :
520 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|