summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-09-11 08:56:22 +0200
committerAndras Timar <andras.timar@collabora.com>2014-09-15 17:07:49 +0200
commit2592687ce6b08bb61d333a1879308e171926fac4 (patch)
tree5c85971b91173ef14d39a86c4073b8be54d13386 /chart2
parent5ca27fed34ac7bbf17140b3bc974b51678cde0c6 (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/11415 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/qa/extras/chart2import.cxx53
-rw-r--r--chart2/qa/extras/charttest.hxx12
-rwxr-xr-xchart2/qa/extras/data/xlsx/number-formats.xlsxbin0 -> 12638 bytes
3 files changed, 65 insertions, 0 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 14419037ff23..67ada3985f1d 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>
@@ -33,6 +34,7 @@ public:
void testPPTXChartSeries();
void testPPTChartSeries();
void testODPChartSeries();
+ void testNumberFormatsXLSX();
CPPUNIT_TEST_SUITE(Chart2ImportTest);
CPPUNIT_TEST(Fdo60083);
@@ -53,6 +55,7 @@ public:
// CPPUNIT_TEST(testPPTChartSeries);
// CPPUNIT_TEST(testPPTXChartSeries);
// CPPUNIT_TEST(testODPChartSeries);
+ CPPUNIT_TEST(testNumberFormatsXLSX);
CPPUNIT_TEST_SUITE_END();
private:
@@ -295,6 +298,56 @@ void Chart2ImportTest::testODPChartSeries()
}
+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("NumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat);
+ bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(false, bSuccess);
+ bSuccess = xPropertySet->getPropertyValue("LinkNumberFormatToSource") >>= 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("NumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat);
+ bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(false, bSuccess);
+ bSuccess = xPropertySet->getPropertyValue("LinkNumberFormatToSource") >>= 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("NumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nChartDataNumberFormat, nNumberFormat);
+ bSuccess = xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(false, bSuccess);
+ bSuccess = xPropertySet->getPropertyValue("LinkNumberFormatToSource") >>= 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 53a465bf05b9..216c915bbc57 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -38,6 +38,9 @@
#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 <iostream>
using namespace com::sun::star;
@@ -294,4 +297,13 @@ std::vector<uno::Sequence<uno::Any> > getDataSeriesLabelsFromChartType( const Re
return aRet;
}
+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
new file mode 100755
index 000000000000..f5250c52eceb
--- /dev/null
+++ b/chart2/qa/extras/data/xlsx/number-formats.xlsx
Binary files differ