summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga991@gmail.com>2020-02-25 12:48:08 +0100
committerLászló Németh <nemeth@numbertext.org>2020-02-27 16:56:23 +0100
commit2a00d51150d410110602c953b3c3895debfcaa98 (patch)
tree02f40d51e016405cd763e0e4f2cf3d67295629fb /xmloff
parent74e3c95b9b628a0b326790b62b4e378a12d02997 (diff)
tdf#108110 ODF chart: import/export of custom position of data point labels
using new attributes loext:custom-label-pos-x and loext:custom-label-pos-y of chart:data-point. This fixes also *import* of DOCX documents with embedded charts, related to the ODF usage in the background. Follow-up of commit 4223ff2be69f03e571464b0b09ad0d278918631b (tdf#48436 Chart: add CustomLabelPosition UNO API property) Change-Id: I985ce27cb6ce988948258d9eab0de13d01c72b97 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89446 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/chart/SchXMLExport.cxx44
-rw-r--r--xmloff/source/chart/SchXMLPlotAreaContext.cxx8
-rw-r--r--xmloff/source/chart/SchXMLSeries2Context.cxx9
-rw-r--r--xmloff/source/chart/transporttypes.hxx1
-rw-r--r--xmloff/source/core/xmltoken.cxx2
-rw-r--r--xmloff/source/token/tokens.txt2
6 files changed, 65 insertions, 1 deletions
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index b2339ab46622..6319585bc36a 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -90,6 +90,7 @@
#include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
#include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
+#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/util/MeasureUnit.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
@@ -120,6 +121,7 @@ namespace
OUString maStyleName;
sal_Int32 mnRepeat;
CustomLabelSeq mCustomLabelText;
+ chart2::RelativePosition mCustomLabelPos;
SchXMLDataPointStruct() : mnRepeat( 1 ) {}
};
@@ -228,6 +230,7 @@ public:
bool bExportContent );
void exportCustomLabel(const CustomLabelSeq & xCustomLabel);
+ void exportCustomLabelPosition(const chart2::RelativePosition & xCustomLabelPosition);
void exportRegressionCurve(
const css::uno::Reference<css::chart2::XDataSeries>& xSeries,
@@ -299,6 +302,28 @@ CustomLabelSeq lcl_getCustomLabelField(sal_Int32 nDataPointIndex,
return CustomLabelSeq();
}
+css::chart2::RelativePosition lcl_getCustomLabelPosition(sal_Int32 nDataPointIndex,
+ const uno::Reference< chart2::XDataSeries >& rSeries)
+{
+ if (!rSeries.is())
+ return chart2::RelativePosition();
+
+ const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion(SvtSaveOptions().GetODFDefaultVersion());
+ if (nCurrentODFVersion <= SvtSaveOptions::ODFVER_012)//do not export to ODF 1.2 or older
+ return chart2::RelativePosition();
+
+ if (Reference<beans::XPropertySet> xLabels = rSeries->getDataPointByIndex(nDataPointIndex); xLabels.is())
+ {
+ if (Any aAny = xLabels->getPropertyValue("CustomLabelPosition"); aAny.hasValue())
+ {
+ chart2::RelativePosition aCustomLabelPos;
+ aAny >>= aCustomLabelPos;
+ return aCustomLabelPos;
+ }
+ }
+ return chart2::RelativePosition();
+}
+
class lcl_MatchesRole
{
public:
@@ -3327,6 +3352,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
SchXMLDataPointStruct aPoint;
aPoint.maStyleName = maAutoStyleNameQueue.front();
aPoint.mCustomLabelText = lcl_getCustomLabelField(nCurrIndex, xSeries);
+ aPoint.mCustomLabelPos = lcl_getCustomLabelPosition(nCurrIndex, xSeries);
maAutoStyleNameQueue.pop();
aDataPointVector.push_back( aPoint );
@@ -3372,7 +3398,8 @@ void SchXMLExportHelper_Impl::exportDataPoints(
{
aPoint = rPoint;
- if( aPoint.maStyleName == aLastPoint.maStyleName && aLastPoint.mCustomLabelText.getLength() < 1 )
+ if( aPoint.maStyleName == aLastPoint.maStyleName && aLastPoint.mCustomLabelText.getLength() < 1 &&
+ aLastPoint.mCustomLabelPos.Primary == 0.0 && aLastPoint.mCustomLabelPos.Secondary == 0.0 )
aPoint.mnRepeat += aLastPoint.mnRepeat;
else if( aLastPoint.mnRepeat > 0 )
{
@@ -3393,6 +3420,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
}
}
nIndex++;
+ exportCustomLabelPosition(aLastPoint.mCustomLabelPos);
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
exportCustomLabel(aLastPoint.mCustomLabelText);
}
@@ -3417,6 +3445,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
}
}
+ exportCustomLabelPosition(aLastPoint.mCustomLabelPos);
SvXMLElementExport aPointElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_POINT, true, true );
exportCustomLabel(aLastPoint.mCustomLabelText);
}
@@ -3437,6 +3466,19 @@ void SchXMLExportHelper_Impl::exportCustomLabel( const CustomLabelSeq & xCustomL
}
}
+void SchXMLExportHelper_Impl::exportCustomLabelPosition( const chart2::RelativePosition & xCustomLabelPosition)
+{
+ if( xCustomLabelPosition.Primary == 0.0 && xCustomLabelPosition.Secondary == 0.0 )
+ return; // nothing to export
+
+ OUStringBuffer aCustomLabelPosString;
+ ::sax::Converter::convertDouble(aCustomLabelPosString, xCustomLabelPosition.Primary);
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_CUSTOM_LABEL_POS_X, aCustomLabelPosString.makeStringAndClear());
+
+ ::sax::Converter::convertDouble(aCustomLabelPosString, xCustomLabelPosition.Secondary);
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_CUSTOM_LABEL_POS_Y, aCustomLabelPosString.makeStringAndClear());
+}
+
void SchXMLExportHelper_Impl::addPosition( const awt::Point & rPosition )
{
mrExport.GetMM100UnitConverter().convertMeasureToXML(
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
index dc32a9e900a0..471478a824ae 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
@@ -722,6 +722,14 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
xSeriesProp->setPropertyValue("DeletedLegendEntries", uno::makeAny(::oox::ContainerHelper::vectorToSequence(deletedLegendEntries)));
}
}
+ else if( IsXMLToken(aLocalName, XML_CUSTOM_LABEL_POS_X ) )
+ {
+ mDataPoint.mCustomLabelPos[0] = xAttrList->getValueByIndex(i).toDouble();
+ }
+ else if( IsXMLToken(aLocalName, XML_CUSTOM_LABEL_POS_Y) )
+ {
+ mDataPoint.mCustomLabelPos[1] = xAttrList->getValueByIndex(i).toDouble();
+ }
}
}
diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx
index a571430c28d0..38ec7c084d2b 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
#include <com/sun/star/chart2/data/XDataSink.hpp>
#include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
+#include <com/sun/star/chart2/RelativePosition.hpp>
#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp>
@@ -1101,6 +1102,14 @@ void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeri
}
xPointProp->setPropertyValue("CustomLabelFields", uno::Any(xLabels));
}
+
+ if( seriesStyle.mCustomLabelPos[0] != 0.0 || seriesStyle.mCustomLabelPos[1] != 0.0 )
+ {
+ chart2::RelativePosition aCustomlabelPosition;
+ aCustomlabelPosition.Primary = seriesStyle.mCustomLabelPos[0];
+ aCustomlabelPosition.Secondary = seriesStyle.mCustomLabelPos[1];
+ xPointProp->setPropertyValue("CustomLabelPosition", uno::Any(aCustomlabelPosition));
+ }
}
catch( const uno::Exception & )
{
diff --git a/xmloff/source/chart/transporttypes.hxx b/xmloff/source/chart/transporttypes.hxx
index 04fbe70ecdd0..cc7dce95ef06 100644
--- a/xmloff/source/chart/transporttypes.hxx
+++ b/xmloff/source/chart/transporttypes.hxx
@@ -172,6 +172,7 @@ struct DataRowPointStyle
sal_Int32 m_nPointRepeat;
OUString msStyleName;
::std::vector<OUString> mCustomLabels;
+ double mCustomLabelPos[2] = { 0.0, 0.0 };
OUString msSeriesStyleNameForDonuts;
sal_Int32 mnAttachedAxis;
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 96115303c31b..9be73cdae89f 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -540,6 +540,8 @@ namespace xmloff::token {
TOKEN( "custom-iconset-index", XML_CUSTOM_ICONSET_INDEX ),
TOKEN( "custom-iconset-name", XML_CUSTOM_ICONSET_NAME ),
TOKEN( "custom-label-field", XML_CUSTOM_LABEL_FIELD ),
+ TOKEN( "custom-label-pos-x", XML_CUSTOM_LABEL_POS_X ),
+ TOKEN( "custom-label-pos-y", XML_CUSTOM_LABEL_POS_Y ),
TOKEN( "cut", XML_CUT ),
TOKEN( "cut-offs", XML_CUT_OFFS ),
TOKEN( "cut_offs", XML_CUT_OFFS2 ),
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index abd7dadcd260..78a0adbf9d85 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -463,6 +463,8 @@ custom-iconset
custom-iconset-index
custom-iconset-name
custom-label-field
+custom-label-pos-x
+custom-label-pos-y
cut
cut-offs
cut_offs