[Libreoffice-commits] core.git: Branch 'feature/pivotcharts' - sc/inc sc/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Feb 27 16:01:37 UTC 2017


 sc/inc/PivotChartDataProvider.hxx              |    5 
 sc/source/ui/unoobj/PivotChartDataProvider.cxx |  207 ++++++++++++-------------
 2 files changed, 109 insertions(+), 103 deletions(-)

New commits:
commit ddb88bbbe04f52206d71f4184d6f5863579cf422
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 27 16:59:11 2017 +0100

    pivotcharts: extract and simplify pivot table data collection
    
    Change-Id: I49b0c4d06c3401f07ab3d2857213b12f109f0d8b

diff --git a/sc/inc/PivotChartDataProvider.hxx b/sc/inc/PivotChartDataProvider.hxx
index e92f847..d1139a5 100644
--- a/sc/inc/PivotChartDataProvider.hxx
+++ b/sc/inc/PivotChartDataProvider.hxx
@@ -29,7 +29,7 @@
 #include <rtl/ustring.hxx>
 #include <svl/itemprop.hxx>
 
-#include "dpsave.hxx"
+#include "dpobject.hxx"
 
 #include <memory>
 #include <vector>
@@ -140,6 +140,8 @@ private:
         css::uno::Reference<css::uno::XComponentContext>& rContext,
         std::vector<css::uno::Reference<css::chart2::data::XLabeledDataSequence>>& rOutLabeledSequences);
 
+    void collectPivotTableData(ScDPObject* pDPObject);
+
     ScDocument*        m_pDocument;
     OUString           m_sPivotTableName;
     SfxItemPropertySet m_aPropSet;
@@ -147,6 +149,7 @@ private:
 
     std::vector<std::vector<PivotChartItem>> m_aCategoriesColumnOrientation;
     std::vector<std::vector<PivotChartItem>> m_aCategoriesRowOrientation;
+    std::vector<std::vector<PivotChartItem>> m_aLabels;
 
     std::vector<css::uno::Reference<css::util::XModifyListener>> m_aValueListeners;
 };
diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx
index 520244c..8d9b3e1 100644
--- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx
@@ -36,8 +36,6 @@
 #include <com/sun/star/sheet/MemberResultFlags.hpp>
 
 #include "dpobject.hxx"
-#include "dpsave.hxx"
-#include "pivot.hxx"
 
 #include "hints.hxx"
 
@@ -244,27 +242,11 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
     return xDataSource;
 }
 
-uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartDataSource(OUString const & aRangeRepresentation)
+void PivotChartDataProvider::collectPivotTableData(ScDPObject* pDPObject)
 {
-    m_aCategoriesColumnOrientation.clear();
-    m_aCategoriesRowOrientation.clear();
-
-    uno::Reference<chart2::data::XDataSource> xDataSource;
-    std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences;
-
-    uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
-    if (!xContext.is())
-        return xDataSource;
-
-    ScDPCollection* pDPCollection = m_pDocument->GetDPCollection();
-    ScDPObject* pDPObject = pDPCollection->GetByName(m_sPivotTableName);
-
     uno::Reference<sheet::XDimensionsSupplier> xDimensionsSupplier(pDPObject->GetSource());
-    uno::Reference<sheet::XDataPilotResults> xDPResults(xDimensionsSupplier, uno::UNO_QUERY);
     uno::Reference<container::XIndexAccess> xDims = new ScNameToIndexAccess(xDimensionsSupplier->getDimensions());
 
-    std::vector<std::vector<PivotChartItem>> m_aLabels;
-
     for (long nDim = 0; nDim < xDims->getCount(); nDim++)
     {
         uno::Reference<uno::XInterface> xDim = ScUnoHelpFunctions::AnyToInterface(xDims->getByIndex(nDim));
@@ -272,110 +254,131 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
         uno::Reference<container::XNamed> xDimName(xDim, uno::UNO_QUERY);
         uno::Reference<sheet::XHierarchiesSupplier> xDimSupp(xDim, uno::UNO_QUERY);
 
-        if (xDimProp.is() && xDimSupp.is())
-        {
-            sheet::DataPilotFieldOrientation eDimOrient = sheet::DataPilotFieldOrientation(
-                ScUnoHelpFunctions::GetEnumProperty(xDimProp, SC_UNO_DP_ORIENTATION,
-                                                    sheet::DataPilotFieldOrientation_HIDDEN));
+        if (!xDimProp.is() || !xDimSupp.is())
+            continue;
 
-            long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION);
-            sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO);
+        sheet::DataPilotFieldOrientation eDimOrient = sheet::DataPilotFieldOrientation(
+            ScUnoHelpFunctions::GetEnumProperty(xDimProp, SC_UNO_DP_ORIENTATION,
+                                                sheet::DataPilotFieldOrientation_HIDDEN));
 
-            if (eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN)
-            {
-                uno::Reference<container::XIndexAccess> xHiers = new ScNameToIndexAccess(xDimSupp->getHierarchies());
-                long nHierarchy = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_USEDHIERARCHY);
-                if (nHierarchy >= xHiers->getCount())
-                    nHierarchy = 0;
+        long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION);
+        sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO);
+
+        if (eDimOrient == sheet::DataPilotFieldOrientation_HIDDEN)
+            continue;
+        uno::Reference<container::XIndexAccess> xHiers = new ScNameToIndexAccess(xDimSupp->getHierarchies());
+        long nHierarchy = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_USEDHIERARCHY);
+        if (nHierarchy >= xHiers->getCount())
+            nHierarchy = 0;
+
+        uno::Reference<uno::XInterface> xHier = ScUnoHelpFunctions::AnyToInterface(xHiers->getByIndex(nHierarchy));
+
+        uno::Reference<sheet::XLevelsSupplier> xHierSupp(xHier, uno::UNO_QUERY);
+
+        if (!xHierSupp.is())
+            continue;
 
-                uno::Reference<uno::XInterface> xHier = ScUnoHelpFunctions::AnyToInterface(xHiers->getByIndex(nHierarchy));
+        uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xHierSupp->getLevels());
 
-                uno::Reference<sheet::XLevelsSupplier> xHierSupp(xHier, uno::UNO_QUERY);
-                if (xHierSupp.is())
+        for (long nLev = 0; nLev < xLevels->getCount(); nLev++)
+        {
+            uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface(xLevels->getByIndex(nLev));
+            uno::Reference<container::XNamed> xLevName(xLevel, uno::UNO_QUERY);
+            uno::Reference<sheet::XDataPilotMemberResults> xLevRes(xLevel, uno::UNO_QUERY );
+
+            if (xLevName.is() && xLevRes.is())
+            {
+                switch (eDimOrient)
                 {
-                    uno::Reference<container::XIndexAccess> xLevels = new ScNameToIndexAccess(xHierSupp->getLevels());
-                    long nLevCount = xLevels->getCount();
-                    for (long nLev = 0; nLev < nLevCount; nLev++)
+                    case sheet::DataPilotFieldOrientation_COLUMN:
                     {
+                        uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults();
+                        size_t i = 0;
+                        OUString sValue;
+                        m_aLabels.resize(aSeq.getLength());
+                        for (sheet::MemberResult & rMember : aSeq)
+                        {
+                            if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER ||
+                                rMember.Flags & sheet::MemberResultFlags::CONTINUE)
+                            {
+                                if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
+                                    sValue = rMember.Caption;
+
+                                if (size_t(nDimPos) >= m_aLabels[i].size())
+                                    m_aLabels[i].resize(nDimPos + 1);
+                                m_aLabels[i][nDimPos] = PivotChartItem(sValue);
 
-                        uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface(xLevels->getByIndex(nLev));
-                        uno::Reference<container::XNamed> xLevName(xLevel, uno::UNO_QUERY);
-                        uno::Reference<sheet::XDataPilotMemberResults> xLevRes(xLevel, uno::UNO_QUERY );
-                        if (xLevName.is() && xLevRes.is())
+                                i++;
+                            }
+                        }
+                        break;
+                    }
+                    case sheet::DataPilotFieldOrientation_ROW:
+                    {
+                        uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults();
+                        m_aCategoriesRowOrientation.resize(aSeq.getLength());
+                        size_t i = 0;
+                        for (sheet::MemberResult & rMember : aSeq)
                         {
-                            switch (eDimOrient)
+                            if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER ||
+                                rMember.Flags & sheet::MemberResultFlags::CONTINUE)
                             {
-                                case sheet::DataPilotFieldOrientation_COLUMN:
+                                std::unique_ptr<PivotChartItem> pItem;
+
+                                double fValue = rMember.Value;
+
+                                if (rtl::math::isNan(fValue))
                                 {
-                                    uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults();
-                                    size_t i = 0;
                                     OUString sValue;
-                                    m_aLabels.resize(aSeq.getLength());
-                                    for (sheet::MemberResult & rMember : aSeq)
-                                    {
-                                        if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER ||
-                                            rMember.Flags & sheet::MemberResultFlags::CONTINUE)
-                                        {
-                                            if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
-                                                sValue = rMember.Caption;
-
-                                            if (size_t(nDimPos) >= m_aLabels[i].size())
-                                                m_aLabels[i].resize(nDimPos + 1);
-                                            m_aLabels[i][nDimPos] = PivotChartItem(sValue);
-
-                                            i++;
-                                        }
-                                    }
-                                    break;
+                                    if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
+                                        sValue = rMember.Caption;
+                                    pItem.reset(new PivotChartItem(sValue));
                                 }
-                                case sheet::DataPilotFieldOrientation_ROW:
+                                else
                                 {
-                                    uno::Sequence<sheet::MemberResult> aSeq = xLevRes->getResults();
-                                    m_aCategoriesRowOrientation.resize(aSeq.getLength());
-                                    size_t i = 0;
-                                    for (sheet::MemberResult & rMember : aSeq)
-                                    {
-                                        if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER ||
-                                            rMember.Flags & sheet::MemberResultFlags::CONTINUE)
-                                        {
-                                            std::unique_ptr<PivotChartItem> pItem;
-
-                                            double fValue = rMember.Value;
-
-                                            if (rtl::math::isNan(fValue))
-                                            {
-                                                OUString sValue;
-                                                if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
-                                                    sValue = rMember.Caption;
-                                                pItem.reset(new PivotChartItem(sValue));
-                                            }
-                                            else
-                                            {
-                                                pItem.reset(new PivotChartItem(fValue, nNumberFormat));
-                                            }
-
-                                            if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size())
-                                                m_aCategoriesColumnOrientation.resize(nDimPos + 1);
-                                            m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem);
-
-                                            if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size())
-                                                m_aCategoriesRowOrientation[i].resize(nDimPos + 1);
-                                            m_aCategoriesRowOrientation[i][nDimPos] = *pItem;
-
-                                            i++;
-                                        }
-                                    }
-                                    break;
+                                    pItem.reset(new PivotChartItem(fValue, nNumberFormat));
                                 }
-                                default:
-                                    break;
+
+                                if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size())
+                                    m_aCategoriesColumnOrientation.resize(nDimPos + 1);
+                                m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem);
+
+                                if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size())
+                                    m_aCategoriesRowOrientation[i].resize(nDimPos + 1);
+                                m_aCategoriesRowOrientation[i][nDimPos] = *pItem;
+
+                                i++;
                             }
                         }
+                        break;
                     }
+                    default:
+                        break;
                 }
             }
         }
     }
+}
+
+uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartDataSource(OUString const & aRangeRepresentation)
+{
+    m_aCategoriesColumnOrientation.clear();
+    m_aCategoriesRowOrientation.clear();
+    m_aLabels.clear();
+
+    uno::Reference<chart2::data::XDataSource> xDataSource;
+    std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences;
+
+    uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
+    if (!xContext.is())
+        return xDataSource;
+
+    ScDPCollection* pDPCollection = m_pDocument->GetDPCollection();
+    ScDPObject* pDPObject = pDPCollection->GetByName(m_sPivotTableName);
+
+    collectPivotTableData(pDPObject);
+
+    uno::Reference<sheet::XDataPilotResults> xDPResults(pDPObject->GetSource(), uno::UNO_QUERY);
 
     {
         std::vector<PivotChartItem> aFirstCategories;


More information about the Libreoffice-commits mailing list