diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2021-08-25 20:51:56 +0530 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-09-01 09:15:03 +0200 |
commit | 9d8324524bdcd1244cd6e9d93b063b981d47c9be (patch) | |
tree | 1bbd6560ef3a292b0685d4b768ea1a07c17259b8 /chart2 | |
parent | b365358075d484e034eb9cd6bceeea9d639835b6 (diff) |
tdf#143942: oox: import/export labels from <c15:datalabelsRange>
When <c15:showDataLabelsRange> boolean flag is present, the imported
label texts are added as the first text field in oox data label model.
The cell-range associated is also preserved. The export part preserves
the how labels were store originally in <c15:datalabelsRange>.
However in order to make the custom labels reflect the contents of the
cells in the associated cell-range, more work needs to be done. For this
the labels present in <c15:datalabelsRange> needs to be made available
as a data-sequence with a new "role" like "point-labels" in
XInternalDataProvider implementation and and make the label renderer
read this data source rather than consulting the custom label fields
property which is static after import.
Change-Id: Ibc7045fa5ea209d463680c96efb49a06662d2500
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121313
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/qa/extras/chart2export2.cxx | 125 | ||||
-rw-r--r-- | chart2/qa/extras/data/xlsx/tdf143942.xlsx | bin | 0 -> 13697 bytes | |||
-rw-r--r-- | chart2/source/model/main/FormattedString.cxx | 34 | ||||
-rw-r--r-- | chart2/source/model/main/FormattedString.hxx | 6 | ||||
-rw-r--r-- | chart2/source/view/charttypes/VSeriesPlotter.cxx | 9 |
5 files changed, 162 insertions, 12 deletions
diff --git a/chart2/qa/extras/chart2export2.cxx b/chart2/qa/extras/chart2export2.cxx index adde208d620c..3a1afef91bd6 100644 --- a/chart2/qa/extras/chart2export2.cxx +++ b/chart2/qa/extras/chart2export2.cxx @@ -98,6 +98,7 @@ public: void testCustomShapeText(); void testuserShapesXLSX(); void testNameRangeXLSX(); + void testTdf143942(); CPPUNIT_TEST_SUITE(Chart2ExportTest2); CPPUNIT_TEST(testSetSeriesToSecondaryAxisXLSX); @@ -159,6 +160,7 @@ public: CPPUNIT_TEST(testCustomShapeText); CPPUNIT_TEST(testuserShapesXLSX); CPPUNIT_TEST(testNameRangeXLSX); + CPPUNIT_TEST(testTdf143942); CPPUNIT_TEST_SUITE_END(); }; @@ -1334,22 +1336,60 @@ void Chart2ExportTest2::testTdf138204() "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLbl/c:tx/c:rich/a:p/a:fld", "type", "CELLRANGE"); + assertXPath( + pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:dLbls/c:dLbl/c:tx/c:rich/a:p/a:fld", + "type", "CELLRANGE"); + Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent); CPPUNIT_ASSERT(xChartDoc.is()); - uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 1)); - CPPUNIT_ASSERT(xDataSeries.is()); + struct CustomLabelsTestData + { + sal_Int32 nSeriesIdx; + sal_Int32 nNumFields; + // First field attributes. + chart2::DataPointCustomLabelFieldType eFieldType; + OUString aCellRange; + OUString aString; + }; + + const CustomLabelsTestData aTestEntries[2] = { + { + // series id of c:ser[1] is 0. + 0, // nSeriesIdx + 1, // nNumFields + chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE, + "Munka1!$F$9", // aCellRange + "67,5%", // aString + }, + { + + // series id of c:ser[2] is 1. + 1, // nSeriesIdx + 1, // nNumFields + chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE, + "Munka1!$G$9", // aCellRange + "32,3%", // aString + }, + }; + + for (const auto& aTestEntry : aTestEntries) + { + uno::Reference<chart2::XDataSeries> xDataSeries( + getDataSeriesFromDoc(xChartDoc, aTestEntry.nSeriesIdx)); + CPPUNIT_ASSERT(xDataSeries.is()); - uno::Reference<beans::XPropertySet> xPropertySet; - uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields; - xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW); - xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; - CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aFields.getLength()); + uno::Reference<beans::XPropertySet> xPropertySet; + uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields; + xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_SET_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(aTestEntry.nNumFields, aFields.getLength()); - CPPUNIT_ASSERT_EQUAL( - chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE, - aFields[0]->getFieldType()); - //CPPUNIT_ASSERT_EQUAL(OUString("67.5%"), aFields[0]->getString()); TODO: Not implemented yet + CPPUNIT_ASSERT_EQUAL(aTestEntry.eFieldType, aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(aTestEntry.aCellRange, aFields[0]->getCellRange()); + CPPUNIT_ASSERT_EQUAL(aTestEntry.aString, aFields[0]->getString()); + } } void Chart2ExportTest2::testTdf138181() @@ -1437,6 +1477,69 @@ void Chart2ExportTest2::testNameRangeXLSX() "[0]!series1"); } +void Chart2ExportTest2::testTdf143942() +{ + load(u"/chart2/qa/extras/data/xlsx/", "tdf143942.xlsx"); + xmlDocUniquePtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML"); + CPPUNIT_ASSERT(pXmlDoc); + + constexpr size_t nLabels = 4; + OUString aCellRange = "Sheet1!$A$2:$A$5"; + OUString aLabels[nLabels] = { + "Test1", + "Test2", + "Tes3", + "Test4", + }; + + assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/c:ext", + "uri", "{02D57815-91ED-43cb-92C2-25804820EDAC}"); + assertXPath(pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/c:ext/" + "c15:datalabelsRange/c15:dlblRangeCache/c:ptCount", + "val", "4"); + assertXPathContent(pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/c:ext/" + "c15:datalabelsRange/c15:f", + aCellRange); + for (size_t i = 0; i < nLabels; ++i) + { + assertXPath(pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dLbls/c:dLbl[" + + OString::number(i + 1) + "]/c:tx/c:rich/a:p/a:fld", + "type", "CELLRANGE"); + assertXPath(pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:dLbls/c:dLbl[" + + OString::number(i + 1) + "]/c:extLst/c:ext/c15:showDataLabelsRange", + "val", "1"); + // Check if the actual label is stored under c15:datalabelsRange + assertXPathContent(pXmlDoc, + "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser[1]/c:extLst/" + "c:ext/c15:datalabelsRange/c15:dlblRangeCache/c:pt[" + + OString::number(i + 1) + "]/c:v", + aLabels[i]); + } + + Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent); + CPPUNIT_ASSERT(xChartDoc.is()); + uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + + uno::Reference<beans::XPropertySet> xPropertySet; + uno::Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aFields; + for (size_t i = 0; i < nLabels; ++i) + { + xPropertySet.set(xDataSeries->getDataPointByIndex(i), uno::UNO_SET_THROW); + xPropertySet->getPropertyValue("CustomLabelFields") >>= aFields; + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aFields.getLength()); + CPPUNIT_ASSERT_EQUAL( + chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE, + aFields[0]->getFieldType()); + CPPUNIT_ASSERT_EQUAL(aCellRange, aFields[0]->getCellRange()); + CPPUNIT_ASSERT_EQUAL(aLabels[i], aFields[0]->getString()); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest2); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/xlsx/tdf143942.xlsx b/chart2/qa/extras/data/xlsx/tdf143942.xlsx Binary files differnew file mode 100644 index 000000000000..33ff6696b7e6 --- /dev/null +++ b/chart2/qa/extras/data/xlsx/tdf143942.xlsx diff --git a/chart2/source/model/main/FormattedString.cxx b/chart2/source/model/main/FormattedString.cxx index 5433f3683d78..782729294789 100644 --- a/chart2/source/model/main/FormattedString.cxx +++ b/chart2/source/model/main/FormattedString.cxx @@ -98,6 +98,7 @@ namespace chart FormattedString::FormattedString() : ::property::OPropertySet( m_aMutex ), m_aType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT), + m_bDataLabelsRange(false), m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) {} @@ -107,6 +108,7 @@ FormattedString::FormattedString( const FormattedString & rOther ) : m_aString( rOther.m_aString ), m_aType(rOther.m_aType), m_aGuid(rOther.m_aGuid), + m_bDataLabelsRange(rOther.m_bDataLabelsRange), m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) {} @@ -172,6 +174,38 @@ void SAL_CALL FormattedString::setGuid( const OUString& guid ) } +sal_Bool SAL_CALL FormattedString::getDataLabelsRange() +{ + MutexGuard aGuard( m_aMutex); + return m_bDataLabelsRange; +} + +void SAL_CALL FormattedString::setDataLabelsRange( sal_Bool dataLabelsRange ) +{ + { + MutexGuard aGuard( m_aMutex); + m_bDataLabelsRange = dataLabelsRange; + } + //don't keep the mutex locked while calling out + fireModifyEvent(); +} + +OUString SAL_CALL FormattedString::getCellRange() +{ + MutexGuard aGuard( m_aMutex); + return m_aCellRange; +} + +void SAL_CALL FormattedString::setCellRange( const OUString& cellRange ) +{ + { + MutexGuard aGuard( m_aMutex); + m_aCellRange = cellRange; + } + //don't keep the mutex locked while calling out + fireModifyEvent(); +} + // ____ XModifyBroadcaster ____ void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) { diff --git a/chart2/source/model/main/FormattedString.hxx b/chart2/source/model/main/FormattedString.hxx index a7f9e36bb134..bd7415fb921a 100644 --- a/chart2/source/model/main/FormattedString.hxx +++ b/chart2/source/model/main/FormattedString.hxx @@ -87,6 +87,10 @@ private: setFieldType( const css::chart2::DataPointCustomLabelFieldType FieldType ) override; virtual OUString SAL_CALL getGuid() override; void SAL_CALL setGuid( const OUString& guid ) override; + virtual sal_Bool SAL_CALL getDataLabelsRange() override; + virtual void SAL_CALL setDataLabelsRange( sal_Bool dataLabelsRange ) override; + virtual OUString SAL_CALL getCellRange() override; + virtual void SAL_CALL setCellRange( const OUString& cellRange ) override; // ____ OPropertySet ____ virtual css::uno::Any GetDefaultValue( sal_Int32 nHandle ) const override; @@ -127,6 +131,8 @@ private: // ____ XDataPointCustomLabelField ____ css::chart2::DataPointCustomLabelFieldType m_aType; OUString m_aGuid; + OUString m_aCellRange; + bool m_bDataLabelsRange; css::uno::Reference< css::util::XModifyListener > m_xModifyEventForwarder; }; diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index b0a591d3c065..b5bfc8d871b0 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -540,9 +540,16 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re aTextList[i] = getLabelTextForValue(rDataSeries, nPointIndex, fValue, true); break; } - case DataPointCustomLabelFieldType_CELLREF: case DataPointCustomLabelFieldType_CELLRANGE: { + if (aCustomLabels[i]->getDataLabelsRange()) + aTextList[i] = aCustomLabels[i]->getString(); + else + aTextList[i] = OUString(); + break; + } + case DataPointCustomLabelFieldType_CELLREF: + { // TODO: for now doesn't show placeholder aTextList[i] = OUString(); break; |