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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Feb 27 15:44:32 UTC 2017


 sc/inc/PivotChartDataSequence.hxx              |   11 +
 sc/source/ui/unoobj/PivotChartDataProvider.cxx |  145 ++++++-------------------
 sc/source/ui/unoobj/PivotChartDataSequence.cxx |   32 +++--
 3 files changed, 69 insertions(+), 119 deletions(-)

New commits:
commit 269f174df0a396294669e0b10cd7f73897c987d0
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 27 16:43:10 2017 +0100

    pivotcharts: set the correct number format for categories
    
    Change-Id: I54980c3fbf37816c77fee549fe8b9728ae76ba28

diff --git a/sc/inc/PivotChartDataSequence.hxx b/sc/inc/PivotChartDataSequence.hxx
index c6655bb..6f4cc7c 100644
--- a/sc/inc/PivotChartDataSequence.hxx
+++ b/sc/inc/PivotChartDataSequence.hxx
@@ -51,25 +51,29 @@ struct PivotChartItem
     double m_fValue;
     OUString m_aString;
     bool m_bIsValue;
+    sal_uInt32 m_nNumberFormat;
 
     explicit PivotChartItem()
         : m_fValue(0.0)
         , m_aString()
         , m_bIsValue(true)
+        , m_nNumberFormat(0)
     {
         rtl::math::setNan(&m_fValue);
     }
 
-    explicit PivotChartItem(double fValue)
+    explicit PivotChartItem(double fValue, sal_uInt32 nNumberFormat)
         : m_fValue(fValue)
         , m_aString()
         , m_bIsValue(true)
+        , m_nNumberFormat(nNumberFormat)
     {}
 
     explicit PivotChartItem(OUString const & rString)
         : m_fValue(0.0)
         , m_aString(rString)
         , m_bIsValue(false)
+        , m_nNumberFormat(0)
     {
         rtl::math::setNan(&m_fValue);
     }
diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx
index c5b9e40..520244c 100644
--- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx
@@ -279,6 +279,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
                                                     sheet::DataPilotFieldOrientation_HIDDEN));
 
             long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION);
+            sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO);
 
             if (eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN)
             {
@@ -337,17 +338,29 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
                                         if (rMember.Flags & sheet::MemberResultFlags::HASMEMBER ||
                                             rMember.Flags & sheet::MemberResultFlags::CONTINUE)
                                         {
-                                            OUString sValue;
-                                            if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
-                                                sValue = rMember.Caption;
+                                            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(PivotChartItem(sValue));
+                                            m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem);
 
                                             if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size())
                                                 m_aCategoriesRowOrientation[i].resize(nDimPos + 1);
-                                            m_aCategoriesRowOrientation[i][nDimPos] = PivotChartItem(sValue);
+                                            m_aCategoriesRowOrientation[i][nDimPos] = *pItem;
 
                                             i++;
                                         }
@@ -393,7 +406,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
 
                     if (nIndex >= aDataRowVector.size())
                         aDataRowVector.resize(nIndex + 1);
-                    aDataRowVector[nIndex].push_back(PivotChartItem(rDataResult.Flags ? rDataResult.Value : fNan));
+                    aDataRowVector[nIndex].push_back(PivotChartItem(rDataResult.Flags ? rDataResult.Value : fNan, 0));
                 }
                 nIndex++;
             }
diff --git a/sc/source/ui/unoobj/PivotChartDataSequence.cxx b/sc/source/ui/unoobj/PivotChartDataSequence.cxx
index 477d1cb..6d68db9 100644
--- a/sc/source/ui/unoobj/PivotChartDataSequence.cxx
+++ b/sc/source/ui/unoobj/PivotChartDataSequence.cxx
@@ -150,10 +150,19 @@ uno::Sequence<OUString> SAL_CALL PivotChartDataSequence::generateLabel(chart2::d
     return aSeq;
 }
 
-sal_Int32 SAL_CALL PivotChartDataSequence::getNumberFormatKeyByIndex(sal_Int32 /*nIndex*/)
+sal_Int32 SAL_CALL PivotChartDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex)
 {
     SolarMutexGuard aGuard;
-    return 0;
+    if (nIndex == -1 && !m_aData.empty())
+    {
+        return m_aData[0].m_nNumberFormat;
+    }
+    else if (nIndex < 0 && size_t(nIndex) >= m_aData.size())
+    {
+        SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
+        return 0;
+    }
+    return m_aData[size_t(nIndex)].m_nNumberFormat;
 }
 
 // XCloneable ================================================================
commit 14dd35da0cbd0e2f0583e98fcebffec623d32a39
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Mon Feb 27 16:39:25 2017 +0100

    fix warnings, clean-up and remove unused thing
    
    Change-Id: Ia2061663fe1ee87bc37d9a20766ef0363caa21be

