[Libreoffice-commits] core.git: Branch 'feature/pivot-table-result-tree' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Thu Apr 18 18:06:50 PDT 2013


 sc/inc/dpresfilter.hxx              |   11 ++++++++---
 sc/inc/dptabsrc.hxx                 |    2 +-
 sc/source/core/data/dpobject.cxx    |   10 +++++-----
 sc/source/core/data/dpresfilter.cxx |   35 +++++++++++++++++++++++++++++++++--
 sc/source/core/data/dptabsrc.cxx    |   28 +++++++++++++---------------
 5 files changed, 60 insertions(+), 26 deletions(-)

New commits:
commit 0f4384269d24dbdb68d2b4f898443aa0f342e336
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Apr 18 21:06:53 2013 -0400

    Retrieve the result value for GETPIVOTDATA for real (finally!)
    
    Change-Id: I68f4fdab667d86e79225a77964ed90373b391d08

diff --git a/sc/inc/dpresfilter.hxx b/sc/inc/dpresfilter.hxx
index 5e6f3e7..9d4617d 100644
--- a/sc/inc/dpresfilter.hxx
+++ b/sc/inc/dpresfilter.hxx
@@ -21,6 +21,10 @@
 
 #include <boost/unordered_map.hpp>
 
+namespace com { namespace sun { namespace star { namespace sheet {
+    struct DataPilotFieldFilter;
+}}}}
+
 struct ScDPResultFilter
 {
     OUString maDimName;
@@ -50,7 +54,6 @@ class ScDPResultFilterSet : boost::noncopyable
 {
 public:
     typedef std::vector<double> ValuesType;
-    typedef boost::unordered_map<OUString, OUString, OUStringHash> FilterSetType;
 
 private:
 
@@ -81,7 +84,6 @@ private:
     struct MemberNode : boost::noncopyable
     {
         const DimensionNode* mpParent;
-        double mfValue;
         ValuesType maValues;
         DimensionsType maChildDimensions;
 
@@ -117,8 +119,11 @@ public:
     void swap(ScDPResultFilterSet& rOther);
 
     bool empty() const;
+    void clear();
 
-    bool getValues(FilterSetType& rFilters, ValuesType& rValues) const;
+    const ValuesType* getResults(
+        const com::sun::star::uno::Sequence<
+            com::sun::star::sheet::DataPilotFieldFilter>& rFilters) const;
 
 #if DEBUG_PIVOT_TABLE
     void dump() const;
diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx
index a51dd47..51b6759 100644
--- a/sc/inc/dptabsrc.hxx
+++ b/sc/inc/dptabsrc.hxx
@@ -201,7 +201,7 @@ public:
                             ::com::sun::star::sheet::DataResult > > SAL_CALL getResults(  )
                                 throw(::com::sun::star::uno::RuntimeException);
 
-    virtual com::sun::star::uno::Sequence<com::sun::star::uno::Any> SAL_CALL
+    virtual com::sun::star::uno::Sequence<double> SAL_CALL
         getFilteredResults(
             const com::sun::star::uno::Sequence<com::sun::star::sheet::DataPilotFieldFilter>& aFilters )
                 throw (com::sun::star::uno::RuntimeException);
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 1a1d2eb..d4446a8 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1355,7 +1355,7 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<shee
     if (it == aDataDims.end())
         return fRet;
 
-    sal_Int32 nDataIndex = std::distance(aDataDims.begin(), it);
+    size_t nDataIndex = std::distance(aDataDims.begin(), it);
 
     uno::Reference<sheet::XDataPilotResults> xDPResults(xSource, uno::UNO_QUERY);
     if (!xDPResults.is())
@@ -1380,11 +1380,11 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<shee
     for (size_t i = 0; i < n; ++i)
         aFilters[i] = rFilters[i];
 
-    uno::Sequence<uno::Any> aRes = xDPResults->getFilteredResults(aFilters);
-
-    fRet = 54.0;
+    uno::Sequence<double> aRes = xDPResults->getFilteredResults(aFilters);
+    if (static_cast<sal_Int32>(nDataIndex) >= aRes.getLength())
+        return fRet;
 
-    return fRet;
+    return aRes[nDataIndex];
 }
 
 // Returns sal_True on success and stores the result in rTarget
diff --git a/sc/source/core/data/dpresfilter.cxx b/sc/source/core/data/dpresfilter.cxx
index 5cda36b..fbb74c1 100644
--- a/sc/source/core/data/dpresfilter.cxx
+++ b/sc/source/core/data/dpresfilter.cxx
@@ -8,7 +8,11 @@
  */
 
 #include "dpresfilter.hxx"
+#include "global.hxx"
 
+#include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
+
+using namespace com::sun::star;
 using namespace std;
 
 ScDPResultFilter::ScDPResultFilter(const OUString& rDimName, bool bDataLayout) :
@@ -156,9 +160,36 @@ bool ScDPResultFilterSet::empty() const
     return mpRoot->maChildDimensions.empty();
 }
 
-bool ScDPResultFilterSet::getValues(FilterSetType& rFilters, ValuesType& rValues) const
+void ScDPResultFilterSet::clear()
+{
+    maPrimaryDimName = EMPTY_OUSTRING;
+    delete mpRoot;
+    mpRoot = new MemberNode(NULL);
+}
+
+const ScDPResultFilterSet::ValuesType* ScDPResultFilterSet::getResults(
+    const uno::Sequence<sheet::DataPilotFieldFilter>& rFilters) const
 {
-    return false;
+    const sheet::DataPilotFieldFilter* p = rFilters.getConstArray();
+    const sheet::DataPilotFieldFilter* pEnd = p + static_cast<size_t>(rFilters.getLength());
+    const MemberNode* pMember = mpRoot;
+    for (; p != pEnd; ++p)
+    {
+        DimensionsType::const_iterator itDim = pMember->maChildDimensions.find(p->FieldName);
+        if (itDim == pMember->maChildDimensions.end())
+            // Specified dimension not found.
+            return NULL;
+
+        const DimensionNode* pDim = itDim->second;
+        MembersType::const_iterator itMem = pDim->maChildMembers.find(p->MatchValue);
+        if (itMem == pDim->maChildMembers.end())
+            // Specified member not found.
+            return NULL;
+
+        pMember = itMem->second;
+    }
+
+    return &pMember->maValues;
 }
 
 #if DEBUG_PIVOT_TABLE
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 8d641b1..5c0d519 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -458,28 +458,24 @@ uno::Sequence< uno::Sequence<sheet::DataResult> > SAL_CALL ScDPSource::getResult
     return aSeq;
 }
 
-namespace {
-
-struct OUStringPrinter
-{
-    void operator() (const OUString& r) const
-    {
-        std::cout << r << " ";
-    }
-};
-
-}
-
-uno::Sequence<uno::Any> ScDPSource::getFilteredResults(
+uno::Sequence<double> ScDPSource::getFilteredResults(
             const uno::Sequence<sheet::DataPilotFieldFilter>& aFilters )
                 throw (uno::RuntimeException)
 {
     if (maResFilterSet.empty())
         getResults(); // Build result tree first.
 
-    // TODO: Traverse the tree.
+    // Get result values from the tree.
+    const ScDPResultFilterSet::ValuesType* pVals = maResFilterSet.getResults(aFilters);
+    if (!pVals)
+        return uno::Sequence<double>();
 
-    return uno::Sequence<uno::Any>();
+    size_t n = pVals->size();
+    uno::Sequence<double> aRet(n);
+    for (size_t i = 0; i < n; ++i)
+        aRet[i] = (*pVals)[i];
+
+    return aRet;
 }
 
 void SAL_CALL ScDPSource::refresh() throw(uno::RuntimeException)
@@ -574,6 +570,8 @@ void ScDPSource::setRepeatIfEmpty(bool bSet)
 
 void ScDPSource::disposeData()
 {
+    maResFilterSet.clear();
+
     if ( pResData )
     {
         //  reset all data...


More information about the Libreoffice-commits mailing list