diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-09-11 08:56:22 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-09-12 13:03:17 +0000 |
commit | 7c3dd4a9c1a05bbb6867ca6db6229da38f5f68ed (patch) | |
tree | b90e1ca3f027b70a37f997aefc85b15aba313a9f /chart2 | |
parent | fe8b83f06fdc93ac06f4035c3ea50c51d0e3d026 (diff) |
bnc#892610: OOXML import: Improve chart number formats.
If sourceLinked is used, do not set "PercentageNumberFormat" even if
showPercent is true. The format string should be used for "NumberFormat".
c8cc89ff802d86b1f3a69afe1b4835b7df7f70c7 unnecessarily disabled
"LinkNumberFormatToSource". Use that for data labels but not for axis.
Also, actually make attaching number format supplier work for Calc.
Previously, non standard formats were added into wrong supplier,
and they were thrown away later because it was attached too late.
(See also ChartModel::attachNumberFormatsSupplier)
(cherry picked from commit d22a4d945ccf1456fbdb2c39802d956afa583a2a)
Conflicts:
chart2/qa/extras/chart2import.cxx
oox/source/drawingml/chart/chartconverter.cxx
Change-Id: Iaf9945abc3d82d0ac63d9f36b8888eb49f39ab57
Reviewed-on: https://gerrit.libreoffice.org/11414
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/CppunitTest_chart2_export.mk | 1 | ||||
-rw-r--r-- | chart2/CppunitTest_chart2_import.mk | 1 | ||||
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 53 | ||||
-rw-r--r-- | chart2/qa/extras/charttest.hxx | 14 | ||||
-rwxr-xr-x | chart2/qa/extras/data/xlsx/number-formats.xlsx | bin | 0 -> 12638 bytes |
5 files changed, 69 insertions, 0 deletions
diff --git a/chart2/CppunitTest_chart2_export.mk b/chart2/CppunitTest_chart2_export.mk index 55127d7ceaab..e2a3f31e239d 100644 --- a/chart2/CppunitTest_chart2_export.mk +++ b/chart2/CppunitTest_chart2_export.mk @@ -60,6 +60,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_export, \ )) $(eval $(call gb_CppunitTest_set_include,chart2_export,\ + -I$(SRCDIR)/chart2/inc \ $$(INCLUDE) \ )) diff --git a/chart2/CppunitTest_chart2_import.mk b/chart2/CppunitTest_chart2_import.mk index 5ae09fddc7d9..3e25b36a53dc 100644 --- a/chart2/CppunitTest_chart2_import.mk +++ b/chart2/CppunitTest_chart2_import.mk @@ -59,6 +59,7 @@ $(eval $(call gb_CppunitTest_use_libraries,chart2_import, \ )) $(eval $(call gb_CppunitTest_set_include,chart2_import,\ + -I$(SRCDIR)/chart2/inc \ $$(INCLUDE) \ )) diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 47df59fbe691..7cff8fd1d8e4 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -11,6 +11,7 @@ #include "charttest.hxx" #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/chart2/CurveStyle.hpp> +#include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart/XChartDocument.hpp> @@ -40,6 +41,7 @@ public: void testSimpleStrictXLSX(); void testDelayedCellImport(); // chart range referencing content on later sheets void testFlatODSStackedColumnChart(); + void testNumberFormatsXLSX(); CPPUNIT_TEST_SUITE(Chart2ImportTest); CPPUNIT_TEST(Fdo60083); @@ -65,6 +67,7 @@ public: CPPUNIT_TEST(testSimpleStrictXLSX); CPPUNIT_TEST(testDelayedCellImport); CPPUNIT_TEST(testFlatODSStackedColumnChart); + CPPUNIT_TEST(testNumberFormatsXLSX); CPPUNIT_TEST_SUITE_END(); private: @@ -384,6 +387,56 @@ void Chart2ImportTest::testFlatODSStackedColumnChart() CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aSeriesSeq.getLength()); } +void Chart2ImportTest::testNumberFormatsXLSX() +{ + load("/chart2/qa/extras/data/xlsx/", "number-formats.xlsx"); + Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent); + CPPUNIT_ASSERT_MESSAGE("failed to load chart", xChartDoc.is()); + + uno::Reference<chart2::XDataSeries> xDataSeries(getDataSeriesFromDoc(xChartDoc, 0)); + CPPUNIT_ASSERT(xDataSeries.is()); + uno::Reference<beans::XPropertySet> xPropertySet; + chart2::DataPointLabel aLabel; + sal_Int32 nNumberFormat; + bool bLinkNumberFormatToSource = false; + bool bSuccess = false; + const sal_Int32 nChartDataNumberFormat = getNumberFormat( + xChartDoc, "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"??_);_(@_)"); + + xPropertySet.set(xDataSeries->getDataPointByIndex(0), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat); + bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(false, bSuccess); + bSuccess = xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource; + CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource); + + xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat); + bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(false, bSuccess); + bSuccess = xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource; + CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource); + + xPropertySet.set(xDataSeries->getDataPointByIndex(2), uno::UNO_QUERY_THROW); + xPropertySet->getPropertyValue("Label") >>= aLabel; + CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber); + CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent); + xPropertySet->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat); + bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat; + CPPUNIT_ASSERT_EQUAL(false, bSuccess); + bSuccess = xPropertySet->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource; + CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to true.", bSuccess && bLinkNumberFormatToSource); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx index 7e260cc415ca..b933b306cb37 100644 --- a/chart2/qa/extras/charttest.hxx +++ b/chart2/qa/extras/charttest.hxx @@ -40,6 +40,11 @@ #include <com/sun/star/chart/XChartDataArray.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> #include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/util/NumberFormat.hpp> + +#include <unonames.hxx> + #include <iostream> #include <libxml/xmlwriter.h> @@ -403,4 +408,13 @@ uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const c return seriesList; } +sal_Int32 getNumberFormat( const Reference<chart2::XChartDocument>& xChartDoc, const OUString& sFormat ) +{ + Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW); + Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats(); + CPPUNIT_ASSERT(xNumberFormats.is()); + + return xNumberFormats->queryKey(sFormat, css::lang::Locale(), sal_False); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/qa/extras/data/xlsx/number-formats.xlsx b/chart2/qa/extras/data/xlsx/number-formats.xlsx Binary files differnew file mode 100755 index 000000000000..f5250c52eceb --- /dev/null +++ b/chart2/qa/extras/data/xlsx/number-formats.xlsx |