diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-18 21:06:53 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-19 00:30:11 -0400 |
commit | 378d38f4cab3fc39e735d39e6ecaeae1df408f34 (patch) | |
tree | 934bc863c1fb72124ea1085d6c24fdb5e3f70506 /sc/source/core | |
parent | c128a7712095831dfb378bb2218fc90a9b18c6d2 (diff) |
Retrieve the result value for GETPIVOTDATA for real (finally!)
Change-Id: I68f4fdab667d86e79225a77964ed90373b391d08
Diffstat (limited to 'sc/source/core')
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/dpresfilter.cxx | 35 | ||||
-rw-r--r-- | sc/source/core/data/dptabsrc.cxx | 28 |
3 files changed, 51 insertions, 22 deletions
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... |