[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - chart2/qa sc/source

Dennis Francis dennis.francis at collabora.co.uk
Wed Aug 2 06:34:06 UTC 2017


 chart2/qa/extras/chart2export.cxx                   |   61 ++++++++++++++++++++
 chart2/qa/extras/data/xls/axis_sourceformatting.xls |binary
 sc/source/filter/excel/xechart.cxx                  |    6 +
 sc/source/filter/excel/xichart.cxx                  |   15 +++-
 sc/source/filter/inc/xlchart.hxx                    |    1 
 5 files changed, 79 insertions(+), 4 deletions(-)

New commits:
commit adf049390cceb11df6ba438f30138d6f92d13b41
Author: Dennis Francis <dennis.francis at collabora.co.uk>
Date:   Mon Jul 31 10:52:55 2017 +0530

    tdf#90352: set/handle LinkNumberFormatToSource property in xls...
    
    Import/Export filter respectively for axis numbers. For ods and
    xlsx this was already getting set/handled correctly.
    
    Also add unit test to assert LinkNumberFormatToSource property
    and number format for import and export-import roundtrip.
    
    Change-Id: Id029ac7d0233ca490a6a00609e9cea8fdafee70f
    Reviewed-on: https://gerrit.libreoffice.org/40577
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    (cherry picked from commit d8e731adb8608aab17385e02f4441ed3122efa40)
    Reviewed-on: https://gerrit.libreoffice.org/40664

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 5975c7a3cfa2..e6b500c32b26 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -71,6 +71,7 @@ public:
     void testFdo78290ScatterChartMarkerX();
     void testFdo78290CombinationChartMarkerX();
     void testAxisNumberFormatODS();
+    void testAxisNumberFormatXLS();
     void testDataLabelBordersDOCX();
     void testDataLabel3DChartDOCX();
     void testDataLabelBarChartDOCX();
@@ -135,6 +136,7 @@ public:
     CPPUNIT_TEST(testFdo78290ScatterChartMarkerX);
     CPPUNIT_TEST(testFdo78290CombinationChartMarkerX);
     CPPUNIT_TEST(testAxisNumberFormatODS);
+    CPPUNIT_TEST(testAxisNumberFormatXLS);
     CPPUNIT_TEST(testDataLabelBordersDOCX);
     CPPUNIT_TEST(testDataLabel3DChartDOCX);
     CPPUNIT_TEST(testDataLabelBarChartDOCX);
@@ -759,6 +761,65 @@ void Chart2ExportTest::testAxisNumberFormatODS()
     aTest.check(xChartDoc);
 }
 
