From 5618ac8ccddbff67b4b27a9c08f97d3bf2bcec3f Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Tue, 10 Dec 2013 12:50:48 -0500 Subject: fdo#66969: Set selected page name after building all dimension members. Because the new implementation relies on the visiblity flag of the dimension members, they need to exist before setting currently selected page, which is still used in documents generated by the older version of LibreOffice. Change-Id: I6cec5fd3d2165f714fc01b596d3761890d87a4ff (cherry picked from commit 2e1b90a4272defb917b23e2e360e171114d6fa4d) Reviewed-on: https://gerrit.libreoffice.org/7027 Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- sc/source/filter/xml/xmldpimp.cxx | 33 ++++++++++++++++++++++++++++++++- sc/source/filter/xml/xmldpimp.hxx | 7 +++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx index 83f58f7b9e56..825060cad26d 100644 --- a/sc/source/filter/xml/xmldpimp.cxx +++ b/sc/source/filter/xml/xmldpimp.cxx @@ -412,6 +412,11 @@ void ScXMLDataPilotTableContext::SetButtons() pDPObject->RefreshAfterLoad(); } +void ScXMLDataPilotTableContext::SetSelectedPage( const OUString& rDimName, const OUString& rSelected ) +{ + maSelectedPages.insert(SelectedPagesType::value_type(rDimName, rSelected)); +} + void ScXMLDataPilotTableContext::AddDimension(ScDPSaveDimension* pDim) { if (pDPSave) @@ -548,10 +553,36 @@ void ScXMLDataPilotTableContext::EndElement() if ( pDPCollection->GetByName(pDPObject->GetName()) ) pDPObject->SetName( String() ); // ignore the invalid name, create a new name in AfterXMLLoading + ProcessSelectedPages(); + pDPCollection->InsertNewTable(pDPObject); SetButtons(); } +void ScXMLDataPilotTableContext::ProcessSelectedPages() +{ + // Set selected pages after building all dimension members. + if (!pDPObject) + return; + + pDPObject->BuildAllDimensionMembers(); + ScDPSaveData* pSaveData = pDPObject->GetSaveData(); + if (!pSaveData) + return; + + SelectedPagesType::const_iterator it = maSelectedPages.begin(), itEnd = maSelectedPages.end(); + for (; it != itEnd; ++it) + { + const OUString& rDimName = it->first; + const OUString& rSelected = it->second; + ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName(rDimName); + if (!pDim) + continue; + + pDim->SetCurrentPage(&rSelected); + } +} + void ScXMLDataPilotTableContext::SetGrandTotal( XMLTokenEnum eOrientation, bool bVisible, const OUString& rDisplayName) { @@ -1111,7 +1142,7 @@ void ScXMLDataPilotFieldContext::EndElement() pDim->SetOrientation(nOrientation); if (bSelectedPage) { - pDim->SetCurrentPage(&sSelectedPage); + pDataPilotTable->SetSelectedPage(pDim->GetName(), sSelectedPage); } pDataPilotTable->AddDimension(pDim); if (bIsGroupField) diff --git a/sc/source/filter/xml/xmldpimp.hxx b/sc/source/filter/xml/xmldpimp.hxx index 1aa851dc1a1e..32f878dee541 100644 --- a/sc/source/filter/xml/xmldpimp.hxx +++ b/sc/source/filter/xml/xmldpimp.hxx @@ -71,6 +71,8 @@ public: class ScXMLDataPilotTableContext : public SvXMLImportContext { + typedef boost::unordered_map SelectedPagesType; + struct GrandTotalItem { OUString maDisplayName; @@ -114,9 +116,13 @@ class ScXMLDataPilotTableContext : public SvXMLImportContext bool bDrillDown:1; bool bHeaderGridLayout:1; + SelectedPagesType maSelectedPages; + const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); } ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); } + void ProcessSelectedPages(); + public: ScXMLDataPilotTableContext( ScXMLImport& rImport, sal_uInt16 nPrfx, @@ -151,6 +157,7 @@ public: void AddGroupDim(const ScDPSaveNumGroupDimension& aNumGroupDim); void AddGroupDim(const ScDPSaveGroupDimension& aGroupDim); void SetButtons(); + void SetSelectedPage( const OUString& rDimName, const OUString& rSelected ); }; class ScXMLDPSourceSQLContext : public SvXMLImportContext -- cgit v1.2.3