[Libreoffice-commits] core.git: chart2/source offapi/com oox/source sc/source sw/qa xmloff/source

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Wed Sep 2 07:42:13 UTC 2020


 chart2/source/controller/chartapiwrapper/WrappedDataCaptionProperties.cxx |    4 ++
 chart2/source/controller/main/ChartController_Tools.cxx                   |    1 
 chart2/source/model/main/DataPointProperties.cxx                          |    3 +-
 chart2/source/tools/DataSeriesHelper.cxx                                  |    6 ++--
 chart2/source/view/main/VDataSeries.cxx                                   |    2 -
 offapi/com/sun/star/chart/ChartDataCaption.idl                            |    8 +++++
 offapi/com/sun/star/chart2/DataPointLabel.idl                             |    7 +++++
 oox/source/drawingml/chart/seriesconverter.cxx                            |   11 ++++---
 sc/source/filter/excel/xichart.cxx                                        |    2 -
 sw/qa/extras/layout/data/tdf136061.docx                                   |binary
 sw/qa/extras/layout/layout.cxx                                            |   14 ++++++++++
 xmloff/source/chart/SchXMLSeries2Context.cxx                              |    2 +
 12 files changed, 49 insertions(+), 11 deletions(-)

New commits:
commit 0d2340998415fb4b2f794054c62ef61c83e32155
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Sat Aug 29 13:44:37 2020 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Wed Sep 2 09:41:32 2020 +0200

    tdf#136061 Chart ODF/OOXML: fix missing custom labels
    
    by UNO extensions ShowCustomLabel in DataPointLabel.idl and
    CUSTOM in ChartDataCaption.idl, fixing OOXML/ODF import/export.
    
    We should display custom data label even if DataPointLabel is
    disabled (e.g. category name and/or value fields are not displayed).
    
    Note: import of the embedded chart of the DOCX unit test
    document uses also ODF format in the background, testing
    also the extension of the native file format.
    
    Change-Id: I73e21f1e69fddec9f3b4163c46b6582cd1c74b5d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101640
    Tested-by: Jenkins
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/source/controller/chartapiwrapper/WrappedDataCaptionProperties.cxx b/chart2/source/controller/chartapiwrapper/WrappedDataCaptionProperties.cxx
index f55540f67db8..c786c1b3913c 100644
--- a/chart2/source/controller/chartapiwrapper/WrappedDataCaptionProperties.cxx
+++ b/chart2/source/controller/chartapiwrapper/WrappedDataCaptionProperties.cxx
@@ -71,7 +71,7 @@ sal_Int32 lcl_LabelToCaption( const chart2::DataPointLabel& rLabel )
 
 chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
 {
-    chart2::DataPointLabel aLabel(false,false,false,false);
+    chart2::DataPointLabel aLabel(false,false,false,false,false);
 
     if( nCaption & css::chart::ChartDataCaption::VALUE )
         aLabel.ShowNumber = true;
@@ -81,6 +81,8 @@ chart2::DataPointLabel lcl_CaptionToLabel( sal_Int32 nCaption )
         aLabel.ShowCategoryName = true;
     if( nCaption & css::chart::ChartDataCaption::SYMBOL )
         aLabel.ShowLegendSymbol = true;
+    if( nCaption & css::chart::ChartDataCaption::CUSTOM )
+        aLabel.ShowCustomLabel = true;
 
     return aLabel;
 }
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 2d8435d9b436..3668321589db 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -761,6 +761,7 @@ bool ChartController::executeDispatch_Delete()
                     aLabel.ShowNumberInPercent = false;
                     aLabel.ShowCategoryName = false;
                     aLabel.ShowLegendSymbol = false;
+                    aLabel.ShowCustomLabel = false;
                     if( aObjectType == OBJECTTYPE_DATA_LABELS )
                     {
                         uno::Reference< chart2::XDataSeries > xSeries( ObjectIdentifier::getDataSeriesForCID( aCID, getModel() ));
diff --git a/chart2/source/model/main/DataPointProperties.cxx b/chart2/source/model/main/DataPointProperties.cxx
index dba488fdd924..dcc343002ffb 100644
--- a/chart2/source/model/main/DataPointProperties.cxx
+++ b/chart2/source/model/main/DataPointProperties.cxx
@@ -515,7 +515,8 @@ void DataPointProperties::AddDefaultsToMap(
             false, // ShowNumber
             false, // ShowNumberInPercent
             false, // ShowCategoryName
-            false  // ShowLegendSymbol
+            false, // ShowLegendSymbol
+            false  // ShowCustomLabel
             ));
 
     PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_TEXT_WORD_WRAP, false );
