1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <test/unoapixml_test.hxx>
13 #include <comphelper/processfactory.hxx>
14 #include <comphelper/propertysequence.hxx>
16 #include <com/sun/star/lang/XComponent.hpp>
17 #include <com/sun/star/frame/Desktop.hpp>
19 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
20 #include <com/sun/star/container/XIndexAccess.hpp>
21 #include <com/sun/star/container/XNamed.hpp>
22 #include <com/sun/star/table/XTableChartsSupplier.hpp>
23 #include <com/sun/star/table/XTableChart.hpp>
24 #include <com/sun/star/table/XTablePivotChartsSupplier.hpp>
25 #include <com/sun/star/table/XTablePivotChart.hpp>
26 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/frame/XStorable.hpp>
30 #include <o3tl/string_view.hxx>
31 #include <unotools/tempfile.hxx>
32 #include <rtl/math.hxx>
33 #include <svx/charthelper.hxx>
35 #include <com/sun/star/chart2/AxisType.hpp>
36 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
37 #include <com/sun/star/chart2/XChartDocument.hpp>
38 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
39 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
40 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
41 #include <com/sun/star/chart2/XFormattedString.hpp>
42 #include <com/sun/star/chart2/XTitle.hpp>
43 #include <com/sun/star/chart2/XTitled.hpp>
44 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
45 #include <com/sun/star/chart2/data/XDataSource.hpp>
46 #include <com/sun/star/chart/XChartDataArray.hpp>
47 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
48 #include <com/sun/star/chart/XDateCategories.hpp>
49 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
50 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
51 #include <com/sun/star/chart/XChartDocument.hpp>
52 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
53 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
54 #include <com/sun/star/util/NumberFormat.hpp>
55 #include <com/sun/star/util/NumberFormatter.hpp>
57 #include <unonames.hxx>
61 #include <string_view>
63 #include <com/sun/star/embed/Aspects.hpp>
64 #include <com/sun/star/embed/XVisualObject.hpp>
65 #include <com/sun/star/chart2/RelativeSize.hpp>
68 using namespace css::uno
;
70 namespace com::sun::star::chart2
{ class XDataSeries
; }
71 namespace com::sun::star::chart2
{ class XDiagram
; }
72 namespace com::sun::star::table
{ class XTableCharts
; }
73 namespace com::sun::star::table
{ class XTablePivotCharts
; }
75 class ChartTest
: public UnoApiXmlTest
78 ChartTest(OUString path
)
83 uno::Sequence
< OUString
> getImpressChartColumnDescriptions(sal_Int32 nPage
, sal_Int32 nShape
);
85 uno::Reference
<chart::XChartDocument
> getChartDocFromDrawImpress( sal_Int32 nPage
, sal_Int32 nShape
);
86 uno::Reference
<chart::XChartDocument
> getChartDocFromDrawImpressNamed( sal_Int32 nPage
, std::u16string_view rName
);
89 uno::Reference
<chart::XChartDocument
> getChartDocFromWriter( sal_Int32 nShape
);
90 Sequence
< OUString
> getFormattedDateCategories( const Reference
<chart2::XChartDocument
>& xChartDoc
);
91 awt::Size
getPageSize( const Reference
< chart2::XChartDocument
> & xChartDoc
);
92 awt::Size
getSize(css::uno::Reference
<chart2::XDiagram
> xDiagram
, const awt::Size
& rPageSize
);
95 Reference
< lang::XComponent
> getChartCompFromSheet( sal_Int32 nSheet
, sal_Int32 nChart
, uno::Reference
< lang::XComponent
> const & xComponent
)
97 // let us assume that we only have one chart per sheet
99 uno::Reference
< sheet::XSpreadsheetDocument
> xDoc(xComponent
, UNO_QUERY_THROW
);
101 uno::Reference
< container::XIndexAccess
> xIA(xDoc
->getSheets(), UNO_QUERY_THROW
);
103 uno::Reference
< table::XTableChartsSupplier
> xChartSupplier( xIA
->getByIndex(nSheet
), UNO_QUERY_THROW
);
105 uno::Reference
< table::XTableCharts
> xCharts
= xChartSupplier
->getCharts();
106 CPPUNIT_ASSERT(xCharts
.is());
108 uno::Reference
< container::XIndexAccess
> xIACharts(xCharts
, UNO_QUERY_THROW
);
109 uno::Reference
< table::XTableChart
> xChart( xIACharts
->getByIndex(nChart
), UNO_QUERY_THROW
);
111 uno::Reference
< document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xChart
, UNO_QUERY_THROW
);
113 uno::Reference
< lang::XComponent
> xChartComp( xEmbObjectSupplier
->getEmbeddedObject(), UNO_SET_THROW
);
119 Reference
< chart2::XChartDocument
> getChartDocFromSheet( sal_Int32 nSheet
, uno::Reference
< lang::XComponent
> const & xComponent
)
121 uno::Reference
< chart2::XChartDocument
> xChartDoc ( getChartCompFromSheet(nSheet
, 0, xComponent
), UNO_QUERY_THROW
);
123 // Update the chart view, so that its draw page is updated and ready for the test
124 css::uno::Reference
<css::frame::XModel
> xModel(xChartDoc
, css::uno::UNO_QUERY_THROW
);
125 ChartHelper::updateChart(xModel
);
130 uno::Reference
<table::XTablePivotCharts
> getTablePivotChartsFromSheet(sal_Int32 nSheet
, uno::Reference
<lang::XComponent
> const & xComponent
)
132 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(xComponent
, UNO_QUERY_THROW
);
134 uno::Reference
<container::XIndexAccess
> xIA(xDoc
->getSheets(), UNO_QUERY_THROW
);
136 uno::Reference
<table::XTablePivotChartsSupplier
> xChartSupplier(xIA
->getByIndex(nSheet
), UNO_QUERY_THROW
);
138 uno::Reference
<table::XTablePivotCharts
> xTablePivotCharts
= xChartSupplier
->getPivotCharts();
139 CPPUNIT_ASSERT(xTablePivotCharts
.is());
141 return xTablePivotCharts
;
144 Reference
<lang::XComponent
> getPivotChartCompFromSheet(sal_Int32 nSheet
, uno::Reference
<lang::XComponent
> const & xComponent
)
146 uno::Reference
<table::XTablePivotCharts
> xTablePivotCharts
= getTablePivotChartsFromSheet(nSheet
, xComponent
);
148 uno::Reference
<container::XIndexAccess
> xIACharts(xTablePivotCharts
, UNO_QUERY_THROW
);
149 uno::Reference
<table::XTablePivotChart
> xTablePivotChart(xIACharts
->getByIndex(0), UNO_QUERY_THROW
);
151 uno::Reference
<document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xTablePivotChart
, UNO_QUERY_THROW
);
153 uno::Reference
<lang::XComponent
> xChartComp(xEmbObjectSupplier
->getEmbeddedObject(), UNO_SET_THROW
);
158 Reference
<chart2::XChartDocument
> getPivotChartDocFromSheet(sal_Int32 nSheet
, uno::Reference
<lang::XComponent
> const & xComponent
)
160 uno::Reference
<chart2::XChartDocument
> xChartDoc(getPivotChartCompFromSheet(nSheet
, xComponent
), UNO_QUERY_THROW
);
164 Reference
<chart2::XChartDocument
> getPivotChartDocFromSheet(uno::Reference
<table::XTablePivotCharts
> const & xTablePivotCharts
, sal_Int32 nIndex
)
166 uno::Reference
<container::XIndexAccess
> xIACharts(xTablePivotCharts
, UNO_QUERY_THROW
);
167 uno::Reference
<table::XTablePivotChart
> xTablePivotChart(xIACharts
->getByIndex(nIndex
), UNO_QUERY_THROW
);
169 uno::Reference
<document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xTablePivotChart
, UNO_QUERY_THROW
);
171 uno::Reference
<lang::XComponent
> xChartComp(xEmbObjectSupplier
->getEmbeddedObject(), UNO_SET_THROW
);
173 uno::Reference
<chart2::XChartDocument
> xChartDoc(xChartComp
, UNO_QUERY_THROW
);
177 Reference
< chart2::XChartType
> getChartTypeFromDoc( Reference
< chart2::XChartDocument
> const & xChartDoc
,
178 sal_Int32 nChartType
, sal_Int32 nCooSys
= 0 )
180 CPPUNIT_ASSERT( xChartDoc
.is() );
182 Reference
<chart2::XDiagram
> xDiagram
= xChartDoc
->getFirstDiagram();
183 CPPUNIT_ASSERT( xDiagram
.is() );
185 Reference
< chart2::XCoordinateSystemContainer
> xCooSysContainer( xDiagram
, UNO_QUERY_THROW
);
187 Sequence
< Reference
< chart2::XCoordinateSystem
> > xCooSysSequence( xCooSysContainer
->getCoordinateSystems());
188 CPPUNIT_ASSERT( xCooSysSequence
.getLength() > nCooSys
);
190 Reference
< chart2::XChartTypeContainer
> xChartTypeContainer( xCooSysSequence
[nCooSys
], UNO_QUERY_THROW
);
192 Sequence
< Reference
< chart2::XChartType
> > xChartTypeSequence( xChartTypeContainer
->getChartTypes() );
193 CPPUNIT_ASSERT( xChartTypeSequence
.getLength() > nChartType
);
195 return xChartTypeSequence
[nChartType
];
198 Reference
<chart2::XAxis
> getAxisFromDoc(
199 const Reference
<chart2::XChartDocument
>& xChartDoc
, sal_Int32 nCooSys
, sal_Int32 nAxisDim
, sal_Int32 nAxisIndex
)
201 Reference
<chart2::XDiagram
> xDiagram
= xChartDoc
->getFirstDiagram();
202 CPPUNIT_ASSERT(xDiagram
.is());
204 Reference
<chart2::XCoordinateSystemContainer
> xCooSysContainer(xDiagram
, UNO_QUERY_THROW
);
206 Sequence
<Reference
<chart2::XCoordinateSystem
> > xCooSysSequence
= xCooSysContainer
->getCoordinateSystems();
207 CPPUNIT_ASSERT(xCooSysSequence
.getLength() > nCooSys
);
209 Reference
<chart2::XCoordinateSystem
> xCoord
= xCooSysSequence
[nCooSys
];
210 CPPUNIT_ASSERT(xCoord
.is());
212 Reference
<chart2::XAxis
> xAxis
= xCoord
->getAxisByDimension(nAxisDim
, nAxisIndex
);
213 CPPUNIT_ASSERT(xAxis
.is());
218 sal_Int32
getNumberOfDataSeries(uno::Reference
<chart2::XChartDocument
> const & xChartDoc
,
219 sal_Int32 nChartType
= 0, sal_Int32 nCooSys
= 0)
221 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc
, nChartType
, nCooSys
);
222 Reference
<chart2::XDataSeriesContainer
> xDataSeriesContainer(xChartType
, UNO_QUERY_THROW
);
224 uno::Sequence
<uno::Reference
<chart2::XDataSeries
>> xSeriesSequence(xDataSeriesContainer
->getDataSeries());
225 return xSeriesSequence
.getLength();
228 Reference
< chart2::XDataSeries
> getDataSeriesFromDoc(uno::Reference
<chart2::XChartDocument
> const & xChartDoc
,
229 sal_Int32 nDataSeries
, sal_Int32 nChartType
= 0,
230 sal_Int32 nCooSys
= 0)
232 Reference
< chart2::XChartType
> xChartType
= getChartTypeFromDoc( xChartDoc
, nChartType
, nCooSys
);
233 Reference
< chart2::XDataSeriesContainer
> xDataSeriesContainer( xChartType
, UNO_QUERY_THROW
);
235 Sequence
< Reference
< chart2::XDataSeries
> > xSeriesSequence( xDataSeriesContainer
->getDataSeries() );
236 CPPUNIT_ASSERT( xSeriesSequence
.getLength() > nDataSeries
);
238 Reference
< chart2::XDataSeries
> xSeries
= xSeriesSequence
[nDataSeries
];
243 Reference
< chart2::data::XDataSequence
> getLabelDataSequenceFromDoc(
244 Reference
< chart2::XChartDocument
> const & xChartDoc
,
245 sal_Int32 nDataSeries
= 0, sal_Int32 nChartType
= 0 )
247 Reference
< chart2::XDataSeries
> xDataSeries
=
248 getDataSeriesFromDoc( xChartDoc
, nDataSeries
, nChartType
);
249 CPPUNIT_ASSERT(xDataSeries
.is());
250 Reference
< chart2::data::XDataSource
> xDataSource( xDataSeries
, uno::UNO_QUERY_THROW
);
251 const Sequence
< Reference
< chart2::data::XLabeledDataSequence
> > xDataSequences
=
252 xDataSource
->getDataSequences();
253 for(auto const & lds
: xDataSequences
)
255 Reference
< chart2::data::XDataSequence
> xLabelSeq
= lds
->getLabel();
262 CPPUNIT_FAIL("no Label sequence found");
265 Reference
< chart2::data::XDataSequence
> getDataSequenceFromDocByRole(
266 Reference
< chart2::XChartDocument
> const & xChartDoc
, std::u16string_view rRole
,
267 sal_Int32 nDataSeries
= 0, sal_Int32 nChartType
= 0 )
269 Reference
< chart2::XDataSeries
> xDataSeries
=
270 getDataSeriesFromDoc( xChartDoc
, nDataSeries
, nChartType
);
271 CPPUNIT_ASSERT(xDataSeries
.is());
272 Reference
< chart2::data::XDataSource
> xDataSource( xDataSeries
, uno::UNO_QUERY_THROW
);
273 const Sequence
< Reference
< chart2::data::XLabeledDataSequence
> > xDataSequences
=
274 xDataSource
->getDataSequences();
275 for(auto const & lds
: xDataSequences
)
277 Reference
< chart2::data::XDataSequence
> xLabelSeq
= lds
->getValues();
278 uno::Reference
< beans::XPropertySet
> xProps(xLabelSeq
, uno::UNO_QUERY
);
282 OUString aRoleName
= xProps
->getPropertyValue("Role").get
<OUString
>();
284 if(aRoleName
== rRole
)
288 return Reference
< chart2::data::XDataSequence
> ();
291 uno::Sequence
< OUString
> getWriterChartColumnDescriptions( Reference
< lang::XComponent
> const & mxComponent
)
293 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
294 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
295 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
296 CPPUNIT_ASSERT( xShape
.is() );
297 uno::Reference
<beans::XPropertySet
> xPropertySet(xShape
, uno::UNO_QUERY
);
298 uno::Reference
< chart2::XChartDocument
> xChartDoc
;
299 xChartDoc
.set( xPropertySet
->getPropertyValue( "Model" ), uno::UNO_QUERY
);
300 CPPUNIT_ASSERT( xChartDoc
.is() );
301 CPPUNIT_ASSERT( xChartDoc
->getDataProvider().is() );
302 uno::Reference
< chart2::XAnyDescriptionAccess
> xAnyDescriptionAccess ( xChartDoc
->getDataProvider(), uno::UNO_QUERY_THROW
);
303 uno::Sequence
< OUString
> seriesList
= xAnyDescriptionAccess
->getColumnDescriptions();
307 std::vector
<std::vector
<double> > getDataSeriesYValuesFromChartType( const Reference
<chart2::XChartType
>& xCT
)
309 Reference
<chart2::XDataSeriesContainer
> xDSCont(xCT
, uno::UNO_QUERY
);
310 CPPUNIT_ASSERT(xDSCont
.is());
311 const Sequence
<uno::Reference
<chart2::XDataSeries
> > aDataSeriesSeq
= xDSCont
->getDataSeries();
313 std::vector
<std::vector
<double> > aRet
;
314 for (uno::Reference
<chart2::XDataSeries
> const & ds
: aDataSeriesSeq
)
316 uno::Reference
<chart2::data::XDataSource
> xDSrc(ds
, uno::UNO_QUERY
);
317 CPPUNIT_ASSERT(xDSrc
.is());
318 const uno::Sequence
<Reference
<chart2::data::XLabeledDataSequence
> > aDataSeqs
= xDSrc
->getDataSequences();
319 for (auto const & lds
: aDataSeqs
)
321 Reference
<chart2::data::XDataSequence
> xValues
= lds
->getValues();
322 CPPUNIT_ASSERT(xValues
.is());
323 Reference
<beans::XPropertySet
> xPropSet(xValues
, uno::UNO_QUERY
);
328 xPropSet
->getPropertyValue("Role") >>= aRoleName
;
329 if (aRoleName
== "values-y")
331 const uno::Sequence
<uno::Any
> aData
= xValues
->getData();
332 std::vector
<double> aValues
;
333 aValues
.reserve(aData
.getLength());
334 for (uno::Any
const & any
: aData
)
338 aValues
.push_back(fVal
);
340 aValues
.push_back(std::numeric_limits
<double>::quiet_NaN());
342 aRet
.push_back(aValues
);
350 std::vector
<uno::Sequence
<uno::Any
> > getDataSeriesLabelsFromChartType( const Reference
<chart2::XChartType
>& xCT
)
352 OUString aLabelRole
= xCT
->getRoleOfSequenceForSeriesLabel();
354 Reference
<chart2::XDataSeriesContainer
> xDSCont(xCT
, uno::UNO_QUERY
);
355 CPPUNIT_ASSERT(xDSCont
.is());
356 const Sequence
<uno::Reference
<chart2::XDataSeries
> > aDataSeriesSeq
= xDSCont
->getDataSeries();
358 std::vector
<uno::Sequence
<uno::Any
> > aRet
;
359 for (auto const & ds
: aDataSeriesSeq
)
361 uno::Reference
<chart2::data::XDataSource
> xDSrc(ds
, uno::UNO_QUERY
);
362 CPPUNIT_ASSERT(xDSrc
.is());
363 const uno::Sequence
<Reference
<chart2::data::XLabeledDataSequence
> > aDataSeqs
= xDSrc
->getDataSequences();
364 for (auto const & lds
: aDataSeqs
)
366 Reference
<chart2::data::XDataSequence
> xValues
= lds
->getValues();
367 CPPUNIT_ASSERT(xValues
.is());
368 Reference
<beans::XPropertySet
> xPropSet(xValues
, uno::UNO_QUERY
);
373 xPropSet
->getPropertyValue("Role") >>= aRoleName
;
374 if (aRoleName
== aLabelRole
)
376 Reference
<chart2::data::XLabeledDataSequence
> xLabel
= lds
;
377 CPPUNIT_ASSERT(xLabel
.is());
378 Reference
<chart2::data::XDataSequence
> xDS2
= xLabel
->getLabel();
379 CPPUNIT_ASSERT(xDS2
.is());
380 uno::Sequence
<uno::Any
> aData
= xDS2
->getData();
381 aRet
.push_back(aData
);
389 uno::Reference
<chart::XChartDocument
> ChartTest::getChartDocFromDrawImpress(
390 sal_Int32 nPage
, sal_Int32 nShape
)
392 uno::Reference
<chart::XChartDocument
> xEmpty
;
394 uno::Reference
<drawing::XDrawPagesSupplier
> xPages(mxComponent
, uno::UNO_QUERY
);
398 uno::Reference
<drawing::XDrawPage
> xPage(
399 xPages
->getDrawPages()->getByIndex(nPage
), uno::UNO_QUERY_THROW
);
401 uno::Reference
<beans::XPropertySet
> xShapeProps(xPage
->getByIndex(nShape
), uno::UNO_QUERY
);
402 if (!xShapeProps
.is())
405 uno::Reference
<frame::XModel
> xDocModel
;
406 xShapeProps
->getPropertyValue("Model") >>= xDocModel
;
410 uno::Reference
<chart::XChartDocument
> xChartDoc(xDocModel
, uno::UNO_QUERY
);
414 uno::Reference
<chart::XChartDocument
> ChartTest::getChartDocFromDrawImpressNamed(sal_Int32 nPage
, std::u16string_view rName
)
416 uno::Reference
<chart::XChartDocument
> xChart
;
418 uno::Reference
<drawing::XDrawPagesSupplier
> xPages(mxComponent
, uno::UNO_QUERY
);
422 uno::Reference
<drawing::XDrawPage
> xPage(xPages
->getDrawPages()->getByIndex(nPage
), uno::UNO_QUERY
);
426 for (sal_Int32 i
=0; i
< xPage
->getCount(); ++i
)
428 uno::Reference
<container::XNamed
> xNamedShape(xPage
->getByIndex(i
), uno::UNO_QUERY
);
429 if (!xNamedShape
.is())
432 if (xNamedShape
->getName() != rName
)
435 uno::Reference
<beans::XPropertySet
> xShapeProps(xNamedShape
, uno::UNO_QUERY
);
436 if (!xShapeProps
.is())
439 uno::Reference
<frame::XModel
> xDocModel
;
440 xShapeProps
->getPropertyValue("Model") >>= xDocModel
;
444 return uno::Reference
<chart::XChartDocument
>(xDocModel
, uno::UNO_QUERY
);
450 uno::Reference
<chart::XChartDocument
> ChartTest::getChartDocFromWriter( sal_Int32 nShape
)
452 // DO NOT use XDrawPageSupplier since SwVirtFlyDrawObj are not created
453 // during import, only in layout!
454 Reference
<text::XTextEmbeddedObjectsSupplier
> xEOS(mxComponent
, uno::UNO_QUERY
);
455 CPPUNIT_ASSERT(xEOS
.is());
456 Reference
<container::XIndexAccess
> xEmbeddeds(xEOS
->getEmbeddedObjects(), uno::UNO_QUERY
);
457 CPPUNIT_ASSERT(xEmbeddeds
.is());
459 Reference
<beans::XPropertySet
> xShapeProps(xEmbeddeds
->getByIndex(nShape
), uno::UNO_QUERY
);
460 CPPUNIT_ASSERT(xShapeProps
.is());
462 Reference
<frame::XModel
> xDocModel
;
463 xShapeProps
->getPropertyValue("Model") >>= xDocModel
;
464 CPPUNIT_ASSERT(xDocModel
.is());
466 uno::Reference
<chart::XChartDocument
> xChartDoc(xDocModel
, uno::UNO_QUERY
);
470 uno::Sequence
< OUString
> ChartTest::getImpressChartColumnDescriptions(sal_Int32 nPage
, sal_Int32 nShape
)
472 uno::Reference
< chart::XChartDocument
> xChartDoc
= getChartDocFromDrawImpress( nPage
, nShape
);
473 uno::Reference
< chart::XChartDataArray
> xChartData ( xChartDoc
->getData(), uno::UNO_QUERY_THROW
);
474 uno::Sequence
< OUString
> seriesList
= xChartData
->getColumnDescriptions();
478 OUString
getTitleString( const Reference
<chart2::XTitled
>& xTitled
)
480 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
481 CPPUNIT_ASSERT(xTitle
.is());
482 const uno::Sequence
<uno::Reference
<chart2::XFormattedString
> > aFSSeq
= xTitle
->getText();
484 for (auto const & fs
: aFSSeq
)
485 aText
+= fs
->getString();
490 sal_Int32
getNumberFormat( const Reference
<chart2::XChartDocument
>& xChartDoc
, const OUString
& sFormat
)
492 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
493 Reference
<util::XNumberFormats
> xNumberFormats
= xNFS
->getNumberFormats();
494 CPPUNIT_ASSERT(xNumberFormats
.is());
496 return xNumberFormats
->queryKey(sFormat
, css::lang::Locale(), false);
499 sal_Int32
getNumberFormatFromAxis( const Reference
<chart2::XAxis
>& xAxis
)
501 Reference
<beans::XPropertySet
> xPS(xAxis
, uno::UNO_QUERY
);
502 CPPUNIT_ASSERT(xPS
.is());
503 sal_Int32 nNumberFormat
= -1;
504 bool bSuccess
= xPS
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
505 CPPUNIT_ASSERT(bSuccess
);
507 return nNumberFormat
;
510 sal_Int16
getNumberFormatType( const Reference
<chart2::XChartDocument
>& xChartDoc
, sal_Int32 nNumberFormat
)
512 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
513 Reference
<util::XNumberFormats
> xNumberFormats
= xNFS
->getNumberFormats();
514 CPPUNIT_ASSERT(xNumberFormats
.is());
516 Reference
<beans::XPropertySet
> xNumPS
= xNumberFormats
->getByKey(nNumberFormat
);
517 CPPUNIT_ASSERT(xNumPS
.is());
519 sal_Int16 nType
= util::NumberFormat::UNDEFINED
;
520 xNumPS
->getPropertyValue("Type") >>= nType
;
525 Sequence
< double > getDateCategories(const Reference
<chart2::XChartDocument
>& xChartDoc
)
527 CPPUNIT_ASSERT(xChartDoc
->hasInternalDataProvider());
528 uno::Reference
< chart2::XInternalDataProvider
> xDataProvider( xChartDoc
->getDataProvider(), uno::UNO_QUERY_THROW
);
529 uno::Reference
< chart::XDateCategories
> xDateCategories( xDataProvider
, uno::UNO_QUERY_THROW
);
530 CPPUNIT_ASSERT(xDateCategories
.is());
531 return xDateCategories
->getDateCategories();
534 Sequence
< OUString
> ChartTest::getFormattedDateCategories( const Reference
<chart2::XChartDocument
>& xChartDoc
)
536 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
537 Reference
< util::XNumberFormatter
> xNumFormatter(
538 util::NumberFormatter::create(comphelper::getComponentContext(m_xSFactory
)), uno::UNO_QUERY_THROW
);
539 xNumFormatter
->attachNumberFormatsSupplier(xNFS
);
541 Reference
<chart2::XAxis
> xAxisX
= getAxisFromDoc(xChartDoc
, 0, 0, 0);
542 chart2::ScaleData aScaleData
= xAxisX
->getScaleData();
543 CPPUNIT_ASSERT_EQUAL(chart2::AxisType::DATE
, aScaleData
.AxisType
);
545 sal_Int32 nNumFmt
= getNumberFormatFromAxis(xAxisX
);
547 Sequence
<double> aDateSeq
= getDateCategories(xChartDoc
);
548 const sal_Int32 nNumCategories
= aDateSeq
.getLength();
549 Sequence
<OUString
> aFormattedDates(nNumCategories
);
550 auto aFormattedDatesRange
= asNonConstRange(aFormattedDates
);
552 for (sal_Int32 nIdx
= 0; nIdx
< nNumCategories
; ++nIdx
)
553 aFormattedDatesRange
[nIdx
] = xNumFormatter
->convertNumberToString(nNumFmt
, aDateSeq
[nIdx
]);
555 return aFormattedDates
;
558 awt::Size
ChartTest::getPageSize( const Reference
< chart2::XChartDocument
> & xChartDoc
)
560 awt::Size
aSize( 0, 0 );
561 uno::Reference
< com::sun::star::embed::XVisualObject
> xVisualObject( xChartDoc
, uno::UNO_QUERY
);
562 CPPUNIT_ASSERT( xVisualObject
.is() );
563 aSize
= xVisualObject
->getVisualAreaSize( com::sun::star::embed::Aspects::MSOLE_CONTENT
);
567 awt::Size
ChartTest::getSize(css::uno::Reference
<chart2::XDiagram
> xDiagram
, const awt::Size
& rPageSize
)
569 Reference
< beans::XPropertySet
> xProp(xDiagram
, uno::UNO_QUERY
);
570 chart2::RelativeSize aRelativeSize
;
571 xProp
->getPropertyValue( "RelativeSize" ) >>= aRelativeSize
;
572 double fX
= aRelativeSize
.Primary
* rPageSize
.Width
;
573 double fY
= aRelativeSize
.Secondary
* rPageSize
.Height
;
575 aSize
.Width
= static_cast< sal_Int32
>( ::rtl::math::round( fX
) );
576 aSize
.Height
= static_cast< sal_Int32
>( ::rtl::math::round( fY
) );
580 uno::Reference
<drawing::XShape
>
581 getShapeByName(const uno::Reference
<drawing::XShapes
>& rShapes
, const OUString
& rName
,
582 const std::function
<bool(const uno::Reference
<drawing::XShape
>&)>& pCondition
585 for (sal_Int32 i
= 0; i
< rShapes
->getCount(); ++i
)
587 uno::Reference
<drawing::XShapes
> xShapes(rShapes
->getByIndex(i
), uno::UNO_QUERY
);
590 uno::Reference
<drawing::XShape
> xRet
= getShapeByName(xShapes
, rName
, pCondition
);
594 uno::Reference
<container::XNamed
> xNamedShape(rShapes
->getByIndex(i
), uno::UNO_QUERY
);
595 if (xNamedShape
->getName() == rName
)
597 uno::Reference
<drawing::XShape
> xShape(xNamedShape
, uno::UNO_QUERY
);
598 if (pCondition
== nullptr || pCondition(xShape
))
602 return uno::Reference
<drawing::XShape
>();
605 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */