[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.1' - 2 commits - sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Dec 10 19:54:12 PST 2013


 sc/inc/dpobject.hxx               |   10 +++---
 sc/source/core/data/dpobject.cxx  |   57 ++++++++++++++++++++++++--------------
 sc/source/filter/xml/xmldpimp.cxx |   33 +++++++++++++++++++++-
 sc/source/filter/xml/xmldpimp.hxx |    7 ++++
 4 files changed, 81 insertions(+), 26 deletions(-)

New commits:
commit 33f5d6cfe7c55a889eb79f73b392f68e36bb43a9
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Dec 10 15:56:06 2013 -0500

    fdo#66969: Reset group dimension data from all referencing pivot objects.
    
    The previous code was doing it only with the first referencing pivot table,
    which would break the rest of them sharing the same cache if
    the first one doesn't contain all group dimensions used in all of the
    referencing pivot tables.
    
    Change-Id: I35d6907ef8db7ed69db42583cac92b2b74406e2c

diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index 06d4957..51d4790 100644
--- a/sc/inc/dpobject.hxx
+++ b/sc/inc/dpobject.hxx
@@ -290,7 +290,7 @@ public:
     private:
         ScDPCache* getExistingCache(const ScRange& rRange);
 
-        void updateCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
+        void updateCache(const ScRange& rRange, std::set<ScDPObject*>& rRefs);
         bool remove(const ScDPCache* p);
     };
 
@@ -313,8 +313,7 @@ public:
         ScDPCache* getExistingCache(const OUString& rName);
 
         void updateCache(
-            const OUString& rName, const ScRange& rRange,
-            const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
+            const OUString& rName, const ScRange& rRange, std::set<ScDPObject*>& rRefs);
         bool remove(const ScDPCache* p);
     };
 
@@ -358,8 +357,9 @@ public:
         com::sun::star::uno::Reference<com::sun::star::sdbc::XRowSet> createRowSet(
             sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand);
 
-        void updateCache(sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand,
-                         const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
+        void updateCache(
+            sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand,
+            std::set<ScDPObject*>& rRefs);
         bool remove(const ScDPCache* p);
     };
 
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 169231a..653bc0c 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2809,6 +2809,25 @@ struct FindInvalidRange : public std::unary_function<ScRange, bool>
     }
 };
 
+void setGroupItemsToCache( ScDPCache& rCache, const std::set<ScDPObject*>& rRefs )
+{
+    // Go through all referencing pivot tables, and re-fill the group dimension info.
+    std::set<ScDPObject*>::const_iterator itRef = rRefs.begin(), itRefEnd = rRefs.end();
+    for (; itRef != itRefEnd; ++itRef)
+    {
+        const ScDPObject* pObj = *itRef;
+        const ScDPSaveData* pSave = pObj->GetSaveData();
+        if (!pSave)
+            continue;
+
+        const ScDPDimensionSaveData* pGroupDims = pSave->GetExistingDimensionData();
+        if (!pGroupDims)
+            continue;
+
+        pGroupDims->WriteToCache(rCache);
+    }
+}
+
 }
 
 bool ScDPCollection::SheetCaches::hasCache(const ScRange& rRange) const
@@ -2926,8 +2945,7 @@ void ScDPCollection::SheetCaches::updateReference(
     }
 }
 
-void ScDPCollection::SheetCaches::updateCache(
-    const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs)
+void ScDPCollection::SheetCaches::updateCache(const ScRange& rRange, std::set<ScDPObject*>& rRefs)
 {
     RangeIndexType::iterator it = std::find(maRanges.begin(), maRanges.end(), rRange);
     if (it == maRanges.end())
@@ -2947,12 +2965,15 @@ void ScDPCollection::SheetCaches::updateCache(
     }
 
     ScDPCache& rCache = *itCache->second;
+
+    // Update the cache with new cell values. This will clear all group dimension info.
     rCache.InitFromDoc(mpDoc, rRange);
-    if (pDimData)
-        pDimData->WriteToCache(rCache);
 
     std::set<ScDPObject*> aRefs(rCache.GetAllReferences());
     rRefs.swap(aRefs);
+
+    // Make sure to re-populate the group dimension info.
+    setGroupItemsToCache(rCache, rRefs);
 }
 
 bool ScDPCollection::SheetCaches::remove(const ScDPCache* p)
@@ -3010,8 +3031,7 @@ size_t ScDPCollection::NameCaches::size() const
 }
 
 void ScDPCollection::NameCaches::updateCache(
-    const OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData,
-    std::set<ScDPObject*>& rRefs)
+    const OUString& rName, const ScRange& rRange, std::set<ScDPObject*>& rRefs)
 {
     CachesType::iterator itr = maCaches.find(rName);
     if (itr == maCaches.end())
@@ -3021,12 +3041,14 @@ void ScDPCollection::NameCaches::updateCache(
     }
 
     ScDPCache& rCache = *itr->second;
+    // Update the cache with new cell values. This will clear all group dimension info.
     rCache.InitFromDoc(mpDoc, rRange);
-    if (pDimData)
-        pDimData->WriteToCache(rCache);
 
     std::set<ScDPObject*> aRefs(rCache.GetAllReferences());
     rRefs.swap(aRefs);
+
+    // Make sure to re-populate the group dimension info.
+    setGroupItemsToCache(rCache, rRefs);
 }
 
 bool ScDPCollection::NameCaches::remove(const ScDPCache* p)
@@ -3171,7 +3193,7 @@ uno::Reference<sdbc::XRowSet> ScDPCollection::DBCaches::createRowSet(
 
 void ScDPCollection::DBCaches::updateCache(
     sal_Int32 nSdbType, const OUString& rDBName, const OUString& rCommand,
-    const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs)
+    std::set<ScDPObject*>& rRefs)
 {
     DBType aType(nSdbType, rDBName, rCommand);
     CachesType::iterator it = maCaches.find(aType);
@@ -3204,12 +3226,12 @@ void ScDPCollection::DBCaches::updateCache(
         return;
     }
 
-    if (pDimData)
-        pDimData->WriteToCache(rCache);
-
     comphelper::disposeComponent(xRowSet);
     std::set<ScDPObject*> aRefs(rCache.GetAllReferences());
     aRefs.swap(rRefs);
+
+    // Make sure to re-populate the group dimension info.
+    setGroupItemsToCache(rCache, rRefs);
 }
 
 bool ScDPCollection::DBCaches::remove(const ScDPCache* p)
@@ -3271,11 +3293,6 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>&
     if (!pDPObj)
         return STR_ERR_DATAPILOTSOURCE;
 
-    const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
-    const ScDPDimensionSaveData* pDimData = NULL;
-    if (pSaveData)
-        pDimData = pSaveData->GetExistingDimensionData();
-
     if (pDPObj->IsSheetData())
     {
         // data source is internal sheet.
@@ -3292,7 +3309,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>&
             // cache by named range
             ScDPCollection::NameCaches& rCaches = GetNameCaches();
             if (rCaches.hasCache(pDesc->GetRangeName()))
-                rCaches.updateCache(pDesc->GetRangeName(), pDesc->GetSourceRange(), pDimData, rRefs);
+                rCaches.updateCache(pDesc->GetRangeName(), pDesc->GetSourceRange(), rRefs);
             else
             {
                 // Not cached yet.  Collect all tables that use this named
@@ -3305,7 +3322,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>&
             // cache by cell range
             ScDPCollection::SheetCaches& rCaches = GetSheetCaches();
             if (rCaches.hasCache(pDesc->GetSourceRange()))
-                rCaches.updateCache(pDesc->GetSourceRange(), pDimData, rRefs);
+                rCaches.updateCache(pDesc->GetSourceRange(), rRefs);
             else
             {
                 // Not cached yet.  Collect all tables that use this range as
@@ -3324,7 +3341,7 @@ sal_uLong ScDPCollection::ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>&
         ScDPCollection::DBCaches& rCaches = GetDBCaches();
         if (rCaches.hasCache(pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject))
             rCaches.updateCache(
-                pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject, pDimData, rRefs);
+                pDesc->GetCommandType(), pDesc->aDBName, pDesc->aObject, rRefs);
         else
         {
             // Not cached yet.  Collect all tables that use this range as
commit b8ea1840a4bdafb711b885c6fed62c94cb117cd6
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Dec 10 12:50:48 2013 -0500

    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

diff --git a/sc/source/filter/xml/xmldpimp.cxx b/sc/source/filter/xml/xmldpimp.cxx
index 83f58f7..825060c 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 1aa851d..32f878d 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<OUString, OUString, OUStringHash> 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


More information about the Libreoffice-commits mailing list