diff --git a/chart2/source/tools/DataSeriesHelper.cxx b/chart2/source/tools/DataSeriesHelper.cxx
index 11f6bf2d94b3..809ba67a931e 100644
--- a/chart2/source/tools/DataSeriesHelper.cxx
+++ b/chart2/source/tools/DataSeriesHelper.cxx
@@ -170,6 +170,7 @@ void lcl_insertOrDeleteDataLabelsToSeriesAndAllPoints( const Reference< chart2::
                         {
                             aLabel.ShowNumberInPercent = false;
                             aLabel.ShowCategoryName = false;
+                            aLabel.ShowCustomLabel = false;
                         }
                         xPointProp->setPropertyValue(CHART_UNONAME_LABEL, uno::Any(aLabel));
                     }
@@ -746,7 +747,7 @@ bool hasDataLabelsAtPoints( const Reference< chart2::XDataSeries >& xSeries )
                     {
                         DataPointLabel aLabel;
                         if( xPointProp->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel )
-                            bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName;
+                            bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName || aLabel.ShowCustomLabel;
                         if( bRet )
                             break;
                     }
@@ -784,7 +785,7 @@ bool hasDataLabelAtPoint( const Reference< chart2::XDataSeries >& xSeries, sal_I
             {
                 DataPointLabel aLabel;
                 if( xProp->getPropertyValue(CHART_UNONAME_LABEL) >>= aLabel )
-                    bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName;
+                    bRet = aLabel.ShowNumber || aLabel.ShowNumberInPercent || aLabel.ShowCategoryName || aLabel.ShowCustomLabel;
             }
         }
     }
@@ -834,6 +835,7 @@ void deleteDataLabelsFromPoint( const Reference< beans::XPropertySet >& xPointPr
             aLabel.ShowNumber = false;
             aLabel.ShowNumberInPercent = false;
             aLabel.ShowCategoryName = false;
+            aLabel.ShowCustomLabel = false;
             xPointProp->setPropertyValue(CHART_UNONAME_LABEL, uno::Any(aLabel));
         }
     }
diff --git a/chart2/source/view/main/VDataSeries.cxx b/chart2/source/view/main/VDataSeries.cxx
index 91388d1c2eda..db93d255fe21 100644
--- a/chart2/source/view/main/VDataSeries.cxx
+++ b/chart2/source/view/main/VDataSeries.cxx
@@ -996,7 +996,7 @@ DataPointLabel* VDataSeries::getDataPointLabelIfLabel( sal_Int32 index ) const
 {
     DataPointLabel* pLabel = getDataPointLabel( index );
     if( !pLabel || (!pLabel->ShowNumber && !pLabel->ShowNumberInPercent
-        && !pLabel->ShowCategoryName ) )
+        && !pLabel->ShowCategoryName && !pLabel->ShowCustomLabel ) )
         return nullptr;
     return pLabel;
 }
diff --git a/offapi/com/sun/star/chart/ChartDataCaption.idl b/offapi/com/sun/star/chart/ChartDataCaption.idl
index c0b589a2efe9..fb5da8034961 100644
--- a/offapi/com/sun/star/chart/ChartDataCaption.idl
+++ b/offapi/com/sun/star/chart/ChartDataCaption.idl
@@ -68,6 +68,14 @@ published constants ChartDataCaption
     /** The symbol of data column/row is additionally displayed in the caption.
      */
     const long SYMBOL = 16;
+
+
+    /** The caption contains a custom text, which belongs
+        to a data point label.
+
+        @since LibreOffice 7.1
+     */
+    const long CUSTOM = 32;
 };
 
 
diff --git a/offapi/com/sun/star/chart2/DataPointLabel.idl b/offapi/com/sun/star/chart2/DataPointLabel.idl
index 5963e8dd93b2..f16245c8797a 100644
--- a/offapi/com/sun/star/chart2/DataPointLabel.idl
+++ b/offapi/com/sun/star/chart2/DataPointLabel.idl
@@ -57,6 +57,13 @@ struct DataPointLabel
         caption.
      */
     boolean                     ShowLegendSymbol;