diff --git a/sc/inc/PivotChartDataSequence.hxx b/sc/inc/PivotChartDataSequence.hxx
index c3f6dd2..c6655bb 100644
--- a/sc/inc/PivotChartDataSequence.hxx
+++ b/sc/inc/PivotChartDataSequence.hxx
@@ -78,7 +78,8 @@ struct PivotChartItem
 class PivotChartDataSequence : public PivotChartDataSequence_Base, public SfxListener
 {
 public:
-    explicit PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, std::vector<PivotChartItem> const & rColumnData);
+    explicit PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID,
+                                    std::vector<PivotChartItem> const & rData);
 
     virtual ~PivotChartDataSequence() override;
     PivotChartDataSequence(const PivotChartDataSequence&) = delete;
@@ -163,7 +164,7 @@ private:
     ScDocument* m_pDocument;
     OUString m_sPivotTableName;
     OUString m_aID;
-    std::vector<PivotChartItem> m_aColumnData;
+    std::vector<PivotChartItem> m_aData;
     css::uno::Sequence<OUString> m_aShortSideLabels;
     css::uno::Sequence<OUString> m_aLongSideLabels;
     SfxItemPropertySet m_aPropSet;
diff --git a/sc/source/ui/unoobj/PivotChartDataProvider.cxx b/sc/source/ui/unoobj/PivotChartDataProvider.cxx
index d3be6e4..c5b9e40 100644
--- a/sc/source/ui/unoobj/PivotChartDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotChartDataProvider.cxx
@@ -209,78 +209,25 @@ void PivotChartDataProvider::setLabeledDataSequence(uno::Reference<chart2::data:
     xResult->setLabel(uno::Reference<chart2::data::XDataSequence>(pLabelSequence.release()));
 }
 
-
-enum class ArrangeDirection
-{
-    COLUMNS,
-    ROWS
-};
-
-void lclArrange(std::vector<std::vector<PivotChartItem>>& rResult,
-                std::vector<std::vector<OUString>>& rInput,
-                std::vector<OUString>& rPath,
-                size_t index, ArrangeDirection eDirection)
+uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartCategoriesDataSource(
+                                                    OUString const & rRangeRepresentation,
+                                                    bool bOrientCol)
 {
-    if (index >= rInput.size() - 1)
-    {
-        if (eDirection == ArrangeDirection::COLUMNS)
-        {
-            for (OUString const & rLabel : rInput[index])
-            {
-                rPath[index] = rLabel;
-
-                size_t i = 0;
-                rResult.resize(rPath.size());
-                for (auto it = rPath.begin(); it != rPath.end(); ++it)
-                {
-                    OUString const & rEach = *it;
-                    rResult[i].push_back(PivotChartItem(rEach));
-                    i++;
-                }
-            }
-        }
-        else if (eDirection == ArrangeDirection::ROWS)
-        {
-            size_t i = 0;
-            for (OUString const & rLabel : rInput[index])
-            {
-                rResult.resize(rInput[index].size());
+    uno::Reference<chart2::data::XDataSource> xDataSource;
+    uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
 
-                rPath[index] = rLabel;
+    if (!xContext.is())
+        return xDataSource;
 
-                for (auto it = rPath.begin(); it != rPath.end(); ++it)
-                {
-                    OUString const & rEach = *it;
-                    rResult[i].push_back(PivotChartItem(rEach));
-                }
-                i++;
-            }
-        }
-    }
-    else
-    {
-        for (OUString const & rLabel : rInput[index])
-        {
-            rPath[index] = rLabel;
-            lclArrange(rResult, rInput, rPath, index + 1, eDirection);
-        }
-    }
-}
+    std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences;
 
-void PivotChartDataProvider::createCategories(
-                    ScDPSaveData* pSaveData, bool bOrientCol,
-                    uno::Reference<uno::XComponentContext>& xContext,
-                    std::vector<uno::Reference<chart2::data::XLabeledDataSequence>>& rOutLabeledSequences)
-{
-    ArrangeDirection eDirection = bOrientCol ? ArrangeDirection::COLUMNS
-                                             : ArrangeDirection::ROWS;
     if (bOrientCol)
     {
         for (std::vector<PivotChartItem> const & rCategories : m_aCategoriesColumnOrientation)
         {
             uno::Reference<chart2::data::XLabeledDataSequence> xResult = createLabeledDataSequence(xContext);
             setLabeledDataSequenceValues(xResult, "categories", "Categories", rCategories);
-            rOutLabeledSequences.push_back(xResult);
+            aLabeledSequences.push_back(xResult);
         }
     }
     else
@@ -289,27 +236,11 @@ void PivotChartDataProvider::createCategories(
         {
             uno::Reference<chart2::data::XLabeledDataSequence> xResult = createLabeledDataSequence(xContext);
             setLabeledDataSequenceValues(xResult, "categories", "Categories", rCategories);
-            rOutLabeledSequences.push_back(xResult);
+            aLabeledSequences.push_back(xResult);
         }
     }
-}
-
-uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotChartCategoriesDataSource(OUString const & aRangeRepresentation, bool bOrientCol)
-{
-    uno::Reference<chart2::data::XDataSource> xDataSource;
-    uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
-    if (!xContext.is())
-        return xDataSource;
-
-    std::vector<uno::Reference<chart2::data::XLabeledDataSequence>> aLabeledSequences;
 
-    ScDPCollection* pDPs = m_pDocument->GetDPCollection();
-    ScDPObject* pDPObject = pDPs->GetByName(m_sPivotTableName);
-    ScDPSaveData* pSaveData = pDPObject->GetSaveData();
-
-    createCategories(pSaveData, bOrientCol, xContext, aLabeledSequences);
-
-    xDataSource.set(new PivotChartDataSource(aRangeRepresentation, aLabeledSequences));
+    xDataSource.set(new PivotChartDataSource(rRangeRepresentation, aLabeledSequences));
     return xDataSource;
 }
 
@@ -348,9 +279,6 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
                                                     sheet::DataPilotFieldOrientation_HIDDEN));
 
             long nDimPos = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_POSITION);
-            bool bIsDataLayout = ScUnoHelpFunctions::GetBoolProperty(xDimProp, SC_UNO_DP_ISDATALAYOUT);
-            bool bHasHiddenMember = ScUnoHelpFunctions::GetBoolProperty(xDimProp, SC_UNO_DP_HAS_HIDDEN_MEMBER);
-            sal_Int32 nNumberFormat = ScUnoHelpFunctions::GetLongProperty(xDimProp, SC_UNO_DP_NUMBERFO);
 
             if (eDimOrient != sheet::DataPilotFieldOrientation_HIDDEN)
             {
@@ -370,12 +298,10 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
                     {
 
                         uno::Reference<uno::XInterface> xLevel = ScUnoHelpFunctions::AnyToInterface(xLevels->getByIndex(nLev));
-                        uno::Reference<container::XNamed> xLevNam(xLevel, uno::UNO_QUERY);
+                        uno::Reference<container::XNamed> xLevName(xLevel, uno::UNO_QUERY);
                         uno::Reference<sheet::XDataPilotMemberResults> xLevRes(xLevel, uno::UNO_QUERY );
-                        if (xLevNam.is() && xLevRes.is())
+                        if (xLevName.is() && xLevRes.is())
                         {
-                            OUString aName = xLevNam->getName();
-
                             switch (eDimOrient)
                             {
                                 case sheet::DataPilotFieldOrientation_COLUMN:
@@ -392,7 +318,7 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
                                             if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
                                                 sValue = rMember.Caption;
 
-                                            if (nDimPos >= m_aLabels[i].size())
+                                            if (size_t(nDimPos) >= m_aLabels[i].size())
                                                 m_aLabels[i].resize(nDimPos + 1);
                                             m_aLabels[i][nDimPos] = PivotChartItem(sValue);
 
@@ -415,11 +341,11 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
                                             if (!(rMember.Flags & sheet::MemberResultFlags::CONTINUE))
                                                 sValue = rMember.Caption;
 
-                                            if (nDimPos >= m_aCategoriesColumnOrientation.size())
+                                            if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size())
                                                 m_aCategoriesColumnOrientation.resize(nDimPos + 1);
                                             m_aCategoriesColumnOrientation[nDimPos].push_back(PivotChartItem(sValue));
 
-                                            if (nDimPos >= m_aCategoriesRowOrientation[i].size())
+                                            if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size())
                                                 m_aCategoriesRowOrientation[i].resize(nDimPos + 1);
                                             m_aCategoriesRowOrientation[i][nDimPos] = PivotChartItem(sValue);
 
@@ -459,7 +385,6 @@ uno::Reference<chart2::data::XDataSource> PivotChartDataProvider::createPivotCha
 
         for (uno::Sequence<sheet::DataResult> const & xDataResults : xDataResultsSequence)
         {
-
             size_t nIndex = 0;
             for (sheet::DataResult const & rDataResult : xDataResults)
             {
@@ -536,26 +461,23 @@ uno::Sequence<beans::PropertyValue> SAL_CALL PivotChartDataProvider::detectArgum
     return aArguments;
 }
 
-sal_Bool SAL_CALL PivotChartDataProvider::createDataSequenceByRangeRepresentationPossible(const OUString& aRangeRepresentation)
+sal_Bool SAL_CALL PivotChartDataProvider::createDataSequenceByRangeRepresentationPossible(const OUString& /*aRangeRepresentation*/)
 {
     SolarMutexGuard aGuard;
-    if (!m_pDocument)
-        return false;
-    return true;
+    return false;
 }
 
 uno::Reference< chart2::data::XDataSequence > SAL_CALL
-    PivotChartDataProvider::createDataSequenceByRangeRepresentation(const OUString& aRangeRepresentation)
+    PivotChartDataProvider::createDataSequenceByRangeRepresentation(const OUString& /*aRangeRepresentation*/)
 {
     SolarMutexGuard aGuard;
     uno::Reference<chart2::data::XDataSequence> xResult;
-
     return xResult;
 }
 
 uno::Reference<chart2::data::XDataSequence> SAL_CALL
-    PivotChartDataProvider::createDataSequenceByValueArray(const OUString& aRole,
-                                                           const OUString& aRangeRepresentation)
+    PivotChartDataProvider::createDataSequenceByValueArray(const OUString& /*aRole*/,
+                                                           const OUString& /*aRangeRepresentation*/)
 {
     return uno::Reference<chart2::data::XDataSequence>();
 }
diff --git a/sc/source/ui/unoobj/PivotChartDataSequence.cxx b/sc/source/ui/unoobj/PivotChartDataSequence.cxx
index c30f514..477d1cb 100644
--- a/sc/source/ui/unoobj/PivotChartDataSequence.cxx
+++ b/sc/source/ui/unoobj/PivotChartDataSequence.cxx
@@ -38,11 +38,12 @@ const SfxItemPropertyMapEntry* lcl_GetDataSequencePropertyMap()
     return aDataSequencePropertyMap_Impl;
 }
 
-PivotChartDataSequence::PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID, std::vector<PivotChartItem> const & rColumnData)
+PivotChartDataSequence::PivotChartDataSequence(ScDocument* pDocument, OUString const & sPivotTableName, OUString const & sID,
+                                               std::vector<PivotChartItem> const & rData)
     : m_pDocument(pDocument)
     , m_sPivotTableName(sPivotTableName)
     , m_aID(sID)
-    , m_aColumnData(rColumnData)
+    , m_aData(rData)
     , m_aShortSideLabels()
     , m_aLongSideLabels()
     , m_aPropSet(lcl_GetDataSequencePropertyMap())
@@ -74,10 +75,10 @@ uno::Sequence<uno::Any> SAL_CALL PivotChartDataSequence::getData()
     if (!m_pDocument)
         throw uno::RuntimeException();
 
-    uno::Sequence<uno::Any> aSeq(m_aColumnData.size());
+    uno::Sequence<uno::Any> aSeq(m_aData.size());
 
     size_t i = 0;
-    for (PivotChartItem const & rItem : m_aColumnData)
+    for (PivotChartItem const & rItem : m_aData)
     {
         if (rItem.m_bIsValue)
             aSeq[i] = uno::makeAny<double>(rItem.m_fValue);
@@ -96,10 +97,10 @@ uno::Sequence<double> SAL_CALL PivotChartDataSequence::getNumericalData()
     if (!m_pDocument)
         throw uno::RuntimeException();
 
-    uno::Sequence<double> aSeq(m_aColumnData.size());
+    uno::Sequence<double> aSeq(m_aData.size());
 
     size_t i = 0;
-    for (PivotChartItem const & rItem : m_aColumnData)
+    for (PivotChartItem const & rItem : m_aData)
     {
         aSeq[i] = rItem.m_fValue;
         i++;
@@ -115,10 +116,10 @@ uno::Sequence<OUString> SAL_CALL PivotChartDataSequence::getTextualData()
     if (!m_pDocument)
         throw uno::RuntimeException();
 
-    uno::Sequence<OUString> aSeq(m_aColumnData.size());
+    uno::Sequence<OUString> aSeq(m_aData.size());
 
     size_t i = 0;
-    for (PivotChartItem const & rItem : m_aColumnData)
+    for (PivotChartItem const & rItem : m_aData)
     {
         if (!rItem.m_bIsValue)
             aSeq[i] = rItem.m_aString;
@@ -162,7 +163,7 @@ uno::Reference<util::XCloneable> SAL_CALL PivotChartDataSequence::createClone()
     SolarMutexGuard aGuard;
 
     std::unique_ptr<PivotChartDataSequence> pClone;
-    pClone.reset(new PivotChartDataSequence(m_pDocument, m_sPivotTableName, m_aID, m_aColumnData));
+    pClone.reset(new PivotChartDataSequence(m_pDocument, m_sPivotTableName, m_aID, m_aData));
     pClone->setRole(m_aRole);
     pClone->setShortSideLabels(m_aShortSideLabels);
     pClone->setLongSideLabels(m_aLongSideLabels);


More information about the Libreoffice-commits mailing list