summaryrefslogtreecommitdiffstats
path: root/oox
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2018-01-04 22:15:32 +0100
committerSzymon Kłos <szymon.klos@collabora.com>2018-01-29 23:49:42 +0100
commit790f9abeb1a1167ad5ab84c5fb855b36669c125b (patch)
treedea7c957b67be7518d2092614b82f18148817265 /oox
parentCheckLinkFormulaNeedingCheck() for .xlsx named expressions (diff)
downloadcore-790f9abeb1a1167ad5ab84c5fb855b36669c125b.tar.gz
core-790f9abeb1a1167ad5ab84c5fb855b36669c125b.zip
tdf#114821 import complex data labels in bar chart
* import static text & fields: VALUE, SERIESNAME, COLUMNNAME * text is formatted * DataPointCustomLabelField with field type (DataPointCustomLabelFieldType) was introduced. * text can have many portions & multiple lines * unit tests for import data labels with formatting Not implemented: CELLREF field support which needs importing some additional data from extLst Shows custom text as a label for data points. Change-Id: Iba8fd508eb16356b05586b93d7b8da32240d2b91 Reviewed-on: https://gerrit.libreoffice.org/48243 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/inc/drawingml/textfield.hxx2
-rw-r--r--oox/source/drawingml/chart/seriesconverter.cxx78
-rw-r--r--oox/source/token/properties.txt1
3 files changed, 81 insertions, 0 deletions
diff --git a/oox/inc/drawingml/textfield.hxx b/oox/inc/drawingml/textfield.hxx
index 9f5bf9cf27af..7cc15a04fce4 100644
--- a/oox/inc/drawingml/textfield.hxx
+++ b/oox/inc/drawingml/textfield.hxx
@@ -38,7 +38,9 @@ public:
const TextParagraphProperties& getTextParagraphProperties() const { return maTextParagraphProperties; }
void setType( const OUString& sType ) { msType = sType; }
+ const OUString& getType() const { return msType; }
void setUuid( const OUString & sUuid ) { msUuid = sUuid; }
+ const OUString& getUuid() const { return msUuid; }
virtual sal_Int32 insertAt(
const ::oox::core::XmlFilterBase& rFilterBase,
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index be17ee8c8079..7c53c712bd88 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -22,11 +22,16 @@
#include <com/sun/star/chart/DataLabelPlacement.hpp>
#include <com/sun/star/chart/ErrorBarStyle.hpp>
#include <com/sun/star/chart2/DataPointLabel.hpp>
+#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
+#include <com/sun/star/chart2/DataPointCustomLabelField.hpp>
+#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp>
#include <com/sun/star/chart2/XDataSeries.hpp>
#include <com/sun/star/chart2/XRegressionCurve.hpp>
#include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
#include <com/sun/star/chart2/data/XDataSink.hpp>
#include <com/sun/star/chart2/data/LabeledDataSequence.hpp>
+#include <com/sun/star/chart2/XFormattedString2.hpp>
+#include <com/sun/star/chart2/FormattedString.hpp>
#include <osl/diagnose.h>
#include <basegfx/numeric/ftools.hxx>
#include <drawingml/chart/datasourceconverter.hxx>
@@ -41,6 +46,10 @@
#include <oox/token/properties.hxx>
#include <oox/token/tokens.hxx>
#include <drawingml/lineproperties.hxx>
+#include <drawingml/textparagraph.hxx>
+#include <drawingml/textrun.hxx>
+#include <drawingml/textfield.hxx>
+#include <drawingml/textbody.hxx>
namespace oox {
namespace drawingml {
@@ -200,6 +209,20 @@ void importBorderProperties( PropertySet& rPropSet, Shape& rShape, const Graphic
rPropSet.setProperty(PROP_LabelBorderColor, uno::makeAny(nColor));
}
+DataPointCustomLabelFieldType lcl_ConvertFieldNameToFieldEnum( const OUString& rField )
+{
+ if (rField == "VALUE")
+ return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE;
+ else if (rField == "SERIESNAME")
+ return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME;
+ else if (rField == "CATEGORYNAME")
+ return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CATEGORYNAME;
+ else if (rField == "CELLREF")
+ return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLREF;
+ else
+ return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT;
+}
+
} // namespace
DataLabelConverter::DataLabelConverter( const ConverterRoot& rParent, DataLabelModel& rModel ) :
@@ -247,6 +270,61 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
if (mrModel.mxShapeProp)
importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper());
+
+ if( mrModel.mxText && mrModel.mxText->mxTextBody && mrModel.mxText->mxTextBody->getParagraphs().size() )
+ {
+ css::uno::Reference< XComponentContext > xContext = getComponentContext();
+ uno::Sequence< css::uno::Reference< XDataPointCustomLabelField > > aSequence;
+
+ auto& rParagraphs = mrModel.mxText->mxTextBody->getParagraphs();
+
+ int nSequenceSize = 0;
+ for( auto& pParagraph : rParagraphs )
+ nSequenceSize += pParagraph->getRuns().size();
+
+ int nParagraphs = rParagraphs.size();
+ if( nParagraphs > 1 )
+ nSequenceSize += nParagraphs - 1;
+
+ aSequence.realloc( nSequenceSize );
+
+ int nPos = 0;
+ for( auto& pParagraph : rParagraphs )
+ {
+ for( auto& pRun : pParagraph->getRuns() )
+ {
+ css::uno::Reference< XDataPointCustomLabelField > xCustomLabel = DataPointCustomLabelField::create( xContext );
+
+ // Store properties
+ oox::PropertySet aPropertySet( xCustomLabel );
+ pRun->getTextCharacterProperties().pushToPropSet( aPropertySet, getFilter() );
+
+ TextField* pField = nullptr;
+ if( ( pField = dynamic_cast< TextField* >( pRun.get() ) ) )
+ {
+ xCustomLabel->setString( pField->getText() );
+ xCustomLabel->setFieldType( lcl_ConvertFieldNameToFieldEnum( pField->getType() ) );
+ xCustomLabel->setGuid( pField->getUuid() );
+ }
+ else if( pRun.get() )
+ {
+ xCustomLabel->setString( pRun->getText() );
+ xCustomLabel->setFieldType( DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT );
+ }
+ aSequence[ nPos++ ] = xCustomLabel;
+ }
+
+ if( nParagraphs > 1 && nPos < nSequenceSize )
+ {
+ css::uno::Reference< XDataPointCustomLabelField > xCustomLabel = DataPointCustomLabelField::create( xContext );
+ xCustomLabel->setFieldType( DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE );
+ xCustomLabel->setString("\n");
+ aSequence[ nPos++ ] = xCustomLabel;
+ }
+ }
+
+ aPropSet.setProperty( PROP_CustomLabelFields, makeAny( aSequence ) );
+ }
}
catch( Exception& )
{
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index caab75eae4d4..5c79a83ed756 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -279,6 +279,7 @@ LabelBorderWidth
LabelPlacement
LabelPosition
LabelSeparator
+CustomLabelFields
LayoutInfo
LeftBorder
LeftBorderDistance