+void Chart2ExportTest::testAxisNumberFormatXLS()
+{
+    struct
+    {
+        void check( const Reference<chart2::XChartDocument>& xChartDoc, bool bNumFmtLinkedActual, sal_Int16 nNumFmtTypeFlag ) const
+        {
+            Reference<chart2::XAxis> xAxisY = getAxisFromDoc( xChartDoc, 0, 1, 0 );
+            bool bNumFmtLinked = false;
+            Reference<beans::XPropertySet> xPS( xAxisY, uno::UNO_QUERY_THROW );
+            xPS->getPropertyValue( "LinkNumberFormatToSource" ) >>= bNumFmtLinked;
+
+            if ( bNumFmtLinkedActual )
+                CPPUNIT_ASSERT_MESSAGE( "Y axis should have its number format linked to source.", bNumFmtLinked );
+            else
+            {
+                CPPUNIT_ASSERT_MESSAGE( "Y axis should not have its number format linked to source.", !bNumFmtLinked );
+
+                sal_Int32 nNumFmt = getNumberFormatFromAxis( xAxisY );
+                sal_Int16 nType = getNumberFormatType( xChartDoc, nNumFmt );
+                if ( nNumFmtTypeFlag == util::NumberFormat::PERCENT )
+                    CPPUNIT_ASSERT_MESSAGE( "Y axis should be percentage format.", ( nType & util::NumberFormat::PERCENT ) );
+                else
+                    CPPUNIT_ASSERT_MESSAGE( "Y axis should be number format.", ( nType & util::NumberFormat::NUMBER ) );
+            }
+        }
+
+        void change( const Reference<chart2::XChartDocument>& xChartDoc, bool bSetNumFmtLinked, sal_Int16 nNumFmtTypeFlag )
+        {
+            Reference<chart2::XAxis> xAxisY = getAxisFromDoc( xChartDoc, 0, 1, 0 );
+            Reference<beans::XPropertySet> xPS( xAxisY, uno::UNO_QUERY_THROW );
+            Any aAny( bSetNumFmtLinked );
+            xPS->setPropertyValue( "LinkNumberFormatToSource", aAny );
+            if ( !bSetNumFmtLinked )
+            {
+                Reference<util::XNumberFormatsSupplier> xNFS( xChartDoc, uno::UNO_QUERY_THROW );
+                Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
+                CPPUNIT_ASSERT( xNumberFormats.is() );
+                lang::Locale aLocale{ "en", "US", "" };
+                Sequence<sal_Int32> aNumFmts = xNumberFormats->queryKeys( nNumFmtTypeFlag, aLocale, false );
+                CPPUNIT_ASSERT( aNumFmts.hasElements() );
+                aAny <<= aNumFmts[0];
+                xPS->setPropertyValue( CHART_UNONAME_NUMFMT, aAny );
+            }
+        }
+
+    } aTest;
+
+    load( "/chart2/qa/extras/data/xls/", "axis_sourceformatting.xls" );
+
+    Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet( 0, mxComponent );
+    aTest.check( xChartDoc, true, util::NumberFormat::PERCENT );
+
+    aTest.change( xChartDoc, false, util::NumberFormat::NUMBER );
+    // Write the document(xls) with changes made close it, load it and check if changes are intact
+    reload( "MS Excel 97" );
+    xChartDoc = getChartDocFromSheet( 0, mxComponent );
+    aTest.check( xChartDoc, false, util::NumberFormat::NUMBER );
+}
+
 void Chart2ExportTest::testDataLabelBordersDOCX()
 {
     struct Check
diff --git a/chart2/qa/extras/data/xls/axis_sourceformatting.xls b/chart2/qa/extras/data/xls/axis_sourceformatting.xls
new file mode 100644
index 000000000000..2ee38b720857
Binary files /dev/null and b/chart2/qa/extras/data/xls/axis_sourceformatting.xls differ
diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx
index e7d19e5227c4..e27b02120314 100644
--- a/sc/source/filter/excel/xechart.cxx
+++ b/sc/source/filter/excel/xechart.cxx
@@ -3001,7 +3001,11 @@ void XclExpChAxis::Convert( Reference< XAxis > const & xAxis, Reference< XAxis >
     // axis number format
     sal_Int32 nApiNumFmt = 0;
     if( !bCategoryAxis && aAxisProp.GetProperty( nApiNumFmt, EXC_CHPROP_NUMBERFORMAT ) )
-        mnNumFmtIdx = GetNumFmtBuffer().Insert( static_cast< sal_uInt32 >( nApiNumFmt ) );
+    {
+        bool bLinkNumberFmtToSource = false;
+        if ( !aAxisProp.GetProperty( bLinkNumberFmtToSource, EXC_CHPROP_NUMBERFORMAT_LINKSRC ) || !bLinkNumberFmtToSource )
+            mnNumFmtIdx = GetNumFmtBuffer().Insert( static_cast< sal_uInt32 >( nApiNumFmt ) );
+    }
 
     // grid -------------------------------------------------------------------
 
diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index 5a9a6ff47943..9eda9e33c883 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -3322,9 +3322,18 @@ Reference< XAxis > XclImpChAxis::CreateAxis( const XclImpChTypeGroup& rTypeGroup
             // label text rotation
             ConvertRotationBase( aAxisProp, true );
             // number format
-            sal_uInt32 nScNumFmt = GetNumFmtBuffer().GetScFormat( mnNumFmtIdx );
-            if( nScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND )
-                aAxisProp.SetProperty( EXC_CHPROP_NUMBERFORMAT, static_cast< sal_Int32 >( nScNumFmt ) );
+            bool bLinkNumberFmtToSource = true;
+            if ( mnNumFmtIdx != EXC_FORMAT_NOTFOUND )
+            {
+                sal_uInt32 nScNumFmt = GetNumFmtBuffer().GetScFormat( mnNumFmtIdx );
+                if( nScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND )
+                {
+                    aAxisProp.SetProperty( EXC_CHPROP_NUMBERFORMAT, static_cast< sal_Int32 >( nScNumFmt ) );
+                    bLinkNumberFmtToSource = false;
+                }
+            }
+
+            aAxisProp.SetProperty( EXC_CHPROP_NUMBERFORMAT_LINKSRC, bLinkNumberFmtToSource );
         }
 
         // axis scaling and increment -----------------------------------------
diff --git a/sc/source/filter/inc/xlchart.hxx b/sc/source/filter/inc/xlchart.hxx
index 32bbc177e926..67cc3646e379 100644
--- a/sc/source/filter/inc/xlchart.hxx
+++ b/sc/source/filter/inc/xlchart.hxx
@@ -96,6 +96,7 @@ class XclRoot;
 #define EXC_CHPROP_MOVING_AVERAGE_PERIOD    "MovingAveragePeriod"
 #define EXC_CHPROP_NEGATIVEERROR            "NegativeError"
 #define EXC_CHPROP_NUMBERFORMAT             "NumberFormat"
+#define EXC_CHPROP_NUMBERFORMAT_LINKSRC     "LinkNumberFormatToSource"
 #define EXC_CHPROP_OFFSET                   "Offset"
 #define EXC_CHPROP_OVERLAPSEQ               "OverlapSequence"
 #define EXC_CHPROP_PERCENTAGENUMFMT         "PercentageNumberFormat"


More information about the Libreoffice-commits mailing list