1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "DataSourceHelper.hxx"
28 #include "macros.hxx"
29 #include "ChartModelHelper.hxx"
30 #include "DiagramHelper.hxx"
31 #include "DataSeriesHelper.hxx"
32 #include "DataSource.hxx"
33 #include "ContainerHelper.hxx"
34 #include "ControllerLockGuard.hxx"
35 #include "PropertyHelper.hxx"
36 #include "CachedDataSequence.hxx"
37 #include "LabeledDataSequence.hxx"
38
39 #include <com/sun/star/chart2/XChartDocument.hpp>
40 #include <com/sun/star/chart2/data/XDataSource.hpp>
41 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
42
43 #include <com/sun/star/chart/ChartDataRowSource.hpp>
44 #include <com/sun/star/chart/ErrorBarStyle.hpp>
45
46 //.............................................................................
47 namespace chart
48 {
49 //.............................................................................
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::chart2;
52 using ::com::sun::star::uno::Reference;
53 using ::com::sun::star::uno::Sequence;
54 using ::rtl::OUString;
55
56 namespace
57 {
lcl_addRanges(::std::vector<::rtl::OUString> & rOutResult,const uno::Reference<data::XLabeledDataSequence> & xLabeledSeq)58 void lcl_addRanges( ::std::vector< ::rtl::OUString > & rOutResult,
59 const uno::Reference< data::XLabeledDataSequence > & xLabeledSeq )
60 {
61 if( ! xLabeledSeq.is())
62 return;
63 uno::Reference< data::XDataSequence > xSeq( xLabeledSeq->getLabel());
64 if( xSeq.is())
65 rOutResult.push_back( xSeq->getSourceRangeRepresentation());
66 xSeq.set( xLabeledSeq->getValues());
67 if( xSeq.is())
68 rOutResult.push_back( xSeq->getSourceRangeRepresentation());
69 }
70
lcl_addDataSourceRanges(::std::vector<::rtl::OUString> & rOutResult,const uno::Reference<data::XDataSource> & xDataSource)71 void lcl_addDataSourceRanges(
72 ::std::vector< ::rtl::OUString > & rOutResult,
73 const uno::Reference< data::XDataSource > & xDataSource )
74 {
75 if( xDataSource.is() )
76 {
77 uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
78 for( sal_Int32 i=0; i<aDataSequences.getLength(); ++i)
79 lcl_addRanges( rOutResult, aDataSequences[i] );
80 }
81 }
82
lcl_addErrorBarRanges(::std::vector<::rtl::OUString> & rOutResult,const uno::Reference<XDataSeries> & xDataSeries)83 void lcl_addErrorBarRanges(
84 ::std::vector< ::rtl::OUString > & rOutResult,
85 const uno::Reference< XDataSeries > & xDataSeries )
86 {
87 uno::Reference< beans::XPropertySet > xSeriesProp( xDataSeries, uno::UNO_QUERY );
88 if( !xSeriesProp.is())
89 return;
90
91 try
92 {
93 uno::Reference< beans::XPropertySet > xErrorBarProp;
94 if( ( xSeriesProp->getPropertyValue( C2U("ErrorBarY")) >>= xErrorBarProp ) &&
95 xErrorBarProp.is())
96 {
97 sal_Int32 eStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
98 if( ( xErrorBarProp->getPropertyValue( C2U("ErrorBarStyle")) >>= eStyle ) &&
99 eStyle == ::com::sun::star::chart::ErrorBarStyle::FROM_DATA )
100 {
101 uno::Reference< data::XDataSource > xErrorBarDataSource( xErrorBarProp, uno::UNO_QUERY );
102 if( xErrorBarDataSource.is() )
103 lcl_addDataSourceRanges( rOutResult, xErrorBarDataSource );
104 }
105 }
106 }
107 catch( const uno::Exception & ex )
108 {
109 ASSERT_EXCEPTION( ex );
110 }
111 }
112
113 } // anonymous namespace
114
createDataSource(const Sequence<Reference<chart2::data::XLabeledDataSequence>> & rSequences)115 Reference< chart2::data::XDataSource > DataSourceHelper::createDataSource(
116 const Sequence< Reference< chart2::data::XLabeledDataSequence > >& rSequences )
117 {
118 return new DataSource(rSequences);
119 }
120
createCachedDataSequence()121 Reference< chart2::data::XDataSequence > DataSourceHelper::createCachedDataSequence()
122 {
123 return new ::chart::CachedDataSequence();
124 }
125
createCachedDataSequence(const::rtl::OUString & rSingleText)126 Reference< chart2::data::XDataSequence > DataSourceHelper::createCachedDataSequence( const ::rtl::OUString& rSingleText )
127 {
128 return new ::chart::CachedDataSequence( rSingleText );
129 }
130
createLabeledDataSequence(const Reference<chart2::data::XDataSequence> & xValues,const Reference<chart2::data::XDataSequence> & xLabels)131 Reference< chart2::data::XLabeledDataSequence > DataSourceHelper::createLabeledDataSequence(
132 const Reference< chart2::data::XDataSequence >& xValues ,
133 const Reference< chart2::data::XDataSequence >& xLabels )
134 {
135 return new ::chart::LabeledDataSequence( xValues, xLabels );
136 }
137
createLabeledDataSequence(const Reference<chart2::data::XDataSequence> & xValues)138 Reference< chart2::data::XLabeledDataSequence > DataSourceHelper::createLabeledDataSequence(
139 const Reference< chart2::data::XDataSequence >& xValues )
140 {
141 return new ::chart::LabeledDataSequence( xValues );
142 }
143
createLabeledDataSequence(const Reference<uno::XComponentContext> & xContext)144 Reference< chart2::data::XLabeledDataSequence > DataSourceHelper::createLabeledDataSequence(
145 const Reference< uno::XComponentContext >& xContext )
146 {
147 return new ::chart::LabeledDataSequence( xContext );
148 }
149
createArguments(bool bUseColumns,bool bFirstCellAsLabel,bool bHasCategories)150 uno::Sequence< beans::PropertyValue > DataSourceHelper::createArguments(
151 bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories )
152 {
153 ::com::sun::star::chart::ChartDataRowSource eRowSource = ::com::sun::star::chart::ChartDataRowSource_ROWS;
154 if( bUseColumns )
155 eRowSource = ::com::sun::star::chart::ChartDataRowSource_COLUMNS;
156
157 uno::Sequence< beans::PropertyValue > aArguments(3);
158 aArguments[0] = beans::PropertyValue( C2U("DataRowSource")
159 , -1, uno::makeAny( eRowSource )
160 , beans::PropertyState_DIRECT_VALUE );
161 aArguments[1] = beans::PropertyValue( C2U("FirstCellAsLabel")
162 , -1, uno::makeAny( bFirstCellAsLabel )
163 , beans::PropertyState_DIRECT_VALUE );
164 aArguments[2] = beans::PropertyValue( C2U("HasCategories")
165 , -1, uno::makeAny( bHasCategories )
166 , beans::PropertyState_DIRECT_VALUE );
167
168 return aArguments;
169 }
170
createArguments(const::rtl::OUString & rRangeRepresentation,const uno::Sequence<sal_Int32> & rSequenceMapping,bool bUseColumns,bool bFirstCellAsLabel,bool bHasCategories)171 uno::Sequence< beans::PropertyValue > DataSourceHelper::createArguments(
172 const ::rtl::OUString & rRangeRepresentation,
173 const uno::Sequence< sal_Int32 >& rSequenceMapping,
174 bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories )
175 {
176 uno::Sequence< beans::PropertyValue > aArguments( createArguments( bUseColumns, bFirstCellAsLabel, bHasCategories ));
177 aArguments.realloc( aArguments.getLength() + 1 );
178 aArguments[aArguments.getLength() - 1] =
179 beans::PropertyValue( C2U("CellRangeRepresentation")
180 , -1, uno::makeAny( rRangeRepresentation )
181 , beans::PropertyState_DIRECT_VALUE );
182 if( rSequenceMapping.getLength() )
183 {
184 aArguments.realloc( aArguments.getLength() + 1 );
185 aArguments[aArguments.getLength() - 1] =
186 beans::PropertyValue( C2U("SequenceMapping")
187 , -1, uno::makeAny( rSequenceMapping )
188 , beans::PropertyState_DIRECT_VALUE );
189 }
190 return aArguments;
191 }
192
readArguments(const uno::Sequence<beans::PropertyValue> & rArguments,::rtl::OUString & rRangeRepresentation,uno::Sequence<sal_Int32> & rSequenceMapping,bool & bUseColumns,bool & bFirstCellAsLabel,bool & bHasCategories)193 void DataSourceHelper::readArguments( const uno::Sequence< beans::PropertyValue >& rArguments
194 , ::rtl::OUString & rRangeRepresentation, uno::Sequence< sal_Int32 >& rSequenceMapping
195 , bool& bUseColumns, bool& bFirstCellAsLabel, bool& bHasCategories )
196 {
197 const beans::PropertyValue* pArguments = rArguments.getConstArray();
198 for(sal_Int32 i=0; i<rArguments.getLength(); ++i, ++pArguments)
199 {
200 const beans::PropertyValue& aProperty = *pArguments;
201 if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DataRowSource" ) ))
202 {
203 ::com::sun::star::chart::ChartDataRowSource eRowSource;
204 if( aProperty.Value >>= eRowSource )
205 bUseColumns = (eRowSource==::com::sun::star::chart::ChartDataRowSource_COLUMNS);
206 }
207 else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FirstCellAsLabel" ) ))
208 {
209 aProperty.Value >>= bFirstCellAsLabel;
210 }
211 else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HasCategories" ) ))
212 {
213 aProperty.Value >>= bHasCategories;
214 }
215 else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CellRangeRepresentation" ) ))
216 {
217 aProperty.Value >>= rRangeRepresentation;
218 }
219 else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SequenceMapping" ) ))
220 {
221 aProperty.Value >>= rSequenceMapping;
222 }
223 }
224 }
225
pressUsedDataIntoRectangularFormat(const uno::Reference<chart2::XChartDocument> & xChartDoc,bool bWithCategories)226 uno::Reference< chart2::data::XDataSource > DataSourceHelper::pressUsedDataIntoRectangularFormat(
227 const uno::Reference< chart2::XChartDocument >& xChartDoc, bool bWithCategories )
228 {
229 ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultVector;
230
231 //categories are always the first sequence
232 Reference< chart2::XDiagram > xDiagram( xChartDoc->getFirstDiagram());
233
234 if( bWithCategories )
235 {
236 Reference< chart2::data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
237 if( xCategories.is() )
238 aResultVector.push_back( xCategories );
239 }
240
241 ::std::vector< Reference< chart2::XDataSeries > > xSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
242 uno::Reference< chart2::data::XDataSource > xSeriesSource(
243 DataSeriesHelper::getDataSource( ContainerHelper::ContainerToSequence(xSeriesVector) ) );
244 Sequence< Reference< chart2::data::XLabeledDataSequence > > aDataSeqences( xSeriesSource->getDataSequences() );
245
246 //the first x-values is always the next sequence //todo ... other x-values get lost for old format
247 Reference< chart2::data::XLabeledDataSequence > xXValues(
248 DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-x") ) );
249 if( xXValues.is() )
250 aResultVector.push_back( xXValues );
251
252 //add all other sequences now without x-values
253 for( sal_Int32 nN=0; nN<aDataSeqences.getLength(); nN++ )
254 {
255 OUString aRole( DataSeriesHelper::GetRole( aDataSeqences[nN] ) );
256 if( !aRole.equals(C2U("values-x")) )
257 aResultVector.push_back( aDataSeqences[nN] );
258 }
259
260 Sequence< Reference< chart2::data::XLabeledDataSequence > > aResultSequence( aResultVector.size() );
261 ::std::copy( aResultVector.begin(), aResultVector.end(), aResultSequence.getArray() );
262
263 return new DataSource( aResultSequence );
264 }
265
getUsedDataRanges(const uno::Reference<chart2::XDiagram> & xDiagram)266 uno::Sequence< ::rtl::OUString > DataSourceHelper::getUsedDataRanges(
267 const uno::Reference< chart2::XDiagram > & xDiagram )
268 {
269 ::std::vector< ::rtl::OUString > aResult;
270
271 if( xDiagram.is())
272 {
273 uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
274 if( xCategories.is() )
275 lcl_addRanges( aResult, xCategories );
276
277 ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
278 for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
279 ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
280 {
281 uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
282 lcl_addDataSourceRanges( aResult, xDataSource );
283 lcl_addErrorBarRanges( aResult, *aSeriesIt );
284 }
285 }
286
287 return ContainerHelper::ContainerToSequence( aResult );
288 }
289
getUsedDataRanges(const uno::Reference<frame::XModel> & xChartModel)290 uno::Sequence< ::rtl::OUString > DataSourceHelper::getUsedDataRanges( const uno::Reference< frame::XModel > & xChartModel )
291 {
292 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
293 return getUsedDataRanges( xDiagram );
294 }
295
getUsedData(const uno::Reference<chart2::XChartDocument> & xChartDoc)296 uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
297 const uno::Reference< chart2::XChartDocument >& xChartDoc )
298 {
299 return pressUsedDataIntoRectangularFormat( xChartDoc );
300 }
301
getUsedData(const uno::Reference<frame::XModel> & xChartModel)302 uno::Reference< chart2::data::XDataSource > DataSourceHelper::getUsedData(
303 const uno::Reference< frame::XModel >& xChartModel )
304 {
305 ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > aResult;
306
307 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
308 uno::Reference< data::XLabeledDataSequence > xCategories( DiagramHelper::getCategoriesFromDiagram( xDiagram ) );
309 if( xCategories.is() )
310 aResult.push_back( xCategories );
311
312 ::std::vector< uno::Reference< XDataSeries > > aSeriesVector( ChartModelHelper::getDataSeries( xChartModel ) );
313 for( ::std::vector< uno::Reference< XDataSeries > >::const_iterator aSeriesIt( aSeriesVector.begin() )
314 ; aSeriesIt != aSeriesVector.end(); ++aSeriesIt )
315 {
316 uno::Reference< data::XDataSource > xDataSource( *aSeriesIt, uno::UNO_QUERY );
317 if( !xDataSource.is() )
318 continue;
319 uno::Sequence< uno::Reference< data::XLabeledDataSequence > > aDataSequences( xDataSource->getDataSequences() );
320 ::std::copy( aDataSequences.getConstArray(), aDataSequences.getConstArray() + aDataSequences.getLength(),
321 ::std::back_inserter( aResult ));
322 }
323
324 return uno::Reference< chart2::data::XDataSource >(
325 new DataSource( ContainerHelper::ContainerToSequence( aResult )));
326 }
327
detectRangeSegmentation(const uno::Reference<frame::XModel> & xChartModel,::rtl::OUString & rOutRangeString,::com::sun::star::uno::Sequence<sal_Int32> & rSequenceMapping,bool & rOutUseColumns,bool & rOutFirstCellAsLabel,bool & rOutHasCategories)328 bool DataSourceHelper::detectRangeSegmentation(
329 const uno::Reference<
330 frame::XModel >& xChartModel
331 , ::rtl::OUString& rOutRangeString
332 , ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
333 , bool& rOutUseColumns
334 , bool& rOutFirstCellAsLabel
335 , bool& rOutHasCategories )
336 {
337 bool bSomethingDetected = false;
338
339 uno::Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY );
340 if( !xChartDocument.is() )
341 return bSomethingDetected;
342 uno::Reference< data::XDataProvider > xDataProvider( xChartDocument->getDataProvider() );
343 if( !xDataProvider.is() )
344 return bSomethingDetected;
345
346 try
347 {
348 DataSourceHelper::readArguments(
349 xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument ) ),
350 rOutRangeString, rSequenceMapping, rOutUseColumns, rOutFirstCellAsLabel, rOutHasCategories );
351 bSomethingDetected = !rOutRangeString.isEmpty();
352
353 uno::Reference< chart2::data::XLabeledDataSequence > xCategories(
354 DiagramHelper::getCategoriesFromDiagram( xChartDocument->getFirstDiagram() ));
355 rOutHasCategories = xCategories.is();
356 }
357 catch( uno::Exception & ex )
358 {
359 ASSERT_EXCEPTION( ex );
360 }
361 return bSomethingDetected;
362 }
363
allArgumentsForRectRangeDetected(const uno::Reference<chart2::XChartDocument> & xChartDocument)364 bool DataSourceHelper::allArgumentsForRectRangeDetected(
365 const uno::Reference< chart2::XChartDocument >& xChartDocument )
366 {
367 bool bHasDataRowSource = false;
368 bool bHasFirstCellAsLabel = false;
369 // bool bHasHasCategories = false;
370 bool bHasCellRangeRepresentation = false;
371 // bool bHasSequenceMapping = false;
372
373 uno::Reference< data::XDataProvider > xDataProvider( xChartDocument->getDataProvider() );
374 if( !xDataProvider.is() )
375 return false;
376
377 try
378 {
379 const uno::Sequence< beans::PropertyValue > aArguments(
380 xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument )));
381 const beans::PropertyValue* pArguments = aArguments.getConstArray();
382 for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
383 {
384 const beans::PropertyValue& aProperty = *pArguments;
385 if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DataRowSource" ) ))
386 {
387 bHasDataRowSource =
388 (aProperty.Value.hasValue() && aProperty.Value.isExtractableTo(
389 ::getCppuType( reinterpret_cast<
390 const ::com::sun::star::chart::ChartDataRowSource * >(0))));
391 }
392 else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "FirstCellAsLabel" ) ))
393 {
394 bHasFirstCellAsLabel =
395 (aProperty.Value.hasValue() && aProperty.Value.isExtractableTo(::getBooleanCppuType()));
396 }
397 // else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HasCategories" ) ))
398 // {
399 // bHasHasCategories =
400 // (aProperty.Value.hasValue() && aProperty.Value.isExtractableTo(::getBooleanCppuType()));
401 // }
402 else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CellRangeRepresentation" ) ))
403 {
404 ::rtl::OUString aRange;
405 bHasCellRangeRepresentation =
406 (aProperty.Value.hasValue() && (aProperty.Value >>= aRange) && !aRange.isEmpty());
407 }
408 // else if( aProperty.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SequenceMapping" ) ))
409 // {
410 // bHasSequenceMapping =
411 // (aProperty.Value.hasValue() && aProperty.Value.isExtractableTo(
412 // ::getCppuType( reinterpret_cast<
413 // const uno::Sequence< sal_Int32 > * >(0))));
414 // }
415 }
416 }
417 catch( const uno::Exception & ex )
418 {
419 ASSERT_EXCEPTION( ex );
420 }
421
422 return (bHasCellRangeRepresentation && bHasDataRowSource && bHasFirstCellAsLabel);
423 }
424
setRangeSegmentation(const uno::Reference<frame::XModel> & xChartModel,const::com::sun::star::uno::Sequence<sal_Int32> & rSequenceMapping,bool bUseColumns,bool bFirstCellAsLabel,bool bUseCategories)425 void DataSourceHelper::setRangeSegmentation(
426 const uno::Reference< frame::XModel >& xChartModel
427 , const ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
428 , bool bUseColumns , bool bFirstCellAsLabel, bool bUseCategories )
429 {
430 uno::Reference< XChartDocument > xChartDocument( xChartModel, uno::UNO_QUERY );
431 if( !xChartDocument.is() )
432 return;
433 uno::Reference< data::XDataProvider > xDataProvider( xChartDocument->getDataProvider() );
434 if( !xDataProvider.is() )
435 return;
436 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartModel ) );
437 if( !xDiagram.is() )
438 return;
439 uno::Reference< chart2::XChartTypeManager > xChartTypeManager( xChartDocument->getChartTypeManager() );
440 if( !xChartTypeManager.is() )
441 return;
442 uno::Reference< lang::XMultiServiceFactory > xTemplateFactory( xChartTypeManager, uno::UNO_QUERY );
443 if( !xTemplateFactory.is() )
444 return;
445
446 ::rtl::OUString aRangeString;
447 bool bDummy;
448 uno::Sequence< sal_Int32 > aDummy;
449 readArguments( xDataProvider->detectArguments( pressUsedDataIntoRectangularFormat( xChartDocument )),
450 aRangeString, aDummy, bDummy, bDummy, bDummy );
451
452 uno::Sequence< beans::PropertyValue > aArguments(
453 createArguments( aRangeString, rSequenceMapping, bUseColumns, bFirstCellAsLabel, bUseCategories ) );
454
455 uno::Reference< chart2::data::XDataSource > xDataSource( xDataProvider->createDataSource(
456 aArguments ) );
457 if( !xDataSource.is() )
458 return;
459
460 ControllerLockGuard aCtrlLockGuard( xChartModel );
461 xDiagram->setDiagramData( xDataSource, aArguments );
462 }
463
getRangesFromLabeledDataSequence(const Reference<data::XLabeledDataSequence> & xLSeq)464 Sequence< OUString > DataSourceHelper::getRangesFromLabeledDataSequence(
465 const Reference< data::XLabeledDataSequence > & xLSeq )
466 {
467 Sequence< OUString > aResult;
468 if( xLSeq.is())
469 {
470 Reference< data::XDataSequence > xLabel( xLSeq->getLabel());
471 Reference< data::XDataSequence > xValues( xLSeq->getValues());
472
473 if( xLabel.is())
474 {
475 if( xValues.is())
476 {
477 aResult.realloc( 2 );
478 aResult[0] = xLabel->getSourceRangeRepresentation();
479 aResult[1] = xValues->getSourceRangeRepresentation();
480 }
481 else
482 {
483 aResult.realloc( 1 );
484 aResult[0] = xLabel->getSourceRangeRepresentation();
485 }
486 }
487 else if( xValues.is())
488 {
489 aResult.realloc( 1 );
490 aResult[0] = xValues->getSourceRangeRepresentation();
491 }
492 }
493 return aResult;
494 }
495
getRangeFromValues(const Reference<data::XLabeledDataSequence> & xLSeq)496 OUString DataSourceHelper::getRangeFromValues(
497 const Reference< data::XLabeledDataSequence > & xLSeq )
498 {
499 OUString aResult;
500 if( xLSeq.is() )
501 {
502 Reference< data::XDataSequence > xValues( xLSeq->getValues() );
503 if( xValues.is() )
504 aResult = xValues->getSourceRangeRepresentation();
505 }
506 return aResult;
507 }
508
getRangesFromDataSource(const Reference<data::XDataSource> & xSource)509 Sequence< OUString > DataSourceHelper::getRangesFromDataSource( const Reference< data::XDataSource > & xSource )
510 {
511 ::std::vector< OUString > aResult;
512 if( xSource.is())
513 {
514 Sequence< Reference< data::XLabeledDataSequence > > aLSeqSeq( xSource->getDataSequences());
515 for( sal_Int32 i=0; i<aLSeqSeq.getLength(); ++i )
516 {
517 Reference< data::XDataSequence > xLabel( aLSeqSeq[i]->getLabel());
518 Reference< data::XDataSequence > xValues( aLSeqSeq[i]->getValues());
519
520 if( xLabel.is())
521 aResult.push_back( xLabel->getSourceRangeRepresentation());
522 if( xValues.is())
523 aResult.push_back( xValues->getSourceRangeRepresentation());
524 }
525 }
526 return ContainerHelper::ContainerToSequence( aResult );
527 }
528
529 //.............................................................................
530 } //namespace chart
531 //.............................................................................
532