diff options
author | Tünde Tóth <tundeth@gmail.com> | 2020-03-02 14:57:20 +0100 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-03-05 12:45:54 +0100 |
commit | 65123d41f62597053bc3893ee4fb46868a6b1f2d (patch) | |
tree | e099c27ca8b6cf3c3cabdce3eda40f096ceeb8d1 | |
parent | 9fab1ba8ddc59924c633aa17c65f7330a4762726 (diff) |
tdf#75330 chart: implement ODF import/export of legend overlay feature
Follow-up of commit 9fab1ba8ddc59924c633aa17c65f7330a4762726
(tdf#75330 add a new overlay/no-overlay feature for the legend).
Change-Id: I7781fd8b926d4add56f3db0d56dceab8e27e5f85
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89836
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 16 | ||||
-rw-r--r-- | chart2/qa/extras/data/ods/legend_overlay.ods | bin | 0 -> 12314 bytes | |||
-rw-r--r-- | include/xmloff/xmltoken.hxx | 1 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLExport.cxx | 18 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLLegendContext.cxx | 31 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 1 | ||||
-rw-r--r-- | xmloff/source/token/tokens.txt | 1 |
7 files changed, 57 insertions, 11 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 217e766e42fc..c3bd2283bf4e 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -158,6 +158,7 @@ public: void testDeletedLegendEntries(); void testTdf130225(); void testTdf126076(); + void testTdf75330(); CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST(testErrorBarXLSX); @@ -279,6 +280,7 @@ public: CPPUNIT_TEST(testDeletedLegendEntries); CPPUNIT_TEST(testTdf130225); CPPUNIT_TEST(testTdf126076); + CPPUNIT_TEST(testTdf75330); CPPUNIT_TEST_SUITE_END(); @@ -2580,6 +2582,20 @@ void Chart2ExportTest::testTdf126076() assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:marker", 0); } +void Chart2ExportTest::testTdf75330() +{ + mbSkipValidation = true; + load("/chart2/qa/extras/data/ods/", "legend_overlay.ods"); + reload("calc8"); + uno::Reference< chart2::XChartDocument > xChart2Doc = getChartDocFromSheet(0, mxComponent); + uno::Reference< chart::XChartDocument > xChartDoc (xChart2Doc, uno::UNO_QUERY); + uno::Reference<drawing::XShape> xLegend = xChartDoc->getLegend(); + Reference<beans::XPropertySet> xPropertySet(xLegend, uno::UNO_QUERY_THROW); + bool bOverlay = false; + CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Overlay") >>= bOverlay); + CPPUNIT_ASSERT(bOverlay); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/data/ods/legend_overlay.ods b/chart2/qa/extras/data/ods/legend_overlay.ods Binary files differnew file mode 100644 index 000000000000..fade626405c1 --- /dev/null +++ b/chart2/qa/extras/data/ods/legend_overlay.ods diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index ba4a588d85eb..a40aa974d327 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -1386,6 +1386,7 @@ namespace xmloff { namespace token { XML_OUTSET, XML_OUTSIDE, XML_OVERLAP, + XML_OVERLAY, XML_P, XML_PACKAGE_NAME, XML_PADDING, diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index 51f399956ae0..4344d6187b5e 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -1370,6 +1370,8 @@ void SchXMLExportHelper_Impl::parseDocument( Reference< chart::XChartDocument > Reference< beans::XPropertySet > xProp( rChartDoc->getLegend(), uno::UNO_QUERY ); if( xProp.is()) { + const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); + // export legend anchor position try { @@ -1382,12 +1384,26 @@ void SchXMLExportHelper_Impl::parseDocument( Reference< chart::XChartDocument > SAL_WARN("xmloff.chart", "Property Align not found in ChartLegend" ); } + // export legend overlay + try + { + if (nCurrentODFVersion > SvtSaveOptions::ODFVER_012) + { + Any aAny( xProp->getPropertyValue("Overlay")); + if(aAny.get<bool>()) + mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_OVERLAY, OUString::boolean(true)); + } + } + catch( const beans::UnknownPropertyException & ) + { + SAL_WARN("xmloff.chart", "Property Overlay not found in ChartLegend" ); + } + // export absolute legend position Reference< drawing::XShape > xLegendShape( xProp, uno::UNO_QUERY ); addPosition( xLegendShape ); // export legend size - const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); if( xLegendShape.is() && nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 ) { try diff --git a/xmloff/source/chart/SchXMLLegendContext.cxx b/xmloff/source/chart/SchXMLLegendContext.cxx index 902fffb25f46..3427fa3683a7 100644 --- a/xmloff/source/chart/SchXMLLegendContext.cxx +++ b/xmloff/source/chart/SchXMLLegendContext.cxx @@ -40,6 +40,7 @@ namespace enum LegendAttributeTokens { XML_TOK_LEGEND_POSITION, + XML_TOK_LEGEND_OVERLAY, XML_TOK_LEGEND_X, XML_TOK_LEGEND_Y, XML_TOK_LEGEND_STYLE_NAME, @@ -54,6 +55,7 @@ enum LegendAttributeTokens const SvXMLTokenMapEntry aLegendAttributeTokenMap[] = { { XML_NAMESPACE_CHART, XML_LEGEND_POSITION, XML_TOK_LEGEND_POSITION }, + { XML_NAMESPACE_LO_EXT, XML_OVERLAY, XML_TOK_LEGEND_OVERLAY }, { XML_NAMESPACE_SVG, XML_X, XML_TOK_LEGEND_X }, { XML_NAMESPACE_SVG, XML_Y, XML_TOK_LEGEND_Y }, { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_LEGEND_STYLE_NAME }, @@ -117,6 +119,7 @@ void SchXMLLegendContext::StartElement( const uno::Reference< xml::sax::XAttribu const SvXMLTokenMap& rAttrTokenMap = theLegendAttributeTokenMap::get(); awt::Point aLegendPos; + bool bOverlay = false; bool bHasXPosition=false; bool bHasYPosition=false; awt::Size aLegendSize; @@ -138,19 +141,27 @@ void SchXMLLegendContext::StartElement( const uno::Reference< xml::sax::XAttribu switch( rAttrTokenMap.Get( nPrefix, aLocalName )) { case XML_TOK_LEGEND_POSITION: + try { - try - { - if( SchXMLEnumConverter::getLegendPositionConverter().importXML( aValue, aAny, GetImport().GetMM100UnitConverter() ) ) - xLegendProps->setPropertyValue("Alignment", aAny ); - } - catch(const beans::UnknownPropertyException&) - { - SAL_INFO("xmloff.chart", "Property Alignment (legend) not found" ); - } + if( SchXMLEnumConverter::getLegendPositionConverter().importXML( aValue, aAny, GetImport().GetMM100UnitConverter() ) ) + xLegendProps->setPropertyValue("Alignment", aAny ); + } + catch(const beans::UnknownPropertyException&) + { + SAL_INFO("xmloff.chart", "Property Alignment (legend) not found" ); + } + break; + case XML_TOK_LEGEND_OVERLAY: + try + { + bOverlay = xAttrList->getValueByIndex(i).toBoolean(); + xLegendProps->setPropertyValue("Overlay", uno::makeAny(bOverlay)); + } + catch(const beans::UnknownPropertyException&) + { + SAL_INFO("xmloff.chart", "Property Overlay (legend) not found" ); } break; - case XML_TOK_LEGEND_X: GetImport().GetMM100UnitConverter().convertMeasureToCore( aLegendPos.X, aValue ); diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 46125e067982..b55c4c9c7a7b 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -1391,6 +1391,7 @@ namespace xmloff::token { TOKEN( "outset", XML_OUTSET ), TOKEN( "outside", XML_OUTSIDE ), TOKEN( "overlap", XML_OVERLAP ), + TOKEN( "overlay", XML_OVERLAY ), TOKEN( "p", XML_P ), TOKEN( "package-name", XML_PACKAGE_NAME ), TOKEN( "padding", XML_PADDING ), diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index 31dae860a15e..5d14dd65c820 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -1304,6 +1304,7 @@ outline-style outset outside overlap +overlay p package-name padding |