Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / xml / xmldpimp.cxx
blob307d55f7f30ebefbcbef769cd4417340c0fca27a
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 nSourceType(SQL),
91 mnRowFieldCount(0),
92 mnColFieldCount(0),
93 mnPageFieldCount(0),
94 mnDataFieldCount(0),
95 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN),
96 bIsNative(true),
97 bIgnoreEmptyRows(false),
98 bIdentifyCategories(false),
99 bTargetRangeAddress(false),
100 bSourceCellRange(false),
101 bShowFilter(true),
102 bDrillDown(true),
103 bHeaderGridLayout(false)
105 if ( !rAttrList.is() )
106 return;
108 for (auto &aIter : *rAttrList)
110 switch (aIter.getToken())
112 case XML_ELEMENT( TABLE, XML_NAME ):
114 sDataPilotTableName = aIter.toString();
116 break;
117 case XML_ELEMENT( TABLE, XML_APPLICATION_DATA ):
119 sApplicationData = aIter.toString();
121 break;
122 case XML_ELEMENT( TABLE, XML_GRAND_TOTAL ):
124 if (IsXMLToken(aIter, XML_BOTH))
126 maRowGrandTotal.mbVisible = true;
127 maColGrandTotal.mbVisible = true;
129 else if (IsXMLToken(aIter, XML_ROW))
131 maRowGrandTotal.mbVisible = true;
132 maColGrandTotal.mbVisible = false;
134 else if (IsXMLToken(aIter, XML_COLUMN))
136 maRowGrandTotal.mbVisible = false;
137 maColGrandTotal.mbVisible = true;
139 else
141 maRowGrandTotal.mbVisible = false;
142 maColGrandTotal.mbVisible = false;
145 break;
146 case XML_ELEMENT( TABLE, XML_IGNORE_EMPTY_ROWS ):
148 bIgnoreEmptyRows = IsXMLToken(aIter, XML_TRUE);
150 break;
151 case XML_ELEMENT( TABLE, XML_IDENTIFY_CATEGORIES ):
153 bIdentifyCategories = IsXMLToken(aIter, XML_TRUE);
155 break;
156 case XML_ELEMENT( TABLE, XML_TARGET_RANGE_ADDRESS ):
158 sal_Int32 nOffset(0);
159 assert(pDoc);
160 bTargetRangeAddress = ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset );
162 break;
163 case XML_ELEMENT( TABLE, XML_BUTTONS ):
165 sButtons = aIter.toString();
167 break;
168 case XML_ELEMENT( TABLE, XML_SHOW_FILTER_BUTTON ):
170 bShowFilter = IsXMLToken(aIter, XML_TRUE);
172 break;
173 case XML_ELEMENT( TABLE, XML_DRILL_DOWN_ON_DOUBLE_CLICK ):
175 bDrillDown = IsXMLToken(aIter, XML_TRUE);
177 break;
178 case XML_ELEMENT( TABLE, XML_HEADER_GRID_LAYOUT ):
180 bHeaderGridLayout = IsXMLToken(aIter, XML_TRUE);
182 break;
187 ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
191 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotTableContext::createFastChildContext(
192 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
194 SvXMLImportContext *pContext = nullptr;
195 sax_fastparser::FastAttributeList *pAttribList =
196 &sax_fastparser::castToFastAttributeList( xAttrList );
198 switch (nElement)
200 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_SQL ):
202 pContext = new ScXMLDPSourceSQLContext(GetScImport(), pAttribList, this);
203 nSourceType = SQL;
205 break;
206 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_TABLE ):
208 pContext = new ScXMLDPSourceTableContext(GetScImport(), pAttribList, this);
209 nSourceType = TABLE;
211 break;
212 case XML_ELEMENT( TABLE, XML_DATABASE_SOURCE_QUERY ):
214 pContext = new ScXMLDPSourceQueryContext(GetScImport(), pAttribList, this);
215 nSourceType = QUERY;
217 break;
218 case XML_ELEMENT( TABLE, XML_SOURCE_SERVICE ):
220 pContext = new ScXMLSourceServiceContext(GetScImport(), pAttribList, this);
221 nSourceType = SERVICE;
223 break;
224 case XML_ELEMENT( TABLE, XML_DATA_PILOT_GRAND_TOTAL ):
225 case XML_ELEMENT( TABLE_EXT, XML_DATA_PILOT_GRAND_TOTAL ):
227 pContext = new ScXMLDataPilotGrandTotalContext(GetScImport(), pAttribList, this);
229 break;
230 case XML_ELEMENT( TABLE, XML_SOURCE_CELL_RANGE ):
232 pContext = new ScXMLSourceCellRangeContext(GetScImport(), pAttribList, this);
233 nSourceType = CELLRANGE;
235 break;
236 case XML_ELEMENT( TABLE, XML_DATA_PILOT_FIELD ):
237 pContext = new ScXMLDataPilotFieldContext(GetScImport(), pAttribList, this);
238 break;
241 return pContext;
244 namespace {
246 const ScDPSaveDimension* getDimension(
247 const std::vector<const ScDPSaveDimension*>& rRowDims,
248 const std::vector<const ScDPSaveDimension*>& rColDims,
249 const std::vector<const ScDPSaveDimension*>& rPageDims,
250 ScDPOutputGeometry::FieldType eType, size_t nPos)
252 switch (eType)
254 case ScDPOutputGeometry::Column:
256 if (rColDims.size() <= nPos)
257 return nullptr;
259 return rColDims[nPos];
261 case ScDPOutputGeometry::Row:
263 if (rRowDims.size() <= nPos)
264 return nullptr;
266 return rRowDims[nPos];
268 case ScDPOutputGeometry::Page:
270 if (rPageDims.size() <= nPos)
271 return nullptr;
273 return rPageDims[nPos];
275 case ScDPOutputGeometry::Data:
276 break;
277 case ScDPOutputGeometry::None:
278 break;
279 default:
280 break;
282 return nullptr;
285 ScDPOutputGeometry::FieldType toFieldType(sheet::DataPilotFieldOrientation nOrient)
287 switch (nOrient)
289 case sheet::DataPilotFieldOrientation_COLUMN:
290 return ScDPOutputGeometry::Column;
291 case sheet::DataPilotFieldOrientation_DATA:
292 return ScDPOutputGeometry::Data;
293 case sheet::DataPilotFieldOrientation_PAGE:
294 return ScDPOutputGeometry::Page;
295 case sheet::DataPilotFieldOrientation_ROW:
296 return ScDPOutputGeometry::Row;
297 case sheet::DataPilotFieldOrientation_HIDDEN:
298 break;
299 default:
300 break;
302 return ScDPOutputGeometry::None;
307 void ScXMLDataPilotTableContext::SetButtons(ScDPObject* pDPObject)
309 ScDPOutputGeometry aGeometry(aTargetRangeAddress, bShowFilter);
310 aGeometry.setColumnFieldCount(mnColFieldCount);
311 aGeometry.setRowFieldCount(mnRowFieldCount);
312 aGeometry.setPageFieldCount(mnPageFieldCount);
313 aGeometry.setDataFieldCount(mnDataFieldCount);
314 aGeometry.setDataLayoutType(toFieldType(mnDataLayoutType));
315 aGeometry.setHeaderLayout(bHeaderGridLayout);
317 std::vector<const ScDPSaveDimension*> aRowDims, aColDims, aPageDims;
318 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims);
319 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims);
320 pDPSave->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aPageDims);
322 OUString sAddress;
323 sal_Int32 nOffset = 0;
324 while( nOffset >= 0 )
326 ScRangeStringConverter::GetTokenByOffset( sAddress, sButtons, nOffset );
327 if( nOffset >= 0 )
329 ScAddress aScAddress;
330 sal_Int32 nAddrOffset(0);
331 if (pDoc && ScRangeStringConverter::GetAddressFromString( aScAddress, sAddress, *pDoc, ::formula::FormulaGrammar::CONV_OOO, nAddrOffset ))
333 std::pair<ScDPOutputGeometry::FieldType, size_t> aBtnType = aGeometry.getFieldButtonType(aScAddress);
334 const ScDPSaveDimension* pDim = getDimension(
335 aRowDims, aColDims, aPageDims, aBtnType.first, aBtnType.second);
337 bool bDimension = pDim != nullptr;
338 bool bDataLayout = pDim && pDim->IsDataLayout();
339 bool bHasHidden = pDim && pDim->HasInvisibleMember();
340 bool bPageDim = pDim && pDim->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE;
342 if (bPageDim)
344 // Page dimension needs 2 buttons.
346 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), ScMF::Button);
348 ScMF nMFlag = ScMF::ButtonPopup;
349 if (bHasHidden)
350 nMFlag |= ScMF::HiddenMember;
351 pDoc->ApplyFlagsTab(aScAddress.Col()+1, aScAddress.Row(), aScAddress.Col()+1, aScAddress.Row(), aScAddress.Tab(), nMFlag);
353 else
355 ScMF nMFlag = ScMF::Button;
356 if (bDataLayout)
358 // Data layout dimension only has a plain button with no popup.
360 else if (bDimension)
362 // Normal dimension has a popup arrow button.
363 if (bHasHidden)
364 nMFlag |= ScMF::HiddenMember;
366 nMFlag |= ScMF::ButtonPopup;
369 pDoc->ApplyFlagsTab(aScAddress.Col(), aScAddress.Row(), aScAddress.Col(), aScAddress.Row(), aScAddress.Tab(), nMFlag);
375 pDPObject->RefreshAfterLoad();
378 void ScXMLDataPilotTableContext::SetSelectedPage( const OUString& rDimName, const OUString& rSelected )
380 maSelectedPages.emplace(rDimName, rSelected);
383 void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim)
385 if (!pDPSave)
386 return;
388 if (pDim->IsDataLayout())
389 mnDataLayoutType = pDim->GetOrientation();
391 // if a dimension with that name has already been inserted,
392 // mark the new one as duplicate
393 if ( !pDim->IsDataLayout() &&
394 pDPSave->GetExistingDimensionByName(pDim->GetName()) )
395 pDim->SetDupFlag(true);
397 switch (pDim->GetOrientation())
399 case sheet::DataPilotFieldOrientation_ROW:
400 ++mnRowFieldCount;
401 break;
402 case sheet::DataPilotFieldOrientation_COLUMN:
403 ++mnColFieldCount;
404 break;
405 case sheet::DataPilotFieldOrientation_PAGE:
406 ++mnPageFieldCount;
407 break;
408 case sheet::DataPilotFieldOrientation_DATA:
409 ++mnDataFieldCount;
410 break;
411 case sheet::DataPilotFieldOrientation_HIDDEN:
412 break;
413 default:
414 break;
417 pDPSave->AddDimension(pDim);
420 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim)
422 if (!pDPDimSaveData)
423 pDPDimSaveData.reset( new ScDPDimensionSaveData );
424 pDPDimSaveData->AddNumGroupDimension(aNumGroupDim);
427 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension& aGroupDim)
429 if (!pDPDimSaveData)
430 pDPDimSaveData.reset( new ScDPDimensionSaveData );
431 pDPDimSaveData->AddGroupDimension(aGroupDim);
434 void SAL_CALL ScXMLDataPilotTableContext::endFastElement( sal_Int32 /*nElement*/ )
436 if (!bTargetRangeAddress)
437 return;
439 std::unique_ptr<ScDPObject> pDPObject(new ScDPObject(pDoc));
440 pDPObject->SetName(sDataPilotTableName);
441 pDPObject->SetTag(sApplicationData);
442 pDPObject->SetOutRange(aTargetRangeAddress);
443 pDPObject->SetHeaderLayout(bHeaderGridLayout);
445 sc::PivotTableSources& rPivotSources = GetScImport().GetPivotTableSources();
447 switch (nSourceType)
449 case SQL :
451 ScImportSourceDesc aImportDesc(pDoc);
452 aImportDesc.aDBName = sDatabaseName;
453 aImportDesc.aObject = sSourceObject;
454 aImportDesc.nType = sheet::DataImportMode_SQL;
455 aImportDesc.bNative = bIsNative;
456 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
458 break;
459 case TABLE :
461 ScImportSourceDesc aImportDesc(pDoc);
462 aImportDesc.aDBName = sDatabaseName;
463 aImportDesc.aObject = sSourceObject;
464 aImportDesc.nType = sheet::DataImportMode_TABLE;
465 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
467 break;
468 case QUERY :
470 ScImportSourceDesc aImportDesc(pDoc);
471 aImportDesc.aDBName = sDatabaseName;
472 aImportDesc.aObject = sSourceObject;
473 aImportDesc.nType = sheet::DataImportMode_QUERY;
474 rPivotSources.appendDBSource(pDPObject.get(), aImportDesc);
476 break;
477 case SERVICE :
479 ScDPServiceDesc aServiceDesc(sServiceName, sServiceSourceName, sServiceSourceObject,
480 sServiceUsername, sServicePassword);
481 rPivotSources.appendServiceSource(pDPObject.get(), aServiceDesc);
483 break;
484 case CELLRANGE :
486 if (bSourceCellRange)
488 ScSheetSourceDesc aSheetDesc(pDoc);
489 if (!sSourceRangeName.isEmpty())
490 // Range name takes precedence.
491 aSheetDesc.SetRangeName(sSourceRangeName);
492 else
493 aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
494 aSheetDesc.SetQueryParam(aSourceQueryParam);
495 rPivotSources.appendSheetSource(pDPObject.get(), aSheetDesc);
498 break;
501 rPivotSources.appendSelectedPages(pDPObject.get(), std::unordered_map(maSelectedPages));
503 pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
504 pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
505 if (!maRowGrandTotal.maDisplayName.isEmpty())
506 // TODO: Right now, we only support one grand total name for both
507 // column and row totals. Take the value from the row total for
508 // now.
509 pDPSave->SetGrandTotalName(maRowGrandTotal.maDisplayName);
511 pDPSave->SetIgnoreEmptyRows(bIgnoreEmptyRows);
512 pDPSave->SetRepeatIfEmpty(bIdentifyCategories);
513 pDPSave->SetFilterButton(bShowFilter);
514 pDPSave->SetDrillDown(bDrillDown);
515 if (pDPDimSaveData)
516 pDPSave->SetDimensionData(pDPDimSaveData.get());
517 pDPObject->SetSaveData(*pDPSave);
519 ScDPCollection* pDPCollection = pDoc->GetDPCollection();
521 // #i94570# Names have to be unique, or the tables can't be accessed by API.
522 if ( pDPCollection->GetByName(pDPObject->GetName()) )
523 pDPObject->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading
525 SetButtons(pDPObject.get());
527 pDPCollection->InsertNewTable(std::move(pDPObject));
530 void ScXMLDataPilotTableContext::SetGrandTotal(
531 XMLTokenEnum eOrientation, bool bVisible, const OUString& rDisplayName)
533 switch (eOrientation)
535 case XML_BOTH:
536 maRowGrandTotal.mbVisible = bVisible;
537 maRowGrandTotal.maDisplayName = rDisplayName;
538 maColGrandTotal.mbVisible = bVisible;
539 maColGrandTotal.maDisplayName = rDisplayName;
540 break;
541 case XML_ROW:
542 maRowGrandTotal.mbVisible = bVisible;
543 maRowGrandTotal.maDisplayName = rDisplayName;
544 break;
545 case XML_COLUMN:
546 maColGrandTotal.mbVisible = bVisible;
547 maColGrandTotal.maDisplayName = rDisplayName;
548 break;
549 default:
550 break;
554 ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( ScXMLImport& rImport,
555 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
556 ScXMLDataPilotTableContext* pDataPilotTable) :
557 ScXMLImportContext( rImport )
559 if ( !rAttrList.is() )
560 return;
562 for (auto &aIter : *rAttrList)
564 switch (aIter.getToken())
566 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
567 pDataPilotTable->SetDatabaseName(aIter.toString());
568 break;
569 case XML_ELEMENT( TABLE, XML_SQL_STATEMENT ):
570 pDataPilotTable->SetSourceObject(aIter.toString());
571 break;
572 case XML_ELEMENT( TABLE, XML_PARSE_SQL_STATEMENT ):
573 pDataPilotTable->SetNative(!IsXMLToken(aIter, XML_TRUE));
574 break;
579 ScXMLDPSourceSQLContext::~ScXMLDPSourceSQLContext()
583 ScXMLDPSourceTableContext::ScXMLDPSourceTableContext( ScXMLImport& rImport,
584 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
585 ScXMLDataPilotTableContext* pDataPilotTable) :
586 ScXMLImportContext( rImport )
588 if ( !rAttrList.is() )
589 return;
591 for (auto &aIter : *rAttrList)
593 switch (aIter.getToken())
595 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
596 pDataPilotTable->SetDatabaseName(aIter.toString());
597 break;
598 case XML_ELEMENT( TABLE, XML_TABLE_NAME ):
599 case XML_ELEMENT( TABLE, XML_DATABASE_TABLE_NAME ):
600 pDataPilotTable->SetSourceObject(aIter.toString());
601 break;
606 ScXMLDPSourceTableContext::~ScXMLDPSourceTableContext()
610 ScXMLDPSourceQueryContext::ScXMLDPSourceQueryContext( ScXMLImport& rImport,
611 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
612 ScXMLDataPilotTableContext* pDataPilotTable) :
613 ScXMLImportContext( rImport )
615 if ( !rAttrList.is() )
616 return;
618 for (auto &aIter : *rAttrList)
620 switch (aIter.getToken())
622 case XML_ELEMENT( TABLE, XML_DATABASE_NAME ):
623 pDataPilotTable->SetDatabaseName(aIter.toString());
624 break;
625 case XML_ELEMENT( TABLE, XML_QUERY_NAME ):
626 pDataPilotTable->SetSourceObject(aIter.toString());
627 break;
632 ScXMLDPSourceQueryContext::~ScXMLDPSourceQueryContext()
636 ScXMLSourceServiceContext::ScXMLSourceServiceContext( ScXMLImport& rImport,
637 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
638 ScXMLDataPilotTableContext* pDataPilotTable) :
639 ScXMLImportContext( rImport )
641 if ( !rAttrList.is() )
642 return;
644 for (auto &aIter : *rAttrList)
646 switch (aIter.getToken())
648 case XML_ELEMENT( TABLE, XML_NAME ):
649 pDataPilotTable->SetServiceName(aIter.toString());
650 break;
651 case XML_ELEMENT( TABLE, XML_SOURCE_NAME ):
652 pDataPilotTable->SetServiceSourceName(aIter.toString());
653 break;
654 case XML_ELEMENT( TABLE, XML_OBJECT_NAME ):
655 pDataPilotTable->SetServiceSourceObject(aIter.toString());
656 break;
657 case XML_ELEMENT( TABLE, XML_USER_NAME ):
658 pDataPilotTable->SetServiceUsername(aIter.toString());
659 break;
660 case XML_ELEMENT( TABLE, XML_PASSWORD ):
661 pDataPilotTable->SetServicePassword(aIter.toString());
662 break;
667 ScXMLSourceServiceContext::~ScXMLSourceServiceContext()
671 ScXMLDataPilotGrandTotalContext::ScXMLDataPilotGrandTotalContext(
672 ScXMLImport& rImport, const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
673 ScXMLDataPilotTableContext* pTableContext ) :
674 ScXMLImportContext( rImport ),
675 mpTableContext(pTableContext),
676 meOrientation(NONE),
677 mbVisible(false)
679 if ( !rAttrList.is() )
680 return;
682 for (auto &aIter : *rAttrList)
684 switch (aIter.getToken())
686 case XML_ELEMENT( TABLE, XML_DISPLAY ):
687 mbVisible = IsXMLToken(aIter, XML_TRUE);
688 break;
689 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
690 if (IsXMLToken(aIter, XML_BOTH))
691 meOrientation = BOTH;
692 else if (IsXMLToken(aIter, XML_ROW))
693 meOrientation = ROW;
694 else if (IsXMLToken(aIter, XML_COLUMN))
695 meOrientation = COLUMN;
696 break;
697 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
698 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
699 maDisplayName = aIter.toString();
700 break;
701 default:
702 break;
707 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
711 void SAL_CALL ScXMLDataPilotGrandTotalContext::endFastElement( sal_Int32 /*nElement*/ )
713 XMLTokenEnum eOrient = XML_NONE;
714 switch (meOrientation)
716 case BOTH:
717 eOrient = XML_BOTH;
718 break;
719 case ROW:
720 eOrient = XML_ROW;
721 break;
722 case COLUMN:
723 eOrient = XML_COLUMN;
724 break;
725 default:
726 break;
728 mpTableContext->SetGrandTotal(eOrient, mbVisible, maDisplayName);
731 ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport& rImport,
732 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
733 ScXMLDataPilotTableContext* pTempDataPilotTable) :
734 ScXMLImportContext( rImport ),
735 pDataPilotTable(pTempDataPilotTable)
737 if ( !rAttrList.is() )
738 return;
740 for (auto &aIter : *rAttrList)
742 switch (aIter.getToken())
744 case XML_ELEMENT( TABLE, XML_CELL_RANGE_ADDRESS ):
746 ScRange aSourceRangeAddress;
747 sal_Int32 nOffset(0);
748 ScDocument* pDoc = GetScImport().GetDocument();
749 assert(pDoc);
750 if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress, aIter.toString(), *pDoc, ::formula::FormulaGrammar::CONV_OOO, nOffset ))
751 pDataPilotTable->SetSourceCellRangeAddress(aSourceRangeAddress);
753 break;
754 case XML_ELEMENT( TABLE, XML_NAME ):
755 pDataPilotTable->SetSourceRangeName(aIter.toString());
756 break;
761 ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
765 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLSourceCellRangeContext::createFastChildContext(
766 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
768 SvXMLImportContext *pContext = nullptr;
769 sax_fastparser::FastAttributeList *pAttribList =
770 &sax_fastparser::castToFastAttributeList( xAttrList );
772 switch (nElement)
774 case XML_ELEMENT( TABLE, XML_FILTER ):
775 pContext = new ScXMLDPFilterContext(GetScImport(), pAttribList, pDataPilotTable);
776 break;
779 return pContext;
782 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport& rImport,
783 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
784 ScXMLDataPilotTableContext* pTempDataPilotTable) :
785 ScXMLImportContext( rImport ),
786 pDataPilotTable(pTempDataPilotTable),
787 fStart(0.0),
788 fEnd(0.0),
789 fStep(0.0),
790 nUsedHierarchy(1),
791 nGroupPart(0),
792 nFunction(ScGeneralFunction::NONE),
793 nOrientation(sheet::DataPilotFieldOrientation_HIDDEN),
794 bSelectedPage(false),
795 bIsGroupField(false),
796 bDateValue(false),
797 bAutoStart(false),
798 bAutoEnd(false),
799 mbHasHiddenMember(false)
801 bool bHasName = false;
802 bool bDataLayout = false;
803 bool bIgnoreSelectedPage = false;
804 OUString aDisplayName;
805 if ( rAttrList.is() )
807 for (auto &aIter : *rAttrList)
809 switch (aIter.getToken())
811 case XML_ELEMENT( TABLE, XML_SOURCE_FIELD_NAME ):
812 sName = aIter.toString();
813 bHasName = true;
814 break;
815 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
816 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
817 aDisplayName = aIter.toString();
818 break;
819 case XML_ELEMENT( TABLE, XML_IS_DATA_LAYOUT_FIELD ):
820 bDataLayout = IsXMLToken(aIter, XML_TRUE);
821 break;
822 case XML_ELEMENT( TABLE, XML_FUNCTION ):
823 nFunction = ScXMLConverter::GetFunctionFromString2( aIter.toString() );
824 break;
825 case XML_ELEMENT( TABLE, XML_ORIENTATION ):
826 nOrientation = ScXMLConverter::GetOrientationFromString( aIter.toString() );
827 break;
828 case XML_ELEMENT( TABLE, XML_SELECTED_PAGE ):
829 sSelectedPage = aIter.toString();
830 bSelectedPage = true;
831 break;
832 case XML_ELEMENT( LO_EXT, XML_IGNORE_SELECTED_PAGE ):
833 bIgnoreSelectedPage = true;
834 break;
835 case XML_ELEMENT( TABLE, XML_USED_HIERARCHY ):
836 nUsedHierarchy = aIter.toInt32();
837 break;
842 // use the new extension elements
843 if (bIgnoreSelectedPage)
844 bSelectedPage = false;
846 if (bHasName)
848 xDim.reset(new ScDPSaveDimension(sName, bDataLayout));
849 if (!aDisplayName.isEmpty())
850 xDim->SetLayoutName(aDisplayName);
854 ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
858 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotFieldContext::createFastChildContext(
859 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
861 SvXMLImportContext *pContext = nullptr;
862 sax_fastparser::FastAttributeList *pAttribList =
863 &sax_fastparser::castToFastAttributeList( xAttrList );
865 switch (nElement)
867 case XML_ELEMENT( TABLE, XML_DATA_PILOT_LEVEL ):
868 pContext = new ScXMLDataPilotLevelContext(GetScImport(), pAttribList, this);
869 break;
870 case XML_ELEMENT( TABLE, XML_DATA_PILOT_FIELD_REFERENCE ):
871 pContext = new ScXMLDataPilotFieldReferenceContext(GetScImport(), pAttribList, this);
872 break;
873 case XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUPS ):
874 pContext = new ScXMLDataPilotGroupsContext(GetScImport(), pAttribList, this);
875 break;
878 return pContext;
881 void ScXMLDataPilotFieldContext::AddMember(std::unique_ptr<ScDPSaveMember> pMember)
883 if (xDim)
885 bool isVisible = pMember->GetIsVisible();
886 xDim->AddMember(std::move(pMember));
887 if (!isVisible)
888 // This member is hidden.
889 mbHasHiddenMember = true;
893 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString& rName)
895 if (xDim)
896 xDim->SetSubtotalName(rName);
899 void ScXMLDataPilotFieldContext::AddGroup(::std::vector<OUString>&& rMembers, const OUString& rName)
901 ScXMLDataPilotGroup aGroup;
902 aGroup.aMembers = std::move(rMembers);
903 aGroup.aName = rName;
904 aGroups.push_back(std::move(aGroup));
907 void SAL_CALL ScXMLDataPilotFieldContext::endFastElement( sal_Int32 /*nElement*/ )
909 if (!xDim)
910 return;
912 xDim->SetUsedHierarchy(nUsedHierarchy);
913 xDim->SetFunction(nFunction);
914 xDim->SetOrientation(nOrientation);
915 if (bSelectedPage)
917 pDataPilotTable->SetSelectedPage(xDim->GetName(), sSelectedPage);
919 pDataPilotTable->AddDimension(xDim.release());
920 if (!bIsGroupField)
921 return;
923 ScDPNumGroupInfo aInfo;
924 aInfo.mbEnable = true;
925 aInfo.mbDateValues = bDateValue;
926 aInfo.mbAutoStart = bAutoStart;
927 aInfo.mbAutoEnd = bAutoEnd;
928 aInfo.mfStart = fStart;
929 aInfo.mfEnd = fEnd;
930 aInfo.mfStep = fStep;
931 if (!sGroupSource.isEmpty())
933 ScDPSaveGroupDimension aGroupDim(sGroupSource, sName);
934 if (nGroupPart)
935 aGroupDim.SetDateInfo(aInfo, nGroupPart);
936 else
938 for (const auto& rGroup : aGroups)
940 ScDPSaveGroupItem aItem(rGroup.aName);
941 for (const auto& rMember : rGroup.aMembers)
943 aItem.AddElement(rMember);
945 aGroupDim.AddGroupItem(aItem);
948 pDataPilotTable->AddGroupDim(aGroupDim);
950 else //NumGroup
952 ScDPSaveNumGroupDimension aNumGroupDim(sName, aInfo);
953 if (nGroupPart)
954 aNumGroupDim.SetDateInfo(aInfo, nGroupPart);
955 pDataPilotTable->AddGroupDim(aNumGroupDim);
959 ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport& rImport,
960 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
961 ScXMLDataPilotFieldContext* pDataPilotField) :
962 ScXMLImportContext( rImport )
964 sheet::DataPilotFieldReference aReference;
966 if ( rAttrList.is() )
968 for (auto &aIter : *rAttrList)
970 switch (aIter.getToken())
972 case XML_ELEMENT( TABLE, XML_TYPE ):
974 if (IsXMLToken(aIter, XML_NONE))
975 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::NONE;
976 else if (IsXMLToken(aIter, XML_MEMBER_DIFFERENCE))
977 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE;
978 else if (IsXMLToken(aIter, XML_MEMBER_PERCENTAGE))
979 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE;
980 else if (IsXMLToken(aIter, XML_MEMBER_PERCENTAGE_DIFFERENCE))
981 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE;
982 else if (IsXMLToken(aIter, XML_RUNNING_TOTAL))
983 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::RUNNING_TOTAL;
984 else if (IsXMLToken(aIter, XML_ROW_PERCENTAGE))
985 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE;
986 else if (IsXMLToken(aIter, XML_COLUMN_PERCENTAGE))
987 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE;
988 else if (IsXMLToken(aIter, XML_TOTAL_PERCENTAGE))
989 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE;
990 else if (IsXMLToken(aIter, XML_INDEX))
991 aReference.ReferenceType = sheet::DataPilotFieldReferenceType::INDEX;
993 break;
994 case XML_ELEMENT( TABLE, XML_FIELD_NAME ):
996 aReference.ReferenceField = aIter.toString();
998 break;
999 case XML_ELEMENT( TABLE, XML_MEMBER_TYPE ):
1001 if (IsXMLToken(aIter, XML_NAMED))
1002 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED;
1003 else if (IsXMLToken(aIter, XML_PREVIOUS))
1004 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::PREVIOUS;
1005 else if (IsXMLToken(aIter, XML_NEXT))
1006 aReference.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NEXT;
1008 break;
1009 case XML_ELEMENT( TABLE, XML_MEMBER_NAME ):
1011 aReference.ReferenceItemName = aIter.toString();
1013 break;
1017 pDataPilotField->SetFieldReference(aReference);
1020 ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1024 ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport& rImport,
1025 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1026 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1027 ScXMLImportContext( rImport ),
1028 pDataPilotField(pTempDataPilotField)
1030 if ( !rAttrList.is() )
1031 return;
1033 for (auto &aIter : *rAttrList)
1035 switch (aIter.getToken())
1037 case XML_ELEMENT( TABLE, XML_SHOW_EMPTY ):
1038 pDataPilotField->SetShowEmpty(IsXMLToken(aIter, XML_TRUE));
1039 break;
1040 case XML_ELEMENT( CALC_EXT, XML_REPEAT_ITEM_LABELS ):
1041 pDataPilotField->SetRepeatItemLabels(IsXMLToken(aIter, XML_TRUE));
1042 break;
1047 ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1051 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotLevelContext::createFastChildContext(
1052 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1054 SvXMLImportContext *pContext = nullptr;
1055 sax_fastparser::FastAttributeList *pAttribList =
1056 &sax_fastparser::castToFastAttributeList( xAttrList );
1058 switch (nElement)
1060 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SUBTOTALS ):
1061 pContext = new ScXMLDataPilotSubTotalsContext(GetScImport(), pDataPilotField);
1062 break;
1063 case XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBERS ):
1064 pContext = new ScXMLDataPilotMembersContext(GetScImport(), pDataPilotField);
1065 break;
1066 case XML_ELEMENT( TABLE, XML_DATA_PILOT_DISPLAY_INFO ):
1067 pContext = new ScXMLDataPilotDisplayInfoContext(GetScImport(), pAttribList, pDataPilotField);
1068 break;
1069 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SORT_INFO ):
1070 pContext = new ScXMLDataPilotSortInfoContext(GetScImport(), pAttribList, pDataPilotField);
1071 break;
1072 case XML_ELEMENT( TABLE, XML_DATA_PILOT_LAYOUT_INFO ):
1073 pContext = new ScXMLDataPilotLayoutInfoContext(GetScImport(), pAttribList, pDataPilotField);
1074 break;
1077 return pContext;
1080 ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport& rImport,
1081 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1082 ScXMLDataPilotFieldContext* pDataPilotField) :
1083 ScXMLImportContext( rImport )
1085 sheet::DataPilotFieldAutoShowInfo aInfo;
1087 if ( rAttrList.is() )
1089 for (auto &aIter : *rAttrList)
1091 switch (aIter.getToken())
1093 case XML_ELEMENT( TABLE, XML_ENABLED ):
1094 if (IsXMLToken(aIter, XML_TRUE))
1095 aInfo.IsEnabled = true;
1096 else
1097 aInfo.IsEnabled = false;
1098 break;
1099 case XML_ELEMENT( TABLE, XML_DISPLAY_MEMBER_MODE ):
1100 if (IsXMLToken(aIter, XML_FROM_TOP))
1101 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_TOP;
1102 else if (IsXMLToken(aIter, XML_FROM_BOTTOM))
1103 aInfo.ShowItemsMode = sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM;
1104 break;
1105 case XML_ELEMENT( TABLE, XML_MEMBER_COUNT ):
1106 aInfo.ItemCount = aIter.toInt32();
1107 break;
1108 case XML_ELEMENT( TABLE, XML_DATA_FIELD ):
1109 aInfo.DataField = aIter.toString();
1110 break;
1114 pDataPilotField->SetAutoShowInfo(aInfo);
1117 ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1121 ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport& rImport,
1122 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1123 ScXMLDataPilotFieldContext* pDataPilotField) :
1124 ScXMLImportContext( rImport )
1126 sheet::DataPilotFieldSortInfo aInfo;
1128 if ( rAttrList.is() )
1130 for (auto &aIter : *rAttrList)
1132 switch (aIter.getToken())
1134 case XML_ELEMENT( TABLE, XML_ORDER ):
1135 if (IsXMLToken(aIter, XML_ASCENDING))
1136 aInfo.IsAscending = true;
1137 else if (IsXMLToken(aIter, XML_DESCENDING))
1138 aInfo.IsAscending = false;
1139 break;
1140 case XML_ELEMENT( TABLE, XML_SORT_MODE ):
1141 if (IsXMLToken(aIter, XML_NONE))
1142 aInfo.Mode = sheet::DataPilotFieldSortMode::NONE;
1143 else if (IsXMLToken(aIter, XML_MANUAL))
1144 aInfo.Mode = sheet::DataPilotFieldSortMode::MANUAL;
1145 else if (IsXMLToken(aIter, XML_NAME))
1146 aInfo.Mode = sheet::DataPilotFieldSortMode::NAME;
1147 else if (IsXMLToken(aIter, XML_DATA))
1148 aInfo.Mode = sheet::DataPilotFieldSortMode::DATA;
1149 break;
1150 case XML_ELEMENT( TABLE, XML_DATA_FIELD ):
1151 aInfo.Field = aIter.toString();
1152 break;
1156 pDataPilotField->SetSortInfo(aInfo);
1159 ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1163 ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport& rImport,
1164 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1165 ScXMLDataPilotFieldContext* pDataPilotField) :
1166 ScXMLImportContext( rImport )
1168 sheet::DataPilotFieldLayoutInfo aInfo;
1170 if ( rAttrList.is() )
1172 for (auto &aIter : *rAttrList)
1174 switch (aIter.getToken())
1176 case XML_ELEMENT( TABLE, XML_ADD_EMPTY_LINES ):
1177 if (IsXMLToken(aIter, XML_TRUE))
1178 aInfo.AddEmptyLines = true;
1179 else
1180 aInfo.AddEmptyLines = false;
1181 break;
1182 case XML_ELEMENT( TABLE, XML_LAYOUT_MODE ):
1183 if (IsXMLToken(aIter, XML_TABULAR_LAYOUT))
1184 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
1185 else if (IsXMLToken(aIter, XML_OUTLINE_SUBTOTALS_TOP))
1186 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
1187 else if (IsXMLToken(aIter, XML_OUTLINE_SUBTOTALS_BOTTOM))
1188 aInfo.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
1189 break;
1193 pDataPilotField->SetLayoutInfo(aInfo);}
1195 ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1199 ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport& rImport,
1200 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1201 ScXMLImportContext( rImport ),
1202 pDataPilotField(pTempDataPilotField)
1205 // has no attributes
1208 ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1212 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotSubTotalsContext::createFastChildContext(
1213 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1215 SvXMLImportContext *pContext = nullptr;
1216 sax_fastparser::FastAttributeList *pAttribList =
1217 &sax_fastparser::castToFastAttributeList( xAttrList );
1219 switch (nElement)
1221 case XML_ELEMENT( TABLE, XML_DATA_PILOT_SUBTOTAL ):
1222 pContext = new ScXMLDataPilotSubTotalContext(GetScImport(), pAttribList, this);
1223 break;
1226 return pContext;
1229 void SAL_CALL ScXMLDataPilotSubTotalsContext::endFastElement( sal_Int32 /*nElement*/ )
1231 pDataPilotField->SetSubTotals(std::vector(maFunctions));
1232 if (!maDisplayName.isEmpty())
1233 pDataPilotField->SetSubTotalName(maDisplayName);
1236 void ScXMLDataPilotSubTotalsContext::AddFunction(ScGeneralFunction nFunction)
1238 maFunctions.push_back(nFunction);
1241 void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString& rName)
1243 maDisplayName = rName;
1246 ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport& rImport,
1247 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1248 ScXMLDataPilotSubTotalsContext* pDataPilotSubTotals) :
1249 ScXMLImportContext( rImport )
1251 if ( !rAttrList.is() )
1252 return;
1254 for (auto &aIter : *rAttrList)
1256 switch (aIter.getToken())
1258 case XML_ELEMENT( TABLE, XML_FUNCTION ):
1259 pDataPilotSubTotals->AddFunction( ScXMLConverter::GetFunctionFromString2( aIter.toString() ) );
1260 break;
1261 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
1262 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
1263 pDataPilotSubTotals->SetDisplayName(aIter.toString());
1264 break;
1269 ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1273 ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport& rImport,
1274 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1275 ScXMLImportContext( rImport ),
1276 pDataPilotField(pTempDataPilotField)
1278 // has no attributes
1281 ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1285 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotMembersContext::createFastChildContext(
1286 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1288 SvXMLImportContext *pContext = nullptr;
1289 sax_fastparser::FastAttributeList *pAttribList =
1290 &sax_fastparser::castToFastAttributeList( xAttrList );
1292 switch (nElement)
1294 case XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBER ):
1295 pContext = new ScXMLDataPilotMemberContext(GetScImport(), pAttribList, pDataPilotField);
1296 break;
1299 return pContext;
1302 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport& rImport,
1303 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1304 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1305 ScXMLImportContext( rImport ),
1306 pDataPilotField(pTempDataPilotField),
1307 bDisplay( true ),
1308 bDisplayDetails( true ),
1309 bHasName( false )
1311 if ( !rAttrList.is() )
1312 return;
1314 for (auto &aIter : *rAttrList)
1316 switch (aIter.getToken())
1318 case XML_ELEMENT( TABLE, XML_NAME ):
1319 sName = aIter.toString();
1320 bHasName = true;
1321 break;
1322 case XML_ELEMENT( TABLE, XML_DISPLAY_NAME ):
1323 case XML_ELEMENT( TABLE_EXT, XML_DISPLAY_NAME ):
1324 maDisplayName = aIter.toString();
1325 break;
1326 case XML_ELEMENT( TABLE, XML_DISPLAY ):
1327 bDisplay = IsXMLToken(aIter, XML_TRUE);
1328 break;
1329 case XML_ELEMENT( TABLE, XML_SHOW_DETAILS ):
1330 bDisplayDetails = IsXMLToken(aIter, XML_TRUE);
1331 break;
1336 ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1340 void SAL_CALL ScXMLDataPilotMemberContext::endFastElement( sal_Int32 /*nElement*/ )
1342 if (bHasName) // #i53407# don't check sName, empty name is allowed
1344 std::unique_ptr<ScDPSaveMember> pMember(new ScDPSaveMember(sName));
1345 if (!maDisplayName.isEmpty())
1346 pMember->SetLayoutName(maDisplayName);
1347 pMember->SetIsVisible(bDisplay);
1348 pMember->SetShowDetails(bDisplayDetails);
1349 pDataPilotField->AddMember(std::move(pMember));
1353 ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport& rImport,
1354 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1355 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1356 ScXMLImportContext( rImport ),
1357 pDataPilotField(pTempDataPilotField)
1359 OUString sGroupSource;
1360 double fStart(0.0);
1361 double fEnd(0.0);
1362 double fStep(0.0);
1363 sal_Int32 nGroupPart(0);
1364 bool bDateValue(false);
1365 bool bAutoStart(true);
1366 bool bAutoEnd(true);
1368 if ( rAttrList.is() )
1370 for (auto &aIter : *rAttrList)
1372 switch (aIter.getToken() & TOKEN_MASK)
1374 case XML_SOURCE_FIELD_NAME :
1376 sGroupSource = aIter.toString();
1378 break;
1379 case XML_DATE_START :
1381 bDateValue = true;
1382 if (IsXMLToken(aIter, XML_AUTO))
1383 bAutoStart = true;
1384 else
1386 GetScImport().GetMM100UnitConverter().convertDateTime(fStart, aIter.toView());
1387 bAutoStart = false;
1390 break;
1391 case XML_DATE_END :
1393 bDateValue = true;
1394 if (IsXMLToken(aIter, XML_AUTO))
1395 bAutoEnd = true;
1396 else
1398 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd, aIter.toView());
1399 bAutoEnd = false;
1402 break;
1403 case XML_START :
1405 if (IsXMLToken(aIter, XML_AUTO))
1406 bAutoStart = true;
1407 else
1409 fStart = aIter.toDouble();
1410 bAutoStart = false;
1413 break;
1414 case XML_END :
1416 if (IsXMLToken(aIter, XML_AUTO))
1417 bAutoEnd = true;
1418 else
1420 fEnd = aIter.toDouble();
1421 bAutoEnd = false;
1424 break;
1425 case XML_STEP :
1427 fStep = aIter.toDouble();
1429 break;
1430 case XML_GROUPED_BY :
1432 if (IsXMLToken(aIter, XML_SECONDS))
1433 nGroupPart = css::sheet::DataPilotFieldGroupBy::SECONDS;
1434 else if (IsXMLToken(aIter, XML_MINUTES))
1435 nGroupPart = css::sheet::DataPilotFieldGroupBy::MINUTES;
1436 else if (IsXMLToken(aIter, XML_HOURS))
1437 nGroupPart = css::sheet::DataPilotFieldGroupBy::HOURS;
1438 else if (IsXMLToken(aIter, XML_DAYS))
1439 nGroupPart = css::sheet::DataPilotFieldGroupBy::DAYS;
1440 else if (IsXMLToken(aIter, XML_MONTHS))
1441 nGroupPart = css::sheet::DataPilotFieldGroupBy::MONTHS;
1442 else if (IsXMLToken(aIter, XML_QUARTERS))
1443 nGroupPart = css::sheet::DataPilotFieldGroupBy::QUARTERS;
1444 else if (IsXMLToken(aIter, XML_YEARS))
1445 nGroupPart = css::sheet::DataPilotFieldGroupBy::YEARS;
1447 break;
1451 pDataPilotField->SetGrouping(sGroupSource, fStart, fEnd, fStep, nGroupPart, bDateValue, bAutoStart, bAutoEnd);
1454 ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1458 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotGroupsContext::createFastChildContext(
1459 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1461 SvXMLImportContext *pContext = nullptr;
1462 sax_fastparser::FastAttributeList *pAttribList =
1463 &sax_fastparser::castToFastAttributeList( xAttrList );
1465 if (nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUP ))
1467 pContext = new ScXMLDataPilotGroupContext(GetScImport(), pAttribList, pDataPilotField);
1470 return pContext;
1473 ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport& rImport,
1474 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1475 ScXMLDataPilotFieldContext* pTempDataPilotField) :
1476 ScXMLImportContext( rImport ),
1477 pDataPilotField(pTempDataPilotField)
1479 if ( rAttrList.is() )
1481 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_NAME ) ) );
1482 if (aIter != rAttrList->end())
1483 sName = aIter.toString();
1487 ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1491 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDataPilotGroupContext::createFastChildContext(
1492 sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
1494 SvXMLImportContext *pContext = nullptr;
1495 sax_fastparser::FastAttributeList *pAttribList =
1496 &sax_fastparser::castToFastAttributeList( xAttrList );
1498 if (nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_MEMBER ) ||
1499 nElement == XML_ELEMENT( TABLE, XML_DATA_PILOT_GROUP_MEMBER ))
1501 pContext = new ScXMLDataPilotGroupMemberContext(GetScImport(), pAttribList, this);
1504 return pContext;
1507 void SAL_CALL ScXMLDataPilotGroupContext::endFastElement( sal_Int32 /*nElement*/ )
1509 pDataPilotField->AddGroup(std::vector(aMembers), sName);
1512 ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport& rImport,
1513 const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList,
1514 ScXMLDataPilotGroupContext* pTempDataPilotGroup) :
1515 ScXMLImportContext( rImport ),
1516 pDataPilotGroup(pTempDataPilotGroup)
1518 if ( rAttrList.is() )
1520 auto aIter( rAttrList->find( XML_ELEMENT( TABLE, XML_NAME ) ) );
1521 if (aIter != rAttrList->end())
1522 sName = aIter.toString();
1526 ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1530 void SAL_CALL ScXMLDataPilotGroupMemberContext::endFastElement( sal_Int32 /*nElement*/ )
1532 if (!sName.isEmpty())
1533 pDataPilotGroup->AddMember(sName);
1536 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */