[Libreoffice-commits] core.git: chart2/qa xmloff/source

Tünde Tóth (via logerrit) logerrit at kemper.freedesktop.org
Thu Feb 13 10:16:31 UTC 2020


 chart2/qa/extras/chart2export.cxx                             |   16 ++++++
 chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx |binary
 xmloff/source/chart/SchXMLExport.cxx                          |   25 +++++++++-
 xmloff/source/chart/SchXMLPlotAreaContext.cxx                 |   19 +++++++
 4 files changed, 59 insertions(+), 1 deletion(-)

New commits:
commit a96ec04a07c35338f5f9a0cb361b9322e5ca9cec
Author:     Tünde Tóth <tundeth at gmail.com>
AuthorDate: Wed Feb 5 13:37:00 2020 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Thu Feb 13 11:15:56 2020 +0100

    tdf#130225 implement ODF export of deleted legend entries of pie charts
    
    Follow-up of the following commits related to the new UNO property
    DeletedLegendEntries for pie charts:
    
    commit 86be3422cd55fa9e44104f1628648061bb6a3495
    (tdf#129857 Chart OOXML export: fix deleted legend entries)
    
    commit 6e847aa817999ab18acd534f9e6a86685bb268fc
    (tdf#129859 XLSX import: don't show deleted legend entries)
    
    Change-Id: Id24cddefa83e50dde1ec6555d02891753483dd5f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88018
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 5ee135f5920b..1ff1064046e1 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -153,6 +153,7 @@ public:
     void testTdf115012();
     void testTdf123206_customLabelText();
     void testDeletedLegendEntries();
+    void testTdf130225();
 
     CPPUNIT_TEST_SUITE(Chart2ExportTest);
     CPPUNIT_TEST(testErrorBarXLSX);
@@ -269,6 +270,7 @@ public:
     CPPUNIT_TEST(testTdf115012);
     CPPUNIT_TEST(testTdf123206_customLabelText);
     CPPUNIT_TEST(testDeletedLegendEntries);
+    CPPUNIT_TEST(testTdf130225);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -2469,6 +2471,20 @@ void Chart2ExportTest::testDeletedLegendEntries()
     }
 }
 
+void Chart2ExportTest::testTdf130225()
+{
+    load("/chart2/qa/extras/data/docx/", "piechart_deleted_legend_entry.docx");
+    reload("Office Open XML Text");
+    Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xChartDoc.is());
+    Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
+    CPPUNIT_ASSERT(xDataSeries.is());
+    Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
+    Sequence<sal_Int32> deletedLegendEntriesSeq;
+    CPPUNIT_ASSERT(xPropertySet->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), deletedLegendEntriesSeq[0]);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx b/chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx
new file mode 100644
index 000000000000..da6b2fa19a63
Binary files /dev/null and b/chart2/qa/extras/data/docx/piechart_deleted_legend_entry.docx differ
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index b3d18c7c758c..12f772b0d8b5 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -3188,10 +3188,15 @@ void SchXMLExportHelper_Impl::exportDataPoints(
 
     bool bVaryColorsByPoint = false;
     Sequence< sal_Int32 > aDataPointSeq;
+    Sequence<sal_Int32> deletedLegendEntriesSeq;
     if( xSeriesProperties.is())
     {
         xSeriesProperties->getPropertyValue("AttributedDataPoints") >>= aDataPointSeq;
         xSeriesProperties->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint;
+
+        const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
+        if( nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 )
+            xSeriesProperties->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq;
     }
 
     sal_Int32 nSize = aDataPointSeq.getLength();
@@ -3362,7 +3367,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
     // initialize so that it doesn't matter if
     // the element is counted in the first iteration
     aLastPoint.mnRepeat = 0;
-
+    sal_Int32 nIndex = 0;
     for( const auto& rPoint : aDataPointVector )
     {
         aPoint = rPoint;
@@ -3379,6 +3384,15 @@ void SchXMLExportHelper_Impl::exportDataPoints(
                 mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
                                     OUString::number( ( aLastPoint.mnRepeat ) ));
 
+            for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+            {
+                if (nIndex == deletedLegendEntry)
+                {
+                    mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDE_LEGEND, OUString::boolean(true));
+                    break;
+                }
+            }
+            nIndex++;
             SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
             exportCustomLabel(aLastPoint.mCustomLabelText);
         }
@@ -3394,6 +3408,15 @@ void SchXMLExportHelper_Impl::exportDataPoints(
             mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_REPEATED,
                                 OUString::number( ( aLastPoint.mnRepeat ) ));
 
+        for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+        {
+            if (nIndex == deletedLegendEntry)
+            {
+                mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDE_LEGEND, OUString::boolean(true));
+                break;
+            }
+        }
+
         SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
         exportCustomLabel(aLastPoint.mCustomLabelText);
     }
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
index 5ea889aa7621..dc32a9e900a0 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
@@ -31,6 +31,7 @@
 #include <xmloff/xmluconv.hxx>
 #include <xmloff/prstylei.hxx>
 #include <xmloff/xmlstyle.hxx>
+#include <oox/helper/containerhelper.hxx>
 
 #include <com/sun/star/awt/Point.hpp>
 #include <com/sun/star/awt/Size.hpp>
@@ -679,6 +680,7 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
     {
         OUString sAttrName = xAttrList->getNameByIndex( i );
         OUString aLocalName;
+        bool bHideLegend = false;
         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
 
         if( nPrefix == XML_NAMESPACE_CHART )
@@ -703,6 +705,23 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
                 sCustomLabelField = xAttrList->getValueByIndex( i );
                 mDataPoint.mCustomLabels.push_back(sCustomLabelField);
             }
+            else if (IsXMLToken(aLocalName, XML_HIDE_LEGEND))
+            {
+                bHideLegend = xAttrList->getValueByIndex(i).toBoolean();
+                if (bHideLegend)
+                {
+                    uno::Sequence<sal_Int32> deletedLegendEntriesSeq;
+                    Reference<beans::XPropertySet> xSeriesProp(mDataPoint.m_xSeries, uno::UNO_QUERY);
+                    xSeriesProp->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq;
+                    std::vector<sal_Int32> deletedLegendEntries;
+                    for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+                    {
+                        deletedLegendEntries.push_back(deletedLegendEntry);
+                    }
+                    deletedLegendEntries.push_back(mDataPoint.m_nPointIndex);
+                    xSeriesProp->setPropertyValue("DeletedLegendEntries", uno::makeAny(::oox::ContainerHelper::vectorToSequence(deletedLegendEntries)));
+                }
+            }
         }
     }
 


More information about the Libreoffice-commits mailing list