[Libreoffice-commits] core.git: Branch 'feature/pivot-table-result-tree' - sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Thu Apr 18 15:04:32 PDT 2013
sc/source/core/data/dpobject.cxx | 47 ++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 8 deletions(-)
New commits:
commit ed2b37e1f766846f07d36386630db12d0ed5024a
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Thu Apr 18 18:04:52 2013 -0400
More progress. Getting closer...
Change-Id: Ic086804d4ef72f2ee53236436244f0f77447a6d0
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index da3cce9..1a1d2eb 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -77,6 +77,8 @@
#include <vector>
#include <memory>
+#include <boost/unordered_map.hpp>
+
using namespace com::sun::star;
using ::std::vector;
using ::std::unary_function;
@@ -1293,15 +1295,42 @@ public:
}
};
-class NameInserter : std::unary_function<const ScDPSaveDimension*, void>
+typedef boost::unordered_map<OUString, size_t, OUStringHash> DimOrderType;
+
+class DimOrderInserter : std::unary_function<const ScDPSaveDimension*, void>
{
- std::vector<OUString>& mrNames;
+ DimOrderType& mrNames;
public:
- NameInserter(std::vector<OUString>& rNames) : mrNames(rNames) {}
+ DimOrderInserter(DimOrderType& rNames) : mrNames(rNames) {}
void operator() (const ScDPSaveDimension* pDim)
{
- mrNames.push_back(pDim->GetName());
+ size_t nRank = mrNames.size();
+ mrNames.insert(
+ DimOrderType::value_type(pDim->GetName(), nRank));
+ }
+};
+
+class LessByDimOrder : std::binary_function<sheet::DataPilotFieldFilter, sheet::DataPilotFieldFilter, bool>
+{
+ const DimOrderType& mrDimOrder;
+
+public:
+ LessByDimOrder(const DimOrderType& rDimOrder) : mrDimOrder(rDimOrder) {}
+
+ bool operator() (const sheet::DataPilotFieldFilter& r1, const sheet::DataPilotFieldFilter& r2) const
+ {
+ size_t nRank1 = mrDimOrder.size();
+ size_t nRank2 = mrDimOrder.size();
+ DimOrderType::const_iterator it1 = mrDimOrder.find(r1.FieldName);
+ if (it1 != mrDimOrder.end())
+ nRank1 = it1->second;
+
+ DimOrderType::const_iterator it2 = mrDimOrder.find(r2.FieldName);
+ if (it2 != mrDimOrder.end())
+ nRank2 = it2->second;
+
+ return nRank1 < nRank2;
}
};
@@ -1338,11 +1367,13 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<shee
// 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: dimension order should be generated only once in ScDPSaveData.
+ DimOrderType aDimOrder;
+ std::for_each(aRowDims.begin(), aRowDims.end(), DimOrderInserter(aDimOrder));
+ std::for_each(aColDims.begin(), aColDims.end(), DimOrderInserter(aDimOrder));
- // TODO: Sort filters by this dimension order...
+ // Sort filters by this dimension order...
+ std::sort(rFilters.begin(), rFilters.end(), LessByDimOrder(aDimOrder));
size_t n = rFilters.size();
uno::Sequence<sheet::DataPilotFieldFilter> aFilters(n);
More information about the Libreoffice-commits
mailing list