summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTünde Tóth <tundeth@gmail.com>2019-12-18 16:46:36 +0100
committerLászló Németh <nemeth@numbertext.org>2020-01-10 14:22:57 +0100
commit86be3422cd55fa9e44104f1628648061bb6a3495 (patch)
tree99e0a154d9e88cba9d121e9ace83419357805530
parent6e847aa817999ab18acd534f9e6a86685bb268fc (diff)
tdf#129857 Chart OOXML export: fix deleted legend entries
The legend showed deleted legend entries too after export. Change-Id: I872654d6e4d3f385c468b7fde03d39e233692fa1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86161 Reviewed-by: László Németh <nemeth@numbertext.org> Tested-by: László Németh <nemeth@numbertext.org>
-rw-r--r--chart2/qa/extras/chart2export.cxx40
-rw-r--r--chart2/qa/extras/chart2import.cxx39
-rw-r--r--oox/source/export/chartexport.cxx82
3 files changed, 120 insertions, 41 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 62aa0764a69a..96278053d59f 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -150,6 +150,7 @@ public:
void testTdf122031();
void testTdf115012();
void testTdf123206_customLabelText();
+ void testDeletedLegendEntries();
CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(testErrorBarXLSX);
@@ -263,6 +264,7 @@ public:
CPPUNIT_TEST(testTdf122031);
CPPUNIT_TEST(testTdf115012);
CPPUNIT_TEST(testTdf123206_customLabelText);
+ CPPUNIT_TEST(testDeletedLegendEntries);
CPPUNIT_TEST_SUITE_END();
@@ -2403,6 +2405,44 @@ void Chart2ExportTest::testTdf123206_customLabelText()
assertXPathContent(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:pieChart/c:ser/c:dLbls/c:dLbl[2]/c:tx/c:rich/a:p/a:r/a:t", "kiscica");
}
+void Chart2ExportTest::testDeletedLegendEntries()
+{
+ load("/chart2/qa/extras/data/xlsx/", "deleted_legend_entry.xlsx");
+ {
+ reload("Calc Office Open XML");
+ Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 1));
+ CPPUNIT_ASSERT(xDataSeries.is());
+ Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
+ bool bShowLegendEntry = true;
+ CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
+ CPPUNIT_ASSERT(!bShowLegendEntry);
+ }
+
+ load("/chart2/qa/extras/data/xlsx/", "deleted_legend_entry2.xlsx");
+ {
+ reload("Calc Office Open XML");
+ Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
+ CPPUNIT_ASSERT(xDataSeries.is());
+ Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
+ bool bShowLegendEntry = true;
+ CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
+ CPPUNIT_ASSERT(!bShowLegendEntry);
+
+ Reference<chart2::XChartDocument> xChartDoc2 = getChartDocFromSheet(1, mxComponent);
+ CPPUNIT_ASSERT(xChartDoc.is());
+ Reference<chart2::XDataSeries> xDataSeries2(getDataSeriesFromDoc(xChartDoc2, 0));
+ CPPUNIT_ASSERT(xDataSeries2.is());
+ Reference<beans::XPropertySet> xPropertySet2(xDataSeries2, uno::UNO_QUERY_THROW);
+ Sequence<sal_Int32> deletedLegendEntriesSeq;
+ CPPUNIT_ASSERT(xPropertySet2->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/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 5fcf205df813..9317785520c6 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -148,10 +148,8 @@ public:
void testXaxisValues();
void testTdf123504();
void testTdf122765();
- void testTdf121991();
void testTdf123206CustomLabelField();
void testTdf125444PercentageCustomLabel();
- void testDeletedLegendEntries();
CPPUNIT_TEST_SUITE(Chart2ImportTest);
CPPUNIT_TEST(Fdo60083);
@@ -249,10 +247,8 @@ public:
CPPUNIT_TEST(testXaxisValues);
CPPUNIT_TEST(testTdf123504);
CPPUNIT_TEST(testTdf122765);
- CPPUNIT_TEST(testTdf121991);
CPPUNIT_TEST(testTdf123206CustomLabelField);
CPPUNIT_TEST(testTdf125444PercentageCustomLabel);
- CPPUNIT_TEST(testDeletedLegendEntries);
CPPUNIT_TEST_SUITE_END();
@@ -2289,19 +2285,6 @@ void Chart2ImportTest::testTdf122765()
CPPUNIT_ASSERT_GREATER(sal_Int32(7000), aSlicePosition.X);
}
-void Chart2ImportTest::testTdf121991()
-{
- load("/chart2/qa/extras/data/xlsx/", "deleted_legend_entry.xlsx");
- Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet(0, mxComponent);
- CPPUNIT_ASSERT(xChartDoc.is());
- Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 1));
- CPPUNIT_ASSERT(xDataSeries.is());
- Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
- bool bShowLegendEntry = true;
- CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
- CPPUNIT_ASSERT(!bShowLegendEntry);
-}
-
void Chart2ImportTest::testTdf123206CustomLabelField()
{
// File contains the deprecated "custom-label-field" attribute of the
@@ -2339,28 +2322,6 @@ void Chart2ImportTest::testTdf125444PercentageCustomLabel()
CPPUNIT_ASSERT_EQUAL(chart2::DataPointCustomLabelFieldType_PERCENTAGE, aLabelFields[2]->getFieldType());
}
-void Chart2ImportTest::testDeletedLegendEntries()
-{
- load("/chart2/qa/extras/data/xlsx/", "deleted_legend_entry2.xlsx");
- Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent);
- CPPUNIT_ASSERT(xChartDoc.is());
- Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0));
- CPPUNIT_ASSERT(xDataSeries.is());
- Reference<beans::XPropertySet> xPropertySet(xDataSeries, uno::UNO_QUERY_THROW);
- bool bShowLegendEntry = true;
- CPPUNIT_ASSERT(xPropertySet->getPropertyValue("ShowLegendEntry") >>= bShowLegendEntry);
- CPPUNIT_ASSERT(!bShowLegendEntry);
-
- Reference<chart2::XChartDocument> xChartDoc2 = getChartDocFromSheet(1, mxComponent);
- CPPUNIT_ASSERT(xChartDoc.is());
- Reference<chart2::XDataSeries> xDataSeries2(getDataSeriesFromDoc(xChartDoc2, 0));
- CPPUNIT_ASSERT(xDataSeries2.is());
- Reference<beans::XPropertySet> xPropertySet2(xDataSeries2, uno::UNO_QUERY_THROW);
- Sequence<sal_Int32> deletedLegendEntriesSeq;
- CPPUNIT_ASSERT(xPropertySet2->getPropertyValue("DeletedLegendEntries") >>= deletedLegendEntriesSeq);
- CPPUNIT_ASSERT_EQUAL(sal_Int32(1), deletedLegendEntriesSeq[0]);
-}
-
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 60172be93a38..8dfb053a1f7d 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -18,6 +18,7 @@
*/
#include <oox/token/namespaces.hxx>
+#include <oox/token/properties.hxx>
#include <oox/token/tokens.hxx>
#include <oox/core/xmlfilterbase.hxx>
#include <oox/export/chartexport.hxx>
@@ -1092,6 +1093,85 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
pFS->singleElement(FSNS(XML_c, XML_legendPos), XML_val, strPos);
}
+ // legendEntry
+ Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(mxNewDiagram, UNO_QUERY_THROW);
+ const Sequence<Reference<chart2::XCoordinateSystem>> xCooSysSequence(xCooSysContainer->getCoordinateSystems());
+ if (!xCooSysSequence.hasElements())
+ return;
+
+ sal_Int32 nIndex = 0;
+ bool bShowLegendEntry;
+ for (const auto& rCooSys : xCooSysSequence)
+ {
+ PropertySet aCooSysProp(rCooSys);
+ bool bSwapXAndY = false;
+ aCooSysProp.getProperty(bSwapXAndY, PROP_SwapXAndYAxis);
+
+ Reference<chart2::XChartTypeContainer> xChartTypeContainer(rCooSys, UNO_QUERY_THROW);
+ const Sequence<Reference<chart2::XChartType>> xChartTypeSequence(xChartTypeContainer->getChartTypes());
+ if (!xChartTypeSequence.hasElements())
+ continue;
+
+ for (const auto& rCT : xChartTypeSequence)
+ {
+ Reference<chart2::XDataSeriesContainer> xDSCont(rCT, UNO_QUERY);
+ if (!xDSCont.is())
+ continue;
+
+ const Sequence<Reference<chart2::XDataSeries>> aDataSeriesSeq = xDSCont->getDataSeries();
+ if (bSwapXAndY)
+ nIndex += aDataSeriesSeq.getLength() - 1;
+ for (const auto& rDataSeries : aDataSeriesSeq)
+ {
+ PropertySet aSeriesProp(rDataSeries);
+ bool bVaryColorsByPoint = false;
+ aSeriesProp.getProperty(bVaryColorsByPoint, PROP_VaryColorsByPoint);
+ if (bVaryColorsByPoint)
+ {
+ Sequence<sal_Int32> deletedLegendEntriesSeq;
+ aSeriesProp.getProperty(deletedLegendEntriesSeq, PROP_DeletedLegendEntries);
+ for (auto& deletedLegendEntry : deletedLegendEntriesSeq)
+ {
+ pFS->startElement(FSNS(XML_c, XML_legendEntry));
+ pFS->singleElement(FSNS(XML_c, XML_idx), XML_val,
+ OString::number(nIndex + deletedLegendEntry));
+ pFS->singleElement(FSNS(XML_c, XML_delete), XML_val, "1");
+ pFS->endElement(FSNS(XML_c, XML_legendEntry));
+ }
+ Reference<chart2::data::XDataSource> xDSrc(rDataSeries, UNO_QUERY);
+ if (!xDSrc.is())
+ continue;
+
+ const Sequence<Reference<chart2::data::XLabeledDataSequence>> aDataSeqs = xDSrc->getDataSequences();
+ for (const auto& rDataSeq : aDataSeqs)
+ {
+ Reference<chart2::data::XDataSequence> xValues = rDataSeq->getValues();
+ if (!xValues.is())
+ continue;
+
+ sal_Int32 nDataSeqSize = xValues->getData().getLength();
+ nIndex += nDataSeqSize;
+ }
+ }
+ else
+ {
+ aSeriesProp.getProperty(bShowLegendEntry, PROP_ShowLegendEntry);
+ if (!bShowLegendEntry)
+ {
+ pFS->startElement(FSNS(XML_c, XML_legendEntry));
+ pFS->singleElement(FSNS(XML_c, XML_idx), XML_val,
+ OString::number(nIndex));
+ pFS->singleElement(FSNS(XML_c, XML_delete), XML_val, "1");
+ pFS->endElement(FSNS(XML_c, XML_legendEntry));
+ }
+ bSwapXAndY ? nIndex-- : nIndex++;
+ }
+ }
+ if (bSwapXAndY)
+ nIndex += aDataSeriesSeq.getLength() + 1;
+ }
+ }
+
uno::Any aRelativePos = xProp->getPropertyValue("RelativePosition");
if (aRelativePos.hasValue())
{
@@ -1139,8 +1219,6 @@ void ChartExport::exportLegend( const Reference< css::chart::XChartDocument >& x
exportTextProps( xProp );
}
- // legendEntry
-
pFS->endElement( FSNS( XML_c, XML_legend ) );
}