summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2021-08-25 20:51:56 +0530
committerAndras Timar <andras.timar@collabora.com>2021-08-30 12:08:22 +0200
commit32b0289cc53527b3eb45a4b6600cd26472f59282 (patch)
treefbbf2d957e5f3b5ae4b9f4dfa7c63d49c555eb15 /xmloff
parentf567bddaad3de2ac02f0d0cbec6e3816b730fae9 (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
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/chart/SchXMLExport.cxx55
-rw-r--r--xmloff/source/chart/SchXMLPlotAreaContext.cxx21
-rw-r--r--xmloff/source/chart/SchXMLPlotAreaContext.hxx4
-rw-r--r--xmloff/source/chart/SchXMLSeries2Context.cxx21
-rw-r--r--xmloff/source/chart/transporttypes.hxx10
-rw-r--r--xmloff/source/core/xmltoken.cxx2
-rw-r--r--xmloff/source/token/tokens.txt2
7 files changed, 92 insertions, 23 deletions
diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx
index 0ee68425c6fc..51fdec8f3175 100644
--- a/xmloff/source/chart/SchXMLExport.cxx
+++ b/xmloff/source/chart/SchXMLExport.cxx
@@ -113,7 +113,18 @@ using ::std::vector;
namespace
{
- using CustomLabelSeq = Sequence<Reference<chart2::XDataPointCustomLabelField>>;
+ struct CustomLabelData
+ {
+ CustomLabelData():
+ mbDataLabelsRange( false )
+ {
+ }
+
+ Sequence<Reference<chart2::XDataPointCustomLabelField>> maFields;
+ bool mbDataLabelsRange;
+ OUString maRange;
+ OUString maGuid;
+ };
struct SchXMLDataPointStruct
{
@@ -123,7 +134,7 @@ namespace
// There is no internal equivalent for <chart:data-label>. It will be generated on the fly
// on export. All about data label is hold in the data point.
- CustomLabelSeq mCustomLabelText; // <text:p> child element in <chart:data-label>
+ CustomLabelData mCustomLabel; // <text:p> child element in <chart:data-label>
OUString msDataLabelStyleName; // chart:style-name attribute in <chart:data-label>
SchXMLDataPointStruct() : mnRepeat( 1 ) {}
@@ -282,30 +293,43 @@ public:
namespace
{
-CustomLabelSeq lcl_getCustomLabelField(SvXMLExport const& rExport,
+CustomLabelData lcl_getCustomLabelField(SvXMLExport const& rExport,
sal_Int32 nDataPointIndex,
const uno::Reference< chart2::XDataSeries >& rSeries)
{
if (!rSeries.is())
- return CustomLabelSeq();
+ return CustomLabelData();
// Custom data label text will be written to the <text:p> child element of a
// <chart:data-label> element. That exists only since ODF 1.2.
const SvtSaveOptions::ODFSaneDefaultVersion nCurrentODFVersion(
rExport.getSaneDefaultVersion());
if (nCurrentODFVersion < SvtSaveOptions::ODFSVER_012)
- return CustomLabelSeq();
+ return CustomLabelData();
if(Reference<beans::XPropertySet> xLabels = rSeries->getDataPointByIndex(nDataPointIndex); xLabels.is())
{
if(Any aAny = xLabels->getPropertyValue("CustomLabelFields"); aAny.hasValue())
{
+ CustomLabelData aData;
Sequence<uno::Reference<chart2::XDataPointCustomLabelField>> aCustomLabels;
aAny >>= aCustomLabels;
- return aCustomLabels;
+ for (auto& rField: aCustomLabels)
+ {
+ if (rField->getFieldType() == chart2::DataPointCustomLabelFieldType_CELLRANGE)
+ {
+ if (rField->getDataLabelsRange())
+ aData.mbDataLabelsRange = true;
+ aData.maRange = rField->getCellRange();
+ aData.maGuid = rField->getGuid();
+ }
+ }
+
+ aData.maFields = aCustomLabels;
+ return aData;
}
}
- return CustomLabelSeq();
+ return CustomLabelData();
}
css::chart2::RelativePosition lcl_getCustomLabelPosition(
@@ -3466,7 +3490,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
maAutoStyleNameQueue.pop();
}
if(bExportNumFmt)
- aPoint.mCustomLabelText = lcl_getCustomLabelField(mrExport, nElement, xSeries);
+ aPoint.mCustomLabel = lcl_getCustomLabelField(mrExport, nElement, xSeries);
aPoint.mCustomLabelPos = lcl_getCustomLabelPosition(mrExport, nElement, xSeries);
aDataPointVector.push_back( aPoint );
@@ -3545,7 +3569,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
aPoint.maStyleName = maAutoStyleNameQueue.front();
maAutoStyleNameQueue.pop();
}
- aPoint.mCustomLabelText = lcl_getCustomLabelField(mrExport, nCurrIndex, xSeries);
+ aPoint.mCustomLabel = lcl_getCustomLabelField(mrExport, nCurrIndex, xSeries);
aPoint.mCustomLabelPos = lcl_getCustomLabelPosition(mrExport, nCurrIndex, xSeries);
if (!aDataLabelPropertyStates.empty())
{
@@ -3601,7 +3625,7 @@ void SchXMLExportHelper_Impl::exportDataPoints(
aPoint = rPoint;
if (aPoint.maStyleName == aLastPoint.maStyleName
- && aLastPoint.mCustomLabelText.getLength() < 1
+ && aLastPoint.mCustomLabel.maFields.getLength() < 1
&& aLastPoint.mCustomLabelPos.Primary == 0.0
&& aLastPoint.mCustomLabelPos.Secondary == 0.0
&& aPoint.msDataLabelStyleName == aLastPoint.msDataLabelStyleName)
@@ -3658,15 +3682,22 @@ void SchXMLExportHelper_Impl::exportDataPoints(
void SchXMLExportHelper_Impl::exportCustomLabel(const SchXMLDataPointStruct& rPoint)
{
- if (rPoint.mCustomLabelText.getLength() < 1 && rPoint.msDataLabelStyleName.isEmpty())
+ if (rPoint.mCustomLabel.maFields.getLength() < 1 && rPoint.msDataLabelStyleName.isEmpty())
return; // nothing to export
if (!rPoint.msDataLabelStyleName.isEmpty())
mrExport.AddAttribute(XML_NAMESPACE_CHART, XML_STYLE_NAME, rPoint.msDataLabelStyleName);
+
+ if (rPoint.mCustomLabel.mbDataLabelsRange)
+ {
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATA_LABELS_CELL_RANGE, rPoint.mCustomLabel.maRange);
+ mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_DATA_LABEL_GUID, rPoint.mCustomLabel.maGuid);
+ }
// TODO svg:x and svg:y for <chart:data-label>
SvXMLElementExport aLabelElem( mrExport, XML_NAMESPACE_CHART, XML_DATA_LABEL, true, true);
SvXMLElementExport aPara( mrExport, XML_NAMESPACE_TEXT, XML_P, true, false );
- for (const Reference<chart2::XDataPointCustomLabelField>& label : rPoint.mCustomLabelText)
+
+ for (const Reference<chart2::XDataPointCustomLabelField>& label : rPoint.mCustomLabel.maFields)
{
// TODO add style
SvXMLElementExport aSpan( mrExport, XML_NAMESPACE_TEXT, XML_SPAN, true, false);
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.cxx b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
index 521fcb58ce41..ce8f915f7c4b 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.cxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.cxx
@@ -617,7 +617,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLDataLabelParaCon
}
SchXMLDataLabelContext::SchXMLDataLabelContext(SvXMLImport& rImport,
- ::std::vector<OUString>& rLabels,
+ CustomLabelsInfo& rLabels,
DataRowPointStyle& rDataLabelStyle)
: SvXMLImportContext(rImport)
, mrLabels(rLabels)
@@ -630,7 +630,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SchXMLDataLabelContext
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
{
if ( nElement == XML_ELEMENT(TEXT, XML_P) )
- return new SchXMLDataLabelParaContext(GetImport(), mrLabels);
+ return new SchXMLDataLabelParaContext(GetImport(), mrLabels.mLabels);
else
XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
return nullptr;
@@ -669,6 +669,19 @@ void SchXMLDataLabelContext::StartElement(const uno::Reference<xml::sax::XAttrib
mrDataLabelStyle.msStyleName = sValue;
}
}
+ else if (nPrefix == XML_NAMESPACE_LO_EXT)
+ {
+ if (IsXMLToken(aLocalName, XML_DATA_LABEL_GUID))
+ {
+ mrLabels.msLabelGuid = sValue;
+ mrLabels.mbDataLabelsRange = true;
+ }
+ else if (IsXMLToken(aLocalName, XML_DATA_LABELS_CELL_RANGE))
+ {
+ mrLabels.msLabelsCellRange = sValue;
+ mrLabels.mbDataLabelsRange = true;
+ }
+ }
}
}
@@ -744,7 +757,7 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
if( IsXMLToken( aLocalName, XML_CUSTOM_LABEL_FIELD) && !mbHasLabelParagraph)
{
sCustomLabelField = xAttrList->getValueByIndex( i );
- mDataPoint.mCustomLabels.push_back(sCustomLabelField);
+ mDataPoint.mCustomLabels.mLabels.push_back(sCustomLabelField);
}
else if (IsXMLToken(aLocalName, XML_HIDE_LEGEND))
{
@@ -779,7 +792,7 @@ void SchXMLDataPointContext::StartElement( const uno::Reference< xml::sax::XAttr
void SchXMLDataPointContext::endFastElement(sal_Int32 )
{
- if(!mDataPoint.msStyleName.isEmpty() || mDataPoint.mCustomLabels.size() > 0)
+ if(!mDataPoint.msStyleName.isEmpty() || mDataPoint.mCustomLabels.mLabels.size() > 0)
{
mrStyleVector.push_back(mDataPoint);
}
diff --git a/xmloff/source/chart/SchXMLPlotAreaContext.hxx b/xmloff/source/chart/SchXMLPlotAreaContext.hxx
index 1e392e8a3b3c..487d2a93a382 100644
--- a/xmloff/source/chart/SchXMLPlotAreaContext.hxx
+++ b/xmloff/source/chart/SchXMLPlotAreaContext.hxx
@@ -163,11 +163,11 @@ public:
class SchXMLDataLabelContext: public SvXMLImportContext
{
private:
- ::std::vector<OUString>& mrLabels;
+ CustomLabelsInfo& mrLabels;
DataRowPointStyle& mrDataLabelStyle;
public:
SchXMLDataLabelContext(SvXMLImport& rImport,
- ::std::vector<OUString>& rLabels, DataRowPointStyle& rDataLabel);
+ CustomLabelsInfo& rLabels, DataRowPointStyle& rDataLabel);
virtual void StartElement(const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList) override;
diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx
index 992a03d64113..c7c86ca49e77 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -1220,16 +1220,28 @@ void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeri
}
// Custom labels might be passed as property
- if(auto nLabelCount = seriesStyle.mCustomLabels.size(); nLabelCount > 0)
+ if(const size_t nLabelCount = seriesStyle.mCustomLabels.mLabels.size(); nLabelCount > 0)
{
+ auto& rCustomLabels = seriesStyle.mCustomLabels;
+
Sequence< Reference<chart2::XDataPointCustomLabelField>> xLabels(nLabelCount);
Reference< uno::XComponentContext > xContext( comphelper::getProcessComponentContext() );
- for( auto j = 0; j< xLabels.getLength(); ++j )
+ for( size_t j = 0; j < nLabelCount; ++j )
{
Reference< chart2::XDataPointCustomLabelField > xCustomLabel = chart2::DataPointCustomLabelField::create(xContext);
xLabels[j] = xCustomLabel;
- xCustomLabel->setString(seriesStyle.mCustomLabels[j]);
- xCustomLabel->setFieldType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT);
+ xCustomLabel->setString(rCustomLabels.mLabels[j]);
+ if ( j == 0 && rCustomLabels.mbDataLabelsRange)
+ {
+ xCustomLabel->setFieldType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLRANGE);
+ xCustomLabel->setGuid(rCustomLabels.msLabelGuid);
+ xCustomLabel->setCellRange(rCustomLabels.msLabelsCellRange);
+ xCustomLabel->setDataLabelsRange(true);
+ }
+ else
+ {
+ xCustomLabel->setFieldType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT);
+ }
// Restore character properties on the text span manually, till
// SchXMLExportHelper_Impl::exportCustomLabel() does not write the style.
@@ -1251,6 +1263,7 @@ void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeri
}
}
}
+
xPointProp->setPropertyValue("CustomLabelFields", uno::Any(xLabels));
xPointProp->setPropertyValue("DataCaption", uno::Any(chart::ChartDataCaption::CUSTOM));
}
diff --git a/xmloff/source/chart/transporttypes.hxx b/xmloff/source/chart/transporttypes.hxx
index 28527c6c06f8..4e395ead292c 100644
--- a/xmloff/source/chart/transporttypes.hxx
+++ b/xmloff/source/chart/transporttypes.hxx
@@ -146,6 +146,14 @@ struct RegressionStyle
{}
};
+struct CustomLabelsInfo
+{
+ ::std::vector<OUString> mLabels;
+ bool mbDataLabelsRange = false;
+ OUString msLabelGuid;
+ OUString msLabelsCellRange;
+};
+
struct DataRowPointStyle
{
enum StyleType
@@ -171,7 +179,7 @@ struct DataRowPointStyle
sal_Int32 m_nPointRepeat;
OUString msStyleName;
OUString msStyleNameOfParent; // e.g. target of line and fill styles of data-labels
- ::std::vector<OUString> mCustomLabels;
+ CustomLabelsInfo mCustomLabels;
double mCustomLabelPos[2] = { 0.0, 0.0 };
// for svg:x and svg:y attribute (in core unit), of element <chart:data-label>
std::optional<sal_Int32> mo_nLabelAbsolutePosX;
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index 02482b39515e..9600a0689fc5 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -579,9 +579,11 @@ namespace xmloff::token {
TOKEN( "data-bar-entry", XML_DATA_BAR_ENTRY ),
TOKEN( "data-cell-range-address", XML_DATA_CELL_RANGE_ADDRESS ),
TOKEN( "data-label", XML_DATA_LABEL ),
+ TOKEN( "data-label-guid", XML_DATA_LABEL_GUID ),
TOKEN( "data-label-number", XML_DATA_LABEL_NUMBER ),
TOKEN( "data-label-symbol", XML_DATA_LABEL_SYMBOL ),
TOKEN( "data-label-text", XML_DATA_LABEL_TEXT ),
+ TOKEN( "data-labels-cell-range", XML_DATA_LABELS_CELL_RANGE ),
TOKEN( "data-pilot-source", XML_DATA_PILOT_SOURCE ),
TOKEN( "data-pilot-field", XML_DATA_PILOT_FIELD ),
TOKEN( "data-pilot-grand-total", XML_DATA_PILOT_GRAND_TOTAL ),
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index ead900650328..bb5e0e89f311 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -491,9 +491,11 @@ data-bar
data-bar-entry
data-cell-range-address
data-label
+data-label-guid
data-label-number
data-label-symbol
data-label-text
+data-labels-cell-range
data-pilot-source
data-pilot-field
data-pilot-grand-total