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()),
90 sDataPilotTableName(),
97 mnDataLayoutType(sheet::DataPilotFieldOrientation_HIDDEN
),
99 bIgnoreEmptyRows(false),
100 bIdentifyCategories(false),
101 bTargetRangeAddress(false),
102 bSourceCellRange(false),
105 bHeaderGridLayout(false)
107 if ( !rAttrList
.is() )
110 for (auto &aIter
: *rAttrList
)
112 switch (aIter
.getToken())
114 case XML_ELEMENT( TABLE
, XML_NAME
):
116 sDataPilotTableName
= aIter
.toString();
119 case XML_ELEMENT( TABLE
, XML_APPLICATION_DATA
):
121 sApplicationData
= aIter
.toString();
124 case XML_ELEMENT( TABLE
, XML_GRAND_TOTAL
):
126 if (IsXMLToken(aIter
, XML_BOTH
))
128 maRowGrandTotal
.mbVisible
= true;
129 maColGrandTotal
.mbVisible
= true;
131 else if (IsXMLToken(aIter
, XML_ROW
))
133 maRowGrandTotal
.mbVisible
= true;
134 maColGrandTotal
.mbVisible
= false;
136 else if (IsXMLToken(aIter
, XML_COLUMN
))
138 maRowGrandTotal
.mbVisible
= false;
139 maColGrandTotal
.mbVisible
= true;
143 maRowGrandTotal
.mbVisible
= false;
144 maColGrandTotal
.mbVisible
= false;
148 case XML_ELEMENT( TABLE
, XML_IGNORE_EMPTY_ROWS
):
150 bIgnoreEmptyRows
= IsXMLToken(aIter
, XML_TRUE
);
153 case XML_ELEMENT( TABLE
, XML_IDENTIFY_CATEGORIES
):
155 bIdentifyCategories
= IsXMLToken(aIter
, XML_TRUE
);
158 case XML_ELEMENT( TABLE
, XML_TARGET_RANGE_ADDRESS
):
160 sal_Int32
nOffset(0);
162 bTargetRangeAddress
= ScRangeStringConverter::GetRangeFromString( aTargetRangeAddress
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
);
165 case XML_ELEMENT( TABLE
, XML_BUTTONS
):
167 sButtons
= aIter
.toString();
170 case XML_ELEMENT( TABLE
, XML_SHOW_FILTER_BUTTON
):
172 bShowFilter
= IsXMLToken(aIter
, XML_TRUE
);
175 case XML_ELEMENT( TABLE
, XML_DRILL_DOWN_ON_DOUBLE_CLICK
):
177 bDrillDown
= IsXMLToken(aIter
, XML_TRUE
);
180 case XML_ELEMENT( TABLE
, XML_HEADER_GRID_LAYOUT
):
182 bHeaderGridLayout
= IsXMLToken(aIter
, XML_TRUE
);
189 ScXMLDataPilotTableContext::~ScXMLDataPilotTableContext()
193 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotTableContext::createFastChildContext(
194 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
196 SvXMLImportContext
*pContext
= nullptr;
197 sax_fastparser::FastAttributeList
*pAttribList
=
198 &sax_fastparser::castToFastAttributeList( xAttrList
);
202 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_SQL
):
204 pContext
= new ScXMLDPSourceSQLContext(GetScImport(), pAttribList
, this);
208 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_TABLE
):
210 pContext
= new ScXMLDPSourceTableContext(GetScImport(), pAttribList
, this);
214 case XML_ELEMENT( TABLE
, XML_DATABASE_SOURCE_QUERY
):
216 pContext
= new ScXMLDPSourceQueryContext(GetScImport(), pAttribList
, this);
220 case XML_ELEMENT( TABLE
, XML_SOURCE_SERVICE
):
222 pContext
= new ScXMLSourceServiceContext(GetScImport(), pAttribList
, this);
223 nSourceType
= SERVICE
;
226 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_GRAND_TOTAL
):
227 case XML_ELEMENT( TABLE_EXT
, XML_DATA_PILOT_GRAND_TOTAL
):
229 pContext
= new ScXMLDataPilotGrandTotalContext(GetScImport(), pAttribList
, this);
232 case XML_ELEMENT( TABLE
, XML_SOURCE_CELL_RANGE
):
234 pContext
= new ScXMLSourceCellRangeContext(GetScImport(), pAttribList
, this);
235 nSourceType
= CELLRANGE
;
238 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_FIELD
):
239 pContext
= new ScXMLDataPilotFieldContext(GetScImport(), pAttribList
, this);
248 const ScDPSaveDimension
* getDimension(
249 const std::vector
<const ScDPSaveDimension
*>& rRowDims
,
250 const std::vector
<const ScDPSaveDimension
*>& rColDims
,
251 const std::vector
<const ScDPSaveDimension
*>& rPageDims
,
252 ScDPOutputGeometry::FieldType eType
, size_t nPos
)
256 case ScDPOutputGeometry::Column
:
258 if (rColDims
.size() <= nPos
)
261 return rColDims
[nPos
];
263 case ScDPOutputGeometry::Row
:
265 if (rRowDims
.size() <= nPos
)
268 return rRowDims
[nPos
];
270 case ScDPOutputGeometry::Page
:
272 if (rPageDims
.size() <= nPos
)
275 return rPageDims
[nPos
];
277 case ScDPOutputGeometry::Data
:
279 case ScDPOutputGeometry::None
:
287 ScDPOutputGeometry::FieldType
toFieldType(sheet::DataPilotFieldOrientation nOrient
)
291 case sheet::DataPilotFieldOrientation_COLUMN
:
292 return ScDPOutputGeometry::Column
;
293 case sheet::DataPilotFieldOrientation_DATA
:
294 return ScDPOutputGeometry::Data
;
295 case sheet::DataPilotFieldOrientation_PAGE
:
296 return ScDPOutputGeometry::Page
;
297 case sheet::DataPilotFieldOrientation_ROW
:
298 return ScDPOutputGeometry::Row
;
299 case sheet::DataPilotFieldOrientation_HIDDEN
:
304 return ScDPOutputGeometry::None
;
309 void ScXMLDataPilotTableContext::SetButtons(ScDPObject
* pDPObject
)
311 ScDPOutputGeometry
aGeometry(aTargetRangeAddress
, bShowFilter
);
312 aGeometry
.setColumnFieldCount(mnColFieldCount
);
313 aGeometry
.setRowFieldCount(mnRowFieldCount
);
314 aGeometry
.setPageFieldCount(mnPageFieldCount
);
315 aGeometry
.setDataFieldCount(mnDataFieldCount
);
316 aGeometry
.setDataLayoutType(toFieldType(mnDataLayoutType
));
317 aGeometry
.setHeaderLayout(bHeaderGridLayout
);
319 std::vector
<const ScDPSaveDimension
*> aRowDims
, aColDims
, aPageDims
;
320 pDPSave
->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW
, aRowDims
);
321 pDPSave
->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN
, aColDims
);
322 pDPSave
->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE
, aPageDims
);
325 sal_Int32 nOffset
= 0;
326 while( nOffset
>= 0 )
328 ScRangeStringConverter::GetTokenByOffset( sAddress
, sButtons
, nOffset
);
331 ScAddress aScAddress
;
332 sal_Int32
nAddrOffset(0);
333 if (pDoc
&& ScRangeStringConverter::GetAddressFromString( aScAddress
, sAddress
, *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nAddrOffset
))
335 std::pair
<ScDPOutputGeometry::FieldType
, size_t> aBtnType
= aGeometry
.getFieldButtonType(aScAddress
);
336 const ScDPSaveDimension
* pDim
= getDimension(
337 aRowDims
, aColDims
, aPageDims
, aBtnType
.first
, aBtnType
.second
);
339 bool bDimension
= pDim
!= nullptr;
340 bool bDataLayout
= pDim
&& pDim
->IsDataLayout();
341 bool bHasHidden
= pDim
&& pDim
->HasInvisibleMember();
342 bool bPageDim
= pDim
&& pDim
->GetOrientation() == sheet::DataPilotFieldOrientation_PAGE
;
346 // Page dimension needs 2 buttons.
348 pDoc
->ApplyFlagsTab(aScAddress
.Col(), aScAddress
.Row(), aScAddress
.Col(), aScAddress
.Row(), aScAddress
.Tab(), ScMF::Button
);
350 ScMF nMFlag
= ScMF::ButtonPopup
;
352 nMFlag
|= ScMF::HiddenMember
;
353 pDoc
->ApplyFlagsTab(aScAddress
.Col()+1, aScAddress
.Row(), aScAddress
.Col()+1, aScAddress
.Row(), aScAddress
.Tab(), nMFlag
);
357 ScMF nMFlag
= ScMF::Button
;
360 // Data layout dimension only has a plain button with no popup.
364 // Normal dimension has a popup arrow button.
366 nMFlag
|= ScMF::HiddenMember
;
368 nMFlag
|= ScMF::ButtonPopup
;
371 pDoc
->ApplyFlagsTab(aScAddress
.Col(), aScAddress
.Row(), aScAddress
.Col(), aScAddress
.Row(), aScAddress
.Tab(), nMFlag
);
377 pDPObject
->RefreshAfterLoad();
380 void ScXMLDataPilotTableContext::SetSelectedPage( const OUString
& rDimName
, const OUString
& rSelected
)
382 maSelectedPages
.emplace(rDimName
, rSelected
);
385 void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension
* pDim
)
390 if (pDim
->IsDataLayout())
391 mnDataLayoutType
= pDim
->GetOrientation();
393 // if a dimension with that name has already been inserted,
394 // mark the new one as duplicate
395 if ( !pDim
->IsDataLayout() &&
396 pDPSave
->GetExistingDimensionByName(pDim
->GetName()) )
397 pDim
->SetDupFlag(true);
399 switch (pDim
->GetOrientation())
401 case sheet::DataPilotFieldOrientation_ROW
:
404 case sheet::DataPilotFieldOrientation_COLUMN
:
407 case sheet::DataPilotFieldOrientation_PAGE
:
410 case sheet::DataPilotFieldOrientation_DATA
:
413 case sheet::DataPilotFieldOrientation_HIDDEN
:
419 pDPSave
->AddDimension(pDim
);
422 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveNumGroupDimension
& aNumGroupDim
)
425 pDPDimSaveData
.reset( new ScDPDimensionSaveData
);
426 pDPDimSaveData
->AddNumGroupDimension(aNumGroupDim
);
429 void ScXMLDataPilotTableContext::AddGroupDim(const ScDPSaveGroupDimension
& aGroupDim
)
432 pDPDimSaveData
.reset( new ScDPDimensionSaveData
);
433 pDPDimSaveData
->AddGroupDimension(aGroupDim
);
436 void SAL_CALL
ScXMLDataPilotTableContext::endFastElement( sal_Int32
/*nElement*/ )
438 if (!bTargetRangeAddress
)
441 std::unique_ptr
<ScDPObject
> pDPObject(new ScDPObject(pDoc
));
442 pDPObject
->SetName(sDataPilotTableName
);
443 pDPObject
->SetTag(sApplicationData
);
444 pDPObject
->SetOutRange(aTargetRangeAddress
);
445 pDPObject
->SetHeaderLayout(bHeaderGridLayout
);
447 sc::PivotTableSources
& rPivotSources
= GetScImport().GetPivotTableSources();
453 ScImportSourceDesc
aImportDesc(pDoc
);
454 aImportDesc
.aDBName
= sDatabaseName
;
455 aImportDesc
.aObject
= sSourceObject
;
456 aImportDesc
.nType
= sheet::DataImportMode_SQL
;
457 aImportDesc
.bNative
= bIsNative
;
458 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
463 ScImportSourceDesc
aImportDesc(pDoc
);
464 aImportDesc
.aDBName
= sDatabaseName
;
465 aImportDesc
.aObject
= sSourceObject
;
466 aImportDesc
.nType
= sheet::DataImportMode_TABLE
;
467 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
472 ScImportSourceDesc
aImportDesc(pDoc
);
473 aImportDesc
.aDBName
= sDatabaseName
;
474 aImportDesc
.aObject
= sSourceObject
;
475 aImportDesc
.nType
= sheet::DataImportMode_QUERY
;
476 rPivotSources
.appendDBSource(pDPObject
.get(), aImportDesc
);
481 ScDPServiceDesc
aServiceDesc(sServiceName
, sServiceSourceName
, sServiceSourceObject
,
482 sServiceUsername
, sServicePassword
);
483 rPivotSources
.appendServiceSource(pDPObject
.get(), aServiceDesc
);
488 if (bSourceCellRange
)
490 ScSheetSourceDesc
aSheetDesc(pDoc
);
491 if (!sSourceRangeName
.isEmpty())
492 // Range name takes precedence.
493 aSheetDesc
.SetRangeName(sSourceRangeName
);
495 aSheetDesc
.SetSourceRange(aSourceCellRangeAddress
);
496 aSheetDesc
.SetQueryParam(aSourceQueryParam
);
497 rPivotSources
.appendSheetSource(pDPObject
.get(), aSheetDesc
);
503 rPivotSources
.appendSelectedPages(pDPObject
.get(), maSelectedPages
);
505 pDPSave
->SetRowGrand(maRowGrandTotal
.mbVisible
);
506 pDPSave
->SetColumnGrand(maColGrandTotal
.mbVisible
);
507 if (!maRowGrandTotal
.maDisplayName
.isEmpty())
508 // TODO: Right now, we only support one grand total name for both
509 // column and row totals. Take the value from the row total for
511 pDPSave
->SetGrandTotalName(maRowGrandTotal
.maDisplayName
);
513 pDPSave
->SetIgnoreEmptyRows(bIgnoreEmptyRows
);
514 pDPSave
->SetRepeatIfEmpty(bIdentifyCategories
);
515 pDPSave
->SetFilterButton(bShowFilter
);
516 pDPSave
->SetDrillDown(bDrillDown
);
518 pDPSave
->SetDimensionData(pDPDimSaveData
.get());
519 pDPObject
->SetSaveData(*pDPSave
);
521 ScDPCollection
* pDPCollection
= pDoc
->GetDPCollection();
523 // #i94570# Names have to be unique, or the tables can't be accessed by API.
524 if ( pDPCollection
->GetByName(pDPObject
->GetName()) )
525 pDPObject
->SetName( OUString() ); // ignore the invalid name, create a new name in AfterXMLLoading
527 SetButtons(pDPObject
.get());
529 pDPCollection
->InsertNewTable(std::move(pDPObject
));
532 void ScXMLDataPilotTableContext::SetGrandTotal(
533 XMLTokenEnum eOrientation
, bool bVisible
, const OUString
& rDisplayName
)
535 switch (eOrientation
)
538 maRowGrandTotal
.mbVisible
= bVisible
;
539 maRowGrandTotal
.maDisplayName
= rDisplayName
;
540 maColGrandTotal
.mbVisible
= bVisible
;
541 maColGrandTotal
.maDisplayName
= rDisplayName
;
544 maRowGrandTotal
.mbVisible
= bVisible
;
545 maRowGrandTotal
.maDisplayName
= rDisplayName
;
548 maColGrandTotal
.mbVisible
= bVisible
;
549 maColGrandTotal
.maDisplayName
= rDisplayName
;
556 ScXMLDPSourceSQLContext::ScXMLDPSourceSQLContext( ScXMLImport
& rImport
,
557 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
558 ScXMLDataPilotTableContext
* pDataPilotTable
) :
559 ScXMLImportContext( rImport
)
561 if ( !rAttrList
.is() )
564 for (auto &aIter
: *rAttrList
)
566 switch (aIter
.getToken())
568 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
569 pDataPilotTable
->SetDatabaseName(aIter
.toString());
571 case XML_ELEMENT( TABLE
, XML_SQL_STATEMENT
):
572 pDataPilotTable
->SetSourceObject(aIter
.toString());
574 case XML_ELEMENT( TABLE
, XML_PARSE_SQL_STATEMENT
):
575 pDataPilotTable
->SetNative(!IsXMLToken(aIter
, XML_TRUE
));
581 ScXMLDPSourceSQLContext::~ScXMLDPSourceSQLContext()
585 ScXMLDPSourceTableContext::ScXMLDPSourceTableContext( ScXMLImport
& rImport
,
586 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
587 ScXMLDataPilotTableContext
* pDataPilotTable
) :
588 ScXMLImportContext( rImport
)
590 if ( !rAttrList
.is() )
593 for (auto &aIter
: *rAttrList
)
595 switch (aIter
.getToken())
597 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
598 pDataPilotTable
->SetDatabaseName(aIter
.toString());
600 case XML_ELEMENT( TABLE
, XML_TABLE_NAME
):
601 case XML_ELEMENT( TABLE
, XML_DATABASE_TABLE_NAME
):
602 pDataPilotTable
->SetSourceObject(aIter
.toString());
608 ScXMLDPSourceTableContext::~ScXMLDPSourceTableContext()
612 ScXMLDPSourceQueryContext::ScXMLDPSourceQueryContext( ScXMLImport
& rImport
,
613 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
614 ScXMLDataPilotTableContext
* pDataPilotTable
) :
615 ScXMLImportContext( rImport
)
617 if ( !rAttrList
.is() )
620 for (auto &aIter
: *rAttrList
)
622 switch (aIter
.getToken())
624 case XML_ELEMENT( TABLE
, XML_DATABASE_NAME
):
625 pDataPilotTable
->SetDatabaseName(aIter
.toString());
627 case XML_ELEMENT( TABLE
, XML_QUERY_NAME
):
628 pDataPilotTable
->SetSourceObject(aIter
.toString());
634 ScXMLDPSourceQueryContext::~ScXMLDPSourceQueryContext()
638 ScXMLSourceServiceContext::ScXMLSourceServiceContext( ScXMLImport
& rImport
,
639 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
640 ScXMLDataPilotTableContext
* pDataPilotTable
) :
641 ScXMLImportContext( rImport
)
643 if ( !rAttrList
.is() )
646 for (auto &aIter
: *rAttrList
)
648 switch (aIter
.getToken())
650 case XML_ELEMENT( TABLE
, XML_NAME
):
651 pDataPilotTable
->SetServiceName(aIter
.toString());
653 case XML_ELEMENT( TABLE
, XML_SOURCE_NAME
):
654 pDataPilotTable
->SetServiceSourceName(aIter
.toString());
656 case XML_ELEMENT( TABLE
, XML_OBJECT_NAME
):
657 pDataPilotTable
->SetServiceSourceObject(aIter
.toString());
659 case XML_ELEMENT( TABLE
, XML_USER_NAME
):
660 pDataPilotTable
->SetServiceUsername(aIter
.toString());
662 case XML_ELEMENT( TABLE
, XML_PASSWORD
):
663 pDataPilotTable
->SetServicePassword(aIter
.toString());
669 ScXMLSourceServiceContext::~ScXMLSourceServiceContext()
673 ScXMLDataPilotGrandTotalContext::ScXMLDataPilotGrandTotalContext(
674 ScXMLImport
& rImport
, const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
675 ScXMLDataPilotTableContext
* pTableContext
) :
676 ScXMLImportContext( rImport
),
677 mpTableContext(pTableContext
),
681 if ( !rAttrList
.is() )
684 for (auto &aIter
: *rAttrList
)
686 switch (aIter
.getToken())
688 case XML_ELEMENT( TABLE
, XML_DISPLAY
):
689 mbVisible
= IsXMLToken(aIter
, XML_TRUE
);
691 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
692 if (IsXMLToken(aIter
, XML_BOTH
))
693 meOrientation
= BOTH
;
694 else if (IsXMLToken(aIter
, XML_ROW
))
696 else if (IsXMLToken(aIter
, XML_COLUMN
))
697 meOrientation
= COLUMN
;
699 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
700 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
701 maDisplayName
= aIter
.toString();
709 ScXMLDataPilotGrandTotalContext::~ScXMLDataPilotGrandTotalContext()
713 void SAL_CALL
ScXMLDataPilotGrandTotalContext::endFastElement( sal_Int32
/*nElement*/ )
715 XMLTokenEnum eOrient
= XML_NONE
;
716 switch (meOrientation
)
725 eOrient
= XML_COLUMN
;
730 mpTableContext
->SetGrandTotal(eOrient
, mbVisible
, maDisplayName
);
733 ScXMLSourceCellRangeContext::ScXMLSourceCellRangeContext( ScXMLImport
& rImport
,
734 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
735 ScXMLDataPilotTableContext
* pTempDataPilotTable
) :
736 ScXMLImportContext( rImport
),
737 pDataPilotTable(pTempDataPilotTable
)
739 if ( !rAttrList
.is() )
742 for (auto &aIter
: *rAttrList
)
744 switch (aIter
.getToken())
746 case XML_ELEMENT( TABLE
, XML_CELL_RANGE_ADDRESS
):
748 ScRange aSourceRangeAddress
;
749 sal_Int32
nOffset(0);
750 ScDocument
* pDoc
= GetScImport().GetDocument();
752 if (ScRangeStringConverter::GetRangeFromString( aSourceRangeAddress
, aIter
.toString(), *pDoc
, ::formula::FormulaGrammar::CONV_OOO
, nOffset
))
753 pDataPilotTable
->SetSourceCellRangeAddress(aSourceRangeAddress
);
756 case XML_ELEMENT( TABLE
, XML_NAME
):
757 pDataPilotTable
->SetSourceRangeName(aIter
.toString());
763 ScXMLSourceCellRangeContext::~ScXMLSourceCellRangeContext()
767 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLSourceCellRangeContext::createFastChildContext(
768 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
770 SvXMLImportContext
*pContext
= nullptr;
771 sax_fastparser::FastAttributeList
*pAttribList
=
772 &sax_fastparser::castToFastAttributeList( xAttrList
);
776 case XML_ELEMENT( TABLE
, XML_FILTER
):
777 pContext
= new ScXMLDPFilterContext(GetScImport(), pAttribList
, pDataPilotTable
);
784 ScXMLDataPilotFieldContext::ScXMLDataPilotFieldContext( ScXMLImport
& rImport
,
785 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
786 ScXMLDataPilotTableContext
* pTempDataPilotTable
) :
787 ScXMLImportContext( rImport
),
788 pDataPilotTable(pTempDataPilotTable
),
795 nFunction(ScGeneralFunction::NONE
),
796 nOrientation(sheet::DataPilotFieldOrientation_HIDDEN
),
797 bSelectedPage(false),
798 bIsGroupField(false),
802 mbHasHiddenMember(false)
804 bool bHasName
= false;
805 bool bDataLayout
= false;
806 bool bIgnoreSelectedPage
= false;
807 OUString aDisplayName
;
808 if ( rAttrList
.is() )
810 for (auto &aIter
: *rAttrList
)
812 switch (aIter
.getToken())
814 case XML_ELEMENT( TABLE
, XML_SOURCE_FIELD_NAME
):
815 sName
= aIter
.toString();
818 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
819 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
820 aDisplayName
= aIter
.toString();
822 case XML_ELEMENT( TABLE
, XML_IS_DATA_LAYOUT_FIELD
):
823 bDataLayout
= IsXMLToken(aIter
, XML_TRUE
);
825 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
826 nFunction
= ScXMLConverter::GetFunctionFromString2( aIter
.toString() );
828 case XML_ELEMENT( TABLE
, XML_ORIENTATION
):
829 nOrientation
= ScXMLConverter::GetOrientationFromString( aIter
.toString() );
831 case XML_ELEMENT( TABLE
, XML_SELECTED_PAGE
):
832 sSelectedPage
= aIter
.toString();
833 bSelectedPage
= true;
835 case XML_ELEMENT( LO_EXT
, XML_IGNORE_SELECTED_PAGE
):
836 bIgnoreSelectedPage
= true;
838 case XML_ELEMENT( TABLE
, XML_USED_HIERARCHY
):
839 nUsedHierarchy
= aIter
.toInt32();
845 // use the new extension elements
846 if (bIgnoreSelectedPage
)
847 bSelectedPage
= false;
851 xDim
.reset(new ScDPSaveDimension(sName
, bDataLayout
));
852 if (!aDisplayName
.isEmpty())
853 xDim
->SetLayoutName(aDisplayName
);
857 ScXMLDataPilotFieldContext::~ScXMLDataPilotFieldContext()
861 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotFieldContext::createFastChildContext(
862 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
864 SvXMLImportContext
*pContext
= nullptr;
865 sax_fastparser::FastAttributeList
*pAttribList
=
866 &sax_fastparser::castToFastAttributeList( xAttrList
);
870 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_LEVEL
):
871 pContext
= new ScXMLDataPilotLevelContext(GetScImport(), pAttribList
, this);
873 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_FIELD_REFERENCE
):
874 pContext
= new ScXMLDataPilotFieldReferenceContext(GetScImport(), pAttribList
, this);
876 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_GROUPS
):
877 pContext
= new ScXMLDataPilotGroupsContext(GetScImport(), pAttribList
, this);
884 void ScXMLDataPilotFieldContext::AddMember(std::unique_ptr
<ScDPSaveMember
> pMember
)
888 bool isVisible
= pMember
->GetIsVisible();
889 xDim
->AddMember(std::move(pMember
));
891 // This member is hidden.
892 mbHasHiddenMember
= true;
896 void ScXMLDataPilotFieldContext::SetSubTotalName(const OUString
& rName
)
899 xDim
->SetSubtotalName(rName
);
902 void ScXMLDataPilotFieldContext::AddGroup(const ::std::vector
<OUString
>& rMembers
, const OUString
& rName
)
904 ScXMLDataPilotGroup aGroup
;
905 aGroup
.aMembers
= rMembers
;
906 aGroup
.aName
= rName
;
907 aGroups
.push_back(aGroup
);
910 void SAL_CALL
ScXMLDataPilotFieldContext::endFastElement( sal_Int32
/*nElement*/ )
915 xDim
->SetUsedHierarchy(nUsedHierarchy
);
916 xDim
->SetFunction(nFunction
);
917 xDim
->SetOrientation(nOrientation
);
920 pDataPilotTable
->SetSelectedPage(xDim
->GetName(), sSelectedPage
);
922 pDataPilotTable
->AddDimension(xDim
.release());
926 ScDPNumGroupInfo aInfo
;
927 aInfo
.mbEnable
= true;
928 aInfo
.mbDateValues
= bDateValue
;
929 aInfo
.mbAutoStart
= bAutoStart
;
930 aInfo
.mbAutoEnd
= bAutoEnd
;
931 aInfo
.mfStart
= fStart
;
933 aInfo
.mfStep
= fStep
;
934 if (!sGroupSource
.isEmpty())
936 ScDPSaveGroupDimension
aGroupDim(sGroupSource
, sName
);
938 aGroupDim
.SetDateInfo(aInfo
, nGroupPart
);
941 for (const auto& rGroup
: aGroups
)
943 ScDPSaveGroupItem
aItem(rGroup
.aName
);
944 for (const auto& rMember
: rGroup
.aMembers
)
946 aItem
.AddElement(rMember
);
948 aGroupDim
.AddGroupItem(aItem
);
951 pDataPilotTable
->AddGroupDim(aGroupDim
);
955 ScDPSaveNumGroupDimension
aNumGroupDim(sName
, aInfo
);
957 aNumGroupDim
.SetDateInfo(aInfo
, nGroupPart
);
958 pDataPilotTable
->AddGroupDim(aNumGroupDim
);
962 ScXMLDataPilotFieldReferenceContext::ScXMLDataPilotFieldReferenceContext( ScXMLImport
& rImport
,
963 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
964 ScXMLDataPilotFieldContext
* pDataPilotField
) :
965 ScXMLImportContext( rImport
)
967 sheet::DataPilotFieldReference aReference
;
969 if ( rAttrList
.is() )
971 for (auto &aIter
: *rAttrList
)
973 switch (aIter
.getToken())
975 case XML_ELEMENT( TABLE
, XML_TYPE
):
977 if (IsXMLToken(aIter
, XML_NONE
))
978 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::NONE
;
979 else if (IsXMLToken(aIter
, XML_MEMBER_DIFFERENCE
))
980 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::ITEM_DIFFERENCE
;
981 else if (IsXMLToken(aIter
, XML_MEMBER_PERCENTAGE
))
982 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE
;
983 else if (IsXMLToken(aIter
, XML_MEMBER_PERCENTAGE_DIFFERENCE
))
984 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE
;
985 else if (IsXMLToken(aIter
, XML_RUNNING_TOTAL
))
986 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::RUNNING_TOTAL
;
987 else if (IsXMLToken(aIter
, XML_ROW_PERCENTAGE
))
988 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::ROW_PERCENTAGE
;
989 else if (IsXMLToken(aIter
, XML_COLUMN_PERCENTAGE
))
990 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::COLUMN_PERCENTAGE
;
991 else if (IsXMLToken(aIter
, XML_TOTAL_PERCENTAGE
))
992 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::TOTAL_PERCENTAGE
;
993 else if (IsXMLToken(aIter
, XML_INDEX
))
994 aReference
.ReferenceType
= sheet::DataPilotFieldReferenceType::INDEX
;
997 case XML_ELEMENT( TABLE
, XML_FIELD_NAME
):
999 aReference
.ReferenceField
= aIter
.toString();
1002 case XML_ELEMENT( TABLE
, XML_MEMBER_TYPE
):
1004 if (IsXMLToken(aIter
, XML_NAMED
))
1005 aReference
.ReferenceItemType
= sheet::DataPilotFieldReferenceItemType::NAMED
;
1006 else if (IsXMLToken(aIter
, XML_PREVIOUS
))
1007 aReference
.ReferenceItemType
= sheet::DataPilotFieldReferenceItemType::PREVIOUS
;
1008 else if (IsXMLToken(aIter
, XML_NEXT
))
1009 aReference
.ReferenceItemType
= sheet::DataPilotFieldReferenceItemType::NEXT
;
1012 case XML_ELEMENT( TABLE
, XML_MEMBER_NAME
):
1014 aReference
.ReferenceItemName
= aIter
.toString();
1020 pDataPilotField
->SetFieldReference(aReference
);
1023 ScXMLDataPilotFieldReferenceContext::~ScXMLDataPilotFieldReferenceContext()
1027 ScXMLDataPilotLevelContext::ScXMLDataPilotLevelContext( ScXMLImport
& rImport
,
1028 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1029 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1030 ScXMLImportContext( rImport
),
1031 pDataPilotField(pTempDataPilotField
)
1033 if ( !rAttrList
.is() )
1036 for (auto &aIter
: *rAttrList
)
1038 switch (aIter
.getToken())
1040 case XML_ELEMENT( TABLE
, XML_SHOW_EMPTY
):
1041 pDataPilotField
->SetShowEmpty(IsXMLToken(aIter
, XML_TRUE
));
1043 case XML_ELEMENT( CALC_EXT
, XML_REPEAT_ITEM_LABELS
):
1044 pDataPilotField
->SetRepeatItemLabels(IsXMLToken(aIter
, XML_TRUE
));
1050 ScXMLDataPilotLevelContext::~ScXMLDataPilotLevelContext()
1054 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotLevelContext::createFastChildContext(
1055 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1057 SvXMLImportContext
*pContext
= nullptr;
1058 sax_fastparser::FastAttributeList
*pAttribList
=
1059 &sax_fastparser::castToFastAttributeList( xAttrList
);
1063 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SUBTOTALS
):
1064 pContext
= new ScXMLDataPilotSubTotalsContext(GetScImport(), pDataPilotField
);
1066 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBERS
):
1067 pContext
= new ScXMLDataPilotMembersContext(GetScImport(), pDataPilotField
);
1069 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_DISPLAY_INFO
):
1070 pContext
= new ScXMLDataPilotDisplayInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1072 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SORT_INFO
):
1073 pContext
= new ScXMLDataPilotSortInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1075 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_LAYOUT_INFO
):
1076 pContext
= new ScXMLDataPilotLayoutInfoContext(GetScImport(), pAttribList
, pDataPilotField
);
1083 ScXMLDataPilotDisplayInfoContext::ScXMLDataPilotDisplayInfoContext( ScXMLImport
& rImport
,
1084 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1085 ScXMLDataPilotFieldContext
* pDataPilotField
) :
1086 ScXMLImportContext( rImport
)
1088 sheet::DataPilotFieldAutoShowInfo aInfo
;
1090 if ( rAttrList
.is() )
1092 for (auto &aIter
: *rAttrList
)
1094 switch (aIter
.getToken())
1096 case XML_ELEMENT( TABLE
, XML_ENABLED
):
1097 if (IsXMLToken(aIter
, XML_TRUE
))
1098 aInfo
.IsEnabled
= true;
1100 aInfo
.IsEnabled
= false;
1102 case XML_ELEMENT( TABLE
, XML_DISPLAY_MEMBER_MODE
):
1103 if (IsXMLToken(aIter
, XML_FROM_TOP
))
1104 aInfo
.ShowItemsMode
= sheet::DataPilotFieldShowItemsMode::FROM_TOP
;
1105 else if (IsXMLToken(aIter
, XML_FROM_BOTTOM
))
1106 aInfo
.ShowItemsMode
= sheet::DataPilotFieldShowItemsMode::FROM_BOTTOM
;
1108 case XML_ELEMENT( TABLE
, XML_MEMBER_COUNT
):
1109 aInfo
.ItemCount
= aIter
.toInt32();
1111 case XML_ELEMENT( TABLE
, XML_DATA_FIELD
):
1112 aInfo
.DataField
= aIter
.toString();
1117 pDataPilotField
->SetAutoShowInfo(aInfo
);
1120 ScXMLDataPilotDisplayInfoContext::~ScXMLDataPilotDisplayInfoContext()
1124 ScXMLDataPilotSortInfoContext::ScXMLDataPilotSortInfoContext( ScXMLImport
& rImport
,
1125 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1126 ScXMLDataPilotFieldContext
* pDataPilotField
) :
1127 ScXMLImportContext( rImport
)
1129 sheet::DataPilotFieldSortInfo aInfo
;
1131 if ( rAttrList
.is() )
1133 for (auto &aIter
: *rAttrList
)
1135 switch (aIter
.getToken())
1137 case XML_ELEMENT( TABLE
, XML_ORDER
):
1138 if (IsXMLToken(aIter
, XML_ASCENDING
))
1139 aInfo
.IsAscending
= true;
1140 else if (IsXMLToken(aIter
, XML_DESCENDING
))
1141 aInfo
.IsAscending
= false;
1143 case XML_ELEMENT( TABLE
, XML_SORT_MODE
):
1144 if (IsXMLToken(aIter
, XML_NONE
))
1145 aInfo
.Mode
= sheet::DataPilotFieldSortMode::NONE
;
1146 else if (IsXMLToken(aIter
, XML_MANUAL
))
1147 aInfo
.Mode
= sheet::DataPilotFieldSortMode::MANUAL
;
1148 else if (IsXMLToken(aIter
, XML_NAME
))
1149 aInfo
.Mode
= sheet::DataPilotFieldSortMode::NAME
;
1150 else if (IsXMLToken(aIter
, XML_DATA
))
1151 aInfo
.Mode
= sheet::DataPilotFieldSortMode::DATA
;
1153 case XML_ELEMENT( TABLE
, XML_DATA_FIELD
):
1154 aInfo
.Field
= aIter
.toString();
1159 pDataPilotField
->SetSortInfo(aInfo
);
1162 ScXMLDataPilotSortInfoContext::~ScXMLDataPilotSortInfoContext()
1166 ScXMLDataPilotLayoutInfoContext::ScXMLDataPilotLayoutInfoContext( ScXMLImport
& rImport
,
1167 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1168 ScXMLDataPilotFieldContext
* pDataPilotField
) :
1169 ScXMLImportContext( rImport
)
1171 sheet::DataPilotFieldLayoutInfo aInfo
;
1173 if ( rAttrList
.is() )
1175 for (auto &aIter
: *rAttrList
)
1177 switch (aIter
.getToken())
1179 case XML_ELEMENT( TABLE
, XML_ADD_EMPTY_LINES
):
1180 if (IsXMLToken(aIter
, XML_TRUE
))
1181 aInfo
.AddEmptyLines
= true;
1183 aInfo
.AddEmptyLines
= false;
1185 case XML_ELEMENT( TABLE
, XML_LAYOUT_MODE
):
1186 if (IsXMLToken(aIter
, XML_TABULAR_LAYOUT
))
1187 aInfo
.LayoutMode
= sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT
;
1188 else if (IsXMLToken(aIter
, XML_OUTLINE_SUBTOTALS_TOP
))
1189 aInfo
.LayoutMode
= sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP
;
1190 else if (IsXMLToken(aIter
, XML_OUTLINE_SUBTOTALS_BOTTOM
))
1191 aInfo
.LayoutMode
= sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM
;
1196 pDataPilotField
->SetLayoutInfo(aInfo
);}
1198 ScXMLDataPilotLayoutInfoContext::~ScXMLDataPilotLayoutInfoContext()
1202 ScXMLDataPilotSubTotalsContext::ScXMLDataPilotSubTotalsContext( ScXMLImport
& rImport
,
1203 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1204 ScXMLImportContext( rImport
),
1205 pDataPilotField(pTempDataPilotField
)
1208 // has no attributes
1211 ScXMLDataPilotSubTotalsContext::~ScXMLDataPilotSubTotalsContext()
1215 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotSubTotalsContext::createFastChildContext(
1216 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1218 SvXMLImportContext
*pContext
= nullptr;
1219 sax_fastparser::FastAttributeList
*pAttribList
=
1220 &sax_fastparser::castToFastAttributeList( xAttrList
);
1224 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_SUBTOTAL
):
1225 pContext
= new ScXMLDataPilotSubTotalContext(GetScImport(), pAttribList
, this);
1232 void SAL_CALL
ScXMLDataPilotSubTotalsContext::endFastElement( sal_Int32
/*nElement*/ )
1234 pDataPilotField
->SetSubTotals(maFunctions
);
1235 if (!maDisplayName
.isEmpty())
1236 pDataPilotField
->SetSubTotalName(maDisplayName
);
1239 void ScXMLDataPilotSubTotalsContext::AddFunction(ScGeneralFunction nFunction
)
1241 maFunctions
.push_back(nFunction
);
1244 void ScXMLDataPilotSubTotalsContext::SetDisplayName(const OUString
& rName
)
1246 maDisplayName
= rName
;
1249 ScXMLDataPilotSubTotalContext::ScXMLDataPilotSubTotalContext( ScXMLImport
& rImport
,
1250 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1251 ScXMLDataPilotSubTotalsContext
* pDataPilotSubTotals
) :
1252 ScXMLImportContext( rImport
)
1254 if ( !rAttrList
.is() )
1257 for (auto &aIter
: *rAttrList
)
1259 switch (aIter
.getToken())
1261 case XML_ELEMENT( TABLE
, XML_FUNCTION
):
1262 pDataPilotSubTotals
->AddFunction( ScXMLConverter::GetFunctionFromString2( aIter
.toString() ) );
1264 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
1265 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
1266 pDataPilotSubTotals
->SetDisplayName(aIter
.toString());
1272 ScXMLDataPilotSubTotalContext::~ScXMLDataPilotSubTotalContext()
1276 ScXMLDataPilotMembersContext::ScXMLDataPilotMembersContext( ScXMLImport
& rImport
,
1277 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1278 ScXMLImportContext( rImport
),
1279 pDataPilotField(pTempDataPilotField
)
1281 // has no attributes
1284 ScXMLDataPilotMembersContext::~ScXMLDataPilotMembersContext()
1288 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotMembersContext::createFastChildContext(
1289 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1291 SvXMLImportContext
*pContext
= nullptr;
1292 sax_fastparser::FastAttributeList
*pAttribList
=
1293 &sax_fastparser::castToFastAttributeList( xAttrList
);
1297 case XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBER
):
1298 pContext
= new ScXMLDataPilotMemberContext(GetScImport(), pAttribList
, pDataPilotField
);
1305 ScXMLDataPilotMemberContext::ScXMLDataPilotMemberContext( ScXMLImport
& rImport
,
1306 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1307 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1308 ScXMLImportContext( rImport
),
1309 pDataPilotField(pTempDataPilotField
),
1311 bDisplayDetails( true ),
1314 if ( !rAttrList
.is() )
1317 for (auto &aIter
: *rAttrList
)
1319 switch (aIter
.getToken())
1321 case XML_ELEMENT( TABLE
, XML_NAME
):
1322 sName
= aIter
.toString();
1325 case XML_ELEMENT( TABLE
, XML_DISPLAY_NAME
):
1326 case XML_ELEMENT( TABLE_EXT
, XML_DISPLAY_NAME
):
1327 maDisplayName
= aIter
.toString();
1329 case XML_ELEMENT( TABLE
, XML_DISPLAY
):
1330 bDisplay
= IsXMLToken(aIter
, XML_TRUE
);
1332 case XML_ELEMENT( TABLE
, XML_SHOW_DETAILS
):
1333 bDisplayDetails
= IsXMLToken(aIter
, XML_TRUE
);
1339 ScXMLDataPilotMemberContext::~ScXMLDataPilotMemberContext()
1343 void SAL_CALL
ScXMLDataPilotMemberContext::endFastElement( sal_Int32
/*nElement*/ )
1345 if (bHasName
) // #i53407# don't check sName, empty name is allowed
1347 std::unique_ptr
<ScDPSaveMember
> pMember(new ScDPSaveMember(sName
));
1348 if (!maDisplayName
.isEmpty())
1349 pMember
->SetLayoutName(maDisplayName
);
1350 pMember
->SetIsVisible(bDisplay
);
1351 pMember
->SetShowDetails(bDisplayDetails
);
1352 pDataPilotField
->AddMember(std::move(pMember
));
1356 ScXMLDataPilotGroupsContext::ScXMLDataPilotGroupsContext( ScXMLImport
& rImport
,
1357 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1358 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1359 ScXMLImportContext( rImport
),
1360 pDataPilotField(pTempDataPilotField
)
1362 OUString sGroupSource
;
1366 sal_Int32
nGroupPart(0);
1367 bool bDateValue(false);
1368 bool bAutoStart(true);
1369 bool bAutoEnd(true);
1371 if ( rAttrList
.is() )
1373 for (auto &aIter
: *rAttrList
)
1375 switch (aIter
.getToken() & TOKEN_MASK
)
1377 case XML_SOURCE_FIELD_NAME
:
1379 sGroupSource
= aIter
.toString();
1382 case XML_DATE_START
:
1385 if (IsXMLToken(aIter
, XML_AUTO
))
1389 GetScImport().GetMM100UnitConverter().convertDateTime(fStart
, aIter
.toString());
1397 if (IsXMLToken(aIter
, XML_AUTO
))
1401 GetScImport().GetMM100UnitConverter().convertDateTime(fEnd
, aIter
.toString());
1408 if (IsXMLToken(aIter
, XML_AUTO
))
1412 fStart
= aIter
.toDouble();
1419 if (IsXMLToken(aIter
, XML_AUTO
))
1423 fEnd
= aIter
.toDouble();
1430 fStep
= aIter
.toDouble();
1433 case XML_GROUPED_BY
:
1435 if (IsXMLToken(aIter
, XML_SECONDS
))
1436 nGroupPart
= css::sheet::DataPilotFieldGroupBy::SECONDS
;
1437 else if (IsXMLToken(aIter
, XML_MINUTES
))
1438 nGroupPart
= css::sheet::DataPilotFieldGroupBy::MINUTES
;
1439 else if (IsXMLToken(aIter
, XML_HOURS
))
1440 nGroupPart
= css::sheet::DataPilotFieldGroupBy::HOURS
;
1441 else if (IsXMLToken(aIter
, XML_DAYS
))
1442 nGroupPart
= css::sheet::DataPilotFieldGroupBy::DAYS
;
1443 else if (IsXMLToken(aIter
, XML_MONTHS
))
1444 nGroupPart
= css::sheet::DataPilotFieldGroupBy::MONTHS
;
1445 else if (IsXMLToken(aIter
, XML_QUARTERS
))
1446 nGroupPart
= css::sheet::DataPilotFieldGroupBy::QUARTERS
;
1447 else if (IsXMLToken(aIter
, XML_YEARS
))
1448 nGroupPart
= css::sheet::DataPilotFieldGroupBy::YEARS
;
1454 pDataPilotField
->SetGrouping(sGroupSource
, fStart
, fEnd
, fStep
, nGroupPart
, bDateValue
, bAutoStart
, bAutoEnd
);
1457 ScXMLDataPilotGroupsContext::~ScXMLDataPilotGroupsContext()
1461 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotGroupsContext::createFastChildContext(
1462 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1464 SvXMLImportContext
*pContext
= nullptr;
1465 sax_fastparser::FastAttributeList
*pAttribList
=
1466 &sax_fastparser::castToFastAttributeList( xAttrList
);
1468 if (nElement
== XML_ELEMENT( TABLE
, XML_DATA_PILOT_GROUP
))
1470 pContext
= new ScXMLDataPilotGroupContext(GetScImport(), pAttribList
, pDataPilotField
);
1476 ScXMLDataPilotGroupContext::ScXMLDataPilotGroupContext( ScXMLImport
& rImport
,
1477 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1478 ScXMLDataPilotFieldContext
* pTempDataPilotField
) :
1479 ScXMLImportContext( rImport
),
1480 pDataPilotField(pTempDataPilotField
)
1482 if ( rAttrList
.is() )
1484 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_NAME
) ) );
1485 if (aIter
!= rAttrList
->end())
1486 sName
= aIter
.toString();
1490 ScXMLDataPilotGroupContext::~ScXMLDataPilotGroupContext()
1494 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
ScXMLDataPilotGroupContext::createFastChildContext(
1495 sal_Int32 nElement
, const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
1497 SvXMLImportContext
*pContext
= nullptr;
1498 sax_fastparser::FastAttributeList
*pAttribList
=
1499 &sax_fastparser::castToFastAttributeList( xAttrList
);
1501 if (nElement
== XML_ELEMENT( TABLE
, XML_DATA_PILOT_MEMBER
) ||
1502 nElement
== XML_ELEMENT( TABLE
, XML_DATA_PILOT_GROUP_MEMBER
))
1504 pContext
= new ScXMLDataPilotGroupMemberContext(GetScImport(), pAttribList
, this);
1510 void SAL_CALL
ScXMLDataPilotGroupContext::endFastElement( sal_Int32
/*nElement*/ )
1512 pDataPilotField
->AddGroup(aMembers
, sName
);
1515 ScXMLDataPilotGroupMemberContext::ScXMLDataPilotGroupMemberContext( ScXMLImport
& rImport
,
1516 const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
,
1517 ScXMLDataPilotGroupContext
* pTempDataPilotGroup
) :
1518 ScXMLImportContext( rImport
),
1519 pDataPilotGroup(pTempDataPilotGroup
)
1521 if ( rAttrList
.is() )
1523 auto aIter( rAttrList
->find( XML_ELEMENT( TABLE
, XML_NAME
) ) );
1524 if (aIter
!= rAttrList
->end())
1525 sName
= aIter
.toString();
1529 ScXMLDataPilotGroupMemberContext::~ScXMLDataPilotGroupMemberContext()
1533 void SAL_CALL
ScXMLDataPilotGroupMemberContext::endFastElement( sal_Int32
/*nElement*/ )
1535 if (!sName
.isEmpty())
1536 pDataPilotGroup
->AddMember(sName
);
1539 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */