1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
)
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
);
72 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_TABLE
) :
74 pContext
= new ScXMLDataPilotTableContext( GetScImport(), pAttribList
);
82 ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
85 ScXMLDataPilotTableContext::ScXMLDataPilotTableContext( ScXMLImport
& rImport
,
86 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
) :
87 ScXMLImportContext( rImport
),
88 pDoc(GetScImport().GetDocument()),
89 pDPSave(new ScDPSaveData()),
95 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN
),
97 bIgnoreEmptyRows(false),
98 bIdentifyCategories(false),
99 bTargetRangeAddress(false),
100 bSourceCellRange(false),
103 bHeaderGridLayout(false)
105 if ( !rAttrList
.is() )
108 for (auto &aIter
: *rAttrList
)
110 switch (aIter
.getToken())
112 case XML_ELEMENT( TABLE
, XML_NAME
):
114 sDataPilotTableName
= aIter
.toString();
117 case XML_ELEMENT( TABLE
, XML_APPLICATION_DATA
):
119 sApplicationData
= aIter
.toString();
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;
141 maRowGrandTotal
.mbVisible
= false;
142 maColGrandTotal
.mbVisible
= false;
146 case XML_ELEMENT( TABLE
, XML_IGNORE_EMPTY_ROWS
):
148 bIgnoreEmptyRows
= IsXMLToken(aIter
, XML_TRUE
);
151 case XML_ELEMENT( TABLE
, XML_IDENTIFY_CATEGORIES
):
153 bIdentifyCategories
= IsXMLToken(aIter
, XML_TRUE
);
156 case XML_ELEMENT( TABLE
, XML_TARGET_RANGE_ADDRESS
):
158 sal_Int32
nOffset(0);
160 bTargetRangeAddress
= ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
163 case XML_ELEMENT( TABLE
, XML_BUTTONS
):
165 sButtons
= aIter
.toString();
168 case XML_ELEMENT( TABLE
, XML_SHOW_FILTER_BUTTON
):
170 bShowFilter
= IsXMLToken(aIter
, XML_TRUE
);
173 case XML_ELEMENT( TABLE
, XML_DRILL_DOWN_ON_DOUBLE_CLICK
):
175 bDrillDown
= IsXMLToken(aIter
, XML_TRUE
);
178 case XML_ELEMENT( TABLE
, XML_HEADER_GRID_LAYOUT
):
180 bHeaderGridLayout
= IsXMLToken(aIter
, XML_TRUE
);
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
);
200 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_SQL
):
202 pContext
= new ScXMLDPSourceSQLContext(GetScImport(), pAttribList
, this);
206 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_TABLE
):
208 pContext
= new ScXMLDPSourceTableContext(GetScImport(), pAttribList
, this);
212 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_QUERY
):
214 pContext
= new ScXMLDPSourceQueryContext(GetScImport(), pAttribList
, this);
218 case XML_ELEMENT( TABLE
, XML_SOURCE_SERVICE
):
220 pContext
= new ScXMLSourceServiceContext(GetScImport(), pAttribList
, this);
221 nSourceType
= SERVICE
;
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);
230 case XML_ELEMENT( TABLE
, XML_SOURCE_CELL_RANGE
):
232 pContext
= new ScXMLSourceCellRangeContext(GetScImport(), pAttribList
, this);
233 nSourceType
= CELLRANGE
;
236 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_FIELD
):
237 pContext
= new ScXMLDataPilotFieldContext(GetScImport(), pAttribList
, this);
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
)
254 case ScDPOutputGeometry::Column
:
256 if (rColDims
.size() <= nPos
)
259 return rColDims
[nPos
];
261 case ScDPOutputGeometry::Row
:
263 if (rRowDims
.size() <= nPos
)
266 return rRowDims
[nPos
];
268 case ScDPOutputGeometry::Page
:
270 if (rPageDims
.size() <= nPos
)
273 return rPageDims
[nPos
];
275 case ScDPOutputGeometry::Data
:
277 case ScDPOutputGeometry::None
:
285 ScDPOutputGeometry::FieldType
toFieldType(sheet::DataPilotFieldOrientation 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
:
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
);
323 sal_Int32 nOffset
= 0;
324 while( nOffset
>= 0 )
326 ScRangeStringConverter::GetTokenByOffset( sAddress
, sButtons
, nOffset
);
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
;
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
;
350 nMFlag
|= ScMF::HiddenMember
;
351 pDoc
->ApplyFlagsTab(aScAddress
.Col()+1, aScAddress
.Row(), aScAddress
.Col()+1, aScAddress
.Row(), aScAddress
.Tab(), nMFlag
);
355 ScMF nMFlag
= ScMF::Button
;
358 // Data layout dimension only has a plain button with no popup.
362 // Normal dimension has a popup arrow button.
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
)
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
:
402 case sheet::DataPilotFieldOrientation_COLUMN
:
405 case sheet::DataPilotFieldOrientation_PAGE
:
408 case sheet::DataPilotFieldOrientation_DATA
:
411 case sheet::DataPilotFieldOrientation_HIDDEN
:
417 pDPSave
->AddDimension(pDim
);
420 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension
& aNumGroupDim
)
423 pDPDimSaveData
.reset( new ScDPDimensionSaveData
);
424 pDPDimSaveData
->AddNumGroupDimension(aNumGroupDim
);
427 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension
& aGroupDim
)
430 pDPDimSaveData
.reset( new ScDPDimensionSaveData
);
431 pDPDimSaveData
->AddGroupDimension(aGroupDim
);
434 void SAL_CALL
ScXMLDataPilotTableContext::endFastElement( sal_Int32
/*nElement*/ )
436 if (!bTargetRangeAddress
)
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();
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
);
461 ScImportSourceDesc
aImportDesc(pDoc
);
462 aImportDesc
.aDBName
= sDatabaseName
;
463 aImportDesc
.aObject
= sSourceObject
;
464 aImportDesc
.nType
= sheet::DataImportMode_TABLE
;
465 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
470 ScImportSourceDesc
aImportDesc(pDoc
);
471 aImportDesc
.aDBName
= sDatabaseName
;
472 aImportDesc
.aObject
= sSourceObject
;
473 aImportDesc
.nType
= sheet::DataImportMode_QUERY
;
474 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
479 ScDPServiceDesc
aServiceDesc(sServiceName
, sServiceSourceName
, sServiceSourceObject
,
480 sServiceUsername
, sServicePassword
);
481 rPivotSources
.appendServiceSource(pDPObject
.get(), aServiceDesc
);
486 if (bSourceCellRange
)
488 ScSheetSourceDesc
aSheetDesc(pDoc
);
489 if (!sSourceRangeName
.isEmpty())
490 // Range name takes precedence.
491 aSheetDesc
.SetRangeName(sSourceRangeName
);
493 aSheetDesc
.SetSourceRange(aSourceCellRangeAddress
);
494 aSheetDesc
.SetQueryParam(aSourceQueryParam
);
495 rPivotSources
.appendSheetSource(pDPObject
.get(), aSheetDesc
);
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
509 pDPSave
->SetGrandTotalName(maRowGrandTotal
.maDisplayName
);
511 pDPSave
->SetIgnoreEmptyRows(bIgnoreEmptyRows
);
512 pDPSave
->SetRepeatIfEmpty(bIdentifyCategories
);
513 pDPSave
->SetFilterButton(bShowFilter
);
514 pDPSave
->SetDrillDown(bDrillDown
);
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
)
536 maRowGrandTotal
.mbVisible
= bVisible
;
537 maRowGrandTotal
.maDisplayName
= rDisplayName
;
538 maColGrandTotal
.mbVisible
= bVisible
;
539 maColGrandTotal
.maDisplayName
= rDisplayName
;
542 maRowGrandTotal
.mbVisible
= bVisible
;
543 maRowGrandTotal
.maDisplayName
= rDisplayName
;
546 maColGrandTotal
.mbVisible
= bVisible
;
547 maColGrandTotal
.maDisplayName
= rDisplayName
;
554 ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( ScXMLImport
& rImport
,
555 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
556 ScXMLDataPilotTableContext
* pDataPilotTable
) :
557 ScXMLImportContext( rImport
)
559 if ( !rAttrList
.is() )
562 for (auto &aIter
: *rAttrList
)
564 switch (aIter
.getToken())
566 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
567 pDataPilotTable
->SetDatabaseName(aIter
.toString());
569 case XML_ELEMENT( TABLE
, XML_SQL_STATEMENT
):
570 pDataPilotTable
->SetSourceObject(aIter
.toString());
572 case XML_ELEMENT( TABLE
, XML_PARSE_SQL_STATEMENT
):
573 pDataPilotTable
->SetNative(!IsXMLToken(aIter
, XML_TRUE
));
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() )
591 for (auto &aIter
: *rAttrList
)
593 switch (aIter
.getToken())
595 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
596 pDataPilotTable
->SetDatabaseName(aIter
.toString());
598 case XML_ELEMENT( TABLE
, XML_TABLE_NAME
):
599 case XML_ELEMENT( TABLE
, XML_DATABASE_TABLE_NAME
):
600 pDataPilotTable
->SetSourceObject(aIter
.toString());
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() )
618 for (auto &aIter
: *rAttrList
)
620 switch (aIter
.getToken())
622 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
623 pDataPilotTable
->SetDatabaseName(aIter
.toString());
625 case XML_ELEMENT( TABLE
, XML_QUERY_NAME
):
626 pDataPilotTable
->SetSourceObject(aIter
.toString());
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() )
644 for (auto &aIter
: *rAttrList
)
646 switch (aIter
.getToken())
648 case XML_ELEMENT( TABLE
, XML_NAME
):
649 pDataPilotTable
->SetServiceName(aIter
.toString());
651 case XML_ELEMENT( TABLE
, XML_SOURCE_NAME
):
652 pDataPilotTable
->SetServiceSourceName(aIter
.toString());
654 case XML_ELEMENT( TABLE
, XML_OBJECT_NAME
):
655 pDataPilotTable
->SetServiceSourceObject(aIter
.toString());
657 case XML_ELEMENT( TABLE
, XML_USER_NAME
):
658 pDataPilotTable
->SetServiceUsername(aIter
.toString());
660 case XML_ELEMENT( TABLE
, XML_PASSWORD
):
661 pDataPilotTable
->SetServicePassword(aIter
.toString());
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
),
679 if ( !rAttrList
.is() )
682 for (auto &aIter
: *rAttrList
)
684 switch (aIter
.getToken())
686 case XML_ELEMENT( TABLE
, XML_DISPLAY
):
687 mbVisible
= IsXMLToken(aIter
, XML_TRUE
);
689 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
690 if (IsXMLToken(aIter
, XML_BOTH
))
691 meOrientation
= BOTH
;
692 else if (IsXMLToken(aIter
, XML_ROW
))
694 else if (IsXMLToken(aIter
, XML_COLUMN
))
695 meOrientation
= COLUMN
;
697 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
698 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
699 maDisplayName
= aIter
.toString();
707 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
711 void SAL_CALL
ScXMLDataPilotGrandTotalContext::endFastElement( sal_Int32
/*nElement*/ )
713 XMLTokenEnum eOrient
= XML_NONE
;
714 switch (meOrientation
)
723 eOrient
= XML_COLUMN
;
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() )
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();
750 if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
))
751 pDataPilotTable
->SetSourceCellRangeAddress(aSourceRangeAddress
);
754 case XML_ELEMENT( TABLE
, XML_NAME
):
755 pDataPilotTable
->SetSourceRangeName(aIter
.toString());
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
);
774 case XML_ELEMENT( TABLE
, XML_FILTER
):
775 pContext
= new ScXMLDPFilterContext(GetScImport(), pAttribList
, pDataPilotTable
);
782 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport
& rImport
,
783 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
784 ScXMLDataPilotTableContext
* pTempDataPilotTable
) :
785 ScXMLImportContext( rImport
),
786 pDataPilotTable(pTempDataPilotTable
),
792 nFunction(ScGeneralFunction::NONE
),
793 nOrientation(sheet::DataPilotFieldOrientation_HIDDEN
),
794 bSelectedPage(false),
795 bIsGroupField(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();
815 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
816 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
817 aDisplayName
= aIter
.toString();
819 case XML_ELEMENT( TABLE
, XML_IS_DATA_LAYOUT_FIELD
):
820 bDataLayout
= IsXMLToken(aIter
, XML_TRUE
);
822 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
823 nFunction
= ScXMLConverter::GetFunctionFromString2( aIter
.toString() );
825 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
826 nOrientation
= ScXMLConverter::GetOrientationFromString( aIter
.toString() );
828 case XML_ELEMENT( TABLE
, XML_SELECTED_PAGE
):
829 sSelectedPage
= aIter
.toString();
830 bSelectedPage
= true;
832 case XML_ELEMENT( LO_EXT
, XML_IGNORE_SELECTED_PAGE
):
833 bIgnoreSelectedPage
= true;
835 case XML_ELEMENT( TABLE
, XML_USED_HIERARCHY
):
836 nUsedHierarchy
= aIter
.toInt32();
842 // use the new extension elements
843 if (bIgnoreSelectedPage
)
844 bSelectedPage
= false;
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
);
867 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_LEVEL
):
868 pContext
= new ScXMLDataPilotLevelContext(GetScImport(), pAttribList
, this);
870 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_FIELD_REFERENCE
):
871 pContext
= new ScXMLDataPilotFieldReferenceContext(GetScImport(), pAttribList
, this);
873 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_GROUPS
):
874 pContext
= new ScXMLDataPilotGroupsContext(GetScImport(), pAttribList
, this);
881 void ScXMLDataPilotFieldContext::AddMember(std::unique_ptr
<ScDPSaveMember
> pMember
)
885 bool isVisible
= pMember
->GetIsVisible();
886 xDim
->AddMember(std::move(pMember
));
888 // This member is hidden.
889 mbHasHiddenMember
= true;
893 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString
& rName
)
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*/ )
912 xDim
->SetUsedHierarchy(nUsedHierarchy
);
913 xDim
->SetFunction(nFunction
);
914 xDim
->SetOrientation(nOrientation
);
917 pDataPilotTable
->SetSelectedPage(xDim
->GetName(), sSelectedPage
);
919 pDataPilotTable
->AddDimension(xDim
.release());
923 ScDPNumGroupInfo aInfo
;
924 aInfo
.mbEnable
= true;
925 aInfo
.mbDateValues
= bDateValue
;
926 aInfo
.mbAutoStart
= bAutoStart
;
927 aInfo
.mbAutoEnd
= bAutoEnd
;
928 aInfo
.mfStart
= fStart
;
930 aInfo
.mfStep
= fStep
;
931 if (!sGroupSource
.isEmpty())
933 ScDPSaveGroupDimension
aGroupDim(sGroupSource
, sName
);
935 aGroupDim
.SetDateInfo(aInfo
, nGroupPart
);
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
);
952 ScDPSaveNumGroupDimension
aNumGroupDim(sName
, aInfo
);
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
;
994 case XML_ELEMENT( TABLE
, XML_FIELD_NAME
):
996 aReference
.ReferenceField
= aIter
.toString();
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
;
1009 case XML_ELEMENT( TABLE
, XML_MEMBER_NAME
):
1011 aReference
.ReferenceItemName
= aIter
.toString();
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() )
1033 for (auto &aIter
: *rAttrList
)
1035 switch (aIter
.getToken())
1037 case XML_ELEMENT( TABLE
, XML_SHOW_EMPTY
):
1038 pDataPilotField
->SetShowEmpty(IsXMLToken(aIter
, XML_TRUE
));
1040 case XML_ELEMENT( CALC_EXT
, XML_REPEAT_ITEM_LABELS
):
1041 pDataPilotField
->SetRepeatItemLabels(IsXMLToken(aIter
, XML_TRUE
));
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
);
1060 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SUBTOTALS
):
1061 pContext
= new ScXMLDataPilotSubTotalsContext(GetScImport(), pDataPilotField
);
1063 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBERS
):
1064 pContext
= new ScXMLDataPilotMembersContext(GetScImport(), pDataPilotField
);
1066 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_DISPLAY_INFO
):
1067 pContext
= new ScXMLDataPilotDisplayInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1069 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SORT_INFO
):
1070 pContext
= new ScXMLDataPilotSortInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1072 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_LAYOUT_INFO
):
1073 pContext
= new ScXMLDataPilotLayoutInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
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;
1097 aInfo
.IsEnabled
= false;
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
;
1105 case XML_ELEMENT( TABLE
, XML_MEMBER_COUNT
):
1106 aInfo
.ItemCount
= aIter
.toInt32();
1108 case XML_ELEMENT( TABLE
, XML_DATA_FIELD
):
1109 aInfo
.DataField
= aIter
.toString();
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;
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
;
1150 case XML_ELEMENT( TABLE
, XML_DATA_FIELD
):
1151 aInfo
.Field
= aIter
.toString();
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;
1180 aInfo
.AddEmptyLines
= false;
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
;
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
);
1221 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SUBTOTAL
):
1222 pContext
= new ScXMLDataPilotSubTotalContext(GetScImport(), pAttribList
, this);
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() )
1254 for (auto &aIter
: *rAttrList
)
1256 switch (aIter
.getToken())
1258 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
1259 pDataPilotSubTotals
->AddFunction( ScXMLConverter::GetFunctionFromString2( aIter
.toString() ) );
1261 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
1262 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
1263 pDataPilotSubTotals
->SetDisplayName(aIter
.toString());
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
);
1294 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBER
):
1295 pContext
= new ScXMLDataPilotMemberContext(GetScImport(), pAttribList
, pDataPilotField
);
1302 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport
& rImport
,
1303 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1304 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1305 ScXMLImportContext( rImport
),
1306 pDataPilotField(pTempDataPilotField
),
1308 bDisplayDetails( true ),
1311 if ( !rAttrList
.is() )
1314 for (auto &aIter
: *rAttrList
)
1316 switch (aIter
.getToken())
1318 case XML_ELEMENT( TABLE
, XML_NAME
):
1319 sName
= aIter
.toString();
1322 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
1323 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
1324 maDisplayName
= aIter
.toString();
1326 case XML_ELEMENT( TABLE
, XML_DISPLAY
):
1327 bDisplay
= IsXMLToken(aIter
, XML_TRUE
);
1329 case XML_ELEMENT( TABLE
, XML_SHOW_DETAILS
):
1330 bDisplayDetails
= IsXMLToken(aIter
, XML_TRUE
);
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
;
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();
1379 case XML_DATE_START
:
1382 if (IsXMLToken(aIter
, XML_AUTO
))
1386 GetScImport().GetMM100UnitConverter().convertDateTime(fStart
, aIter
.toView());
1394 if (IsXMLToken(aIter
, XML_AUTO
))
1398 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd
, aIter
.toView());
1405 if (IsXMLToken(aIter
, XML_AUTO
))
1409 fStart
= aIter
.toDouble();
1416 if (IsXMLToken(aIter
, XML_AUTO
))
1420 fEnd
= aIter
.toDouble();
1427 fStep
= aIter
.toDouble();
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
;
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
);
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);
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: */