Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / xml / xmldpimp.cxx
blob15dd638deaeb827ae49947d3848e5ef42dd4a3ac
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/xmlnmspe.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;
50 using ::com::sun::star::xml::sax::XAttributeList;
52 ScXMLDataPilotTablesContext::ScXMLDataPilotTablesContext( ScXMLImport& rImport ) :
53 ScXMLImportContext( rImport )
55 // has no Attributes
56 rImport.LockSolarMutex();
59 ScXMLDataPilotTablesContext::~ScXMLDataPilotTablesContext()
61 GetScImport().UnlockSolarMutex();
64 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotTablesContext::createFastChildContext(
65 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
67 SvXMLImportContext *pContext = nullptr;
68 sax_fastparser::FastAttributeList *pAttribList =
69 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
71 switch (nElement)
73 case XML_ELEMENT( TABLE, XML_DATA_PILOT_TABLE ) :
75 pContext = new ScXMLDataPilotTableContext( GetScImport(), pAttribList );
77 break;
80 if( !pContext )
81 pContext = new SvXMLImportContext( GetImport() );
83 return pContext;
86 ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
87 mbVisible(true) {}
89 ScXMLDataPilotTableContext::ScXMLDataPilotTableContext( ScXMLImport& rImport,
90 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList ) :
91 ScXMLImportContext( rImport ),
92 pDoc(GetScImport().GetDocument()),
93 pDPSave(new ScDPSaveData()),
94 sDataPilotTableName(),
95 sApplicationData(),
96 nSourceType(SQL),
97 mnRowFieldCount(0),
98 mnColFieldCount(0),
99 mnPageFieldCount(0),
100 mnDataFieldCount(0),
101 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN),
102 bIsNative(true),
103 bIgnoreEmptyRows(false),
104 bIdentifyCategories(false),
105 bTargetRangeAddress(false),
106 bSourceCellRange(false),
107 bShowFilter(true),
108 bDrillDown(true),
109 bHeaderGridLayout(false)
111 if ( rAttrList.is() )
113 for (auto &aIter : *rAttrList)
115 switch (aIter.getToken())
117 case XML_ELEMENT( TABLE, XML_NAME ):
119 sDataPilotTableName = aIter.toString();
121 break;
122 case XML_ELEMENT( TABLE, XML_APPLICATION_DATA ):
124 sApplicationData = aIter.toString();
126 break;
127 case XML_ELEMENT( TABLE, XML_GRAND_TOTAL ):
129 if (IsXMLToken(aIter, XML_BOTH))
131 maRowGrandTotal.mbVisible = true;
132 maColGrandTotal.mbVisible = true;
134 else if (IsXMLToken(aIter, XML_ROW))
136 maRowGrandTotal.mbVisible = true;
137 maColGrandTotal.mbVisible = false;
139 else if (IsXMLToken(aIter, XML_COLUMN))
141 maRowGrandTotal.mbVisible = false;
142 maColGrandTotal.mbVisible = true;
144 else
146 maRowGrandTotal.mbVisible = false;
147 maColGrandTotal.mbVisible = false;
150 break;
151 case XML_ELEMENT( TABLE, XML_IGNORE_EMPTY_ROWS ):
153 bIgnoreEmptyRows = IsXMLToken(aIter, XML_TRUE);
155 break;
156 case XML_ELEMENT( TABLE, XML_IDENTIFY_CATEGORIES ):
158 bIdentifyCategories = IsXMLToken(aIter, XML_TRUE);
160 break;
161 case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
163 sal_Int32 nOffset(0);
164 bTargetRangeAddress = ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress, aIter.toString(), pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
166 break;
167 case XML_ELEMENT( TABLE, XML_BUTTONS ):
169 sButtons = aIter.toString();
171 break;
172 case XML_ELEMENT( TABLE, XML_SHOW_FILTER_BUTTON ):
174 bShowFilter = IsXMLToken(aIter, XML_TRUE);
176 break;
177 case XML_ELEMENT( TABLE, XML_DRILL_DOWN_ON_DOUBLE_CLICK ):
179 bDrillDown = IsXMLToken(aIter, XML_TRUE);
181 break;
182 case XML_ELEMENT( TABLE, XML_HEADER_GRID_LAYOUT ):
184 bHeaderGridLayout = IsXMLToken(aIter, XML_TRUE);
186 break;
192 ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
196 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotTableContext::createFastChildContext(
197 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
199 SvXMLImportContext *pContext = nullptr;
200 sax_fastparser::FastAttributeList *pAttribList =
201 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
203 switch (nElement)
205 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_SQL ):
207 pContext = new ScXMLDPSourceSQLContext(GetScImport(), pAttribList, this);
208 nSourceType = SQL;
210 break;
211 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_TABLE ):
213 pContext = new ScXMLDPSourceTableContext(GetScImport(), pAttribList, this);
214 nSourceType = TABLE;
216 break;
217 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_QUERY ):
219 pContext = new ScXMLDPSourceQueryContext(GetScImport(), pAttribList, this);
220 nSourceType = QUERY;
222 break;
223 case XML_ELEMENT( TABLE, XML_SOURCE_SERVICE ):
225 pContext = new ScXMLSourceServiceContext(GetScImport(), pAttribList, this);
226 nSourceType = SERVICE;
228 break;
229 case XML_ELEMENT( TABLE, XML_DATA_PILOT_GRAND_TOTAL ):
230 case XML_ELEMENT( TABLE_EXT, XML_DATA_PILOT_GRAND_TOTAL ):
232 pContext = new ScXMLDataPilotGrandTotalContext(GetScImport(), pAttribList, this);
234 break;
235 case XML_ELEMENT( TABLE, XML_SOURCE_CELL_RANGE ):
237 pContext = new ScXMLSourceCellRangeContext(GetScImport(), pAttribList, this);
238 nSourceType = CELLRANGE;
240 break;
241 case XML_ELEMENT( TABLE, XML_DATA_PILOT_FIELD ):
242 pContext = new ScXMLDataPilotFieldContext(GetScImport(), pAttribList, this);
243 break;
246 if( !pContext )
247 pContext = new SvXMLImportContext( GetImport() );
249 return pContext;
252 namespace {
254 const ScDPSaveDimension* getDimension(
255 const std::vector<const ScDPSaveDimension*>& rRowDims,
256 const std::vector<const ScDPSaveDimension*>& rColDims,
257 const std::vector<const ScDPSaveDimension*>& rPageDims,
258 ScDPOutputGeometry::FieldType eType, size_t nPos)
260 switch (eType)
262 case ScDPOutputGeometry::Column:
264 if (rColDims.size() <= nPos)
265 return nullptr;
267 return rColDims[nPos];
269 case ScDPOutputGeometry::Row:
271 if (rRowDims.size() <= nPos)
272 return nullptr;
274 return rRowDims[nPos];
276 case ScDPOutputGeometry::Page:
278 if (rPageDims.size() <= nPos)
279 return nullptr;
281 return rPageDims[nPos];
283 case ScDPOutputGeometry::Data:
284 break;
285 case ScDPOutputGeometry::None:
286 break;
287 default:
288 break;
290 return nullptr;
293 ScDPOutputGeometry::FieldType toFieldType(sheet::DataPilotFieldOrientation nOrient)
295 switch (nOrient)
297 case sheet::DataPilotFieldOrientation_COLUMN:
298 return ScDPOutputGeometry::Column;
299 case sheet::DataPilotFieldOrientation_DATA:
300 return ScDPOutputGeometry::Data;
301 case sheet::DataPilotFieldOrientation_PAGE:
302 return ScDPOutputGeometry::Page;
303 case sheet::DataPilotFieldOrientation_ROW:
304 return ScDPOutputGeometry::Row;
305 case sheet::DataPilotFieldOrientation_HIDDEN:
306 break;
307 default:
308 break;
310 return ScDPOutputGeometry::None;
315 void ScXMLDataPilotTableContext::SetButtons(ScDPObject* pDPObject)
317 ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter);
318 aGeometry.setColumnFieldCount(mnColFieldCount);
319 aGeometry.setRowFieldCount(mnRowFieldCount);
320 aGeometry.setPageFieldCount(mnPageFieldCount);
321 aGeometry.setDataFieldCount(mnDataFieldCount);
322 aGeometry.setDataLayoutType(toFieldType(mnDataLayoutType));
323 aGeometry.setHeaderLayout(bHeaderGridLayout);
325 std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims;
326 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims);
327 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims);
328 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aPageDims);
330 OUString sAddress;
331 sal_Int32 nOffset = 0;
332 while( nOffset >= 0 )
334 ScRangeStringConverter::GetTokenByOffset( sAddress, sButtons, nOffset );
335 if( nOffset >= 0 )
337 ScAddress aScAddress;
338 sal_Int32 nAddrOffset(0);
339 if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset ))
341 std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress);
342 const ScDPSaveDimension* pDim = getDimension(
343 aRowDims, aColDims, aPageDims, aBtnType.first, aBtnType.second);
345 bool bDimension = pDim != nullptr;
346 bool bDataLayout = pDim && pDim->IsDataLayout();
347 bool bHasHidden = pDim && pDim->HasInvisibleMember();
348 bool bPageDim = pDim && pDim->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE;
350 if (bPageDim)
352 // Page dimension needs 2 buttons.
354 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), ScMF::Button);
356 ScMF nMFlag = ScMF::ButtonPopup;
357 if (bHasHidden)
358 nMFlag |= ScMF::HiddenMember;
359 pDoc->ApplyFlagsTab(aScAddress.Col()+1, aScAddress.Row(), aScAddress.Col()+1, aScAddress.Row(), aScAddress.Tab(), nMFlag);
361 else
363 ScMF nMFlag = ScMF::Button;
364 if (bDataLayout)
366 // Data layout dimension only has a plain button with no popup.
368 else if (bDimension)
370 // Normal dimension has a popup arrow button.
371 if (bHasHidden)
372 nMFlag |= ScMF::HiddenMember;
374 nMFlag |= ScMF::ButtonPopup;
377 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag);
383 pDPObject->RefreshAfterLoad();
386 void ScXMLDataPilotTableContext::SetSelectedPage( const OUString& rDimName, const OUString& rSelected )
388 maSelectedPages.emplace(rDimName, rSelected);
391 void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim)
393 if (pDPSave)
395 if (pDim->IsDataLayout())
396 mnDataLayoutType = pDim->GetOrientation();
398 // if a dimension with that name has already been inserted,
399 // mark the new one as duplicate
400 if ( !pDim->IsDataLayout() &&
401 pDPSave->GetExistingDimensionByName(pDim->GetName()) )
402 pDim->SetDupFlag(true);
404 switch (pDim->GetOrientation())
406 case sheet::DataPilotFieldOrientation_ROW:
407 ++mnRowFieldCount;
408 break;
409 case sheet::DataPilotFieldOrientation_COLUMN:
410 ++mnColFieldCount;
411 break;
412 case sheet::DataPilotFieldOrientation_PAGE:
413 ++mnPageFieldCount;
414 break;
415 case sheet::DataPilotFieldOrientation_DATA:
416 ++mnDataFieldCount;
417 break;
418 case sheet::DataPilotFieldOrientation_HIDDEN:
419 break;
420 default:
421 break;
424 pDPSave->AddDimension(pDim);
428 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim)
430 if (!pDPDimSaveData)
431 pDPDimSaveData.reset( new ScDPDimensionSaveData );
432 pDPDimSaveData->AddNumGroupDimension(aNumGroupDim);
435 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGroupDim)
437 if (!pDPDimSaveData)
438 pDPDimSaveData.reset( new ScDPDimensionSaveData );
439 pDPDimSaveData->AddGroupDimension(aGroupDim);
442 void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ )
444 if (!bTargetRangeAddress)
445 return;
447 std::unique_ptr<ScDPObject> pDPObject(new ScDPObject(pDoc));
448 pDPObject->SetName(sDataPilotTableName);
449 pDPObject->SetTag(sApplicationData);
450 pDPObject->SetOutRange(aTargetRangeAddress);
451 pDPObject->SetHeaderLayout(bHeaderGridLayout);
453 sc::PivotTableSources& rPivotSources = GetScImport().GetPivotTableSources();
455 switch (nSourceType)
457 case SQL :
459 ScImportSourceDesc aImportDesc(pDoc);
460 aImportDesc.aDBName = sDatabaseName;
461 aImportDesc.aObject = sSourceObject;
462 aImportDesc.nType = sheet::DataImportMode_SQL;
463 aImportDesc.bNative = bIsNative;
464 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
466 break;
467 case TABLE :
469 ScImportSourceDesc aImportDesc(pDoc);
470 aImportDesc.aDBName = sDatabaseName;
471 aImportDesc.aObject = sSourceObject;
472 aImportDesc.nType = sheet::DataImportMode_TABLE;
473 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
475 break;
476 case QUERY :
478 ScImportSourceDesc aImportDesc(pDoc);
479 aImportDesc.aDBName = sDatabaseName;
480 aImportDesc.aObject = sSourceObject;
481 aImportDesc.nType = sheet::DataImportMode_QUERY;
482 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
484 break;
485 case SERVICE :
487 ScDPServiceDesc aServiceDesc(sServiceName, sServiceSourceName, sServiceSourceObject,
488 sServiceUsername, sServicePassword);
489 rPivotSources.appendServiceSource(pDPObject.get(), aServiceDesc);
491 break;
492 case CELLRANGE :
494 if (bSourceCellRange)
496 ScSheetSourceDesc aSheetDesc(pDoc);
497 if (!sSourceRangeName.isEmpty())
498 // Range name takes precedence.
499 aSheetDesc.SetRangeName(sSourceRangeName);
500 else
501 aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
502 aSheetDesc.SetQueryParam(aSourceQueryParam);
503 rPivotSources.appendSheetSource(pDPObject.get(), aSheetDesc);
506 break;
509 rPivotSources.appendSelectedPages(pDPObject.get(), maSelectedPages);
511 pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
512 pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
513 if (!maRowGrandTotal.maDisplayName.isEmpty())
514 // TODO: Right now, we only support one grand total name for both
515 // column and row totals. Take the value from the row total for
516 // now.
517 pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
519 pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
520 pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
521 pDPSave->SetFilterButton(bShowFilter);
522 pDPSave->SetDrillDown(bDrillDown);
523 if (pDPDimSaveData)
524 pDPSave->SetDimensionData(pDPDimSaveData.get());
525 pDPObject->SetSaveData(*pDPSave);
527 ScDPCollection* pDPCollection = pDoc->GetDPCollection();
529 // #i94570# Names have to be unique, or the tables can't be accessed by API.
530 if ( pDPCollection->GetByName(pDPObject->GetName()) )
531 pDPObject->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading
533 SetButtons(pDPObject.get());
535 pDPCollection->InsertNewTable(std::move(pDPObject));
538 void ScXMLDataPilotTableContext::SetGrandTotal(
539 XMLTokenEnum eOrientation, bool bVisible, const OUString& rDisplayName)
541 switch (eOrientation)
543 case XML_BOTH:
544 maRowGrandTotal.mbVisible = bVisible;
545 maRowGrandTotal.maDisplayName = rDisplayName;
546 maColGrandTotal.mbVisible = bVisible;
547 maColGrandTotal.maDisplayName = rDisplayName;
548 break;
549 case XML_ROW:
550 maRowGrandTotal.mbVisible = bVisible;
551 maRowGrandTotal.maDisplayName = rDisplayName;
552 break;
553 case XML_COLUMN:
554 maColGrandTotal.mbVisible = bVisible;
555 maColGrandTotal.maDisplayName = rDisplayName;
556 break;
557 default:
558 break;
562 ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( ScXMLImport& rImport,
563 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
564 ScXMLDataPilotTableContext* pDataPilotTable) :
565 ScXMLImportContext( rImport )
567 if ( rAttrList.is() )
569 for (auto &aIter : *rAttrList)
571 switch (aIter.getToken())
573 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
574 pDataPilotTable->SetDatabaseName(aIter.toString());
575 break;
576 case XML_ELEMENT( TABLE, XML_SQL_STATEMENT ):
577 pDataPilotTable->SetSourceObject(aIter.toString());
578 break;
579 case XML_ELEMENT( TABLE, XML_PARSE_SQL_STATEMENT ):
580 pDataPilotTable->SetNative(!IsXMLToken(aIter, XML_TRUE));
581 break;
587 ScXMLDPSourceSQLContext::~ScXMLDPSourceSQLContext()
591 ScXMLDPSourceTableContext::ScXMLDPSourceTableContext( ScXMLImport& rImport,
592 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
593 ScXMLDataPilotTableContext* pDataPilotTable) :
594 ScXMLImportContext( rImport )
596 if ( rAttrList.is() )
598 for (auto &aIter : *rAttrList)
600 switch (aIter.getToken())
602 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
603 pDataPilotTable->SetDatabaseName(aIter.toString());
604 break;
605 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
606 case XML_ELEMENT( TABLE, XML_DATABASE_TABLE_NAME ):
607 pDataPilotTable->SetSourceObject(aIter.toString());
608 break;
614 ScXMLDPSourceTableContext::~ScXMLDPSourceTableContext()
618 ScXMLDPSourceQueryContext::ScXMLDPSourceQueryContext( ScXMLImport& rImport,
619 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
620 ScXMLDataPilotTableContext* pDataPilotTable) :
621 ScXMLImportContext( rImport )
623 if ( rAttrList.is() )
625 for (auto &aIter : *rAttrList)
627 switch (aIter.getToken())
629 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
630 pDataPilotTable->SetDatabaseName(aIter.toString());
631 break;
632 case XML_ELEMENT( TABLE, XML_QUERY_NAME ):
633 pDataPilotTable->SetSourceObject(aIter.toString());
634 break;
640 ScXMLDPSourceQueryContext::~ScXMLDPSourceQueryContext()
644 ScXMLSourceServiceContext::ScXMLSourceServiceContext( ScXMLImport& rImport,
645 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
646 ScXMLDataPilotTableContext* pDataPilotTable) :
647 ScXMLImportContext( rImport )
649 if ( rAttrList.is() )
651 for (auto &aIter : *rAttrList)
653 switch (aIter.getToken())
655 case XML_ELEMENT( TABLE, XML_NAME ):
656 pDataPilotTable->SetServiceName(aIter.toString());
657 break;
658 case XML_ELEMENT( TABLE, XML_SOURCE_NAME ):
659 pDataPilotTable->SetServiceSourceName(aIter.toString());
660 break;
661 case XML_ELEMENT( TABLE, XML_OBJECT_NAME ):
662 pDataPilotTable->SetServiceSourceObject(aIter.toString());
663 break;
664 case XML_ELEMENT( TABLE, XML_USER_NAME ):
665 pDataPilotTable->SetServiceUsername(aIter.toString());
666 break;
667 case XML_ELEMENT( TABLE, XML_PASSWORD ):
668 pDataPilotTable->SetServicePassword(aIter.toString());
669 break;
675 ScXMLSourceServiceContext::~ScXMLSourceServiceContext()
679 ScXMLDataPilotGrandTotalContext::ScXMLDataPilotGrandTotalContext(
680 ScXMLImport& rImport, const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
681 ScXMLDataPilotTableContext* pTableContext ) :
682 ScXMLImportContext( rImport ),
683 mpTableContext(pTableContext),
684 meOrientation(NONE),
685 mbVisible(false)
687 if ( rAttrList.is() )
689 for (auto &aIter : *rAttrList)
691 switch (aIter.getToken())
693 case XML_ELEMENT( TABLE, XML_DISPLAY ):
694 mbVisible = IsXMLToken(aIter, XML_TRUE);
695 break;
696 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
697 if (IsXMLToken(aIter, XML_BOTH))
698 meOrientation = BOTH;
699 else if (IsXMLToken(aIter, XML_ROW))
700 meOrientation = ROW;
701 else if (IsXMLToken(aIter, XML_COLUMN))
702 meOrientation = COLUMN;
703 break;
704 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
705 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
706 maDisplayName = aIter.toString();
707 break;
708 default:
709 break;
715 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
719 void SAL_CALL ScXMLDataPilotGrandTotalContext::endFastElement( sal_Int32 /*nElement*/ )
721 XMLTokenEnum eOrient = XML_NONE;
722 switch (meOrientation)
724 case BOTH:
725 eOrient = XML_BOTH;
726 break;
727 case ROW:
728 eOrient = XML_ROW;
729 break;
730 case COLUMN:
731 eOrient = XML_COLUMN;
732 break;
733 default:
734 break;
736 mpTableContext->SetGrandTotal(eOrient, mbVisible, maDisplayName);
739 ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport& rImport,
740 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
741 ScXMLDataPilotTableContext* pTempDataPilotTable) :
742 ScXMLImportContext( rImport ),
743 pDataPilotTable(pTempDataPilotTable)
745 if ( rAttrList.is() )
747 for (auto &aIter : *rAttrList)
749 switch (aIter.getToken())
751 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
753 ScRange aSourceRangeAddress;
754 sal_Int32 nOffset(0);
755 if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress, aIter.toString(), GetScImport().GetDocument(), ::formula::FormulaGrammar::CONV_OOO, nOffset ))
756 pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
758 break;
759 case XML_ELEMENT( TABLE, XML_NAME ):
760 pDataPilotTable->SetSourceRangeName(aIter.toString());
761 break;
767 ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
771 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSourceCellRangeContext::createFastChildContext(
772 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
774 SvXMLImportContext *pContext = nullptr;
775 sax_fastparser::FastAttributeList *pAttribList =
776 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
778 switch (nElement)
780 case XML_ELEMENT( TABLE, XML_FILTER ):
781 pContext = new ScXMLDPFilterContext(GetScImport(), pAttribList, pDataPilotTable);
782 break;
785 if( !pContext )
786 pContext = new SvXMLImportContext( GetImport() );
788 return pContext;
791 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport& rImport,
792 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
793 ScXMLDataPilotTableContext* pTempDataPilotTable) :
794 ScXMLImportContext( rImport ),
795 pDataPilotTable(pTempDataPilotTable),
796 xDim(),
797 fStart(0.0),
798 fEnd(0.0),
799 fStep(0.0),
800 nUsedHierarchy(1),
801 nGroupPart(0),
802 nFunction(ScGeneralFunction::NONE),
803 nOrientation(sheet::DataPilotFieldOrientation_HIDDEN),
804 bSelectedPage(false),
805 bIsGroupField(false),
806 bDateValue(false),
807 bAutoStart(false),
808 bAutoEnd(false),
809 mbHasHiddenMember(false)
811 bool bHasName = false;
812 bool bDataLayout = false;
813 bool bIgnoreSelectedPage = false;
814 OUString aDisplayName;
815 if ( rAttrList.is() )
817 for (auto &aIter : *rAttrList)
819 switch (aIter.getToken())
821 case XML_ELEMENT( TABLE, XML_SOURCE_FIELD_NAME ):
822 sName = aIter.toString();
823 bHasName = true;
824 break;
825 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
826 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
827 aDisplayName = aIter.toString();
828 break;
829 case XML_ELEMENT( TABLE, XML_IS_DATA_LAYOUT_FIELD ):
830 bDataLayout = IsXMLToken(aIter, XML_TRUE);
831 break;
832 case XML_ELEMENT( TABLE, XML_FUNCTION ):
833 nFunction = ScXMLConverter::GetFunctionFromString2( aIter.toString() );
834 break;
835 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
836 nOrientation = ScXMLConverter::GetOrientationFromString( aIter.toString() );
837 break;
838 case XML_ELEMENT( TABLE, XML_SELECTED_PAGE ):
839 sSelectedPage = aIter.toString();
840 bSelectedPage = true;
841 break;
842 case XML_ELEMENT( LO_EXT, XML_IGNORE_SELECTED_PAGE ):
843 bIgnoreSelectedPage = true;
844 break;
845 case XML_ELEMENT( TABLE, XML_USED_HIERARCHY ):
846 nUsedHierarchy = aIter.toInt32();
847 break;
852 // use the new extension elements
853 if (bIgnoreSelectedPage)
854 bSelectedPage = false;
856 if (bHasName)
858 xDim.reset(new ScDPSaveDimension(sName, bDataLayout));
859 if (!aDisplayName.isEmpty())
860 xDim->SetLayoutName(aDisplayName);
864 ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
868 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotFieldContext::createFastChildContext(
869 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
871 SvXMLImportContext *pContext = nullptr;
872 sax_fastparser::FastAttributeList *pAttribList =
873 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
875 switch (nElement)
877 case XML_ELEMENT( TABLE, XML_DATA_PILOT_LEVEL ):
878 pContext = new ScXMLDataPilotLevelContext(GetScImport(), pAttribList, this);
879 break;
880 case XML_ELEMENT( TABLE, XML_DATA_PILOT_FIELD_REFERENCE ):
881 pContext = new ScXMLDataPilotFieldReferenceContext(GetScImport(), pAttribList, this);
882 break;
883 case XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUPS ):
884 pContext = new ScXMLDataPilotGroupsContext(GetScImport(), pAttribList, this);
885 break;
888 if( !pContext )
889 pContext = new SvXMLImportContext( GetImport() );
891 return pContext;
894 void ScXMLDataPilotFieldContext::AddMember(std::unique_ptr<ScDPSaveMember> pMember)
896 if (xDim)
898 bool isVisible = pMember->GetIsVisible();
899 xDim->AddMember(std::move(pMember));
900 if (!isVisible)
901 // This member is hidden.
902 mbHasHiddenMember = true;
906 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString& rName)
908 if (xDim)
909 xDim->SetSubtotalName(rName);
912 void ScXMLDataPilotFieldContext::AddGroup(const ::std::vector<OUString>& rMembers, const OUString& rName)
914 ScXMLDataPilotGroup aGroup;
915 aGroup.aMembers = rMembers;
916 aGroup.aName = rName;
917 aGroups.push_back(aGroup);
920 void SAL_CALL ScXMLDataPilotFieldContext::endFastElement( sal_Int32 /*nElement*/ )
922 if (xDim)
924 xDim->SetUsedHierarchy(nUsedHierarchy);
925 xDim->SetFunction(nFunction);
926 xDim->SetOrientation(nOrientation);
927 if (bSelectedPage)
929 pDataPilotTable->SetSelectedPage(xDim->GetName(), sSelectedPage);
931 pDataPilotTable->AddDimension(xDim.release());
932 if (bIsGroupField)
934 ScDPNumGroupInfo aInfo;
935 aInfo.mbEnable = true;
936 aInfo.mbDateValues = bDateValue;
937 aInfo.mbAutoStart = bAutoStart;
938 aInfo.mbAutoEnd = bAutoEnd;
939 aInfo.mfStart = fStart;
940 aInfo.mfEnd = fEnd;
941 aInfo.mfStep = fStep;
942 if (!sGroupSource.isEmpty())
944 ScDPSaveGroupDimension aGroupDim(sGroupSource, sName);
945 if (nGroupPart)
946 aGroupDim.SetDateInfo(aInfo, nGroupPart);
947 else
949 for (const auto& rGroup : aGroups)
951 ScDPSaveGroupItem aItem(rGroup.aName);
952 for (const auto& rMember : rGroup.aMembers)
954 aItem.AddElement(rMember);
956 aGroupDim.AddGroupItem(aItem);
959 pDataPilotTable->AddGroupDim(aGroupDim);
961 else //NumGroup
963 ScDPSaveNumGroupDimension aNumGroupDim(sName, aInfo);
964 if (nGroupPart)
965 aNumGroupDim.SetDateInfo(aInfo, nGroupPart);
966 pDataPilotTable->AddGroupDim(aNumGroupDim);
972 ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport& rImport,
973 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
974 ScXMLDataPilotFieldContext* pDataPilotField) :
975 ScXMLImportContext( rImport )
977 sheet::DataPilotFieldReference aReference;
979 if ( rAttrList.is() )
981 for (auto &aIter : *rAttrList)
983 switch (aIter.getToken())
985 case XML_ELEMENT( TABLE, XML_TYPE ):
987 if (IsXMLToken(aIter, XML_NONE))
988 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::NONE;
989 else if (IsXMLToken(aIter, XML_MEMBER_DIFFERENCE))
990 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE;
991 else if (IsXMLToken(aIter, XML_MEMBER_PERCENTAGE))
992 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE;
993 else if (IsXMLToken(aIter, XML_MEMBER_PERCENTAGE_DIFFERENCE))
994 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
995 else if (IsXMLToken(aIter, XML_RUNNING_TOTAL))
996 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::RUNNING_TOTAL;
997 else if (IsXMLToken(aIter, XML_ROW_PERCENTAGE))
998 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE;
999 else if (IsXMLToken(aIter, XML_COLUMN_PERCENTAGE))
1000 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
1001 else if (IsXMLToken(aIter, XML_TOTAL_PERCENTAGE))
1002 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
1003 else if (IsXMLToken(aIter, XML_INDEX))
1004 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::INDEX;
1006 break;
1007 case XML_ELEMENT( TABLE, XML_FIELD_NAME ):
1009 aReference.ReferenceField = aIter.toString();
1011 break;
1012 case XML_ELEMENT( TABLE, XML_MEMBER_TYPE ):
1014 if (IsXMLToken(aIter, XML_NAMED))
1015 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
1016 else if (IsXMLToken(aIter, XML_PREVIOUS))
1017 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::PREVIOUS;
1018 else if (IsXMLToken(aIter, XML_NEXT))
1019 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NEXT;
1021 break;
1022 case XML_ELEMENT( TABLE, XML_MEMBER_NAME ):
1024 aReference.ReferenceItemName = aIter.toString();
1026 break;
1030 pDataPilotField->SetFieldReference(aReference);
1033 ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1037 ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport& rImport,
1038 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1039 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1040 ScXMLImportContext( rImport ),
1041 pDataPilotField(pTempDataPilotField)
1043 if ( rAttrList.is() )
1045 for (auto &aIter : *rAttrList)
1047 switch (aIter.getToken())
1049 case XML_ELEMENT( TABLE, XML_SHOW_EMPTY ):
1050 pDataPilotField->SetShowEmpty(IsXMLToken(aIter, XML_TRUE));
1051 break;
1052 case XML_ELEMENT( CALC_EXT, XML_REPEAT_ITEM_LABELS ):
1053 pDataPilotField->SetRepeatItemLabels(IsXMLToken(aIter, XML_TRUE));
1054 break;
1060 ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1064 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotLevelContext::createFastChildContext(
1065 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1067 SvXMLImportContext *pContext = nullptr;
1068 sax_fastparser::FastAttributeList *pAttribList =
1069 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
1071 switch (nElement)
1073 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SUBTOTALS ):
1074 pContext = new ScXMLDataPilotSubTotalsContext(GetScImport(), pDataPilotField);
1075 break;
1076 case XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBERS ):
1077 pContext = new ScXMLDataPilotMembersContext(GetScImport(), pDataPilotField);
1078 break;
1079 case XML_ELEMENT( TABLE, XML_DATA_PILOT_DISPLAY_INFO ):
1080 pContext = new ScXMLDataPilotDisplayInfoContext(GetScImport(), pAttribList, pDataPilotField);
1081 break;
1082 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SORT_INFO ):
1083 pContext = new ScXMLDataPilotSortInfoContext(GetScImport(), pAttribList, pDataPilotField);
1084 break;
1085 case XML_ELEMENT( TABLE, XML_DATA_PILOT_LAYOUT_INFO ):
1086 pContext = new ScXMLDataPilotLayoutInfoContext(GetScImport(), pAttribList, pDataPilotField);
1087 break;
1090 if( !pContext )
1091 pContext = new SvXMLImportContext( GetImport() );
1093 return pContext;
1096 ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport& rImport,
1097 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1098 ScXMLDataPilotFieldContext* pDataPilotField) :
1099 ScXMLImportContext( rImport )
1101 sheet::DataPilotFieldAutoShowInfo aInfo;
1103 if ( rAttrList.is() )
1105 for (auto &aIter : *rAttrList)
1107 switch (aIter.getToken())
1109 case XML_ELEMENT( TABLE, XML_ENABLED ):
1110 if (IsXMLToken(aIter, XML_TRUE))
1111 aInfo.IsEnabled = true;
1112 else
1113 aInfo.IsEnabled = false;
1114 break;
1115 case XML_ELEMENT( TABLE, XML_DISPLAY_MEMBER_MODE ):
1116 if (IsXMLToken(aIter, XML_FROM_TOP))
1117 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_TOP;
1118 else if (IsXMLToken(aIter, XML_FROM_BOTTOM))
1119 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM;
1120 break;
1121 case XML_ELEMENT( TABLE, XML_MEMBER_COUNT ):
1122 aInfo.ItemCount = aIter.toInt32();
1123 break;
1124 case XML_ELEMENT( TABLE, XML_DATA_FIELD ):
1125 aInfo.DataField = aIter.toString();
1126 break;
1130 pDataPilotField->SetAutoShowInfo(aInfo);
1133 ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1137 ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport& rImport,
1138 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1139 ScXMLDataPilotFieldContext* pDataPilotField) :
1140 ScXMLImportContext( rImport )
1142 sheet::DataPilotFieldSortInfo aInfo;
1144 if ( rAttrList.is() )
1146 for (auto &aIter : *rAttrList)
1148 switch (aIter.getToken())
1150 case XML_ELEMENT( TABLE, XML_ORDER ):
1151 if (IsXMLToken(aIter, XML_ASCENDING))
1152 aInfo.IsAscending = true;
1153 else if (IsXMLToken(aIter, XML_DESCENDING))
1154 aInfo.IsAscending = false;
1155 break;
1156 case XML_ELEMENT( TABLE, XML_SORT_MODE ):
1157 if (IsXMLToken(aIter, XML_NONE))
1158 aInfo.Mode = sheet::DataPilotFieldSortMode::NONE;
1159 else if (IsXMLToken(aIter, XML_MANUAL))
1160 aInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
1161 else if (IsXMLToken(aIter, XML_NAME))
1162 aInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
1163 else if (IsXMLToken(aIter, XML_DATA))
1164 aInfo.Mode = sheet::DataPilotFieldSortMode::DATA;
1165 break;
1166 case XML_ELEMENT( TABLE, XML_DATA_FIELD ):
1167 aInfo.Field = aIter.toString();
1168 break;
1172 pDataPilotField->SetSortInfo(aInfo);
1175 ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1179 ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport& rImport,
1180 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1181 ScXMLDataPilotFieldContext* pDataPilotField) :
1182 ScXMLImportContext( rImport )
1184 sheet::DataPilotFieldLayoutInfo aInfo;
1186 if ( rAttrList.is() )
1188 for (auto &aIter : *rAttrList)
1190 switch (aIter.getToken())
1192 case XML_ELEMENT( TABLE, XML_ADD_EMPTY_LINES ):
1193 if (IsXMLToken(aIter, XML_TRUE))
1194 aInfo.AddEmptyLines = true;
1195 else
1196 aInfo.AddEmptyLines = false;
1197 break;
1198 case XML_ELEMENT( TABLE, XML_LAYOUT_MODE ):
1199 if (IsXMLToken(aIter, XML_TABULAR_LAYOUT))
1200 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
1201 else if (IsXMLToken(aIter, XML_OUTLINE_SUBTOTALS_TOP))
1202 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
1203 else if (IsXMLToken(aIter, XML_OUTLINE_SUBTOTALS_BOTTOM))
1204 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
1205 break;
1209 pDataPilotField->SetLayoutInfo(aInfo);}
1211 ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1215 ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport,
1216 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1217 ScXMLImportContext( rImport ),
1218 pDataPilotField(pTempDataPilotField)
1221 // has no attributes
1224 ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1228 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotSubTotalsContext::createFastChildContext(
1229 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1231 SvXMLImportContext *pContext = nullptr;
1232 sax_fastparser::FastAttributeList *pAttribList =
1233 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
1235 switch (nElement)
1237 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SUBTOTAL ):
1238 pContext = new ScXMLDataPilotSubTotalContext(GetScImport(), pAttribList, this);
1239 break;
1242 if( !pContext )
1243 pContext = new SvXMLImportContext( GetImport() );
1245 return pContext;
1248 void SAL_CALL ScXMLDataPilotSubTotalsContext::endFastElement( sal_Int32 /*nElement*/ )
1250 pDataPilotField->SetSubTotals(maFunctions);
1251 if (!maDisplayName.isEmpty())
1252 pDataPilotField->SetSubTotalName(maDisplayName);
1255 void ScXMLDataPilotSubTotalsContext::AddFunction(ScGeneralFunction nFunction)
1257 maFunctions.push_back(nFunction);
1260 void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
1262 maDisplayName = rName;
1265 ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport& rImport,
1266 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1267 ScXMLDataPilotSubTotalsContext* pDataPilotSubTotals) :
1268 ScXMLImportContext( rImport )
1270 if ( rAttrList.is() )
1272 for (auto &aIter : *rAttrList)
1274 switch (aIter.getToken())
1276 case XML_ELEMENT( TABLE, XML_FUNCTION ):
1277 pDataPilotSubTotals->AddFunction( ScXMLConverter::GetFunctionFromString2( aIter.toString() ) );
1278 break;
1279 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
1280 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
1281 pDataPilotSubTotals->SetDisplayName(aIter.toString());
1282 break;
1288 ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1292 ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport& rImport,
1293 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1294 ScXMLImportContext( rImport ),
1295 pDataPilotField(pTempDataPilotField)
1297 // has no attributes
1300 ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1304 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotMembersContext::createFastChildContext(
1305 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1307 SvXMLImportContext *pContext = nullptr;
1308 sax_fastparser::FastAttributeList *pAttribList =
1309 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
1311 switch (nElement)
1313 case XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBER ):
1314 pContext = new ScXMLDataPilotMemberContext(GetScImport(), pAttribList, pDataPilotField);
1315 break;
1318 if( !pContext )
1319 pContext = new SvXMLImportContext( GetImport() );
1321 return pContext;
1324 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport& rImport,
1325 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1326 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1327 ScXMLImportContext( rImport ),
1328 pDataPilotField(pTempDataPilotField),
1329 bDisplay( true ),
1330 bDisplayDetails( true ),
1331 bHasName( false )
1333 if ( rAttrList.is() )
1335 for (auto &aIter : *rAttrList)
1337 switch (aIter.getToken())
1339 case XML_ELEMENT( TABLE, XML_NAME ):
1340 sName = aIter.toString();
1341 bHasName = true;
1342 break;
1343 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
1344 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
1345 maDisplayName = aIter.toString();
1346 break;
1347 case XML_ELEMENT( TABLE, XML_DISPLAY ):
1348 bDisplay = IsXMLToken(aIter, XML_TRUE);
1349 break;
1350 case XML_ELEMENT( TABLE, XML_SHOW_DETAILS ):
1351 bDisplayDetails = IsXMLToken(aIter, XML_TRUE);
1352 break;
1358 ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1362 void SAL_CALL ScXMLDataPilotMemberContext::endFastElement( sal_Int32 /*nElement*/ )
1364 if (bHasName) // #i53407# don't check sName, empty name is allowed
1366 std::unique_ptr<ScDPSaveMember> pMember(new ScDPSaveMember(sName));
1367 if (!maDisplayName.isEmpty())
1368 pMember->SetLayoutName(maDisplayName);
1369 pMember->SetIsVisible(bDisplay);
1370 pMember->SetShowDetails(bDisplayDetails);
1371 pDataPilotField->AddMember(std::move(pMember));
1375 ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport& rImport,
1376 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1377 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1378 ScXMLImportContext( rImport ),
1379 pDataPilotField(pTempDataPilotField)
1381 OUString sGroupSource;
1382 double fStart(0.0);
1383 double fEnd(0.0);
1384 double fStep(0.0);
1385 sal_Int32 nGroupPart(0);
1386 bool bDateValue(false);
1387 bool bAutoStart(true);
1388 bool bAutoEnd(true);
1390 if ( rAttrList.is() )
1392 for (auto &aIter : *rAttrList)
1394 switch (aIter.getToken() & TOKEN_MASK)
1396 case XML_SOURCE_FIELD_NAME :
1398 sGroupSource = aIter.toString();
1400 break;
1401 case XML_DATE_START :
1403 bDateValue = true;
1404 if (IsXMLToken(aIter, XML_AUTO))
1405 bAutoStart = true;
1406 else
1408 GetScImport().GetMM100UnitConverter().convertDateTime(fStart, aIter.toString());
1409 bAutoStart = false;
1412 break;
1413 case XML_DATE_END :
1415 bDateValue = true;
1416 if (IsXMLToken(aIter, XML_AUTO))
1417 bAutoEnd = true;
1418 else
1420 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd, aIter.toString());
1421 bAutoEnd = false;
1424 break;
1425 case XML_START :
1427 if (IsXMLToken(aIter, XML_AUTO))
1428 bAutoStart = true;
1429 else
1431 fStart = aIter.toDouble();
1432 bAutoStart = false;
1435 break;
1436 case XML_END :
1438 if (IsXMLToken(aIter, XML_AUTO))
1439 bAutoEnd = true;
1440 else
1442 fEnd = aIter.toDouble();
1443 bAutoEnd = false;
1446 break;
1447 case XML_STEP :
1449 fStep = aIter.toDouble();
1451 break;
1452 case XML_GROUPED_BY :
1454 if (IsXMLToken(aIter, XML_SECONDS))
1455 nGroupPart = css::sheet::DataPilotFieldGroupBy::SECONDS;
1456 else if (IsXMLToken(aIter, XML_MINUTES))
1457 nGroupPart = css::sheet::DataPilotFieldGroupBy::MINUTES;
1458 else if (IsXMLToken(aIter, XML_HOURS))
1459 nGroupPart = css::sheet::DataPilotFieldGroupBy::HOURS;
1460 else if (IsXMLToken(aIter, XML_DAYS))
1461 nGroupPart = css::sheet::DataPilotFieldGroupBy::DAYS;
1462 else if (IsXMLToken(aIter, XML_MONTHS))
1463 nGroupPart = css::sheet::DataPilotFieldGroupBy::MONTHS;
1464 else if (IsXMLToken(aIter, XML_QUARTERS))
1465 nGroupPart = css::sheet::DataPilotFieldGroupBy::QUARTERS;
1466 else if (IsXMLToken(aIter, XML_YEARS))
1467 nGroupPart = css::sheet::DataPilotFieldGroupBy::YEARS;
1469 break;
1473 pDataPilotField->SetGrouping(sGroupSource, fStart, fEnd, fStep, nGroupPart, bDateValue, bAutoStart, bAutoEnd);
1476 ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1480 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotGroupsContext::createFastChildContext(
1481 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1483 SvXMLImportContext *pContext = nullptr;
1484 sax_fastparser::FastAttributeList *pAttribList =
1485 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
1487 if (nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUP ))
1489 pContext = new ScXMLDataPilotGroupContext(GetScImport(), pAttribList, pDataPilotField);
1492 if( !pContext )
1493 pContext = new SvXMLImportContext( GetImport() );
1495 return pContext;
1498 ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport& rImport,
1499 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1500 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1501 ScXMLImportContext( rImport ),
1502 pDataPilotField(pTempDataPilotField)
1504 if ( rAttrList.is() )
1506 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_NAME ) ) );
1507 if (aIter != rAttrList->end())
1508 sName = aIter.toString();
1512 ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1516 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotGroupContext::createFastChildContext(
1517 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1519 SvXMLImportContext *pContext = nullptr;
1520 sax_fastparser::FastAttributeList *pAttribList =
1521 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList );
1523 if (nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBER ) ||
1524 nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUP_MEMBER ))
1526 pContext = new ScXMLDataPilotGroupMemberContext(GetScImport(), pAttribList, this);
1529 if( !pContext )
1530 pContext = new SvXMLImportContext( GetImport() );
1532 return pContext;
1535 void SAL_CALL ScXMLDataPilotGroupContext::endFastElement( sal_Int32 /*nElement*/ )
1537 pDataPilotField->AddGroup(aMembers, sName);
1540 ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport& rImport,
1541 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1542 ScXMLDataPilotGroupContext* pTempDataPilotGroup) :
1543 ScXMLImportContext( rImport ),
1544 pDataPilotGroup(pTempDataPilotGroup)
1546 if ( rAttrList.is() )
1548 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_NAME ) ) );
1549 if (aIter != rAttrList->end())
1550 sName = aIter.toString();
1554 ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1558 void SAL_CALL ScXMLDataPilotGroupMemberContext::endFastElement( sal_Int32 /*nElement*/ )
1560 if (!sName.isEmpty())
1561 pDataPilotGroup->AddMember(sName);
1564 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */