[Libreoffice-commits] core.git: 3 commits - chart2/qa oox/inc oox/source
Kohei Yoshida
kohei.yoshida at collabora.com
Mon Jul 7 16:06:28 PDT 2014
chart2/qa/extras/chart2export.cxx | 28 ----
chart2/qa/extras/chart2import.cxx | 61 ++++++++++
chart2/qa/extras/charttest.hxx | 36 +++++
chart2/qa/extras/data/pptx/stacked-non-stacked-mix-y-axis.pptx |binary
oox/inc/drawingml/chart/axisconverter.hxx | 10 -
oox/source/drawingml/chart/axisconverter.cxx | 46 +++++--
oox/source/drawingml/chart/objectformatter.cxx | 8 -
oox/source/drawingml/chart/plotareaconverter.cxx | 6
oox/source/token/properties.txt | 1
9 files changed, 141 insertions(+), 55 deletions(-)
New commits:
commit dc4355e51764d18b36f748e7a743abde53cf9b9f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Jul 7 19:04:41 2014 -0400
bnc#881025: Write test for this.
Change-Id: Ifb1f83bbe5f9bb9ecb7fca26f883d1331052f10d
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 68f6091..899ff10 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -719,27 +719,17 @@ void Chart2ExportTest::testAxisNumberFormatODS()
{
void check( const Reference<chart2::XChartDocument>& xChartDoc )
{
- Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, UNO_QUERY_THROW);
- Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
- CPPUNIT_ASSERT(xNumberFormats.is());
-
Reference<chart2::XAxis> xAxisX = getAxisFromDoc(xChartDoc, 0, 0, 0);
Reference<chart2::XTitled> xTitle(xAxisX, UNO_QUERY_THROW);
OUString aTitleText = getTitleString(xTitle);
CPPUNIT_ASSERT_EQUAL(OUString("Linked To Source"), aTitleText);
- Reference<beans::XPropertySet> xPS(xAxisX, UNO_QUERY_THROW);
-
- sal_Int32 nNumFmt = -1;
- xPS->getPropertyValue("NumberFormat") >>= nNumFmt;
- CPPUNIT_ASSERT_MESSAGE("Failed to get a number format value from X axis.", nNumFmt != -1);
- Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumFmt);
- CPPUNIT_ASSERT(xNumPS.is());
- sal_Int16 nType = util::NumberFormat::UNDEFINED;
- xNumPS->getPropertyValue("Type") >>= nType;
+ sal_Int32 nNumFmt = getNumberFormatFromAxis(xAxisX);
+ sal_Int16 nType = getNumberFormatType(xChartDoc, nNumFmt);
CPPUNIT_ASSERT_MESSAGE("X axis should be percentage format.", (nType & util::NumberFormat::PERCENT));
bool bNumFmtLinked = false;
+ Reference<beans::XPropertySet> xPS(xAxisX, uno::UNO_QUERY_THROW);
xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked;
CPPUNIT_ASSERT_MESSAGE("X axis should have its number format linked to source.", bNumFmtLinked);
@@ -748,18 +738,12 @@ void Chart2ExportTest::testAxisNumberFormatODS()
aTitleText = getTitleString(xTitle);
CPPUNIT_ASSERT_EQUAL(OUString("Not Linked"), aTitleText);
- xPS.set(xAxisY, UNO_QUERY_THROW);
-
- nNumFmt = -1;
- xPS->getPropertyValue("NumberFormat") >>= nNumFmt;
- CPPUNIT_ASSERT_MESSAGE("Failed to get a number format value from Y axis.", nNumFmt != -1);
- xNumPS = xNumberFormats->getByKey(nNumFmt);
- CPPUNIT_ASSERT(xNumPS.is());
- nType = util::NumberFormat::UNDEFINED;
- xNumPS->getPropertyValue("Type") >>= nType;
+ nNumFmt = getNumberFormatFromAxis(xAxisY);
+ nType = getNumberFormatType(xChartDoc, nNumFmt);
CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
bNumFmtLinked = true;
+ xPS.set(xAxisY, uno::UNO_QUERY_THROW);
xPS->getPropertyValue("LinkNumberFormatToSource") >>= bNumFmtLinked;
CPPUNIT_ASSERT_MESSAGE("Y axis should not have its number format linked to source.", !bNumFmtLinked);
}
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index e0728ed..7851291 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -40,6 +40,7 @@ public:
* hidden columns for internal data table yet).
*/
void testPPTXHiddenDataSeries();
+ void testPPTXStackedNonStackedYAxis();
void testPPTChartSeries();
void testODPChartSeries();
void testBnc864396();
@@ -70,6 +71,7 @@ public:
CPPUNIT_TEST(testPPTChartSeries);
CPPUNIT_TEST(testPPTXChartSeries);
CPPUNIT_TEST(testPPTXHiddenDataSeries);
+ CPPUNIT_TEST(testPPTXStackedNonStackedYAxis);
CPPUNIT_TEST(testODPChartSeries);
CPPUNIT_TEST(testBnc864396);
CPPUNIT_TEST(testBnc882383);
@@ -365,6 +367,65 @@ void Chart2ImportTest::testPPTXHiddenDataSeries()
CPPUNIT_ASSERT_EQUAL(OUString("Category 4"), aCategories[3][0]);
}
+void Chart2ImportTest::testPPTXStackedNonStackedYAxis()
+{
+ load("/chart2/qa/extras/data/pptx/", "stacked-non-stacked-mix-y-axis.pptx");
+
+ // 1st chart is a normal stacked column.
+ Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ Reference<chart2::XTitled> xTitled(xChartDoc, uno::UNO_QUERY_THROW);
+ OUString aTitle = getTitleString(xTitled);
+ CPPUNIT_ASSERT_EQUAL(OUString("Stacked"), aTitle);
+
+ // Get the Y-axis.
+ Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
+ CPPUNIT_ASSERT(xYAxis.is());
+
+ sal_Int32 nNumberFormat = getNumberFormatFromAxis(xYAxis);
+ sal_Int16 nType = getNumberFormatType(xChartDoc, nNumberFormat);
+ CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
+ CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType & util::NumberFormat::PERCENT));
+
+ // 2nd chart is a percent-stacked column.
+ xChartDoc.set(getChartDocFromDrawImpress(1, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ xTitled.set(xChartDoc, uno::UNO_QUERY_THROW);
+ aTitle = getTitleString(xTitled);
+ CPPUNIT_ASSERT_EQUAL(OUString("100% Stacked"), aTitle);
+
+ // Get the Y-axis.
+ xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
+ CPPUNIT_ASSERT(xYAxis.is());
+
+ // Get the number format of the Y-axis.
+ nNumberFormat = getNumberFormatFromAxis(xYAxis);
+ nType = getNumberFormatType(xChartDoc, nNumberFormat);
+ CPPUNIT_ASSERT_MESSAGE("Y axis should be a percent format.", (nType & util::NumberFormat::PERCENT));
+
+ // 3rd chart is a mixture of normal-stacked column with a percent-stacked
+ // area chart series. Excel in this case sets the Y-axis to be
+ // non-percent axis and we should do the same for interoperability.
+ xChartDoc.set(getChartDocFromDrawImpress(2, 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ xTitled.set(xChartDoc, uno::UNO_QUERY_THROW);
+ aTitle = getTitleString(xTitled);
+ CPPUNIT_ASSERT_EQUAL(OUString("Stacked column mixed with 100% stacked area"), aTitle);
+
+ // Get the Y-axis.
+ xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
+ CPPUNIT_ASSERT(xYAxis.is());
+
+ // Get the number format of the Y-axis.
+ nNumberFormat = getNumberFormatFromAxis(xYAxis);
+ nType = getNumberFormatType(xChartDoc, nNumberFormat);
+ CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
+ CPPUNIT_ASSERT_MESSAGE("Y axis should NOT be a percent format.", !(nType & util::NumberFormat::PERCENT));
+}
+
void Chart2ImportTest::testODPChartSeries()
{
//test chart series names for odp
diff --git a/chart2/qa/extras/charttest.hxx b/chart2/qa/extras/charttest.hxx
index f3d1991..318bac2 100644
--- a/chart2/qa/extras/charttest.hxx
+++ b/chart2/qa/extras/charttest.hxx
@@ -482,16 +482,42 @@ uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const c
return seriesList;
}
-OUString getTitleString( const Reference<chart2::XTitled>& xTitled, sal_Int32 nIndex = 0 )
+OUString getTitleString( const Reference<chart2::XTitled>& xTitled )
{
uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
CPPUNIT_ASSERT(xTitle.is());
uno::Sequence<uno::Reference<chart2::XFormattedString> > aFSSeq = xTitle->getText();
- CPPUNIT_ASSERT(aFSSeq.getLength() > nIndex);
- uno::Reference<chart2::XFormattedString> xFS = aFSSeq[nIndex];
- CPPUNIT_ASSERT(xFS.is());
+ OUString aText;
+ for (sal_Int32 i = 0; i < aFSSeq.getLength(); ++i)
+ aText += aFSSeq[i]->getString();
- return xFS->getString();
+ return aText;
+}
+
+sal_Int32 getNumberFormatFromAxis( const Reference<chart2::XAxis>& xAxis )
+{
+ Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xPS.is());
+ sal_Int32 nNumberFormat = -1;
+ bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
+ CPPUNIT_ASSERT(bSuccess);
+
+ return nNumberFormat;
+}
+
+sal_Int16 getNumberFormatType( const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nNumberFormat )
+{
+ Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW);
+ Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
+ CPPUNIT_ASSERT(xNumberFormats.is());
+
+ Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumberFormat);
+ CPPUNIT_ASSERT(xNumPS.is());
+
+ sal_Int16 nType = util::NumberFormat::UNDEFINED;
+ xNumPS->getPropertyValue("Type") >>= nType;
+
+ return nType;
}
#endif // INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
diff --git a/chart2/qa/extras/data/pptx/stacked-non-stacked-mix-y-axis.pptx b/chart2/qa/extras/data/pptx/stacked-non-stacked-mix-y-axis.pptx
new file mode 100755
index 0000000..27d099d
Binary files /dev/null and b/chart2/qa/extras/data/pptx/stacked-non-stacked-mix-y-axis.pptx differ
commit b8c444a46b2f41dae673c6118d84276be0e6c87d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Jul 7 16:38:29 2014 -0400
bnc#881025: Mark axis a percent axis only when all data series are percent.
Change-Id: I302cc1e5b164b2ce9999087293b034ec930951af
diff --git a/oox/inc/drawingml/chart/axisconverter.hxx b/oox/inc/drawingml/chart/axisconverter.hxx
index e3cb8d0..fd464ad 100644
--- a/oox/inc/drawingml/chart/axisconverter.hxx
+++ b/oox/inc/drawingml/chart/axisconverter.hxx
@@ -60,12 +60,10 @@ public:
virtual ~AxisConverter();
/** Creates a chart2 axis and inserts it into the passed coordinate system. */
- void convertFromModel(
- const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem >& rxCoordSystem,
- TypeGroupConverter& rTypeGroup,
- const AxisModel* pCrossingAxis,
- sal_Int32 nAxesSetIdx,
- sal_Int32 nAxisIdx );
+ void convertFromModel(
+ const css::uno::Reference<css::chart2::XCoordinateSystem>& rxCoordSystem,
+ RefVector<TypeGroupConverter>& rTypeGroups, const AxisModel* pCrossingAxis,
+ sal_Int32 nAxesSetIdx, sal_Int32 nAxisIdx );
};
diff --git a/oox/source/drawingml/chart/axisconverter.cxx b/oox/source/drawingml/chart/axisconverter.cxx
index 075f6a0..ed74ef5 100644
--- a/oox/source/drawingml/chart/axisconverter.cxx
+++ b/oox/source/drawingml/chart/axisconverter.cxx
@@ -103,6 +103,26 @@ sal_Int32 lclGetTickMark( sal_Int32 nToken )
return NONE;
}
+/**
+ * The groups is of percent type only when all of its members are of percent
+ * type.
+ */
+bool isPercent( const RefVector<TypeGroupConverter>& rTypeGroups )
+{
+ if (rTypeGroups.empty())
+ return false;
+
+ RefVector<TypeGroupConverter>::const_iterator it = rTypeGroups.begin(), itEnd = rTypeGroups.end();
+ for (; it != itEnd; ++it)
+ {
+ TypeGroupConverter& rConv = **it;
+ if (!rConv.isPercent())
+ return false;
+ }
+
+ return true;
+}
+
} // namespace
AxisConverter::AxisConverter( const ConverterRoot& rParent, AxisModel& rModel ) :
@@ -114,16 +134,20 @@ AxisConverter::~AxisConverter()
{
}
-void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCoordSystem,
- TypeGroupConverter& rTypeGroup, const AxisModel* pCrossingAxis, sal_Int32 nAxesSetIdx, sal_Int32 nAxisIdx )
+void AxisConverter::convertFromModel(
+ const Reference< XCoordinateSystem >& rxCoordSystem,
+ RefVector<TypeGroupConverter>& rTypeGroups, const AxisModel* pCrossingAxis, sal_Int32 nAxesSetIdx, sal_Int32 nAxisIdx )
{
+ if (rTypeGroups.empty())
+ return;
+
Reference< XAxis > xAxis;
try
{
namespace cssc = ::com::sun::star::chart;
namespace cssc2 = ::com::sun::star::chart2;
- const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo();
+ const TypeGroupInfo& rTypeInfo = rTypeGroups.front()->getTypeInfo();
ObjectFormatter& rFormatter = getFormatter();
// create the axis object (always)
@@ -183,7 +207,7 @@ void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCo
currently). */
aScaleData.AxisType = (bDateAxis && !mrModel.mbAuto) ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY;
aScaleData.AutoDateAxis = mrModel.mbAuto;
- aScaleData.Categories = rTypeGroup.createCategorySequence();
+ aScaleData.Categories = rTypeGroups.front()->createCategorySequence();
}
else
{
@@ -193,11 +217,11 @@ void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCo
break;
case API_Y_AXIS:
OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( valAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" );
- aScaleData.AxisType = rTypeGroup.isPercent() ? cssc2::AxisType::PERCENT : cssc2::AxisType::REALNUMBER;
+ aScaleData.AxisType = isPercent(rTypeGroups) ? cssc2::AxisType::PERCENT : cssc2::AxisType::REALNUMBER;
break;
case API_Z_AXIS:
OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( serAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:serAx)" );
- OSL_ENSURE( rTypeGroup.isDeep3dChart(), "AxisConverter::convertFromModel - series axis not supported by this chart type" );
+ OSL_ENSURE( rTypeGroups.front()->isDeep3dChart(), "AxisConverter::convertFromModel - series axis not supported by this chart type" );
aScaleData.AxisType = cssc2::AxisType::SERIES;
break;
}
@@ -324,7 +348,7 @@ void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCo
// axis title ---------------------------------------------------------
// in radar charts, title objects may exist, but are not shown
- if( mrModel.mxTitle.is() && (rTypeGroup.getTypeInfo().meTypeCategory != TYPECATEGORY_RADAR) )
+ if( mrModel.mxTitle.is() && (rTypeGroups.front()->getTypeInfo().meTypeCategory != TYPECATEGORY_RADAR) )
{
Reference< XTitled > xTitled( xAxis, UNO_QUERY_THROW );
TitleConverter aTitleConv( *this, *mrModel.mxTitle );
diff --git a/oox/source/drawingml/chart/plotareaconverter.cxx b/oox/source/drawingml/chart/plotareaconverter.cxx
index c8980da..f79bab8 100644
--- a/oox/source/drawingml/chart/plotareaconverter.cxx
+++ b/oox/source/drawingml/chart/plotareaconverter.cxx
@@ -163,15 +163,15 @@ void AxesSetConverter::convertFromModel( const Reference< XDiagram >& rxDiagram,
ModelRef< AxisModel > xYAxis = lclGetOrCreateAxis( mrModel.maAxes, API_Y_AXIS, C_TOKEN( valAx ) );
AxisConverter aXAxisConv( *this, *xXAxis );
- aXAxisConv.convertFromModel( xCoordSystem, rFirstTypeGroup, xYAxis.get(), nAxesSetIdx, API_X_AXIS );
+ aXAxisConv.convertFromModel( xCoordSystem, aTypeGroups, xYAxis.get(), nAxesSetIdx, API_X_AXIS );
AxisConverter aYAxisConv( *this, *xYAxis );
- aYAxisConv.convertFromModel( xCoordSystem, rFirstTypeGroup, xXAxis.get(), nAxesSetIdx, API_Y_AXIS );
+ aYAxisConv.convertFromModel( xCoordSystem, aTypeGroups, xXAxis.get(), nAxesSetIdx, API_Y_AXIS );
if( rFirstTypeGroup.isDeep3dChart() )
{
ModelRef< AxisModel > xZAxis = lclGetOrCreateAxis( mrModel.maAxes, API_Z_AXIS, C_TOKEN( serAx ) );
AxisConverter aZAxisConv( *this, *xZAxis );
- aZAxisConv.convertFromModel( xCoordSystem, rFirstTypeGroup, 0, nAxesSetIdx, API_Z_AXIS );
+ aZAxisConv.convertFromModel( xCoordSystem, aTypeGroups, 0, nAxesSetIdx, API_Z_AXIS );
}
// convert all chart type groups, this converts all series data and formatting
commit af5a6615dfdbe5c2cacdcacb00fc6f418b925c06
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Mon Jul 7 13:26:23 2014 -0400
Adjust for the splitting of number format properties in chart.
Since 1d38cb365543924f9c50014e6b2227e77de1d0c9, "number format" and
"link number format to source" properties are 2 separate properties. Adjust
OOXML import code for that split.
Also, always set axis' number format via NumberFormat property even when it's
a percent format. The axis object doesn't keep a non-percent and percent
number formats separately.
Change-Id: I8667b6f1a78d88cc37d059518919ad1b37f154e1
diff --git a/oox/source/drawingml/chart/axisconverter.cxx b/oox/source/drawingml/chart/axisconverter.cxx
index d11f327..075f6a0 100644
--- a/oox/source/drawingml/chart/axisconverter.cxx
+++ b/oox/source/drawingml/chart/axisconverter.cxx
@@ -301,13 +301,7 @@ void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCo
// number format ------------------------------------------------------
if( (aScaleData.AxisType == cssc2::AxisType::REALNUMBER) || (aScaleData.AxisType == cssc2::AxisType::PERCENT) )
- {
- bool bPercent = false;
- if( mrModel.maNumberFormat.maFormatCode.indexOf('%') >= 0)
- bPercent = true;
- mrModel.maNumberFormat.mbSourceLinked = false;
- getFormatter().convertNumberFormat( aAxisProp, mrModel.maNumberFormat, bPercent );
- }
+ getFormatter().convertNumberFormat(aAxisProp, mrModel.maNumberFormat, false);
// position of crossing axis ------------------------------------------
diff --git a/oox/source/drawingml/chart/objectformatter.cxx b/oox/source/drawingml/chart/objectformatter.cxx
index 1fe5c75..8fd7dc4 100644
--- a/oox/source/drawingml/chart/objectformatter.cxx
+++ b/oox/source/drawingml/chart/objectformatter.cxx
@@ -1088,11 +1088,7 @@ void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFo
if( mxData->mxNumFmts.is() )
{
sal_Int32 nPropId = bPercentFormat ? PROP_PercentageNumberFormat : PROP_NumberFormat;
- if( rNumberFormat.mbSourceLinked || rNumberFormat.maFormatCode.isEmpty() )
- {
- rPropSet.setAnyProperty( nPropId, Any() );
- }
- else try
+ try
{
sal_Int32 nIndex = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general") ?
mxData->mxNumTypes->getStandardIndex( mxData->maFromLocale ) :
@@ -1105,6 +1101,8 @@ void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFo
OSL_FAIL( OStringBuffer( "ObjectFormatter::convertNumberFormat - cannot create number format '" ).
append( OUStringToOString( rNumberFormat.maFormatCode, osl_getThreadTextEncoding() ) ).append( '\'' ).getStr() );
}
+
+ rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.mbSourceLinked));
}
}
diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt
index 0ad6d7a..44c7597 100644
--- a/oox/source/token/properties.txt
+++ b/oox/source/token/properties.txt
@@ -298,6 +298,7 @@ LineStartWidth
LineStyle
LineTransparence
LineWidth
+LinkNumberFormatToSource
LinkURL
LoadReadonly
LookUpLabels
More information about the Libreoffice-commits
mailing list