[Libreoffice-commits] core.git: 2 commits - sc/Library_sc.mk sc/qa sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Sun Mar 9 15:46:35 PDT 2014


 sc/Library_sc.mk                                       |    1 
 sc/qa/unit/data/ods/pivot-table-named-range-source.ods |binary
 sc/qa/unit/subsequent_filters-test.cxx                 |   29 ++++
 sc/source/filter/xml/pivotsource.cxx                   |  121 +++++++++++++++++
 sc/source/filter/xml/pivotsource.hxx                   |   90 ++++++++++++
 sc/source/filter/xml/xmldpimp.cxx                      |   45 +-----
 sc/source/filter/xml/xmldpimp.hxx                      |    2 
 sc/source/filter/xml/xmlimprt.cxx                      |   10 +
 sc/source/filter/xml/xmlimprt.hxx                      |    5 
 9 files changed, 269 insertions(+), 34 deletions(-)

New commits:
commit 057d269c5d1faf45c4c935b2f8120c45e646de65
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Mar 9 18:40:13 2014 -0400

    fdo#75960: Process pivot tables after named ranges are all set.
    
    Especially for those pivot tables that reference named ranges as their
    data sources, it's critical that we process them after named ranges are
    set. Else things would start to fail.
    
    Change-Id: I4bf8aa1a844aae3953f2dfbeba0e4d2542a7e53f

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index c723a4e..efc7d5e 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -305,6 +305,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/filter/xml/celltextparacontext \
     sc/source/filter/xml/editattributemap \
     sc/source/filter/xml/importcontext \
+    sc/source/filter/xml/pivotsource \
     sc/source/filter/xml/sheetdata \
     sc/source/filter/xml/xmlannoi \
     sc/source/filter/xml/xmlbodyi \
diff --git a/sc/source/filter/xml/pivotsource.cxx b/sc/source/filter/xml/pivotsource.cxx
new file mode 100644
index 0000000..43b5a4d
--- /dev/null
+++ b/sc/source/filter/xml/pivotsource.cxx
@@ -0,0 +1,121 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "pivotsource.hxx"
+
+#include <dpsave.hxx>
+
+namespace sc {
+
+PivotTableSources::SelectedPages::SelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected ) :
+    mpDP(pObj), maSelectedPages(rSelected) {}
+
+PivotTableSources::SheetSource::SheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc ) :
+    mpDP(pObj), maDesc(rDesc) {}
+
+PivotTableSources::DBSource::DBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc ) :
+    mpDP(pObj), maDesc(rDesc) {}
+
+PivotTableSources::ServiceSource::ServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc ) :
+    mpDP(pObj), maDesc(rDesc) {}
+
+PivotTableSources::PivotTableSources() {}
+
+void PivotTableSources::appendSheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc )
+{
+    maSheetSources.push_back(SheetSource(pObj, rDesc));
+}
+
+void PivotTableSources::appendDBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc )
+{
+    maDBSources.push_back(DBSource(pObj, rDesc));
+}
+
+void PivotTableSources::appendServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc )
+{
+    maServiceSources.push_back(ServiceSource(pObj, rDesc));
+}
+
+void PivotTableSources::appendSelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected )
+{
+    if (rSelected.empty())
+        return;
+
+    maSelectedPagesList.push_back(SelectedPages(pObj, rSelected));
+}
+
+namespace {
+
+struct SelectedPageProcessor : std::unary_function<PivotTableSources::SelectedPages, void>
+{
+    void operator() ( PivotTableSources::SelectedPages& rItem )
+    {
+        // Set selected pages after building all dimension members.
+        if (!rItem.mpDP)
+            return;
+
+        rItem.mpDP->BuildAllDimensionMembers();
+        ScDPSaveData* pSaveData = rItem.mpDP->GetSaveData();
+        if (!pSaveData)
+            return;
+
+        PivotTableSources::SelectedPagesType::const_iterator it = rItem.maSelectedPages.begin(), itEnd = rItem.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);
+        }
+    }
+};
+
+struct PivotSheetDescSetter : std::unary_function<sc::PivotTableSources::SheetSource, void>
+{
+    void operator() ( sc::PivotTableSources::SheetSource& rSrc )
+    {
+        ScDPObject* pObj = rSrc.mpDP;
+        pObj->SetSheetDesc(rSrc.maDesc);
+    }
+};
+
+struct PivotDBDescSetter : std::unary_function<sc::PivotTableSources::DBSource, void>
+{
+    void operator() ( sc::PivotTableSources::DBSource& rSrc )
+    {
+        ScDPObject* pObj = rSrc.mpDP;
+        pObj->SetImportDesc(rSrc.maDesc);
+    }
+};
+
+struct PivotServiceDataSetter : std::unary_function<sc::PivotTableSources::ServiceSource, void>
+{
+    void operator() ( sc::PivotTableSources::ServiceSource& rSrc )
+    {
+        ScDPObject* pObj = rSrc.mpDP;
+        pObj->SetServiceData(rSrc.maDesc);
+    }
+};
+
+}
+
+void PivotTableSources::process()
+{
+    std::for_each(maSheetSources.begin(), maSheetSources.end(), PivotSheetDescSetter());
+    std::for_each(maDBSources.begin(), maDBSources.end(), PivotDBDescSetter());
+    std::for_each(maServiceSources.begin(), maServiceSources.end(), PivotServiceDataSetter());
+    std::for_each(maSelectedPagesList.begin(), maSelectedPagesList.end(), SelectedPageProcessor());
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/pivotsource.hxx b/sc/source/filter/xml/pivotsource.hxx
new file mode 100644
index 0000000..c50e397
--- /dev/null
+++ b/sc/source/filter/xml/pivotsource.hxx
@@ -0,0 +1,90 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef SC_FILER_XML_PIVOTSOURCE_HXX
+#define SC_FILER_XML_PIVOTSOURCE_HXX
+
+#include <dpshttab.hxx>
+#include <dpsdbtab.hxx>
+#include <dpobject.hxx>
+
+#include <vector>
+#include <boost/unordered_map.hpp>
+
+namespace sc {
+
+/**
+ * Store pivot table data that need to be post-processeed at the end of the
+ * import.
+ */
+struct PivotTableSources
+{
+    typedef boost::unordered_map<OUString, OUString, OUStringHash> SelectedPagesType;
+    typedef boost::unordered_map<ScDPObject*, SelectedPagesType> SelectedPagesMapType;
+
+    struct SelectedPages
+    {
+        ScDPObject* mpDP;
+        SelectedPagesType maSelectedPages;
+
+        SelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected );
+    };
+
+    struct SheetSource
+    {
+        ScDPObject* mpDP;
+        ScSheetSourceDesc maDesc;
+
+        SheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc );
+    };
+
+    struct DBSource
+    {
+        ScDPObject* mpDP;
+        ScImportSourceDesc maDesc;
+
+        DBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc );
+    };
+
+    struct ServiceSource
+    {
+        ScDPObject* mpDP;
+        ScDPServiceDesc maDesc;
+
+        ServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc );
+    };
+
+    typedef std::vector<SelectedPages> SelectedPagesListType;
+
+    typedef std::vector<SheetSource>    SheetSourcesType;
+    typedef std::vector<DBSource>       DBSourcesType;
+    typedef std::vector<ServiceSource>  ServiceSourcesType;
+
+    SelectedPagesListType maSelectedPagesList;
+
+    SheetSourcesType    maSheetSources;
+    DBSourcesType       maDBSources;
+    ServiceSourcesType  maServiceSources;
+
+    PivotTableSources();
+
+    void appendSheetSource( ScDPObject* pObj, const ScSheetSourceDesc& rDesc );
+    void appendDBSource( ScDPObject* pObj, const ScImportSourceDesc& rDesc );
+    void appendServiceSource( ScDPObject* pObj, const ScDPServiceDesc& rDesc );
+
+    void appendSelectedPages( ScDPObject* pObj, const SelectedPagesType& rSelected );
+
+    void process();
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index f976333..72cefa2 100644
--- a/sc/source/filter/xml/xmldpimp.cxx
+++ b/sc/source/filter/xml/xmldpimp.cxx
@@ -32,6 +32,8 @@
 #include "rangeutl.hxx"
 #include "dpoutputgeometry.hxx"
 
+#include "pivotsource.hxx"
+
 #include <xmloff/xmltkmap.hxx>
 #include <xmloff/nmspmap.hxx>
 #include <xmloff/xmltoken.hxx>
@@ -477,6 +479,9 @@ void ScXMLDataPilotTableContext::EndElement()
     pDPObject->SetTag(sApplicationData);
     pDPObject->SetOutRange(aTargetRangeAddress);
     pDPObject->SetHeaderLayout(bHeaderGridLayout);
+
+    sc::PivotTableSources& rPivotSources = GetScImport().GetPivotTableSources();
+
     switch (nSourceType)
     {
         case SQL :
@@ -486,7 +491,7 @@ void ScXMLDataPilotTableContext::EndElement()
             aImportDesc.aObject = sSourceObject;
             aImportDesc.nType = sheet::DataImportMode_SQL;
             aImportDesc.bNative = bIsNative;
-            pDPObject->SetImportDesc(aImportDesc);
+            rPivotSources.appendDBSource(pDPObject, aImportDesc);
         }
         break;
         case TABLE :
@@ -495,7 +500,7 @@ void ScXMLDataPilotTableContext::EndElement()
             aImportDesc.aDBName = sDatabaseName;
             aImportDesc.aObject = sSourceObject;
             aImportDesc.nType = sheet::DataImportMode_TABLE;
-            pDPObject->SetImportDesc(aImportDesc);
+            rPivotSources.appendDBSource(pDPObject, aImportDesc);
         }
         break;
         case QUERY :
@@ -504,14 +509,14 @@ void ScXMLDataPilotTableContext::EndElement()
             aImportDesc.aDBName = sDatabaseName;
             aImportDesc.aObject = sSourceObject;
             aImportDesc.nType = sheet::DataImportMode_QUERY;
-            pDPObject->SetImportDesc(aImportDesc);
+            rPivotSources.appendDBSource(pDPObject, aImportDesc);
         }
         break;
         case SERVICE :
         {
-            ScDPServiceDesc aServiceDesk(sServiceName, sServiceSourceName, sServiceSourceObject,
+            ScDPServiceDesc aServiceDesc(sServiceName, sServiceSourceName, sServiceSourceObject,
                                 sServiceUsername, sServicePassword);
-            pDPObject->SetServiceData(aServiceDesk);
+            rPivotSources.appendServiceSource(pDPObject, aServiceDesc);
         }
         break;
         case CELLRANGE :
@@ -525,12 +530,14 @@ void ScXMLDataPilotTableContext::EndElement()
                 else
                     aSheetDesc.SetSourceRange(aSourceCellRangeAddress);
                 aSheetDesc.SetQueryParam(aSourceQueryParam);
-                pDPObject->SetSheetDesc(aSheetDesc);
+                rPivotSources.appendSheetSource(pDPObject, aSheetDesc);
             }
         }
         break;
     }
 
+    rPivotSources.appendSelectedPages(pDPObject, maSelectedPages);
+
     pDPSave->SetRowGrand(maRowGrandTotal.mbVisible);
     pDPSave->SetColumnGrand(maColGrandTotal.mbVisible);
     if (!maRowGrandTotal.maDisplayName.isEmpty())
@@ -553,36 +560,10 @@ void ScXMLDataPilotTableContext::EndElement()
     if ( pDPCollection->GetByName(pDPObject->GetName()) )
         pDPObject->SetName( OUString() );     // 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)
 {
diff --git a/sc/source/filter/xml/xmldpimp.hxx b/sc/source/filter/xml/xmldpimp.hxx
index 41ba27c..e27107b 100644
--- a/sc/source/filter/xml/xmldpimp.hxx
+++ b/sc/source/filter/xml/xmldpimp.hxx
@@ -121,8 +121,6 @@ class ScXMLDataPilotTableContext : public SvXMLImportContext
     const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
     ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
 
-    void ProcessSelectedPages();
-
 public:
 
     ScXMLDataPilotTableContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index d76420d..b6cd710 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -67,6 +67,7 @@
 #include "editutil.hxx"
 #include "editattributemap.hxx"
 #include "documentimport.hxx"
+#include "pivotsource.hxx"
 
 #include <comphelper/extract.hxx>
 
@@ -1961,6 +1962,14 @@ sc::ImportPostProcessData* ScXMLImport::GetPostProcessData()
     return mpPostProcessData;
 }
 
+sc::PivotTableSources& ScXMLImport::GetPivotTableSources()
+{
+    if (!mpPivotSources)
+        mpPivotSources.reset(new sc::PivotTableSources);
+
+    return *mpPivotSources;
+}
+
 SvXMLImportContext *ScXMLImport::CreateContext( sal_uInt16 nPrefix,
                                                const OUString& rLocalName,
                                                const uno::Reference<xml::sax::XAttributeList>& xAttrList )
@@ -3223,6 +3232,7 @@ void SAL_CALL ScXMLImport::endDocument()
             SetLabelRanges();
             SetNamedRanges();
             SetSheetNamedRanges();
+            GetPivotTableSources().process();
         }
         GetProgressBarHelper()->End();  // make room for subsequent SfxProgressBars
         if (pDoc)
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index dd57ccc..3ab6857 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -58,6 +58,7 @@ class ScDocumentImport;
 namespace sc {
 
 struct ImportPostProcessData;
+struct PivotTableSources;
 
 }
 
@@ -827,6 +828,8 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
     boost::scoped_ptr<ScDocumentImport> mpDocImport;
     boost::scoped_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
     boost::scoped_ptr<ScEditEngineDefaulter> mpEditEngine;
+    boost::scoped_ptr<sc::PivotTableSources> mpPivotSources;
+
     mutable boost::scoped_ptr<ScXMLEditAttributeMap> mpEditAttrMap;
     ScXMLChangeTrackingImportHelper*    pChangeTrackingImportHelper;
     ScMyViewContextList                 aViewContextList;
@@ -1105,6 +1108,8 @@ public:
     void SetPostProcessData( sc::ImportPostProcessData* p );
     sc::ImportPostProcessData* GetPostProcessData();
 
+    sc::PivotTableSources& GetPivotTableSources();
+
     void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
     {
         if (!pMyNamedExpressions)
commit 93e4276addbaaf574e07f7f1a993c653c536645d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Sun Mar 9 18:38:02 2014 -0400

    fdo#75960: Write unit test for this.
    
    The window failed to launch ultimately due to failure of GetHeaderDim()
    call.
    
    Change-Id: I80c99a9ab1f33b4acee5324f417b7a3a26a91a22

diff --git a/sc/qa/unit/data/ods/pivot-table-named-range-source.ods b/sc/qa/unit/data/ods/pivot-table-named-range-source.ods
new file mode 100644
index 0000000..db3b966
Binary files /dev/null and b/sc/qa/unit/data/ods/pivot-table-named-range-source.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 5336a58..b34c192 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -142,6 +142,7 @@ public:
     void testCellAnchoredShapesODS();
 
     void testPivotTableBasicODS();
+    void testPivotTableNamedRangeSourceODS();
     void testPivotTableSharedCacheGroupODS();
     void testGetPivotDataXLS();
 
@@ -210,6 +211,7 @@ public:
     CPPUNIT_TEST(testCellAnchoredShapesODS);
 
     CPPUNIT_TEST(testPivotTableBasicODS);
+    CPPUNIT_TEST(testPivotTableNamedRangeSourceODS);
     CPPUNIT_TEST(testPivotTableSharedCacheGroupODS);
     CPPUNIT_TEST(testGetPivotDataXLS);
     CPPUNIT_TEST(testRowHeightODS);
@@ -1687,6 +1689,33 @@ void ScFiltersTest::testPivotTableBasicODS()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testPivotTableNamedRangeSourceODS()
+{
+    ScDocShellRef xDocSh = loadDoc("pivot-table-named-range-source.", ODS);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load pivot-table-named-range-source.ods", xDocSh.Is());
+
+    ScDocument* pDoc = xDocSh->GetDocument();
+
+    ScDPCollection* pDPs = pDoc->GetDPCollection();
+    CPPUNIT_ASSERT(pDPs->GetCount() == 1);
+
+    ScDPObject* pDP = (*pDPs)[0];
+    CPPUNIT_ASSERT(pDP);
+
+    // Make sure this pivot table is based on a named range source.
+    const ScSheetSourceDesc* pDesc = pDP->GetSheetDesc();
+    CPPUNIT_ASSERT(pDesc);
+    CPPUNIT_ASSERT_EQUAL(OUString("MyRange"), pDesc->GetRangeName());
+
+    sal_uInt16 nOrient;
+    long nDim = pDP->GetHeaderDim(ScAddress(0,1,1), nOrient);
+    CPPUNIT_ASSERT_MESSAGE("Failed to detect header dimension.", nDim == 0);
+    CPPUNIT_ASSERT_MESSAGE("This dimension should be a page dimension.",
+                           nOrient == sheet::DataPilotFieldOrientation_PAGE);
+
+    xDocSh->DoClose();
+}
+
 namespace {
 
 bool checkVisiblePageFieldMember( const ScDPSaveDimension::MemberList& rMembers, const OUString& rVisibleMember )


More information about the Libreoffice-commits mailing list