+
+    /** The caption contains a custom label text, which belongs
+        to a data point label.
+
+        @since LibreOffice 7.1
+     */
+    boolean                     ShowCustomLabel;
 };
 
 
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index b80ea05ae481..b1b6019dfb40 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -109,7 +109,7 @@ void convertTextProperty(PropertySet& rPropSet, ObjectFormatter& rFormatter,
 
 void lclConvertLabelFormatting( PropertySet& rPropSet, ObjectFormatter& rFormatter,
                                 const DataLabelModelBase& rDataLabel, const TypeGroupConverter& rTypeGroup,
-                                bool bDataSeriesLabel, bool bMSO2007Doc )
+                                bool bDataSeriesLabel, bool bCustomLabelField, bool bMSO2007Doc )
 {
     const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo();
 
@@ -137,7 +137,7 @@ void lclConvertLabelFormatting( PropertySet& rPropSet, ObjectFormatter& rFormatt
     // type of attached label
     if( bHasAnyElement || rDataLabel.mbDeleted )
     {
-        DataPointLabel aPointLabel( bShowValue, bShowPercent, bShowCateg, bShowSymbol );
+        DataPointLabel aPointLabel( bShowValue, bShowPercent, bShowCateg, bShowSymbol, bCustomLabelField );
         rPropSet.setProperty( PROP_Label, aPointLabel );
     }
 
@@ -271,7 +271,8 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
     {
         bool bMSO2007Doc = getFilter().isMSO2007Document();
         PropertySet aPropSet( rxDataSeries->getDataPointByIndex( mrModel.mnIndex ) );
-        lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, false, bMSO2007Doc );
+        bool bCustomLabelField = mrModel.mxText && mrModel.mxText->mxTextBody && !mrModel.mxText->mxTextBody->getParagraphs().empty();
+        lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, false, bCustomLabelField, bMSO2007Doc );
         const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo();
         bool bIsPie = rTypeInfo.meTypeCategory == TYPECATEGORY_PIE;
 
@@ -289,7 +290,7 @@ void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDat
             importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(),
                                  rHelper);
         }
-        if( mrModel.mxText && mrModel.mxText->mxTextBody && !mrModel.mxText->mxTextBody->getParagraphs().empty() )
+        if( bCustomLabelField )
         {
             css::uno::Reference< XComponentContext > xContext = getComponentContext();
             uno::Sequence< css::uno::Reference< XDataPointCustomLabelField > > aSequence;
@@ -405,7 +406,7 @@ void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDa
         // tdf#132174: the inner data table has no own cell number format.
         if( getChartDocument()->hasInternalDataProvider() && mrModel.mobShowVal.get(!bMSO2007Doc) )
             mrModel.maNumberFormat.mbSourceLinked = false;
-        lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, true, bMSO2007Doc );
+        lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, true, false, bMSO2007Doc );
 
         if (mrModel.mxShapeProp)
         {
diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index 4683fec797b9..43f6d7c2ccb8 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -1102,7 +1102,7 @@ void XclImpChText::ConvertDataLabel( ScfPropertySet& rPropSet, const XclChTypeIn
     bool bShowSymbol = bShowAny && ::get_flag( maData.mnFlags, EXC_CHTEXT_SHOWSYMBOL );
 
     // create API struct for label values, set API label separator
-    cssc2::DataPointLabel aPointLabel( bShowValue, bShowPercent, bShowCateg, bShowSymbol );
+    cssc2::DataPointLabel aPointLabel( bShowValue, bShowPercent, bShowCateg, bShowSymbol, false );
     rPropSet.SetProperty( EXC_CHPROP_LABEL, aPointLabel );
     OUString aSep = mxLabelProps ? mxLabelProps->maSeparator : OUString('\n');
     if( aSep.isEmpty() )
diff --git a/sw/qa/extras/layout/data/tdf136061.docx b/sw/qa/extras/layout/data/tdf136061.docx
new file mode 100644
index 000000000000..c91e3438ffbf
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf136061.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 5e8f2d89eed4..008419887c75 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -3068,6 +3068,20 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf134146)
     assertXPath(pXmlDoc, "//textarray", 14);
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf136061)
+{
+    SwDoc* pDoc = createDoc("tdf136061.docx");
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocUniquePtr pXmlDoc = dumpAndParse(dumper, *xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+    // This failed, if the custom text of data label is missing.
+    assertXPathContent(pXmlDoc, "//textarray[16]/text", "Customlabel");
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf116925)
 {
     SwDoc* pDoc = createDoc("tdf116925.docx");
diff --git a/xmloff/source/chart/SchXMLSeries2Context.cxx b/xmloff/source/chart/SchXMLSeries2Context.cxx
index 11031697a180..5a9ef3800060 100644
--- a/xmloff/source/chart/SchXMLSeries2Context.cxx
+++ b/xmloff/source/chart/SchXMLSeries2Context.cxx
@@ -36,6 +36,7 @@
 
 #include <com/sun/star/chart/ChartAxisAssign.hpp>
 #include <com/sun/star/chart/ChartSymbolType.hpp>
+#include <com/sun/star/chart/ChartDataCaption.hpp>
 #include <com/sun/star/chart/ErrorBarStyle.hpp>
 #include <com/sun/star/chart/XChartDocument.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -1142,6 +1143,7 @@ void SchXMLSeries2Context::setStylesToDataPoints( SeriesDefaultsAndStyles& rSeri
                         }
                     }
                     xPointProp->setPropertyValue("CustomLabelFields", uno::Any(xLabels));
+                    xPointProp->setPropertyValue("DataCaption", uno::Any(chart::ChartDataCaption::CUSTOM));
                 }
 
                 if( seriesStyle.mCustomLabelPos[0] != 0.0 || seriesStyle.mCustomLabelPos[1] != 0.0 )


More information about the Libreoffice-commits mailing list