LibreOffice Module sc (master)  1
pivottablefragment.cxx
Go to the documentation of this file.
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 #include <pivottablefragment.hxx>
21 #include <pivottablebuffer.hxx>
22 #include <biffhelper.hxx>
23 #include <oox/token/namespaces.hxx>
24 
25 namespace oox::xls {
26 
27 using namespace ::oox::core;
28 
30  WorksheetContextBase( rFragment ),
31  mrTableField( rTableField )
32 {
33 }
34 
36 {
37  switch( getCurrentElement() )
38  {
39  case XLS_TOKEN( pivotField ):
40  switch( nElement )
41  {
42  case XLS_TOKEN( items ): return this;
43  case XLS_TOKEN( autoSortScope ): return this;
44  }
45  break;
46  case XLS_TOKEN( items ):
47  if( nElement == XLS_TOKEN( item ) ) mrTableField.importItem( rAttribs );
48  break;
49  case XLS_TOKEN( autoSortScope ):
50  if( nElement == XLS_TOKEN( pivotArea ) ) return this;
51  break;
52  case XLS_TOKEN( pivotArea ):
53  if( nElement == XLS_TOKEN( references ) ) return this;
54  break;
55  case XLS_TOKEN( references ):
56  if( nElement == XLS_TOKEN( reference ) ) { mrTableField.importReference( rAttribs ); return this; }
57  break;
58  case XLS_TOKEN( reference ):
59  if( nElement == XLS_TOKEN( x ) ) mrTableField.importReferenceItem( rAttribs );
60  break;
61  }
62  return nullptr;
63 }
64 
66 {
67  if( isRootElement() )
68  mrTableField.importPivotField( rAttribs );
69 }
70 
72 {
73  switch( getCurrentElement() )
74  {
75  case BIFF12_ID_PTFIELD:
76  switch( nRecId )
77  {
78  case BIFF12_ID_PTFITEMS: return this;
79  case BIFF12_ID_AUTOSORTSCOPE: return this;
80  }
81  break;
82  case BIFF12_ID_PTFITEMS:
83  if( nRecId == BIFF12_ID_PTFITEM ) mrTableField.importPTFItem( rStrm );
84  break;
86  if( nRecId == BIFF12_ID_PIVOTAREA ) return this;
87  break;
89  if( nRecId == BIFF12_ID_PTREFERENCES ) return this;
90  break;
92  if( nRecId == BIFF12_ID_PTREFERENCE ) { mrTableField.importPTReference( rStrm ); return this; }
93  break;
96  break;
97  }
98  return nullptr;
99 }
100 
102 {
103  if( isRootElement() )
104  mrTableField.importPTField( rStrm );
105 }
106 
108  WorksheetContextBase( rFragment ),
109  mrTableFilter( rTableFilter )
110 {
111 }
112 
114 {
115  switch( getCurrentElement() )
116  {
117  case XLS_TOKEN( filter ):
118  if( nElement == XLS_TOKEN( autoFilter ) ) return this;
119  break;
120  case XLS_TOKEN( autoFilter ):
121  if( nElement == XLS_TOKEN( filterColumn ) ) return this;
122  break;
123  case XLS_TOKEN( filterColumn ):
124  if( nElement == XLS_TOKEN( top10 ) ) mrTableFilter.importTop10( rAttribs );
125  break;
126  }
127  return nullptr;
128 }
129 
131 {
132  if( isRootElement() )
133  mrTableFilter.importFilter( rAttribs );
134 }
135 
137 {
138  switch( getCurrentElement() )
139  {
140  case BIFF12_ID_PTFILTER:
141  if( nRecId == BIFF12_ID_AUTOFILTER ) return this;
142  break;
144  if( nRecId == BIFF12_ID_FILTERCOLUMN ) return this;
145  break;
147  if( nRecId == BIFF12_ID_TOP10FILTER ) mrTableFilter.importTop10Filter( rStrm );
148  break;
149  }
150  return nullptr;
151 }
152 
154 {
155  if( isRootElement() )
156  mrTableFilter.importPTFilter( rStrm );
157 }
158 
159 PivotTableFragment::PivotTableFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
160  WorksheetFragmentBase( rHelper, rFragmentPath ),
161  mrPivotTable( getPivotTables().createPivotTable() )
162 {
163 }
164 
166 {
167  switch( getCurrentElement() )
168  {
169  case XML_ROOT_CONTEXT:
170  if( nElement == XLS_TOKEN( pivotTableDefinition ) ) { mrPivotTable.importPivotTableDefinition( rAttribs ); return this; }
171  break;
172 
173  case XLS_TOKEN( pivotTableDefinition ):
174  switch( nElement )
175  {
176  case XLS_TOKEN( location ): mrPivotTable.importLocation( rAttribs, getSheetIndex() ); break;
177  case XLS_TOKEN( pivotFields ): return this;
178  case XLS_TOKEN( rowFields ): return this;
179  case XLS_TOKEN( colFields ): return this;
180  case XLS_TOKEN( pageFields ): return this;
181  case XLS_TOKEN( dataFields ): return this;
182  case XLS_TOKEN( filters ): return this;
183  case XLS_TOKEN(pivotTableStyleInfo):
184  mrPivotTable.putToInteropGrabBag("pivotTableStyleInfo", rAttribs);
185  break;
186  }
187  break;
188 
189  case XLS_TOKEN( pivotFields ):
190  if( nElement == XLS_TOKEN( pivotField ) ) return new PivotTableFieldContext( *this, mrPivotTable.createTableField() );
191  break;
192  case XLS_TOKEN( rowFields ):
193  if( nElement == XLS_TOKEN( field ) ) mrPivotTable.importRowField( rAttribs );
194  break;
195  case XLS_TOKEN( colFields ):
196  if( nElement == XLS_TOKEN( field ) ) mrPivotTable.importColField( rAttribs );
197  break;
198  case XLS_TOKEN( pageFields ):
199  if( nElement == XLS_TOKEN( pageField ) ) mrPivotTable.importPageField( rAttribs );
200  break;
201  case XLS_TOKEN( dataFields ):
202  if( nElement == XLS_TOKEN( dataField ) ) mrPivotTable.importDataField( rAttribs );
203  break;
204  case XLS_TOKEN( filters ):
205  if( nElement == XLS_TOKEN( filter ) ) return new PivotTableFilterContext( *this, mrPivotTable.createTableFilter() );
206  break;
207  }
208  return nullptr;
209 }
210 
212 {
213  switch( getCurrentElement() )
214  {
215  case XML_ROOT_CONTEXT:
216  if( nRecId == BIFF12_ID_PTDEFINITION ) { mrPivotTable.importPTDefinition( rStrm ); return this; }
217  break;
218 
220  switch( nRecId )
221  {
223  case BIFF12_ID_PTFIELDS: return this;
226  case BIFF12_ID_PTPAGEFIELDS: return this;
227  case BIFF12_ID_PTDATAFIELDS: return this;
228  case BIFF12_ID_PTFILTERS: return this;
229  }
230  break;
231 
232  case BIFF12_ID_PTFIELDS:
233  if( nRecId == BIFF12_ID_PTFIELD ) return new PivotTableFieldContext( *this, mrPivotTable.createTableField() );
234  break;
236  if( nRecId == BIFF12_ID_PTPAGEFIELD ) mrPivotTable.importPTPageField( rStrm );
237  break;
239  if( nRecId == BIFF12_ID_PTDATAFIELD ) mrPivotTable.importPTDataField( rStrm );
240  break;
241  case BIFF12_ID_PTFILTERS:
242  if( nRecId == BIFF12_ID_PTFILTER ) return new PivotTableFilterContext( *this, mrPivotTable.createTableFilter() );
243  break;
244  }
245  return nullptr;
246 }
247 
248 const RecordInfo* PivotTableFragment::getRecordInfos() const
249 {
250  static const RecordInfo spRecInfos[] =
251  {
273  { -1, -1 }
274  };
275  return spRecInfos;
276 }
277 
278 } // namespace oox::xls
279 
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 BIFF12_ID_PTDATAFIELD
Definition: biffhelper.hxx:190
const sal_Int32 BIFF12_ID_PTFITEMS
Definition: biffhelper.hxx:198
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
const sal_Int32 BIFF12_ID_PTLOCATION
Definition: biffhelper.hxx:199
const sal_Int32 BIFF12_ID_AUTOSORTSCOPE
Definition: biffhelper.hxx:34
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
void importRowField(const AttributeList &rAttribs)
Reads the index of a field located in the row dimension.
void importPTReferenceItem(SequenceInputStream &rStrm)
Imports pivot field item reference settings from the PTREFERENCEITEM record.
const sal_Int32 BIFF12_ID_PIVOTAREA
Definition: biffhelper.hxx:185
float x
const sal_Int32 BIFF12_ID_PTFIELD
Definition: biffhelper.hxx:193
void importColField(const AttributeList &rAttribs)
Reads the index of a field located in the column dimension.
PivotTableFieldContext(WorksheetFragmentBase &rFragment, PivotTableField &rTableField)
void importDataField(const AttributeList &rAttribs)
Reads the settings of a field located in the data dimension from the dataField element.
void importPTFItem(SequenceInputStream &rStrm)
Imports settings of an item in this pivot field from the PTFITEM record.
const sal_Int32 BIFF12_ID_PTCOLFIELDS
Definition: biffhelper.hxx:189
void importLocation(const AttributeList &rAttribs, sal_Int16 nSheet)
Reads the location of the pivot table from the location element.
const sal_Int32 BIFF12_ID_PTREFERENCEITEM
Definition: biffhelper.hxx:203
void importTop10Filter(SequenceInputStream &rStrm)
Reads additional settings of a field filter from the TOP10FILTER record.
virtual void onStartElement(const AttributeList &rAttribs) override
const sal_Int32 BIFF12_ID_PTFIELDS
Definition: biffhelper.hxx:194
const sal_Int32 BIFF12_ID_AUTOFILTER
Definition: biffhelper.hxx:33
void importPivotTableDefinition(const AttributeList &rAttribs)
Reads global pivot table settings from the pivotTableDefinition element.
void importPageField(const AttributeList &rAttribs)
Reads the settings of a field located in the page dimension from the pageField element.
const sal_Int32 BIFF12_ID_PTREFERENCES
Definition: biffhelper.hxx:204
void importPTPageField(SequenceInputStream &rStrm)
Reads the settings of a field located in the page dimension from the PTPAGEFIELD record.
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
void importFilter(const AttributeList &rAttribs)
Reads the settings of a field filter from the filter element.
const sal_Int32 BIFF12_ID_PTFITEM
Definition: biffhelper.hxx:197
const sal_Int32 BIFF12_ID_PTREFERENCE
Definition: biffhelper.hxx:202
const sal_Int32 BIFF12_ID_PTFILTERS
Definition: biffhelper.hxx:196
sal_Int32 getCurrentElement() const
virtual void onStartRecord(SequenceInputStream &rStrm) override
const sal_Int32 BIFF12_ID_FILTERCOLUMN
Definition: biffhelper.hxx:122
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
void putToInteropGrabBag(const OUString &sName, const AttributeList &rAttribs)
Puts the attributes to the named grab bag value.
void importPTRowFields(SequenceInputStream &rStrm)
Reads the indexes of all fields located in the row dimension from a PTROWFIELDS record.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
void importPTDefinition(SequenceInputStream &rStrm)
Reads global pivot table settings from the PTDEFINITION record.
Fragment handler derived from the WorksheetHelper helper class.
PivotTableField & createTableField()
Creates and returns a new pivot table field.
void importPTLocation(SequenceInputStream &rStrm, sal_Int16 nSheet)
Reads the location of the pivot table from the PTLOCATION record.
void importPTDataField(SequenceInputStream &rStrm)
Reads the settings of a field located in the data dimension from the PTDATAFIELD record.
void importPTField(SequenceInputStream &rStrm)
Imports pivot field settings from the PTFIELD record.
void importTop10(const AttributeList &rAttribs)
Reads additional settings of a field filter from the top10 element.
Context handler derived from the WorksheetHelper helper class.
PivotTableFilterContext(WorksheetFragmentBase &rFragment, PivotTableFilter &rTableFilter)
virtual void onStartRecord(SequenceInputStream &rStrm) override
const sal_Int32 BIFF12_ID_TOP10FILTER
Definition: biffhelper.hxx:231
void importItem(const AttributeList &rAttribs)
Imports settings of an item in this pivot field from the item element.
SCTAB getSheetIndex() const
Returns the index of the current sheet.
void importReferenceItem(const AttributeList &rAttribs)
Imports pivot field item reference settings from the x element.
const sal_Int32 BIFF12_ID_PTDATAFIELDS
Definition: biffhelper.hxx:191
const sal_Int32 BIFF12_ID_PTPAGEFIELDS
Definition: biffhelper.hxx:201
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
const sal_Int32 XML_ROOT_CONTEXT
void importReference(const AttributeList &rAttribs)
Imports pivot field reference settings from the reference element.
PivotTableFragment(const WorksheetHelper &rHelper, const OUString &rFragmentPath)
PivotTableFilter & createTableFilter()
Creates and returns a new pivot table filter.
const sal_Int32 BIFF12_ID_PTPAGEFIELD
Definition: biffhelper.hxx:200
void importPTReference(SequenceInputStream &rStrm)
Imports pivot field reference settings from the PTREFERENCE record.
const sal_Int32 BIFF12_ID_PTFILTER
Definition: biffhelper.hxx:195
void importPTFilter(SequenceInputStream &rStrm)
Reads the settings of a field filter from the PTFILTER record.
const sal_Int32 BIFF12_ID_PTROWFIELDS
Definition: biffhelper.hxx:205
virtual void onStartElement(const AttributeList &rAttribs) override
void importPivotField(const AttributeList &rAttribs)
Imports pivot field settings from the pivotField element.
const sal_Int32 BIFF12_ID_PTDEFINITION
Definition: biffhelper.hxx:192
void importPTColFields(SequenceInputStream &rStrm)
Reads the indexes of all fields located in the column dimension from a PTCOLFIELDS record...