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/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
)
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
);
73 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_TABLE
) :
75 pContext
= new ScXMLDataPilotTableContext( GetScImport(), pAttribList
);
81 pContext
= new SvXMLImportContext( GetImport() );
86 ScXMLDataPilotTableContext::GrandTotalItem::GrandTotalItem() :
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(),
101 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN
),
103 bIgnoreEmptyRows(false),
104 bIdentifyCategories(false),
105 bTargetRangeAddress(false),
106 bSourceCellRange(false),
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();
122 case XML_ELEMENT( TABLE
, XML_APPLICATION_DATA
):
124 sApplicationData
= aIter
.toString();
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;
146 maRowGrandTotal
.mbVisible
= false;
147 maColGrandTotal
.mbVisible
= false;
151 case XML_ELEMENT( TABLE
, XML_IGNORE_EMPTY_ROWS
):
153 bIgnoreEmptyRows
= IsXMLToken(aIter
, XML_TRUE
);
156 case XML_ELEMENT( TABLE
, XML_IDENTIFY_CATEGORIES
):
158 bIdentifyCategories
= IsXMLToken(aIter
, XML_TRUE
);
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
);
167 case XML_ELEMENT( TABLE
, XML_BUTTONS
):
169 sButtons
= aIter
.toString();
172 case XML_ELEMENT( TABLE
, XML_SHOW_FILTER_BUTTON
):
174 bShowFilter
= IsXMLToken(aIter
, XML_TRUE
);
177 case XML_ELEMENT( TABLE
, XML_DRILL_DOWN_ON_DOUBLE_CLICK
):
179 bDrillDown
= IsXMLToken(aIter
, XML_TRUE
);
182 case XML_ELEMENT( TABLE
, XML_HEADER_GRID_LAYOUT
):
184 bHeaderGridLayout
= IsXMLToken(aIter
, XML_TRUE
);
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
);
205 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_SQL
):
207 pContext
= new ScXMLDPSourceSQLContext(GetScImport(), pAttribList
, this);
211 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_TABLE
):
213 pContext
= new ScXMLDPSourceTableContext(GetScImport(), pAttribList
, this);
217 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_QUERY
):
219 pContext
= new ScXMLDPSourceQueryContext(GetScImport(), pAttribList
, this);
223 case XML_ELEMENT( TABLE
, XML_SOURCE_SERVICE
):
225 pContext
= new ScXMLSourceServiceContext(GetScImport(), pAttribList
, this);
226 nSourceType
= SERVICE
;
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);
235 case XML_ELEMENT( TABLE
, XML_SOURCE_CELL_RANGE
):
237 pContext
= new ScXMLSourceCellRangeContext(GetScImport(), pAttribList
, this);
238 nSourceType
= CELLRANGE
;
241 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_FIELD
):
242 pContext
= new ScXMLDataPilotFieldContext(GetScImport(), pAttribList
, this);
247 pContext
= new SvXMLImportContext( GetImport() );
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
)
262 case ScDPOutputGeometry::Column
:
264 if (rColDims
.size() <= nPos
)
267 return rColDims
[nPos
];
269 case ScDPOutputGeometry::Row
:
271 if (rRowDims
.size() <= nPos
)
274 return rRowDims
[nPos
];
276 case ScDPOutputGeometry::Page
:
278 if (rPageDims
.size() <= nPos
)
281 return rPageDims
[nPos
];
283 case ScDPOutputGeometry::Data
:
285 case ScDPOutputGeometry::None
:
293 ScDPOutputGeometry::FieldType
toFieldType(sheet::DataPilotFieldOrientation 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
:
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
);
331 sal_Int32 nOffset
= 0;
332 while( nOffset
>= 0 )
334 ScRangeStringConverter::GetTokenByOffset( sAddress
, sButtons
, nOffset
);
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
;
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
;
358 nMFlag
|= ScMF::HiddenMember
;
359 pDoc
->ApplyFlagsTab(aScAddress
.Col()+1, aScAddress
.Row(), aScAddress
.Col()+1, aScAddress
.Row(), aScAddress
.Tab(), nMFlag
);
363 ScMF nMFlag
= ScMF::Button
;
366 // Data layout dimension only has a plain button with no popup.
370 // Normal dimension has a popup arrow button.
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
)
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
:
409 case sheet::DataPilotFieldOrientation_COLUMN
:
412 case sheet::DataPilotFieldOrientation_PAGE
:
415 case sheet::DataPilotFieldOrientation_DATA
:
418 case sheet::DataPilotFieldOrientation_HIDDEN
:
424 pDPSave
->AddDimension(pDim
);
428 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension
& aNumGroupDim
)
431 pDPDimSaveData
.reset( new ScDPDimensionSaveData
);
432 pDPDimSaveData
->AddNumGroupDimension(aNumGroupDim
);
435 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension
& aGroupDim
)
438 pDPDimSaveData
.reset( new ScDPDimensionSaveData
);
439 pDPDimSaveData
->AddGroupDimension(aGroupDim
);
442 void SAL_CALL
ScXMLDataPilotTableContext::endFastElement( sal_Int32
/*nElement*/ )
444 if (!bTargetRangeAddress
)
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();
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
);
469 ScImportSourceDesc
aImportDesc(pDoc
);
470 aImportDesc
.aDBName
= sDatabaseName
;
471 aImportDesc
.aObject
= sSourceObject
;
472 aImportDesc
.nType
= sheet::DataImportMode_TABLE
;
473 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
478 ScImportSourceDesc
aImportDesc(pDoc
);
479 aImportDesc
.aDBName
= sDatabaseName
;
480 aImportDesc
.aObject
= sSourceObject
;
481 aImportDesc
.nType
= sheet::DataImportMode_QUERY
;
482 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
487 ScDPServiceDesc
aServiceDesc(sServiceName
, sServiceSourceName
, sServiceSourceObject
,
488 sServiceUsername
, sServicePassword
);
489 rPivotSources
.appendServiceSource(pDPObject
.get(), aServiceDesc
);
494 if (bSourceCellRange
)
496 ScSheetSourceDesc
aSheetDesc(pDoc
);
497 if (!sSourceRangeName
.isEmpty())
498 // Range name takes precedence.
499 aSheetDesc
.SetRangeName(sSourceRangeName
);
501 aSheetDesc
.SetSourceRange(aSourceCellRangeAddress
);
502 aSheetDesc
.SetQueryParam(aSourceQueryParam
);
503 rPivotSources
.appendSheetSource(pDPObject
.get(), aSheetDesc
);
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
517 pDPSave
->SetGrandTotalName(maRowGrandTotal
.maDisplayName
);
519 pDPSave
->SetIgnoreEmptyRows(bIgnoreEmptyRows
);
520 pDPSave
->SetRepeatIfEmpty(bIdentifyCategories
);
521 pDPSave
->SetFilterButton(bShowFilter
);
522 pDPSave
->SetDrillDown(bDrillDown
);
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
)
544 maRowGrandTotal
.mbVisible
= bVisible
;
545 maRowGrandTotal
.maDisplayName
= rDisplayName
;
546 maColGrandTotal
.mbVisible
= bVisible
;
547 maColGrandTotal
.maDisplayName
= rDisplayName
;
550 maRowGrandTotal
.mbVisible
= bVisible
;
551 maRowGrandTotal
.maDisplayName
= rDisplayName
;
554 maColGrandTotal
.mbVisible
= bVisible
;
555 maColGrandTotal
.maDisplayName
= rDisplayName
;
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());
576 case XML_ELEMENT( TABLE
, XML_SQL_STATEMENT
):
577 pDataPilotTable
->SetSourceObject(aIter
.toString());
579 case XML_ELEMENT( TABLE
, XML_PARSE_SQL_STATEMENT
):
580 pDataPilotTable
->SetNative(!IsXMLToken(aIter
, XML_TRUE
));
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());
605 case XML_ELEMENT( TABLE
, XML_TABLE_NAME
):
606 case XML_ELEMENT( TABLE
, XML_DATABASE_TABLE_NAME
):
607 pDataPilotTable
->SetSourceObject(aIter
.toString());
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());
632 case XML_ELEMENT( TABLE
, XML_QUERY_NAME
):
633 pDataPilotTable
->SetSourceObject(aIter
.toString());
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());
658 case XML_ELEMENT( TABLE
, XML_SOURCE_NAME
):
659 pDataPilotTable
->SetServiceSourceName(aIter
.toString());
661 case XML_ELEMENT( TABLE
, XML_OBJECT_NAME
):
662 pDataPilotTable
->SetServiceSourceObject(aIter
.toString());
664 case XML_ELEMENT( TABLE
, XML_USER_NAME
):
665 pDataPilotTable
->SetServiceUsername(aIter
.toString());
667 case XML_ELEMENT( TABLE
, XML_PASSWORD
):
668 pDataPilotTable
->SetServicePassword(aIter
.toString());
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
),
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
);
696 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
697 if (IsXMLToken(aIter
, XML_BOTH
))
698 meOrientation
= BOTH
;
699 else if (IsXMLToken(aIter
, XML_ROW
))
701 else if (IsXMLToken(aIter
, XML_COLUMN
))
702 meOrientation
= COLUMN
;
704 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
705 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
706 maDisplayName
= aIter
.toString();
715 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
719 void SAL_CALL
ScXMLDataPilotGrandTotalContext::endFastElement( sal_Int32
/*nElement*/ )
721 XMLTokenEnum eOrient
= XML_NONE
;
722 switch (meOrientation
)
731 eOrient
= XML_COLUMN
;
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
);
759 case XML_ELEMENT( TABLE
, XML_NAME
):
760 pDataPilotTable
->SetSourceRangeName(aIter
.toString());
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
);
780 case XML_ELEMENT( TABLE
, XML_FILTER
):
781 pContext
= new ScXMLDPFilterContext(GetScImport(), pAttribList
, pDataPilotTable
);
786 pContext
= new SvXMLImportContext( GetImport() );
791 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport
& rImport
,
792 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
793 ScXMLDataPilotTableContext
* pTempDataPilotTable
) :
794 ScXMLImportContext( rImport
),
795 pDataPilotTable(pTempDataPilotTable
),
802 nFunction(ScGeneralFunction::NONE
),
803 nOrientation(sheet::DataPilotFieldOrientation_HIDDEN
),
804 bSelectedPage(false),
805 bIsGroupField(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();
825 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
826 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
827 aDisplayName
= aIter
.toString();
829 case XML_ELEMENT( TABLE
, XML_IS_DATA_LAYOUT_FIELD
):
830 bDataLayout
= IsXMLToken(aIter
, XML_TRUE
);
832 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
833 nFunction
= ScXMLConverter::GetFunctionFromString2( aIter
.toString() );
835 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
836 nOrientation
= ScXMLConverter::GetOrientationFromString( aIter
.toString() );
838 case XML_ELEMENT( TABLE
, XML_SELECTED_PAGE
):
839 sSelectedPage
= aIter
.toString();
840 bSelectedPage
= true;
842 case XML_ELEMENT( LO_EXT
, XML_IGNORE_SELECTED_PAGE
):
843 bIgnoreSelectedPage
= true;
845 case XML_ELEMENT( TABLE
, XML_USED_HIERARCHY
):
846 nUsedHierarchy
= aIter
.toInt32();
852 // use the new extension elements
853 if (bIgnoreSelectedPage
)
854 bSelectedPage
= false;
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
);
877 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_LEVEL
):
878 pContext
= new ScXMLDataPilotLevelContext(GetScImport(), pAttribList
, this);
880 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_FIELD_REFERENCE
):
881 pContext
= new ScXMLDataPilotFieldReferenceContext(GetScImport(), pAttribList
, this);
883 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_GROUPS
):
884 pContext
= new ScXMLDataPilotGroupsContext(GetScImport(), pAttribList
, this);
889 pContext
= new SvXMLImportContext( GetImport() );
894 void ScXMLDataPilotFieldContext::AddMember(std::unique_ptr
<ScDPSaveMember
> pMember
)
898 bool isVisible
= pMember
->GetIsVisible();
899 xDim
->AddMember(std::move(pMember
));
901 // This member is hidden.
902 mbHasHiddenMember
= true;
906 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString
& rName
)
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*/ )
924 xDim
->SetUsedHierarchy(nUsedHierarchy
);
925 xDim
->SetFunction(nFunction
);
926 xDim
->SetOrientation(nOrientation
);
929 pDataPilotTable
->SetSelectedPage(xDim
->GetName(), sSelectedPage
);
931 pDataPilotTable
->AddDimension(xDim
.release());
934 ScDPNumGroupInfo aInfo
;
935 aInfo
.mbEnable
= true;
936 aInfo
.mbDateValues
= bDateValue
;
937 aInfo
.mbAutoStart
= bAutoStart
;
938 aInfo
.mbAutoEnd
= bAutoEnd
;
939 aInfo
.mfStart
= fStart
;
941 aInfo
.mfStep
= fStep
;
942 if (!sGroupSource
.isEmpty())
944 ScDPSaveGroupDimension
aGroupDim(sGroupSource
, sName
);
946 aGroupDim
.SetDateInfo(aInfo
, nGroupPart
);
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
);
963 ScDPSaveNumGroupDimension
aNumGroupDim(sName
, aInfo
);
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
;
1007 case XML_ELEMENT( TABLE
, XML_FIELD_NAME
):
1009 aReference
.ReferenceField
= aIter
.toString();
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
;
1022 case XML_ELEMENT( TABLE
, XML_MEMBER_NAME
):
1024 aReference
.ReferenceItemName
= aIter
.toString();
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
));
1052 case XML_ELEMENT( CALC_EXT
, XML_REPEAT_ITEM_LABELS
):
1053 pDataPilotField
->SetRepeatItemLabels(IsXMLToken(aIter
, XML_TRUE
));
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
);
1073 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SUBTOTALS
):
1074 pContext
= new ScXMLDataPilotSubTotalsContext(GetScImport(), pDataPilotField
);
1076 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBERS
):
1077 pContext
= new ScXMLDataPilotMembersContext(GetScImport(), pDataPilotField
);
1079 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_DISPLAY_INFO
):
1080 pContext
= new ScXMLDataPilotDisplayInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1082 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SORT_INFO
):
1083 pContext
= new ScXMLDataPilotSortInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1085 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_LAYOUT_INFO
):
1086 pContext
= new ScXMLDataPilotLayoutInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1091 pContext
= new SvXMLImportContext( GetImport() );
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;
1113 aInfo
.IsEnabled
= false;
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
;
1121 case XML_ELEMENT( TABLE
, XML_MEMBER_COUNT
):
1122 aInfo
.ItemCount
= aIter
.toInt32();
1124 case XML_ELEMENT( TABLE
, XML_DATA_FIELD
):
1125 aInfo
.DataField
= aIter
.toString();
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;
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
;
1166 case XML_ELEMENT( TABLE
, XML_DATA_FIELD
):
1167 aInfo
.Field
= aIter
.toString();
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;
1196 aInfo
.AddEmptyLines
= false;
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
;
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
);
1237 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SUBTOTAL
):
1238 pContext
= new ScXMLDataPilotSubTotalContext(GetScImport(), pAttribList
, this);
1243 pContext
= new SvXMLImportContext( GetImport() );
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() ) );
1279 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
1280 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
1281 pDataPilotSubTotals
->SetDisplayName(aIter
.toString());
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
);
1313 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBER
):
1314 pContext
= new ScXMLDataPilotMemberContext(GetScImport(), pAttribList
, pDataPilotField
);
1319 pContext
= new SvXMLImportContext( GetImport() );
1324 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport
& rImport
,
1325 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1326 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1327 ScXMLImportContext( rImport
),
1328 pDataPilotField(pTempDataPilotField
),
1330 bDisplayDetails( true ),
1333 if ( rAttrList
.is() )
1335 for (auto &aIter
: *rAttrList
)
1337 switch (aIter
.getToken())
1339 case XML_ELEMENT( TABLE
, XML_NAME
):
1340 sName
= aIter
.toString();
1343 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
1344 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
1345 maDisplayName
= aIter
.toString();
1347 case XML_ELEMENT( TABLE
, XML_DISPLAY
):
1348 bDisplay
= IsXMLToken(aIter
, XML_TRUE
);
1350 case XML_ELEMENT( TABLE
, XML_SHOW_DETAILS
):
1351 bDisplayDetails
= IsXMLToken(aIter
, XML_TRUE
);
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
;
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();
1401 case XML_DATE_START
:
1404 if (IsXMLToken(aIter
, XML_AUTO
))
1408 GetScImport().GetMM100UnitConverter().convertDateTime(fStart
, aIter
.toString());
1416 if (IsXMLToken(aIter
, XML_AUTO
))
1420 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd
, aIter
.toString());
1427 if (IsXMLToken(aIter
, XML_AUTO
))
1431 fStart
= aIter
.toDouble();
1438 if (IsXMLToken(aIter
, XML_AUTO
))
1442 fEnd
= aIter
.toDouble();
1449 fStep
= aIter
.toDouble();
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
;
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
);
1493 pContext
= new SvXMLImportContext( GetImport() );
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);
1530 pContext
= new SvXMLImportContext( GetImport() );
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: */