diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-18 16:35:23 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-19 00:30:10 -0400 |
commit | 1939399c0a1558e7b8b5f05a5eace5d84f896939 (patch) | |
tree | 2a1a7e4c047248da3f11221cbf8347f8f04ff8ba /sc | |
parent | Add some more notes to make it easier to pick up on this for my next visit. (diff) | |
download | core-1939399c0a1558e7b8b5f05a5eace5d84f896939.tar.gz core-1939399c0a1558e7b8b5f05a5eace5d84f896939.zip |
More progress. Getting more clue, but still not out of the dark yet.
Change-Id: I0467cd95e2c6f2f353333b24e1aba737d99e5c20
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/dpobject.hxx | 3 | ||||
-rw-r--r-- | sc/inc/dpresfilter.hxx | 16 | ||||
-rw-r--r-- | sc/source/core/data/dpobject.cxx | 45 | ||||
-rw-r--r-- | sc/source/core/data/dpresfilter.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/dptabsrc.cxx | 25 | ||||
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 2 |
6 files changed, 78 insertions, 23 deletions
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx index fd7c59822fcf..c217f1ed40ba 100644 --- a/sc/inc/dpobject.hxx +++ b/sc/inc/dpobject.hxx @@ -181,8 +181,7 @@ public: double GetPivotData( const OUString& rDataFieldName, - const com::sun::star::uno::Sequence< - com::sun::star::sheet::DataPilotFieldFilter>& rFilters); + std::vector<com::sun::star::sheet::DataPilotFieldFilter>& rFilters); bool GetPivotData( ScDPGetPivotDataField& rTarget, /* returns result */ const std::vector< ScDPGetPivotDataField >& rFilters ); diff --git a/sc/inc/dpresfilter.hxx b/sc/inc/dpresfilter.hxx index 05bcdcb45ae1..5e6f3e7199a6 100644 --- a/sc/inc/dpresfilter.hxx +++ b/sc/inc/dpresfilter.hxx @@ -17,10 +17,10 @@ #if DEBUG_PIVOT_TABLE #include <map> -#else -#include <boost/unordered_map.hpp> #endif +#include <boost/unordered_map.hpp> + struct ScDPResultFilter { OUString maDimName; @@ -48,6 +48,12 @@ struct ScDPResultFilter */ class ScDPResultFilterSet : boost::noncopyable { +public: + typedef std::vector<double> ValuesType; + typedef boost::unordered_map<OUString, OUString, OUStringHash> FilterSetType; + +private: + struct MemberNode; struct DimensionNode; #if DEBUG_PIVOT_TABLE @@ -58,7 +64,6 @@ class ScDPResultFilterSet : boost::noncopyable typedef boost::unordered_map<ScDPItemData, MemberNode*, ScDPItemData::Hash> MembersType; typedef boost::unordered_map<OUString, DimensionNode*, OUStringHash> DimensionsType; #endif - typedef std::vector<double> ValuesType; struct DimensionNode : boost::noncopyable { @@ -92,6 +97,7 @@ class ScDPResultFilterSet : boost::noncopyable MemberNode* mpRoot; public: + ScDPResultFilterSet(); ~ScDPResultFilterSet(); @@ -110,6 +116,10 @@ public: void swap(ScDPResultFilterSet& rOther); + bool empty() const; + + bool getValues(FilterSetType& rFilters, ValuesType& rValues) const; + #if DEBUG_PIVOT_TABLE void dump() const; #endif diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index d04197ef69d8..d30d1d1c8a6f 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -1295,9 +1295,21 @@ public: } }; +class NameInserter : std::unary_function<const ScDPSaveDimension*, void> +{ + std::vector<OUString>& mrNames; +public: + NameInserter(std::vector<OUString>& rNames) : mrNames(rNames) {} + + void operator() (const ScDPSaveDimension* pDim) + { + mrNames.push_back(pDim->GetName()); + } +}; + } -double ScDPObject::GetPivotData(const OUString& rDataFieldName, const uno::Sequence<sheet::DataPilotFieldFilter>& rFilters) +double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<sheet::DataPilotFieldFilter>& rFilters) { double fRet; rtl::math::setNan(&fRet); @@ -1306,23 +1318,40 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, const uno::Seque CreateObjects(); - std::vector<const ScDPSaveDimension*> aDims; - pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDims); - if (aDims.empty()) + std::vector<const ScDPSaveDimension*> aDataDims; + pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDataDims); + if (aDataDims.empty()) return fRet; std::vector<const ScDPSaveDimension*>::iterator it = std::find_if( - aDims.begin(), aDims.end(), FindByName(rDataFieldName)); - if (it == aDims.end()) + aDataDims.begin(), aDataDims.end(), FindByName(rDataFieldName)); + if (it == aDataDims.end()) return fRet; - sal_Int32 nDataIndex = std::distance(aDims.begin(), it); + sal_Int32 nDataIndex = std::distance(aDataDims.begin(), it); uno::Reference<sheet::XDataPilotResults> xDPResults(xSource, uno::UNO_QUERY); if (!xDPResults.is()) return fRet; - uno::Sequence<uno::Any> aRes = xDPResults->getFilteredResults(rFilters); + std::vector<const ScDPSaveDimension*> aRowDims, aColDims; + pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aRowDims); + pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aColDims); + + // Dimensions must be sorted in order of appearance, and row dimensions + // must come before column dimensions. + std::vector<OUString> aDimOrder; + std::for_each(aRowDims.begin(), aRowDims.end(), NameInserter(aDimOrder)); + std::for_each(aColDims.begin(), aColDims.end(), NameInserter(aDimOrder)); + + // TODO: Sort filters by this dimension order... + + size_t n = rFilters.size(); + uno::Sequence<sheet::DataPilotFieldFilter> aFilters(n); + for (size_t i = 0; i < n; ++i) + aFilters[i] = rFilters[i]; + + uno::Sequence<uno::Any> aRes = xDPResults->getFilteredResults(aFilters); fRet = 54.0; diff --git a/sc/source/core/data/dpresfilter.cxx b/sc/source/core/data/dpresfilter.cxx index 0ae8c94c5fdd..5cda36bcc4f5 100644 --- a/sc/source/core/data/dpresfilter.cxx +++ b/sc/source/core/data/dpresfilter.cxx @@ -151,6 +151,16 @@ void ScDPResultFilterSet::swap(ScDPResultFilterSet& rOther) std::swap<MemberNode*>(mpRoot, rOther.mpRoot); } +bool ScDPResultFilterSet::empty() const +{ + return mpRoot->maChildDimensions.empty(); +} + +bool ScDPResultFilterSet::getValues(FilterSetType& rFilters, ValuesType& rValues) const +{ + return false; +} + #if DEBUG_PIVOT_TABLE void ScDPResultFilterSet::dump() const { diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index b7a1c51eaa5f..8d641b1fb715 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -45,6 +45,7 @@ #include "dpitemdata.hxx" #include "dputil.hxx" #include "dpresfilter.hxx" +#include "dpmacros.hxx" #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/sheet/DataPilotFieldFilter.hpp> @@ -457,20 +458,26 @@ 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( const uno::Sequence<sheet::DataPilotFieldFilter>& aFilters ) throw (uno::RuntimeException) { - sal_Int32 n = aFilters.getLength(); - std::vector<sheet::DataPilotFieldFilter> aSorted; - aSorted.reserve(n); - for (sal_Int32 i = 0; i < n; ++i) - aSorted.push_back(aFilters[i]); - - // Sort filters by order of appearance. Row fields come before column fields. + if (maResFilterSet.empty()) + getResults(); // Build result tree first. - // TODO: maResFilterSet maintains the result tree, so we can probably - // extract the field sort order from there somehow. + // TODO: Traverse the tree. return uno::Sequence<uno::Any>(); } diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index a5a8d8330a49..67328043e71a 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -3108,7 +3108,7 @@ void ScInterpreter::ScGetPivotData() // Standard syntax: separate name/value pairs sal_uInt16 nFilterCount = nParamCount / 2 - 1; - uno::Sequence<sheet::DataPilotFieldFilter> aFilters(nFilterCount); + std::vector<sheet::DataPilotFieldFilter> aFilters(nFilterCount); sal_uInt16 i = nFilterCount; while (i-- > 0) |