[Libreoffice-commits] core.git: Branch 'feature/pivot-table-result-tree' - sc/inc sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Thu Apr 18 13:33:39 PDT 2013
sc/inc/dpobject.hxx | 3 --
sc/inc/dpresfilter.hxx | 16 ++++++++++--
sc/source/core/data/dpobject.cxx | 45 +++++++++++++++++++++++++++++-------
sc/source/core/data/dpresfilter.cxx | 10 ++++++++
sc/source/core/data/dptabsrc.cxx | 25 ++++++++++++--------
sc/source/core/tool/interpr2.cxx | 2 -
6 files changed, 78 insertions(+), 23 deletions(-)
New commits:
commit c6319ba81bcdd2fb570e006ccc5fe607dddb0117
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Thu Apr 18 16:35:23 2013 -0400
More progress. Getting more clue, but still not out of the dark yet.
Change-Id: I0467cd95e2c6f2f353333b24e1aba737d99e5c20
diff --git a/sc/inc/dpobject.hxx b/sc/inc/dpobject.hxx
index fd7c598..c217f1e 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 05bcdcb..5e6f3e7 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 ae01b53..da3cce9 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -1293,9 +1293,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);
@@ -1304,23 +1316,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 0ae8c94..5cda36b 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 b7a1c51..8d641b1 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 3aff11e..2276501 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)
More information about the Libreoffice-commits
mailing list