[Libreoffice-commits] core.git: 3 commits - chart2/qa oox/source
Matúš Kukan
matus.kukan at collabora.com
Tue Jul 29 13:59:26 PDT 2014
chart2/qa/extras/chart2import.cxx | 68 ++++++++++++++
chart2/qa/extras/charttest.hxx | 9 +
chart2/qa/extras/data/pptx/percentage-number-formats.pptx |binary
oox/source/drawingml/chart/modelbase.cxx | 3
oox/source/drawingml/chart/objectformatter.cxx | 11 +-
oox/source/drawingml/chart/seriesconverter.cxx | 5 -
6 files changed, 88 insertions(+), 8 deletions(-)
New commits:
commit dbe2da93340cb0b693f49afc93812199a39bb118
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Tue Jul 29 21:09:08 2014 +0200
Add chart import, percentage number formats, unit test.
Change-Id: Id1b73c153f4b09ab94446452e7eb096b529473f4
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index 7851291..659987a 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -10,6 +10,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:
* hidden columns for internal data table yet).
*/
void testPPTXHiddenDataSeries();
+ void testPPTXPercentageNumberFormats();
void testPPTXStackedNonStackedYAxis();
void testPPTChartSeries();
void testODPChartSeries();
@@ -71,6 +73,7 @@ public:
CPPUNIT_TEST(testPPTChartSeries);
CPPUNIT_TEST(testPPTXChartSeries);
CPPUNIT_TEST(testPPTXHiddenDataSeries);
+ CPPUNIT_TEST(testPPTXPercentageNumberFormats);
CPPUNIT_TEST(testPPTXStackedNonStackedYAxis);
CPPUNIT_TEST(testODPChartSeries);
CPPUNIT_TEST(testBnc864396);
@@ -367,6 +370,71 @@ void Chart2ImportTest::testPPTXHiddenDataSeries()
CPPUNIT_ASSERT_EQUAL(OUString("Category 4"), aCategories[3][0]);
}
+void Chart2ImportTest::testPPTXPercentageNumberFormats()
+{
+ load("/chart2/qa/extras/data/pptx/", "percentage-number-formats.pptx");
+
+ // 1st chart
+ Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(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;
+ const sal_Int32 nPercentFormatSimple = getNumberFormat(xChartDoc, "0%");
+ const sal_Int32 nPercentFormatDecimal = getNumberFormat(xChartDoc, "0.00%");
+
+ 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("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple, nNumberFormat);
+
+ xPropertySet.set(xDataSeries->getDataPointByIndex(1), uno::UNO_QUERY_THROW);
+ xPropertySet->getPropertyValue("Label") >>= aLabel;
+ CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumber);
+ CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
+ xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal, nNumberFormat);
+
+ 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("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nPercentFormatSimple, nNumberFormat);
+
+ xPropertySet.set(xDataSeries->getDataPointByIndex(3), uno::UNO_QUERY_THROW);
+ xPropertySet->getPropertyValue("Label") >>= aLabel;
+ CPPUNIT_ASSERT_EQUAL(sal_False, aLabel.ShowNumber);
+ CPPUNIT_ASSERT_EQUAL(sal_True, aLabel.ShowNumberInPercent);
+ xPropertySet->getPropertyValue("PercentageNumberFormat") >>= nNumberFormat;
+ CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimal, nNumberFormat);
+
+ // 2nd chart
+ xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
+ CPPUNIT_ASSERT(xYAxis.is());
+
+ Reference<beans::XPropertySet> xPS(xYAxis, uno::UNO_QUERY_THROW);
+ bool bLinkNumberFormatToSource = true;
+ bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_LINK_TO_SRC_NUMFMT) >>= bLinkNumberFormatToSource;
+ CPPUNIT_ASSERT_MESSAGE("\"LinkNumberFormatToSource\" should be set to false.", bSuccess && !bLinkNumberFormatToSource);
+
+ // FIXME: This should be in fact "0.00%".
+ // see TODO in oox/source/drawingml/chart/modelbase.cxx
+ const sal_Int32 nPercentFormatDecimalShort = getNumberFormat(xChartDoc, "0.0%");
+ nNumberFormat = getNumberFormatFromAxis(xYAxis);
+ CPPUNIT_ASSERT_EQUAL(nPercentFormatDecimalShort, nNumberFormat);
+ sal_Int16 nType = getNumberFormatType(xChartDoc, nNumberFormat);
+ CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType & util::NumberFormat::PERCENT));
+}
+
void Chart2ImportTest::testPPTXStackedNonStackedYAxis()
{
load("/chart2/qa/extras/data/pptx/", "stacked-non-stacked-mix-y-axis.pptx");
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index 318bac2..7c53b95 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -494,6 +494,15 @@ OUString getTitleString( const Reference<chart2::XTitled>& xTitled )
return aText;
}
+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);
+}
+
sal_Int32 getNumberFormatFromAxis( const Reference<chart2::XAxis>& xAxis )
{
Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY);
diff --git a/chart2/qa/extras/data/pptx/percentage-number-formats.pptx b/chart2/qa/extras/data/pptx/percentage-number-formats.pptx
new file mode 100755
index 0000000..280c7ef
Binary files /dev/null and b/chart2/qa/extras/data/pptx/percentage-number-formats.pptx differ
commit c8cc89ff802d86b1f3a69afe1b4835b7df7f70c7
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Tue Jul 29 21:10:22 2014 +0200
Fix some number format issues, bnc#862510
Set "LinkNumberFormatToSource" to false, so that format code is not
ignored.
Also, do not inherit format code common for all labels, if there is
specific format code for a data label.
Change-Id: I505311d5df641d61e616e354734bd332609fa122
diff --git a/oox/source/drawingml/chart/modelbase.cxx b/oox/source/drawingml/chart/modelbase.cxx
index d3e6961..27cb179 100644
--- a/oox/source/drawingml/chart/modelbase.cxx
+++ b/oox/source/drawingml/chart/modelbase.cxx
@@ -33,8 +33,7 @@ NumberFormat::NumberFormat() :
void NumberFormat::setAttributes( const AttributeList& rAttribs )
{
maFormatCode = rAttribs.getString( XML_formatCode, OUString() );
- // default is 'false', not 'true' as specified
- mbSourceLinked = rAttribs.getBool( XML_sourceLinked, false );
+ // TODO: if XML_sourceLinked is true, <c:formatCode> should be used instead.
}
LayoutModel::LayoutModel() :
diff --git a/oox/source/drawingml/chart/objectformatter.cxx b/oox/source/drawingml/chart/objectformatter.cxx
index 3b91afe..89fa237 100644
--- a/oox/source/drawingml/chart/objectformatter.cxx
+++ b/oox/source/drawingml/chart/objectformatter.cxx
@@ -1106,7 +1106,9 @@ void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFo
append( OUStringToOString( rNumberFormat.maFormatCode, osl_getThreadTextEncoding() ) ).append( '\'' ).getStr() );
}
- rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.mbSourceLinked));
+ // Format code is ignored if "LinkNumberFormatToSource" is set to "true" :-/
+ // See AxisHelper::getExplicitNumberFormatKeyForAxis()
+ rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.maFormatCode.isEmpty()));
}
}
diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx
index 5326ff4..b1b9960 100644
--- a/oox/source/drawingml/chart/seriesconverter.cxx
+++ b/oox/source/drawingml/chart/seriesconverter.cxx
@@ -253,9 +253,8 @@ void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDa
// data point label settings
for( DataLabelsModel::DataLabelVector::iterator aIt = mrModel.maPointLabels.begin(), aEnd = mrModel.maPointLabels.end(); aIt != aEnd; ++aIt )
{
- (*aIt)->maNumberFormat.maFormatCode = mrModel.maNumberFormat.maFormatCode;
- if( !mrModel.maNumberFormat.maFormatCode.isEmpty() )
- (*aIt)->maNumberFormat.mbSourceLinked = false;
+ if ((*aIt)->maNumberFormat.maFormatCode.isEmpty())
+ (*aIt)->maNumberFormat = mrModel.maNumberFormat;
DataLabelConverter aLabelConv( *this, **aIt );
aLabelConv.convertFromModel( rxDataSeries, rTypeGroup );
commit 5f47e319428a703ea53ce49d166e7628aaa60789
Author: Matúš Kukan <matus.kukan at collabora.com>
Date: Tue Jul 29 07:53:22 2014 +0200
bnc#862510: PPTX import: Properly show data labels in percent format.
Usually, "General" is "0.00" number format, but in this case, when we
want to show percent value, MSO writes that instead of "0%".
Change-Id: I748719765f58e66f9f3fb43c2b527c6823ef6fa1
diff --git a/oox/source/drawingml/chart/objectformatter.cxx b/oox/source/drawingml/chart/objectformatter.cxx
index b919e6b..3b91afe 100644
--- a/oox/source/drawingml/chart/objectformatter.cxx
+++ b/oox/source/drawingml/chart/objectformatter.cxx
@@ -1091,9 +1091,12 @@ void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFo
sal_Int32 nPropId = bPercentFormat ? PROP_PercentageNumberFormat : PROP_NumberFormat;
try
{
- sal_Int32 nIndex = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general") ?
+ bool bGeneral = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general");
+ sal_Int32 nIndex = bGeneral && !bPercentFormat ?
mxData->mxNumTypes->getStandardIndex( mxData->maFromLocale ) :
- mxData->mxNumFmts->addNewConverted( rNumberFormat.maFormatCode, mxData->maEnUsLocale, mxData->maFromLocale );
+ mxData->mxNumFmts->addNewConverted(
+ bGeneral ? OUString("0%") : rNumberFormat.maFormatCode,
+ mxData->maEnUsLocale, mxData->maFromLocale );
if( nIndex >= 0 )
rPropSet.setProperty( nPropId, nIndex );
}
More information about the Libreoffice-commits
mailing list