nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / filter / xml / xmldpimp.cxx
blob8447d800f1607e1d645b493c229a40756ba444b8
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 #include "xmldpimp.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlfilti.hxx"
23 #include <document.hxx>
24 #include <dpshttab.hxx>
25 #include <dpsdbtab.hxx>
26 #include <attrib.hxx>
27 #include "XMLConverter.hxx"
28 #include <dpdimsave.hxx>
29 #include <rangeutl.hxx>
30 #include <dpoutputgeometry.hxx>
31 #include <generalfunction.hxx>
33 #include "pivotsource.hxx"
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmlnamespace.hxx>
37 #include <xmloff/xmluconv.hxx>
39 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
40 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
41 #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
42 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
43 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
44 #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
45 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
47 using namespace com::sun::star;
48 using namespace xmloff::token;
49 using ::com::sun::star::uno::Reference;
51 ScXMLDataPilotTablesContext::ScXMLDataPilotTablesContext( ScXMLImport& rImport ) :
52 ScXMLImportContext( rImport )
54 // has no Attributes
55 rImport.LockSolarMutex();
58 ScXMLDataPilotTablesContext::~ScXMLDataPilotTablesContext()
60 GetScImport().UnlockSolarMutex();
63 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotTablesContext::createFastChildContext(
64 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
66 SvXMLImportContext *pContext = nullptr;
67 sax_fastparser::FastAttributeList *pAttribList =
68 &sax_fastparser::castToFastAttributeList( xAttrList );
70 switch (nElement)
72 case XML_ELEMENT( TABLE, XML_DATA_PILOT_TABLE ) :
74 pContext = new ScXMLDataPilotTableContext( GetScImport(), pAttribList );
76 break;
79 return pContext;
82 ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
83 mbVisible(true) {}
85 ScXMLDataPilotTableContext::ScXMLDataPilotTableContext( ScXMLImport& rImport,
86 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
87 ScXMLImportContext( rImport ),
88 pDoc(GetScImport().GetDocument()),
89 pDPSave(new ScDPSaveData()),
90 sDataPilotTableName(),
91 sApplicationData(),
92 nSourceType(SQL),
93 mnRowFieldCount(0),
94 mnColFieldCount(0),
95 mnPageFieldCount(0),
96 mnDataFieldCount(0),
97 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN),
98 bIsNative(true),
99 bIgnoreEmptyRows(false),
100 bIdentifyCategories(false),
101 bTargetRangeAddress(false),
102 bSourceCellRange(false),
103 bShowFilter(true),
104 bDrillDown(true),
105 bHeaderGridLayout(false)
107 if ( !rAttrList.is() )
108 return;
110 for (auto &aIter : *rAttrList)
112 switch (aIter.getToken())
114 case XML_ELEMENT( TABLE, XML_NAME ):
116 sDataPilotTableName = aIter.toString();
118 break;
119 case XML_ELEMENT( TABLE, XML_APPLICATION_DATA ):
121 sApplicationData = aIter.toString();
123 break;
124 case XML_ELEMENT( TABLE, XML_GRAND_TOTAL ):
126 if (IsXMLToken(aIter, XML_BOTH))
128 maRowGrandTotal.mbVisible = true;
129 maColGrandTotal.mbVisible = true;
131 else if (IsXMLToken(aIter, XML_ROW))
133 maRowGrandTotal.mbVisible = true;
134 maColGrandTotal.mbVisible = false;
136 else if (IsXMLToken(aIter, XML_COLUMN))
138 maRowGrandTotal.mbVisible = false;
139 maColGrandTotal.mbVisible = true;
141 else
143 maRowGrandTotal.mbVisible = false;
144 maColGrandTotal.mbVisible = false;
147 break;
148 case XML_ELEMENT( TABLE, XML_IGNORE_EMPTY_ROWS ):
150 bIgnoreEmptyRows = IsXMLToken(aIter, XML_TRUE);
152 break;
153 case XML_ELEMENT( TABLE, XML_IDENTIFY_CATEGORIES ):
155 bIdentifyCategories = IsXMLToken(aIter, XML_TRUE);
157 break;
158 case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
160 sal_Int32 nOffset(0);
161 assert(pDoc);
162 bTargetRangeAddress = ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
164 break;
165 case XML_ELEMENT( TABLE, XML_BUTTONS ):
167 sButtons = aIter.toString();
169 break;
170 case XML_ELEMENT( TABLE, XML_SHOW_FILTER_BUTTON ):
172 bShowFilter = IsXMLToken(aIter, XML_TRUE);
174 break;
175 case XML_ELEMENT( TABLE, XML_DRILL_DOWN_ON_DOUBLE_CLICK ):
177 bDrillDown = IsXMLToken(aIter, XML_TRUE);
179 break;
180 case XML_ELEMENT( TABLE, XML_HEADER_GRID_LAYOUT ):
182 bHeaderGridLayout = IsXMLToken(aIter, XML_TRUE);
184 break;
189 ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
193 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotTableContext::createFastChildContext(
194 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
196 SvXMLImportContext *pContext = nullptr;
197 sax_fastparser::FastAttributeList *pAttribList =
198 &sax_fastparser::castToFastAttributeList( xAttrList );
200 switch (nElement)
202 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_SQL ):
204 pContext = new ScXMLDPSourceSQLContext(GetScImport(), pAttribList, this);
205 nSourceType = SQL;
207 break;
208 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_TABLE ):
210 pContext = new ScXMLDPSourceTableContext(GetScImport(), pAttribList, this);
211 nSourceType = TABLE;
213 break;
214 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_QUERY ):
216 pContext = new ScXMLDPSourceQueryContext(GetScImport(), pAttribList, this);
217 nSourceType = QUERY;
219 break;
220 case XML_ELEMENT( TABLE, XML_SOURCE_SERVICE ):
222 pContext = new ScXMLSourceServiceContext(GetScImport(), pAttribList, this);
223 nSourceType = SERVICE;
225 break;
226 case XML_ELEMENT( TABLE, XML_DATA_PILOT_GRAND_TOTAL ):
227 case XML_ELEMENT( TABLE_EXT, XML_DATA_PILOT_GRAND_TOTAL ):
229 pContext = new ScXMLDataPilotGrandTotalContext(GetScImport(), pAttribList, this);
231 break;
232 case XML_ELEMENT( TABLE, XML_SOURCE_CELL_RANGE ):
234 pContext = new ScXMLSourceCellRangeContext(GetScImport(), pAttribList, this);
235 nSourceType = CELLRANGE;
237 break;
238 case XML_ELEMENT( TABLE, XML_DATA_PILOT_FIELD ):
239 pContext = new ScXMLDataPilotFieldContext(GetScImport(), pAttribList, this);
240 break;
243 return pContext;
246 namespace {
248 const ScDPSaveDimension* getDimension(
249 const std::vector<const ScDPSaveDimension*>& rRowDims,
250 const std::vector<const ScDPSaveDimension*>& rColDims,
251 const std::vector<const ScDPSaveDimension*>& rPageDims,
252 ScDPOutputGeometry::FieldType eType, size_t nPos)
254 switch (eType)
256 case ScDPOutputGeometry::Column:
258 if (rColDims.size() <= nPos)
259 return nullptr;
261 return rColDims[nPos];
263 case ScDPOutputGeometry::Row:
265 if (rRowDims.size() <= nPos)
266 return nullptr;
268 return rRowDims[nPos];
270 case ScDPOutputGeometry::Page:
272 if (rPageDims.size() <= nPos)
273 return nullptr;
275 return rPageDims[nPos];
277 case ScDPOutputGeometry::Data:
278 break;
279 case ScDPOutputGeometry::None:
280 break;
281 default:
282 break;
284 return nullptr;
287 ScDPOutputGeometry::FieldType toFieldType(sheet::DataPilotFieldOrientation nOrient)
289 switch (nOrient)
291 case sheet::DataPilotFieldOrientation_COLUMN:
292 return ScDPOutputGeometry::Column;
293 case sheet::DataPilotFieldOrientation_DATA:
294 return ScDPOutputGeometry::Data;
295 case sheet::DataPilotFieldOrientation_PAGE:
296 return ScDPOutputGeometry::Page;
297 case sheet::DataPilotFieldOrientation_ROW:
298 return ScDPOutputGeometry::Row;
299 case sheet::DataPilotFieldOrientation_HIDDEN:
300 break;
301 default:
302 break;
304 return ScDPOutputGeometry::None;
309 void ScXMLDataPilotTableContext::SetButtons(ScDPObject* pDPObject)
311 ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter);
312 aGeometry.setColumnFieldCount(mnColFieldCount);
313 aGeometry.setRowFieldCount(mnRowFieldCount);
314 aGeometry.setPageFieldCount(mnPageFieldCount);
315 aGeometry.setDataFieldCount(mnDataFieldCount);
316 aGeometry.setDataLayoutType(toFieldType(mnDataLayoutType));
317 aGeometry.setHeaderLayout(bHeaderGridLayout);
319 std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims;
320 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims);
321 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims);
322 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aPageDims);
324 OUString sAddress;
325 sal_Int32 nOffset = 0;
326 while( nOffset >= 0 )
328 ScRangeStringConverter::GetTokenByOffset( sAddress, sButtons, nOffset );
329 if( nOffset >= 0 )
331 ScAddress aScAddress;
332 sal_Int32 nAddrOffset(0);
333 if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, *pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset ))
335 std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress);
336 const ScDPSaveDimension* pDim = getDimension(
337 aRowDims, aColDims, aPageDims, aBtnType.first, aBtnType.second);
339 bool bDimension = pDim != nullptr;
340 bool bDataLayout = pDim && pDim->IsDataLayout();
341 bool bHasHidden = pDim && pDim->HasInvisibleMember();
342 bool bPageDim = pDim && pDim->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE;
344 if (bPageDim)
346 // Page dimension needs 2 buttons.
348 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), ScMF::Button);
350 ScMF nMFlag = ScMF::ButtonPopup;
351 if (bHasHidden)
352 nMFlag |= ScMF::HiddenMember;
353 pDoc->ApplyFlagsTab(aScAddress.Col()+1, aScAddress.Row(), aScAddress.Col()+1, aScAddress.Row(), aScAddress.Tab(), nMFlag);
355 else
357 ScMF nMFlag = ScMF::Button;
358 if (bDataLayout)
360 // Data layout dimension only has a plain button with no popup.
362 else if (bDimension)
364 // Normal dimension has a popup arrow button.
365 if (bHasHidden)
366 nMFlag |= ScMF::HiddenMember;
368 nMFlag |= ScMF::ButtonPopup;
371 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag);
377 pDPObject->RefreshAfterLoad();
380 void ScXMLDataPilotTableContext::SetSelectedPage( const OUString& rDimName, const OUString& rSelected )
382 maSelectedPages.emplace(rDimName, rSelected);
385 void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim)
387 if (!pDPSave)
388 return;
390 if (pDim->IsDataLayout())
391 mnDataLayoutType = pDim->GetOrientation();
393 // if a dimension with that name has already been inserted,
394 // mark the new one as duplicate
395 if ( !pDim->IsDataLayout() &&
396 pDPSave->GetExistingDimensionByName(pDim->GetName()) )
397 pDim->SetDupFlag(true);
399 switch (pDim->GetOrientation())
401 case sheet::DataPilotFieldOrientation_ROW:
402 ++mnRowFieldCount;
403 break;
404 case sheet::DataPilotFieldOrientation_COLUMN:
405 ++mnColFieldCount;
406 break;
407 case sheet::DataPilotFieldOrientation_PAGE:
408 ++mnPageFieldCount;
409 break;
410 case sheet::DataPilotFieldOrientation_DATA:
411 ++mnDataFieldCount;
412 break;
413 case sheet::DataPilotFieldOrientation_HIDDEN:
414 break;
415 default:
416 break;
419 pDPSave->AddDimension(pDim);
422 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim)
424 if (!pDPDimSaveData)
425 pDPDimSaveData.reset( new ScDPDimensionSaveData );
426 pDPDimSaveData->AddNumGroupDimension(aNumGroupDim);
429 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGroupDim)
431 if (!pDPDimSaveData)
432 pDPDimSaveData.reset( new ScDPDimensionSaveData );
433 pDPDimSaveData->AddGroupDimension(aGroupDim);
436 void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ )
438 if (!bTargetRangeAddress)
439 return;
441 std::unique_ptr<ScDPObject> pDPObject(new ScDPObject(pDoc));
442 pDPObject->SetName(sDataPilotTableName);
443 pDPObject->SetTag(sApplicationData);
444 pDPObject->SetOutRange(aTargetRangeAddress);
445 pDPObject->SetHeaderLayout(bHeaderGridLayout);
447 sc::PivotTableSources& rPivotSources = GetScImport().GetPivotTableSources();
449 switch (nSourceType)
451 case SQL :
453 ScImportSourceDesc aImportDesc(pDoc);
454 aImportDesc.aDBName = sDatabaseName;
455 aImportDesc.aObject = sSourceObject;
456 aImportDesc.nType = sheet::DataImportMode_SQL;
457 aImportDesc.bNative = bIsNative;
458 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
460 break;
461 case TABLE :
463 ScImportSourceDesc aImportDesc(pDoc);
464 aImportDesc.aDBName = sDatabaseName;
465 aImportDesc.aObject = sSourceObject;
466 aImportDesc.nType = sheet::DataImportMode_TABLE;
467 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
469 break;
470 case QUERY :
472 ScImportSourceDesc aImportDesc(pDoc);
473 aImportDesc.aDBName = sDatabaseName;
474 aImportDesc.aObject = sSourceObject;
475 aImportDesc.nType = sheet::DataImportMode_QUERY;
476 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
478 break;
479 case SERVICE :
481 ScDPServiceDesc aServiceDesc(sServiceName, sServiceSourceName, sServiceSourceObject,
482 sServiceUsername, sServicePassword);
483 rPivotSources.appendServiceSource(pDPObject.get(), aServiceDesc);
485 break;
486 case CELLRANGE :
488 if (bSourceCellRange)
490 ScSheetSourceDesc aSheetDesc(pDoc);
491 if (!sSourceRangeName.isEmpty())
492 // Range name takes precedence.
493 aSheetDesc.SetRangeName(sSourceRangeName);
494 else
495 aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
496 aSheetDesc.SetQueryParam(aSourceQueryParam);
497 rPivotSources.appendSheetSource(pDPObject.get(), aSheetDesc);
500 break;
503 rPivotSources.appendSelectedPages(pDPObject.get(), maSelectedPages);
505 pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
506 pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
507 if (!maRowGrandTotal.maDisplayName.isEmpty())
508 // TODO: Right now, we only support one grand total name for both
509 // column and row totals. Take the value from the row total for
510 // now.
511 pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
513 pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
514 pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
515 pDPSave->SetFilterButton(bShowFilter);
516 pDPSave->SetDrillDown(bDrillDown);
517 if (pDPDimSaveData)
518 pDPSave->SetDimensionData(pDPDimSaveData.get());
519 pDPObject->SetSaveData(*pDPSave);
521 ScDPCollection* pDPCollection = pDoc->GetDPCollection();
523 // #i94570# Names have to be unique, or the tables can't be accessed by API.
524 if ( pDPCollection->GetByName(pDPObject->GetName()) )
525 pDPObject->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading
527 SetButtons(pDPObject.get());
529 pDPCollection->InsertNewTable(std::move(pDPObject));
532 void ScXMLDataPilotTableContext::SetGrandTotal(
533 XMLTokenEnum eOrientation, bool bVisible, const OUString& rDisplayName)
535 switch (eOrientation)
537 case XML_BOTH:
538 maRowGrandTotal.mbVisible = bVisible;
539 maRowGrandTotal.maDisplayName = rDisplayName;
540 maColGrandTotal.mbVisible = bVisible;
541 maColGrandTotal.maDisplayName = rDisplayName;
542 break;
543 case XML_ROW:
544 maRowGrandTotal.mbVisible = bVisible;
545 maRowGrandTotal.maDisplayName = rDisplayName;
546 break;
547 case XML_COLUMN:
548 maColGrandTotal.mbVisible = bVisible;
549 maColGrandTotal.maDisplayName = rDisplayName;
550 break;
551 default:
552 break;
556 ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( ScXMLImport& rImport,
557 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
558 ScXMLDataPilotTableContext* pDataPilotTable) :
559 ScXMLImportContext( rImport )
561 if ( !rAttrList.is() )
562 return;
564 for (auto &aIter : *rAttrList)
566 switch (aIter.getToken())
568 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
569 pDataPilotTable->SetDatabaseName(aIter.toString());
570 break;
571 case XML_ELEMENT( TABLE, XML_SQL_STATEMENT ):
572 pDataPilotTable->SetSourceObject(aIter.toString());
573 break;
574 case XML_ELEMENT( TABLE, XML_PARSE_SQL_STATEMENT ):
575 pDataPilotTable->SetNative(!IsXMLToken(aIter, XML_TRUE));
576 break;
581 ScXMLDPSourceSQLContext::~ScXMLDPSourceSQLContext()
585 ScXMLDPSourceTableContext::ScXMLDPSourceTableContext( ScXMLImport& rImport,
586 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
587 ScXMLDataPilotTableContext* pDataPilotTable) :
588 ScXMLImportContext( rImport )
590 if ( !rAttrList.is() )
591 return;
593 for (auto &aIter : *rAttrList)
595 switch (aIter.getToken())
597 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
598 pDataPilotTable->SetDatabaseName(aIter.toString());
599 break;
600 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
601 case XML_ELEMENT( TABLE, XML_DATABASE_TABLE_NAME ):
602 pDataPilotTable->SetSourceObject(aIter.toString());
603 break;
608 ScXMLDPSourceTableContext::~ScXMLDPSourceTableContext()
612 ScXMLDPSourceQueryContext::ScXMLDPSourceQueryContext( ScXMLImport& rImport,
613 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
614 ScXMLDataPilotTableContext* pDataPilotTable) :
615 ScXMLImportContext( rImport )
617 if ( !rAttrList.is() )
618 return;
620 for (auto &aIter : *rAttrList)
622 switch (aIter.getToken())
624 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
625 pDataPilotTable->SetDatabaseName(aIter.toString());
626 break;
627 case XML_ELEMENT( TABLE, XML_QUERY_NAME ):
628 pDataPilotTable->SetSourceObject(aIter.toString());
629 break;
634 ScXMLDPSourceQueryContext::~ScXMLDPSourceQueryContext()
638 ScXMLSourceServiceContext::ScXMLSourceServiceContext( ScXMLImport& rImport,
639 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
640 ScXMLDataPilotTableContext* pDataPilotTable) :
641 ScXMLImportContext( rImport )
643 if ( !rAttrList.is() )
644 return;
646 for (auto &aIter : *rAttrList)
648 switch (aIter.getToken())
650 case XML_ELEMENT( TABLE, XML_NAME ):
651 pDataPilotTable->SetServiceName(aIter.toString());
652 break;
653 case XML_ELEMENT( TABLE, XML_SOURCE_NAME ):
654 pDataPilotTable->SetServiceSourceName(aIter.toString());
655 break;
656 case XML_ELEMENT( TABLE, XML_OBJECT_NAME ):
657 pDataPilotTable->SetServiceSourceObject(aIter.toString());
658 break;
659 case XML_ELEMENT( TABLE, XML_USER_NAME ):
660 pDataPilotTable->SetServiceUsername(aIter.toString());
661 break;
662 case XML_ELEMENT( TABLE, XML_PASSWORD ):
663 pDataPilotTable->SetServicePassword(aIter.toString());
664 break;
669 ScXMLSourceServiceContext::~ScXMLSourceServiceContext()
673 ScXMLDataPilotGrandTotalContext::ScXMLDataPilotGrandTotalContext(
674 ScXMLImport& rImport, const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
675 ScXMLDataPilotTableContext* pTableContext ) :
676 ScXMLImportContext( rImport ),
677 mpTableContext(pTableContext),
678 meOrientation(NONE),
679 mbVisible(false)
681 if ( !rAttrList.is() )
682 return;
684 for (auto &aIter : *rAttrList)
686 switch (aIter.getToken())
688 case XML_ELEMENT( TABLE, XML_DISPLAY ):
689 mbVisible = IsXMLToken(aIter, XML_TRUE);
690 break;
691 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
692 if (IsXMLToken(aIter, XML_BOTH))
693 meOrientation = BOTH;
694 else if (IsXMLToken(aIter, XML_ROW))
695 meOrientation = ROW;
696 else if (IsXMLToken(aIter, XML_COLUMN))
697 meOrientation = COLUMN;
698 break;
699 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
700 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
701 maDisplayName = aIter.toString();
702 break;
703 default:
704 break;
709 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
713 void SAL_CALL ScXMLDataPilotGrandTotalContext::endFastElement( sal_Int32 /*nElement*/ )
715 XMLTokenEnum eOrient = XML_NONE;
716 switch (meOrientation)
718 case BOTH:
719 eOrient = XML_BOTH;
720 break;
721 case ROW:
722 eOrient = XML_ROW;
723 break;
724 case COLUMN:
725 eOrient = XML_COLUMN;
726 break;
727 default:
728 break;
730 mpTableContext->SetGrandTotal(eOrient, mbVisible, maDisplayName);
733 ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport& rImport,
734 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
735 ScXMLDataPilotTableContext* pTempDataPilotTable) :
736 ScXMLImportContext( rImport ),
737 pDataPilotTable(pTempDataPilotTable)
739 if ( !rAttrList.is() )
740 return;
742 for (auto &aIter : *rAttrList)
744 switch (aIter.getToken())
746 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
748 ScRange aSourceRangeAddress;
749 sal_Int32 nOffset(0);
750 ScDocument* pDoc = GetScImport().GetDocument();
751 assert(pDoc);
752 if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
753 pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
755 break;
756 case XML_ELEMENT( TABLE, XML_NAME ):
757 pDataPilotTable->SetSourceRangeName(aIter.toString());
758 break;
763 ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
767 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSourceCellRangeContext::createFastChildContext(
768 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
770 SvXMLImportContext *pContext = nullptr;
771 sax_fastparser::FastAttributeList *pAttribList =
772 &sax_fastparser::castToFastAttributeList( xAttrList );
774 switch (nElement)
776 case XML_ELEMENT( TABLE, XML_FILTER ):
777 pContext = new ScXMLDPFilterContext(GetScImport(), pAttribList, pDataPilotTable);
778 break;
781 return pContext;
784 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport& rImport,
785 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
786 ScXMLDataPilotTableContext* pTempDataPilotTable) :
787 ScXMLImportContext( rImport ),
788 pDataPilotTable(pTempDataPilotTable),
789 xDim(),
790 fStart(0.0),
791 fEnd(0.0),
792 fStep(0.0),
793 nUsedHierarchy(1),
794 nGroupPart(0),
795 nFunction(ScGeneralFunction::NONE),
796 nOrientation(sheet::DataPilotFieldOrientation_HIDDEN),
797 bSelectedPage(false),
798 bIsGroupField(false),
799 bDateValue(false),
800 bAutoStart(false),
801 bAutoEnd(false),
802 mbHasHiddenMember(false)
804 bool bHasName = false;
805 bool bDataLayout = false;
806 bool bIgnoreSelectedPage = false;
807 OUString aDisplayName;
808 if ( rAttrList.is() )
810 for (auto &aIter : *rAttrList)
812 switch (aIter.getToken())
814 case XML_ELEMENT( TABLE, XML_SOURCE_FIELD_NAME ):
815 sName = aIter.toString();
816 bHasName = true;
817 break;
818 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
819 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
820 aDisplayName = aIter.toString();
821 break;
822 case XML_ELEMENT( TABLE, XML_IS_DATA_LAYOUT_FIELD ):
823 bDataLayout = IsXMLToken(aIter, XML_TRUE);
824 break;
825 case XML_ELEMENT( TABLE, XML_FUNCTION ):
826 nFunction = ScXMLConverter::GetFunctionFromString2( aIter.toString() );
827 break;
828 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
829 nOrientation = ScXMLConverter::GetOrientationFromString( aIter.toString() );
830 break;
831 case XML_ELEMENT( TABLE, XML_SELECTED_PAGE ):
832 sSelectedPage = aIter.toString();
833 bSelectedPage = true;
834 break;
835 case XML_ELEMENT( LO_EXT, XML_IGNORE_SELECTED_PAGE ):
836 bIgnoreSelectedPage = true;
837 break;
838 case XML_ELEMENT( TABLE, XML_USED_HIERARCHY ):
839 nUsedHierarchy = aIter.toInt32();
840 break;
845 // use the new extension elements
846 if (bIgnoreSelectedPage)
847 bSelectedPage = false;
849 if (bHasName)
851 xDim.reset(new ScDPSaveDimension(sName, bDataLayout));
852 if (!aDisplayName.isEmpty())
853 xDim->SetLayoutName(aDisplayName);
857 ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
861 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotFieldContext::createFastChildContext(
862 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
864 SvXMLImportContext *pContext = nullptr;
865 sax_fastparser::FastAttributeList *pAttribList =
866 &sax_fastparser::castToFastAttributeList( xAttrList );
868 switch (nElement)
870 case XML_ELEMENT( TABLE, XML_DATA_PILOT_LEVEL ):
871 pContext = new ScXMLDataPilotLevelContext(GetScImport(), pAttribList, this);
872 break;
873 case XML_ELEMENT( TABLE, XML_DATA_PILOT_FIELD_REFERENCE ):
874 pContext = new ScXMLDataPilotFieldReferenceContext(GetScImport(), pAttribList, this);
875 break;
876 case XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUPS ):
877 pContext = new ScXMLDataPilotGroupsContext(GetScImport(), pAttribList, this);
878 break;
881 return pContext;
884 void ScXMLDataPilotFieldContext::AddMember(std::unique_ptr<ScDPSaveMember> pMember)
886 if (xDim)
888 bool isVisible = pMember->GetIsVisible();
889 xDim->AddMember(std::move(pMember));
890 if (!isVisible)
891 // This member is hidden.
892 mbHasHiddenMember = true;
896 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString& rName)
898 if (xDim)
899 xDim->SetSubtotalName(rName);
902 void ScXMLDataPilotFieldContext::AddGroup(const ::std::vector<OUString>& rMembers, const OUString& rName)
904 ScXMLDataPilotGroup aGroup;
905 aGroup.aMembers = rMembers;
906 aGroup.aName = rName;
907 aGroups.push_back(aGroup);
910 void SAL_CALL ScXMLDataPilotFieldContext::endFastElement( sal_Int32 /*nElement*/ )
912 if (!xDim)
913 return;
915 xDim->SetUsedHierarchy(nUsedHierarchy);
916 xDim->SetFunction(nFunction);
917 xDim->SetOrientation(nOrientation);
918 if (bSelectedPage)
920 pDataPilotTable->SetSelectedPage(xDim->GetName(), sSelectedPage);
922 pDataPilotTable->AddDimension(xDim.release());
923 if (!bIsGroupField)
924 return;
926 ScDPNumGroupInfo aInfo;
927 aInfo.mbEnable = true;
928 aInfo.mbDateValues = bDateValue;
929 aInfo.mbAutoStart = bAutoStart;
930 aInfo.mbAutoEnd = bAutoEnd;
931 aInfo.mfStart = fStart;
932 aInfo.mfEnd = fEnd;
933 aInfo.mfStep = fStep;
934 if (!sGroupSource.isEmpty())
936 ScDPSaveGroupDimension aGroupDim(sGroupSource, sName);
937 if (nGroupPart)
938 aGroupDim.SetDateInfo(aInfo, nGroupPart);
939 else
941 for (const auto& rGroup : aGroups)
943 ScDPSaveGroupItem aItem(rGroup.aName);
944 for (const auto& rMember : rGroup.aMembers)
946 aItem.AddElement(rMember);
948 aGroupDim.AddGroupItem(aItem);
951 pDataPilotTable->AddGroupDim(aGroupDim);
953 else //NumGroup
955 ScDPSaveNumGroupDimension aNumGroupDim(sName, aInfo);
956 if (nGroupPart)
957 aNumGroupDim.SetDateInfo(aInfo, nGroupPart);
958 pDataPilotTable->AddGroupDim(aNumGroupDim);
962 ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport& rImport,
963 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
964 ScXMLDataPilotFieldContext* pDataPilotField) :
965 ScXMLImportContext( rImport )
967 sheet::DataPilotFieldReference aReference;
969 if ( rAttrList.is() )
971 for (auto &aIter : *rAttrList)
973 switch (aIter.getToken())
975 case XML_ELEMENT( TABLE, XML_TYPE ):
977 if (IsXMLToken(aIter, XML_NONE))
978 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::NONE;
979 else if (IsXMLToken(aIter, XML_MEMBER_DIFFERENCE))
980 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE;
981 else if (IsXMLToken(aIter, XML_MEMBER_PERCENTAGE))
982 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE;
983 else if (IsXMLToken(aIter, XML_MEMBER_PERCENTAGE_DIFFERENCE))
984 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
985 else if (IsXMLToken(aIter, XML_RUNNING_TOTAL))
986 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::RUNNING_TOTAL;
987 else if (IsXMLToken(aIter, XML_ROW_PERCENTAGE))
988 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE;
989 else if (IsXMLToken(aIter, XML_COLUMN_PERCENTAGE))
990 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
991 else if (IsXMLToken(aIter, XML_TOTAL_PERCENTAGE))
992 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
993 else if (IsXMLToken(aIter, XML_INDEX))
994 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::INDEX;
996 break;
997 case XML_ELEMENT( TABLE, XML_FIELD_NAME ):
999 aReference.ReferenceField = aIter.toString();
1001 break;
1002 case XML_ELEMENT( TABLE, XML_MEMBER_TYPE ):
1004 if (IsXMLToken(aIter, XML_NAMED))
1005 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
1006 else if (IsXMLToken(aIter, XML_PREVIOUS))
1007 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::PREVIOUS;
1008 else if (IsXMLToken(aIter, XML_NEXT))
1009 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NEXT;
1011 break;
1012 case XML_ELEMENT( TABLE, XML_MEMBER_NAME ):
1014 aReference.ReferenceItemName = aIter.toString();
1016 break;
1020 pDataPilotField->SetFieldReference(aReference);
1023 ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1027 ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport& rImport,
1028 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1029 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1030 ScXMLImportContext( rImport ),
1031 pDataPilotField(pTempDataPilotField)
1033 if ( !rAttrList.is() )
1034 return;
1036 for (auto &aIter : *rAttrList)
1038 switch (aIter.getToken())
1040 case XML_ELEMENT( TABLE, XML_SHOW_EMPTY ):
1041 pDataPilotField->SetShowEmpty(IsXMLToken(aIter, XML_TRUE));
1042 break;
1043 case XML_ELEMENT( CALC_EXT, XML_REPEAT_ITEM_LABELS ):
1044 pDataPilotField->SetRepeatItemLabels(IsXMLToken(aIter, XML_TRUE));
1045 break;
1050 ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1054 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotLevelContext::createFastChildContext(
1055 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1057 SvXMLImportContext *pContext = nullptr;
1058 sax_fastparser::FastAttributeList *pAttribList =
1059 &sax_fastparser::castToFastAttributeList( xAttrList );
1061 switch (nElement)
1063 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SUBTOTALS ):
1064 pContext = new ScXMLDataPilotSubTotalsContext(GetScImport(), pDataPilotField);
1065 break;
1066 case XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBERS ):
1067 pContext = new ScXMLDataPilotMembersContext(GetScImport(), pDataPilotField);
1068 break;
1069 case XML_ELEMENT( TABLE, XML_DATA_PILOT_DISPLAY_INFO ):
1070 pContext = new ScXMLDataPilotDisplayInfoContext(GetScImport(), pAttribList, pDataPilotField);
1071 break;
1072 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SORT_INFO ):
1073 pContext = new ScXMLDataPilotSortInfoContext(GetScImport(), pAttribList, pDataPilotField);
1074 break;
1075 case XML_ELEMENT( TABLE, XML_DATA_PILOT_LAYOUT_INFO ):
1076 pContext = new ScXMLDataPilotLayoutInfoContext(GetScImport(), pAttribList, pDataPilotField);
1077 break;
1080 return pContext;
1083 ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport& rImport,
1084 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1085 ScXMLDataPilotFieldContext* pDataPilotField) :
1086 ScXMLImportContext( rImport )
1088 sheet::DataPilotFieldAutoShowInfo aInfo;
1090 if ( rAttrList.is() )
1092 for (auto &aIter : *rAttrList)
1094 switch (aIter.getToken())
1096 case XML_ELEMENT( TABLE, XML_ENABLED ):
1097 if (IsXMLToken(aIter, XML_TRUE))
1098 aInfo.IsEnabled = true;
1099 else
1100 aInfo.IsEnabled = false;
1101 break;
1102 case XML_ELEMENT( TABLE, XML_DISPLAY_MEMBER_MODE ):
1103 if (IsXMLToken(aIter, XML_FROM_TOP))
1104 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_TOP;
1105 else if (IsXMLToken(aIter, XML_FROM_BOTTOM))
1106 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM;
1107 break;
1108 case XML_ELEMENT( TABLE, XML_MEMBER_COUNT ):
1109 aInfo.ItemCount = aIter.toInt32();
1110 break;
1111 case XML_ELEMENT( TABLE, XML_DATA_FIELD ):
1112 aInfo.DataField = aIter.toString();
1113 break;
1117 pDataPilotField->SetAutoShowInfo(aInfo);
1120 ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1124 ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport& rImport,
1125 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1126 ScXMLDataPilotFieldContext* pDataPilotField) :
1127 ScXMLImportContext( rImport )
1129 sheet::DataPilotFieldSortInfo aInfo;
1131 if ( rAttrList.is() )
1133 for (auto &aIter : *rAttrList)
1135 switch (aIter.getToken())
1137 case XML_ELEMENT( TABLE, XML_ORDER ):
1138 if (IsXMLToken(aIter, XML_ASCENDING))
1139 aInfo.IsAscending = true;
1140 else if (IsXMLToken(aIter, XML_DESCENDING))
1141 aInfo.IsAscending = false;
1142 break;
1143 case XML_ELEMENT( TABLE, XML_SORT_MODE ):
1144 if (IsXMLToken(aIter, XML_NONE))
1145 aInfo.Mode = sheet::DataPilotFieldSortMode::NONE;
1146 else if (IsXMLToken(aIter, XML_MANUAL))
1147 aInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
1148 else if (IsXMLToken(aIter, XML_NAME))
1149 aInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
1150 else if (IsXMLToken(aIter, XML_DATA))
1151 aInfo.Mode = sheet::DataPilotFieldSortMode::DATA;
1152 break;
1153 case XML_ELEMENT( TABLE, XML_DATA_FIELD ):
1154 aInfo.Field = aIter.toString();
1155 break;
1159 pDataPilotField->SetSortInfo(aInfo);
1162 ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1166 ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport& rImport,
1167 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1168 ScXMLDataPilotFieldContext* pDataPilotField) :
1169 ScXMLImportContext( rImport )
1171 sheet::DataPilotFieldLayoutInfo aInfo;
1173 if ( rAttrList.is() )
1175 for (auto &aIter : *rAttrList)
1177 switch (aIter.getToken())
1179 case XML_ELEMENT( TABLE, XML_ADD_EMPTY_LINES ):
1180 if (IsXMLToken(aIter, XML_TRUE))
1181 aInfo.AddEmptyLines = true;
1182 else
1183 aInfo.AddEmptyLines = false;
1184 break;
1185 case XML_ELEMENT( TABLE, XML_LAYOUT_MODE ):
1186 if (IsXMLToken(aIter, XML_TABULAR_LAYOUT))
1187 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
1188 else if (IsXMLToken(aIter, XML_OUTLINE_SUBTOTALS_TOP))
1189 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
1190 else if (IsXMLToken(aIter, XML_OUTLINE_SUBTOTALS_BOTTOM))
1191 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
1192 break;
1196 pDataPilotField->SetLayoutInfo(aInfo);}
1198 ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1202 ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport,
1203 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1204 ScXMLImportContext( rImport ),
1205 pDataPilotField(pTempDataPilotField)
1208 // has no attributes
1211 ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1215 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotSubTotalsContext::createFastChildContext(
1216 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1218 SvXMLImportContext *pContext = nullptr;
1219 sax_fastparser::FastAttributeList *pAttribList =
1220 &sax_fastparser::castToFastAttributeList( xAttrList );
1222 switch (nElement)
1224 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SUBTOTAL ):
1225 pContext = new ScXMLDataPilotSubTotalContext(GetScImport(), pAttribList, this);
1226 break;
1229 return pContext;
1232 void SAL_CALL ScXMLDataPilotSubTotalsContext::endFastElement( sal_Int32 /*nElement*/ )
1234 pDataPilotField->SetSubTotals(maFunctions);
1235 if (!maDisplayName.isEmpty())
1236 pDataPilotField->SetSubTotalName(maDisplayName);
1239 void ScXMLDataPilotSubTotalsContext::AddFunction(ScGeneralFunction nFunction)
1241 maFunctions.push_back(nFunction);
1244 void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
1246 maDisplayName = rName;
1249 ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport& rImport,
1250 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1251 ScXMLDataPilotSubTotalsContext* pDataPilotSubTotals) :
1252 ScXMLImportContext( rImport )
1254 if ( !rAttrList.is() )
1255 return;
1257 for (auto &aIter : *rAttrList)
1259 switch (aIter.getToken())
1261 case XML_ELEMENT( TABLE, XML_FUNCTION ):
1262 pDataPilotSubTotals->AddFunction( ScXMLConverter::GetFunctionFromString2( aIter.toString() ) );
1263 break;
1264 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
1265 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
1266 pDataPilotSubTotals->SetDisplayName(aIter.toString());
1267 break;
1272 ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1276 ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport& rImport,
1277 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1278 ScXMLImportContext( rImport ),
1279 pDataPilotField(pTempDataPilotField)
1281 // has no attributes
1284 ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1288 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotMembersContext::createFastChildContext(
1289 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1291 SvXMLImportContext *pContext = nullptr;
1292 sax_fastparser::FastAttributeList *pAttribList =
1293 &sax_fastparser::castToFastAttributeList( xAttrList );
1295 switch (nElement)
1297 case XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBER ):
1298 pContext = new ScXMLDataPilotMemberContext(GetScImport(), pAttribList, pDataPilotField);
1299 break;
1302 return pContext;
1305 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport& rImport,
1306 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1307 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1308 ScXMLImportContext( rImport ),
1309 pDataPilotField(pTempDataPilotField),
1310 bDisplay( true ),
1311 bDisplayDetails( true ),
1312 bHasName( false )
1314 if ( !rAttrList.is() )
1315 return;
1317 for (auto &aIter : *rAttrList)
1319 switch (aIter.getToken())
1321 case XML_ELEMENT( TABLE, XML_NAME ):
1322 sName = aIter.toString();
1323 bHasName = true;
1324 break;
1325 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
1326 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
1327 maDisplayName = aIter.toString();
1328 break;
1329 case XML_ELEMENT( TABLE, XML_DISPLAY ):
1330 bDisplay = IsXMLToken(aIter, XML_TRUE);
1331 break;
1332 case XML_ELEMENT( TABLE, XML_SHOW_DETAILS ):
1333 bDisplayDetails = IsXMLToken(aIter, XML_TRUE);
1334 break;
1339 ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1343 void SAL_CALL ScXMLDataPilotMemberContext::endFastElement( sal_Int32 /*nElement*/ )
1345 if (bHasName) // #i53407# don't check sName, empty name is allowed
1347 std::unique_ptr<ScDPSaveMember> pMember(new ScDPSaveMember(sName));
1348 if (!maDisplayName.isEmpty())
1349 pMember->SetLayoutName(maDisplayName);
1350 pMember->SetIsVisible(bDisplay);
1351 pMember->SetShowDetails(bDisplayDetails);
1352 pDataPilotField->AddMember(std::move(pMember));
1356 ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport& rImport,
1357 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1358 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1359 ScXMLImportContext( rImport ),
1360 pDataPilotField(pTempDataPilotField)
1362 OUString sGroupSource;
1363 double fStart(0.0);
1364 double fEnd(0.0);
1365 double fStep(0.0);
1366 sal_Int32 nGroupPart(0);
1367 bool bDateValue(false);
1368 bool bAutoStart(true);
1369 bool bAutoEnd(true);
1371 if ( rAttrList.is() )
1373 for (auto &aIter : *rAttrList)
1375 switch (aIter.getToken() & TOKEN_MASK)
1377 case XML_SOURCE_FIELD_NAME :
1379 sGroupSource = aIter.toString();
1381 break;
1382 case XML_DATE_START :
1384 bDateValue = true;
1385 if (IsXMLToken(aIter, XML_AUTO))
1386 bAutoStart = true;
1387 else
1389 GetScImport().GetMM100UnitConverter().convertDateTime(fStart, aIter.toString());
1390 bAutoStart = false;
1393 break;
1394 case XML_DATE_END :
1396 bDateValue = true;
1397 if (IsXMLToken(aIter, XML_AUTO))
1398 bAutoEnd = true;
1399 else
1401 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd, aIter.toString());
1402 bAutoEnd = false;
1405 break;
1406 case XML_START :
1408 if (IsXMLToken(aIter, XML_AUTO))
1409 bAutoStart = true;
1410 else
1412 fStart = aIter.toDouble();
1413 bAutoStart = false;
1416 break;
1417 case XML_END :
1419 if (IsXMLToken(aIter, XML_AUTO))
1420 bAutoEnd = true;
1421 else
1423 fEnd = aIter.toDouble();
1424 bAutoEnd = false;
1427 break;
1428 case XML_STEP :
1430 fStep = aIter.toDouble();
1432 break;
1433 case XML_GROUPED_BY :
1435 if (IsXMLToken(aIter, XML_SECONDS))
1436 nGroupPart = css::sheet::DataPilotFieldGroupBy::SECONDS;
1437 else if (IsXMLToken(aIter, XML_MINUTES))
1438 nGroupPart = css::sheet::DataPilotFieldGroupBy::MINUTES;
1439 else if (IsXMLToken(aIter, XML_HOURS))
1440 nGroupPart = css::sheet::DataPilotFieldGroupBy::HOURS;
1441 else if (IsXMLToken(aIter, XML_DAYS))
1442 nGroupPart = css::sheet::DataPilotFieldGroupBy::DAYS;
1443 else if (IsXMLToken(aIter, XML_MONTHS))
1444 nGroupPart = css::sheet::DataPilotFieldGroupBy::MONTHS;
1445 else if (IsXMLToken(aIter, XML_QUARTERS))
1446 nGroupPart = css::sheet::DataPilotFieldGroupBy::QUARTERS;
1447 else if (IsXMLToken(aIter, XML_YEARS))
1448 nGroupPart = css::sheet::DataPilotFieldGroupBy::YEARS;
1450 break;
1454 pDataPilotField->SetGrouping(sGroupSource, fStart, fEnd, fStep, nGroupPart, bDateValue, bAutoStart, bAutoEnd);
1457 ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1461 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotGroupsContext::createFastChildContext(
1462 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1464 SvXMLImportContext *pContext = nullptr;
1465 sax_fastparser::FastAttributeList *pAttribList =
1466 &sax_fastparser::castToFastAttributeList( xAttrList );
1468 if (nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUP ))
1470 pContext = new ScXMLDataPilotGroupContext(GetScImport(), pAttribList, pDataPilotField);
1473 return pContext;
1476 ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport& rImport,
1477 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1478 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1479 ScXMLImportContext( rImport ),
1480 pDataPilotField(pTempDataPilotField)
1482 if ( rAttrList.is() )
1484 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_NAME ) ) );
1485 if (aIter != rAttrList->end())
1486 sName = aIter.toString();
1490 ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1494 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotGroupContext::createFastChildContext(
1495 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1497 SvXMLImportContext *pContext = nullptr;
1498 sax_fastparser::FastAttributeList *pAttribList =
1499 &sax_fastparser::castToFastAttributeList( xAttrList );
1501 if (nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBER ) ||
1502 nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUP_MEMBER ))
1504 pContext = new ScXMLDataPilotGroupMemberContext(GetScImport(), pAttribList, this);
1507 return pContext;
1510 void SAL_CALL ScXMLDataPilotGroupContext::endFastElement( sal_Int32 /*nElement*/ )
1512 pDataPilotField->AddGroup(aMembers, sName);
1515 ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport& rImport,
1516 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1517 ScXMLDataPilotGroupContext* pTempDataPilotGroup) :
1518 ScXMLImportContext( rImport ),
1519 pDataPilotGroup(pTempDataPilotGroup)
1521 if ( rAttrList.is() )
1523 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_NAME ) ) );
1524 if (aIter != rAttrList->end())
1525 sName = aIter.toString();
1529 ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1533 void SAL_CALL ScXMLDataPilotGroupMemberContext::endFastElement( sal_Int32 /*nElement*/ )
1535 if (!sName.isEmpty())
1536 pDataPilotGroup->AddMember(sName);
1539 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */