summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-04-18 21:06:53 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-04-19 00:30:11 -0400
commit378d38f4cab3fc39e735d39e6ecaeae1df408f34 (patch)
tree934bc863c1fb72124ea1085d6c24fdb5e3f70506 /sc
parentc128a7712095831dfb378bb2218fc90a9b18c6d2 (diff)
Retrieve the result value for GETPIVOTDATA for real (finally!)
Change-Id: I68f4fdab667d86e79225a77964ed90373b391d08
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/dpresfilter.hxx11
-rw-r--r--sc/inc/dptabsrc.hxx2
-rw-r--r--sc/source/core/data/dpobject.cxx10
-rw-r--r--sc/source/core/data/dpresfilter.cxx35
-rw-r--r--sc/source/core/data/dptabsrc.cxx28
5 files changed, 60 insertions, 26 deletions
diff --git a/sc/inc/dpresfilter.hxx b/sc/inc/dpresfilter.hxx
index 5e6f3e7199a6..9d4617d08a7a 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 a51dd478e30f..51b6759c8c1c 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 7bc111f8daf9..8ac05abfb480 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1357,7 +1357,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())
@@ -1382,11 +1382,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 5cda36bcc4f5..fbb74c1d6417 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 8d641b1fb715..5c0d519cce44 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...