Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include <rtl/math.hxx>
22 : :
23 : : #include <valarray>
24 : :
25 : : #include "InternalDataProvider.hxx"
26 : : #include "LabeledDataSequence.hxx"
27 : : #include "DataSource.hxx"
28 : : #include "PropertyHelper.hxx"
29 : : #include "macros.hxx"
30 : : #include "XMLRangeHelper.hxx"
31 : : #include "ContainerHelper.hxx"
32 : : #include "CommonConverters.hxx"
33 : : #include "CommonFunctors.hxx"
34 : : #include "UncachedDataSequence.hxx"
35 : : #include "DataSourceHelper.hxx"
36 : : #include "ChartModelHelper.hxx"
37 : : #include "DiagramHelper.hxx"
38 : : #include "ExplicitCategoriesProvider.hxx"
39 : :
40 : : #include <com/sun/star/chart2/XChartDocument.hpp>
41 : : #include <com/sun/star/chart2/data/XDataSequence.hpp>
42 : : #include <com/sun/star/chart/ChartDataRowSource.hpp>
43 : : #include <rtl/ustrbuf.hxx>
44 : : #include <unotools/charclass.hxx>
45 : : #include <comphelper/sequenceashashmap.hxx>
46 : :
47 : : #include <vector>
48 : : #include <algorithm>
49 : :
50 : : using namespace ::com::sun::star;
51 : : using namespace ::std;
52 : :
53 : : using ::com::sun::star::uno::Reference;
54 : : using ::com::sun::star::uno::Sequence;
55 : : using ::rtl::OUString;
56 : : using ::rtl::OUStringBuffer;
57 : :
58 : : namespace chart
59 : : {
60 : :
61 : : // ================================================================================
62 : :
63 : : namespace
64 : : {
65 : :
66 : : // note: in xmloff this name is used to indicate usage of own data
67 : 16 : static const ::rtl::OUString lcl_aServiceName(
68 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.InternalDataProvider" ));
69 : :
70 : 16 : static const ::rtl::OUString lcl_aCategoriesRangeName(
71 : : RTL_CONSTASCII_USTRINGPARAM( "categories" ));
72 : 16 : static const ::rtl::OUString lcl_aCategoriesLevelRangeNamePrefix(
73 : : RTL_CONSTASCII_USTRINGPARAM( "categoriesL " )); //L <-> level
74 : 16 : static const ::rtl::OUString lcl_aCategoriesPointRangeNamePrefix(
75 : : RTL_CONSTASCII_USTRINGPARAM( "categoriesP " )); //P <-> point
76 : 16 : static const ::rtl::OUString lcl_aCategoriesRoleName(
77 : : RTL_CONSTASCII_USTRINGPARAM( "categories" ));
78 : 16 : static const ::rtl::OUString lcl_aLabelRangePrefix(
79 : : RTL_CONSTASCII_USTRINGPARAM( "label " ));
80 : 16 : static const ::rtl::OUString lcl_aCompleteRange(
81 : : RTL_CONSTASCII_USTRINGPARAM( "all" ));
82 : :
83 : : typedef ::std::multimap< OUString, uno::WeakReference< chart2::data::XDataSequence > >
84 : : lcl_tSequenceMap;
85 : :
86 : 0 : Sequence< OUString > lcl_AnyToStringSequence( const Sequence< uno::Any >& aAnySeq )
87 : : {
88 : 0 : Sequence< OUString > aResult;
89 [ # # ]: 0 : aResult.realloc( aAnySeq.getLength() );
90 : 0 : transform( aAnySeq.getConstArray(), aAnySeq.getConstArray() + aAnySeq.getLength(),
91 [ # # ]: 0 : aResult.getArray(), CommonFunctors::AnyToString() );
92 : 0 : return aResult;
93 : : }
94 : :
95 : 195 : Sequence< uno::Any > lcl_StringToAnySequence( const Sequence< OUString >& aStringSeq )
96 : : {
97 : 195 : Sequence< uno::Any > aResult;
98 [ + - ]: 195 : aResult.realloc( aStringSeq.getLength() );
99 : 195 : transform( aStringSeq.getConstArray(), aStringSeq.getConstArray() + aStringSeq.getLength(),
100 [ + - + - ]: 390 : aResult.getArray(), CommonFunctors::makeAny< OUString >() );
101 : 195 : return aResult;
102 : : }
103 : :
104 : : struct lcl_setModified : public ::std::unary_function< lcl_tSequenceMap, void >
105 : : {
106 : 0 : void operator() ( const lcl_tSequenceMap::value_type & rMapEntry )
107 : : {
108 : : // convert weak reference to reference
109 [ # # ]: 0 : Reference< chart2::data::XDataSequence > xSeq( rMapEntry.second );
110 [ # # ]: 0 : if( xSeq.is())
111 : : {
112 [ # # ]: 0 : Reference< util::XModifiable > xMod( xSeq, uno::UNO_QUERY );
113 [ # # ]: 0 : if( xMod.is())
114 [ # # ][ # # ]: 0 : xMod->setModified( sal_True );
115 : 0 : }
116 : 0 : }
117 : : };
118 : :
119 : : struct lcl_internalizeSeries : public ::std::unary_function< Reference< chart2::XDataSeries >, void >
120 : : {
121 : 15 : lcl_internalizeSeries( InternalData & rInternalData,
122 : : InternalDataProvider & rProvider,
123 : : bool bConnectToModel, bool bDataInColumns ) :
124 : : m_rInternalData( rInternalData ),
125 : : m_rProvider( rProvider ),
126 : : m_bConnectToModel( bConnectToModel ),
127 : 15 : m_bDataInColumns( bDataInColumns )
128 : 15 : {}
129 : 195 : void operator() ( const Reference< chart2::XDataSeries > & xSeries )
130 : : {
131 [ + - ]: 195 : Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY );
132 [ + - ]: 195 : Reference< chart2::data::XDataSink > xSink( xSeries, uno::UNO_QUERY );
133 [ + - ][ + - ]: 195 : if( xSource.is() && xSink.is() )
[ + - ]
134 : : {
135 [ + - ][ + - ]: 195 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aOldSeriesData = xSource->getDataSequences();
136 [ + - ]: 195 : Sequence< Reference< chart2::data::XLabeledDataSequence > > aNewSeriesData( aOldSeriesData.getLength() );
137 [ + + ]: 390 : for( sal_Int32 i=0; i<aOldSeriesData.getLength(); ++i )
138 : : {
139 [ + - ][ + - ]: 195 : sal_Int32 nNewIndex( m_bDataInColumns ? m_rInternalData.appendColumn() : m_rInternalData.appendRow() );
[ # # ]
140 : 195 : OUString aIdentifier( OUString::valueOf( nNewIndex ));
141 : : //@todo: deal also with genericXDataSequence
142 [ + - ][ + - ]: 195 : Reference< chart2::data::XNumericalDataSequence > xValues( aOldSeriesData[i]->getValues(), uno::UNO_QUERY );
[ + - ][ + - ]
143 [ + - ][ + - ]: 195 : Reference< chart2::data::XTextualDataSequence > xLabel( aOldSeriesData[i]->getLabel(), uno::UNO_QUERY );
[ + - ][ + - ]
144 : 195 : Reference< chart2::data::XDataSequence > xNewValues;
145 : :
146 [ + - ]: 195 : if( xValues.is() )
147 : : {
148 [ + - ][ + - ]: 195 : ::std::vector< double > aValues( ContainerHelper::SequenceToVector( xValues->getNumericalData()));
[ + - ][ + - ]
149 [ + - ]: 195 : if( m_bDataInColumns )
150 [ + - ]: 195 : m_rInternalData.setColumnValues( nNewIndex, aValues );
151 : : else
152 [ # # ]: 0 : m_rInternalData.setRowValues( nNewIndex, aValues );
153 [ - + ]: 195 : if( m_bConnectToModel )
154 : : {
155 [ # # ][ # # ]: 0 : xNewValues.set( m_rProvider.createDataSequenceByRangeRepresentation( aIdentifier ));
156 : : comphelper::copyProperties(
157 : : Reference< beans::XPropertySet >( xValues, uno::UNO_QUERY ),
158 [ # # ][ # # ]: 0 : Reference< beans::XPropertySet >( xNewValues, uno::UNO_QUERY ));
[ # # ]
159 : 195 : }
160 : : }
161 : :
162 [ + - ]: 195 : if( xLabel.is() )
163 : : {
164 [ + - ]: 195 : if( m_bDataInColumns )
165 [ + - ][ + - ]: 195 : m_rInternalData.setComplexColumnLabel( nNewIndex, ContainerHelper::SequenceToVector( lcl_StringToAnySequence( xLabel->getTextualData() ) ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
166 : : else
167 [ # # ][ # # ]: 0 : m_rInternalData.setComplexRowLabel( nNewIndex, ContainerHelper::SequenceToVector( lcl_StringToAnySequence( xLabel->getTextualData() ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
168 [ - + ]: 195 : if( m_bConnectToModel )
169 : : {
170 : : Reference< chart2::data::XDataSequence > xNewLabel(
171 [ # # ]: 0 : m_rProvider.createDataSequenceByRangeRepresentation( lcl_aLabelRangePrefix + aIdentifier ));
172 : : comphelper::copyProperties(
173 : : Reference< beans::XPropertySet >( xLabel, uno::UNO_QUERY ),
174 [ # # ][ # # ]: 0 : Reference< beans::XPropertySet >( xNewLabel, uno::UNO_QUERY ));
[ # # ]
175 [ # # ]: 0 : aNewSeriesData[i] = Reference< chart2::data::XLabeledDataSequence >(
176 [ # # ][ # # ]: 0 : new LabeledDataSequence( xNewValues, xNewLabel ));
[ # # ][ # # ]
177 : : }
178 : : }
179 : : else
180 : : {
181 [ # # ]: 0 : if( m_bConnectToModel )
182 [ # # ]: 0 : aNewSeriesData[i] = Reference< chart2::data::XLabeledDataSequence >(
183 [ # # ][ # # ]: 0 : new LabeledDataSequence( xNewValues ));
[ # # ][ # # ]
184 : : }
185 : 195 : }
186 [ - + ]: 195 : if( m_bConnectToModel )
187 [ # # ][ # # ]: 195 : xSink->setData( aNewSeriesData );
[ + - ][ + - ]
188 : 195 : }
189 : 195 : }
190 : :
191 : : private:
192 : : InternalData & m_rInternalData;
193 : : InternalDataProvider & m_rProvider;
194 : : bool m_bConnectToModel;
195 : : bool m_bDataInColumns;
196 : : };
197 : :
198 : : struct lcl_copyFromLevel : public ::std::unary_function< vector< uno::Any >, uno::Any >
199 : : {
200 : : public:
201 : :
202 : 3235 : explicit lcl_copyFromLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
203 : 3235 : {}
204 : :
205 : 12940 : uno::Any operator() ( const vector< uno::Any >& rVector )
206 : : {
207 : 12940 : uno::Any aRet;
208 [ + - ]: 12940 : if( m_nLevel < static_cast< sal_Int32 >(rVector.size()) )
209 : 12940 : aRet = rVector[m_nLevel];
210 : 12940 : return aRet;
211 : : }
212 : :
213 : : private:
214 : : sal_Int32 m_nLevel;
215 : : };
216 : :
217 : : struct lcl_getStringFromLevelVector : public ::std::unary_function< vector< uno::Any >, OUString >
218 : : {
219 : : public:
220 : :
221 : 29 : explicit lcl_getStringFromLevelVector( sal_Int32 nLevel ) : m_nLevel( nLevel )
222 : 29 : {}
223 : :
224 : 141 : OUString operator() ( const vector< uno::Any >& rVector )
225 : : {
226 : 141 : OUString aString;
227 [ + - ]: 141 : if( m_nLevel < static_cast< sal_Int32 >(rVector.size()) )
228 : 141 : aString = CommonFunctors::AnyToString()(rVector[m_nLevel]);
229 : 141 : return aString;
230 : : }
231 : :
232 : : private:
233 : : sal_Int32 m_nLevel;
234 : : };
235 : :
236 : :
237 : : struct lcl_setAnyAtLevel : public ::std::binary_function< vector< uno::Any >, uno::Any, vector< uno::Any > >
238 : : {
239 : : public:
240 : :
241 : 15 : explicit lcl_setAnyAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
242 : 15 : {}
243 : :
244 : 45 : vector< uno::Any > operator() ( const vector< uno::Any >& rVector, const uno::Any& rNewValue )
245 : : {
246 : 45 : vector< uno::Any > aRet( rVector );
247 [ + - ]: 45 : if( m_nLevel >= static_cast< sal_Int32 >(aRet.size()) )
248 [ + - ]: 45 : aRet.resize( m_nLevel+1 );
249 : 45 : aRet[ m_nLevel ]=rNewValue;
250 : 45 : return aRet;
251 : : }
252 : :
253 : : private:
254 : : sal_Int32 m_nLevel;
255 : : };
256 : :
257 : : struct lcl_setAnyAtLevelFromStringSequence : public ::std::binary_function< vector< uno::Any >, OUString, vector< uno::Any > >
258 : : {
259 : : public:
260 : :
261 : 4 : explicit lcl_setAnyAtLevelFromStringSequence( sal_Int32 nLevel ) : m_nLevel( nLevel )
262 : 4 : {}
263 : :
264 : 14 : vector< uno::Any > operator() ( const vector< uno::Any >& rVector, const OUString& rNewValue )
265 : : {
266 : 14 : vector< uno::Any > aRet( rVector );
267 [ + - ]: 14 : if( m_nLevel >= static_cast< sal_Int32 >(aRet.size()) )
268 [ + - ]: 14 : aRet.resize( m_nLevel+1 );
269 [ + - ]: 14 : aRet[ m_nLevel ]=uno::makeAny(rNewValue);
270 : 14 : return aRet;
271 : : }
272 : :
273 : : private:
274 : : sal_Int32 m_nLevel;
275 : : };
276 : :
277 : : struct lcl_insertAnyAtLevel : public ::std::unary_function< vector< uno::Any >, void >
278 : : {
279 : : public:
280 : :
281 : 0 : explicit lcl_insertAnyAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
282 : 0 : {}
283 : :
284 : 0 : void operator() ( vector< uno::Any >& rVector )
285 : : {
286 [ # # ]: 0 : if( m_nLevel > static_cast< sal_Int32 >(rVector.size()) )
287 [ # # ]: 0 : rVector.resize( m_nLevel );
288 : :
289 : 0 : vector< uno::Any >::iterator aIt( rVector.begin() );
290 [ # # ][ # # ]: 0 : for( sal_Int32 nN=0; aIt<rVector.end(); aIt++, nN++)
[ # # ]
291 : : {
292 [ # # ]: 0 : if( nN==m_nLevel )
293 : 0 : break;
294 : : }
295 [ # # ]: 0 : rVector.insert( aIt, uno::Any() );
296 : 0 : }
297 : :
298 : : private:
299 : : sal_Int32 m_nLevel;
300 : : };
301 : :
302 : : struct lcl_removeAnyAtLevel : public ::std::unary_function< vector< uno::Any >, void >
303 : : {
304 : : public:
305 : :
306 : 0 : explicit lcl_removeAnyAtLevel( sal_Int32 nLevel ) : m_nLevel( nLevel )
307 : 0 : {}
308 : :
309 : 0 : void operator() ( vector< uno::Any >& rVector )
310 : : {
311 : 0 : vector< uno::Any >::iterator aIt( rVector.begin() );
312 [ # # ][ # # ]: 0 : for( sal_Int32 nN=0; aIt<rVector.end(); aIt++, nN++)
[ # # ]
313 : : {
314 [ # # ]: 0 : if( nN==m_nLevel )
315 : : {
316 [ # # ]: 0 : rVector.erase( aIt );
317 : 0 : break;
318 : : }
319 : : }
320 : 0 : }
321 : :
322 : : private:
323 : : sal_Int32 m_nLevel;
324 : : };
325 : :
326 : : } // anonymous namespace
327 : :
328 : : // ================================================================================
329 : :
330 : 0 : InternalDataProvider::InternalDataProvider( const Reference< uno::XComponentContext > & /*_xContext*/)
331 [ # # ][ # # ]: 0 : : m_bDataInColumns( true )
332 : 0 : {}
333 : :
334 : 71 : InternalDataProvider::InternalDataProvider( const Reference< chart2::XChartDocument > & xChartDoc, bool bConnectToModel )
335 [ + - ][ + - ]: 71 : : m_bDataInColumns( true )
336 : : {
337 : : try
338 : : {
339 [ + - ]: 71 : Reference< chart2::XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartDoc ) );
340 [ + + ]: 71 : if( xDiagram.is())
341 : : {
342 [ + - ]: 15 : Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
343 : :
344 : : //data in columns?
345 : : {
346 : 15 : ::rtl::OUString aRangeString;
347 : 15 : bool bFirstCellAsLabel = true;
348 : 15 : bool bHasCategories = true;
349 [ + - ]: 15 : uno::Sequence< sal_Int32 > aSequenceMapping;
350 [ + - ][ + - ]: 15 : DataSourceHelper::detectRangeSegmentation( xChartModel, aRangeString, aSequenceMapping, m_bDataInColumns, bFirstCellAsLabel, bHasCategories );
351 : : }
352 : :
353 : : // categories
354 : : {
355 [ + - ]: 15 : vector< vector< uno::Any > > aNewCategories;//inner count is level
356 : : {
357 [ + - ][ + - ]: 15 : ExplicitCategoriesProvider aExplicitCategoriesProvider( ChartModelHelper::getFirstCoordinateSystem(xChartModel), xChartModel );
358 : :
359 [ + - ]: 15 : const Sequence< Reference< chart2::data::XLabeledDataSequence> >& rSplitCategoriesList( aExplicitCategoriesProvider.getSplitCategoriesList() );
360 : 15 : sal_Int32 nLevelCount = rSplitCategoriesList.getLength();
361 [ + + ]: 30 : for( sal_Int32 nL = 0; nL<nLevelCount; nL++ )
362 : : {
363 : 15 : Reference< chart2::data::XLabeledDataSequence > xLDS( rSplitCategoriesList[nL] );
364 [ - + ]: 15 : if( !xLDS.is() )
365 : 0 : continue;
366 [ + - ]: 15 : Sequence< uno::Any > aDataSeq;
367 [ + - ][ + - ]: 15 : Reference< chart2::data::XDataSequence > xSeq( xLDS->getValues() );
368 [ + - ]: 15 : if( xSeq.is() )
369 [ + - ][ + - ]: 15 : aDataSeq = xSeq->getData();
[ + - ][ + - ]
370 : 15 : sal_Int32 nLength = aDataSeq.getLength();
371 : 15 : sal_Int32 nCatLength = static_cast< sal_Int32 >(aNewCategories.size());
372 [ + - ]: 15 : if( nCatLength < nLength )
373 [ + - ]: 15 : aNewCategories.resize( nLength );
374 [ # # ]: 0 : else if( nLength < nCatLength )
375 [ # # ]: 0 : aDataSeq.realloc( nCatLength );
376 : : transform( aNewCategories.begin(), aNewCategories.end(), aDataSeq.getConstArray(),
377 [ + - ]: 15 : aNewCategories.begin(), lcl_setAnyAtLevel(nL) );
378 [ + - ][ + - ]: 15 : }
379 [ - + ]: 15 : if( !nLevelCount )
380 : : {
381 [ # # ]: 0 : Sequence< OUString > aSimplecategories = aExplicitCategoriesProvider.getSimpleCategories();
382 : 0 : sal_Int32 nLength = aSimplecategories.getLength();
383 [ # # ]: 0 : aNewCategories.reserve( nLength );
384 [ # # ]: 0 : for( sal_Int32 nN=0; nN<nLength; nN++)
385 : : {
386 [ # # ]: 0 : vector< uno::Any > aVector(1);
387 [ # # ][ # # ]: 0 : aVector[0] = uno::makeAny( aSimplecategories[nN] );
388 [ # # ]: 0 : aNewCategories.push_back( aVector );
389 [ # # ]: 0 : }
390 [ + - ]: 15 : }
391 : : }
392 : :
393 [ + - ]: 15 : if( m_bDataInColumns )
394 [ + - ]: 15 : m_aInternalData.setComplexRowLabels( aNewCategories );
395 : : else
396 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( aNewCategories );
397 [ - + ]: 15 : if( bConnectToModel )
398 : : DiagramHelper::setCategoriesToDiagram( new LabeledDataSequence(
399 [ # # ][ # # ]: 15 : createDataSequenceByRangeRepresentation( lcl_aCategoriesRangeName )), xDiagram );
[ # # ][ # # ]
[ # # ]
400 : : }
401 : :
402 : : // data series
403 [ + - ]: 15 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVector( ChartModelHelper::getDataSeries( xChartDoc ));
404 [ + - ]: 15 : ::std::for_each( aSeriesVector.begin(), aSeriesVector.end(), lcl_internalizeSeries( m_aInternalData, *this, bConnectToModel, m_bDataInColumns ) );
405 [ # # ]: 71 : }
406 : : }
407 [ # # ]: 0 : catch( const uno::Exception & ex )
408 : : {
409 : : ASSERT_EXCEPTION( ex );
410 : : }
411 : 71 : }
412 : :
413 : : // copy-CTOR
414 : 0 : InternalDataProvider::InternalDataProvider( const InternalDataProvider & rOther ) :
415 : : impl::InternalDataProvider_Base(),
416 : : m_aSequenceMap( rOther.m_aSequenceMap ),
417 : : m_aInternalData( rOther.m_aInternalData ),
418 [ # # ][ # # ]: 0 : m_bDataInColumns( rOther.m_bDataInColumns )
419 : 0 : {}
420 : :
421 : 71 : InternalDataProvider::~InternalDataProvider()
422 [ - + ]: 142 : {}
423 : :
424 : 528 : void InternalDataProvider::lcl_addDataSequenceToMap(
425 : : const OUString & rRangeRepresentation,
426 : : const Reference< chart2::data::XDataSequence > & xSequence )
427 : : {
428 : : m_aSequenceMap.insert(
429 : : tSequenceMap::value_type(
430 : : rRangeRepresentation,
431 [ + - ][ + - ]: 528 : uno::WeakReference< chart2::data::XDataSequence >( xSequence )));
[ + - ]
432 : 528 : }
433 : :
434 : 0 : void InternalDataProvider::lcl_deleteMapReferences( const OUString & rRangeRepresentation )
435 : : {
436 : : // set sequence to deleted by setting its range to an empty string
437 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( rRangeRepresentation ));
438 [ # # ]: 0 : for( tSequenceMap::iterator aIt( aRange.first ); aIt != aRange.second; ++aIt )
439 : : {
440 [ # # ]: 0 : Reference< chart2::data::XDataSequence > xSeq( aIt->second );
441 [ # # ]: 0 : if( xSeq.is())
442 : : {
443 [ # # ]: 0 : Reference< container::XNamed > xNamed( xSeq, uno::UNO_QUERY );
444 [ # # ]: 0 : if( xNamed.is())
445 [ # # ][ # # ]: 0 : xNamed->setName( OUString());
446 : : }
447 : 0 : }
448 : : // remove from map
449 [ # # ]: 0 : m_aSequenceMap.erase( aRange.first, aRange.second );
450 : 0 : }
451 : :
452 : 0 : void InternalDataProvider::lcl_adaptMapReferences(
453 : : const OUString & rOldRangeRepresentation,
454 : : const OUString & rNewRangeRepresentation )
455 : : {
456 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( rOldRangeRepresentation ));
457 [ # # ]: 0 : tSequenceMap aNewElements;
458 [ # # ]: 0 : for( tSequenceMap::iterator aIt( aRange.first ); aIt != aRange.second; ++aIt )
459 : : {
460 [ # # ]: 0 : Reference< chart2::data::XDataSequence > xSeq( aIt->second );
461 [ # # ]: 0 : if( xSeq.is())
462 : : {
463 [ # # ]: 0 : Reference< container::XNamed > xNamed( xSeq, uno::UNO_QUERY );
464 [ # # ]: 0 : if( xNamed.is())
465 [ # # ][ # # ]: 0 : xNamed->setName( rNewRangeRepresentation );
466 : : }
467 [ # # ][ # # ]: 0 : aNewElements.insert( tSequenceMap::value_type( rNewRangeRepresentation, aIt->second ));
[ # # ]
468 : 0 : }
469 : : // erase map values for old index
470 [ # # ]: 0 : m_aSequenceMap.erase( aRange.first, aRange.second );
471 : : // add new entries for values with new index
472 : : ::std::copy( aNewElements.begin(), aNewElements.end(),
473 : : ::std::inserter( m_aSequenceMap,
474 [ # # ][ # # ]: 0 : m_aSequenceMap.upper_bound( rNewRangeRepresentation )));
[ # # ]
475 : 0 : }
476 : :
477 : 0 : void InternalDataProvider::lcl_increaseMapReferences(
478 : : sal_Int32 nBegin, sal_Int32 nEnd )
479 : : {
480 [ # # ]: 0 : for( sal_Int32 nIndex = nEnd - 1; nIndex >= nBegin; --nIndex )
481 : : {
482 : : lcl_adaptMapReferences( OUString::valueOf( nIndex ),
483 [ # # ]: 0 : OUString::valueOf( nIndex + 1 ));
484 : : lcl_adaptMapReferences( lcl_aLabelRangePrefix + OUString::valueOf( nIndex ),
485 [ # # ]: 0 : lcl_aLabelRangePrefix + OUString::valueOf( nIndex + 1 ));
486 : : }
487 : 0 : }
488 : :
489 : 0 : void InternalDataProvider::lcl_decreaseMapReferences(
490 : : sal_Int32 nBegin, sal_Int32 nEnd )
491 : : {
492 [ # # ]: 0 : for( sal_Int32 nIndex = nBegin; nIndex < nEnd; ++nIndex )
493 : : {
494 : : lcl_adaptMapReferences( OUString::valueOf( nIndex ),
495 [ # # ]: 0 : OUString::valueOf( nIndex - 1 ));
496 : : lcl_adaptMapReferences( lcl_aLabelRangePrefix + OUString::valueOf( nIndex ),
497 [ # # ]: 0 : lcl_aLabelRangePrefix + OUString::valueOf( nIndex - 1 ));
498 : : }
499 : 0 : }
500 : :
501 : 456 : Reference< chart2::data::XDataSequence > InternalDataProvider::lcl_createDataSequenceAndAddToMap(
502 : : const OUString & rRangeRepresentation )
503 : : {
504 : 456 : OUString aRangeRepresentation = rRangeRepresentation;
505 [ - + ]: 456 : if( aRangeRepresentation.indexOf('{') >= 0 )
506 : : {
507 [ # # ]: 0 : ::std::vector< double > aNewData;
508 [ # # ]: 0 : ::std::vector< uno::Any > aNewLabels;
509 : 0 : OUString aToken;
510 : 0 : sal_Int32 nCategories = 0;
511 : 0 : sal_Int32 nIndex = 0;
512 : 0 : bool bValues = true;
513 : 0 : bool bLabelSet = false;
514 : 0 : OUString str = aRangeRepresentation.replace('{',' ').replace('}',' ');
515 : :
516 [ # # ]: 0 : m_aInternalData.clearDefaultData();
517 [ # # ]: 0 : sal_Int32 n = m_aInternalData.getColumnCount();
518 [ # # ]: 0 : if( n )
519 : 0 : n = n - 1;
520 : :
521 [ # # ]: 0 : do
522 : : {
523 : : // TODO: This will be problematic if ';' is used in label names
524 : : // '"' character also needs to be considered in such cases
525 : 0 : aToken = str.getToken(0,';',nIndex);
526 [ # # ]: 0 : if( aToken.isEmpty() )
527 : 0 : break;
528 [ # # ]: 0 : if( aToken.indexOf('"') < 0 )
529 : : {
530 [ # # ]: 0 : aNewData.push_back( aToken.toDouble() );
531 : : }
532 : : else
533 : : {
534 [ # # ][ # # ]: 0 : aNewLabels.push_back( uno::makeAny(aToken.replace('"', ' ').trim()) );
535 [ # # ][ # # : 0 : if( !nCategories &&
# # # # ]
536 [ # # ][ # # ]: 0 : ( !m_aInternalData.getComplexColumnLabel(n).size() ||
[ # # ]
537 [ # # ][ # # ]: 0 : !m_aInternalData.getComplexColumnLabel(n).front().hasValue() ) )
[ # # ][ # # ]
538 : : {
539 [ # # ]: 0 : m_aInternalData.setComplexColumnLabel( n, aNewLabels );
540 : 0 : bLabelSet = true;
541 : : }
542 : : else
543 : : {
544 [ # # ]: 0 : m_aInternalData.setComplexRowLabel(nCategories, aNewLabels);
545 [ # # ][ # # ]: 0 : if(nCategories==1 && bLabelSet)
546 : : {
547 [ # # ]: 0 : ::std::vector< uno::Any > aLabels;
548 [ # # ][ # # ]: 0 : m_aInternalData.setComplexRowLabel( 0, m_aInternalData.getComplexColumnLabel( n ) );
549 [ # # ]: 0 : m_aInternalData.setComplexColumnLabel( n, aLabels );
550 : : }
551 : : }
552 [ # # ]: 0 : aNewLabels.pop_back();
553 : 0 : nCategories++;
554 : 0 : bValues = false;
555 : : }
556 : : } while( nIndex >= 0 );
557 : :
558 [ # # ]: 0 : if( bValues )
559 : : {
560 [ # # ]: 0 : m_aInternalData.insertColumn( n );
561 [ # # ]: 0 : m_aInternalData.setColumnValues( n, aNewData );
562 : 0 : aRangeRepresentation = OUString::valueOf( n );
563 : : }
564 [ # # ]: 0 : else if( nCategories > 1 )
565 : : {
566 : 0 : aRangeRepresentation = lcl_aCategoriesRangeName;
567 : : }
568 : : else
569 : : {
570 : 0 : aRangeRepresentation = lcl_aLabelRangePrefix+OUString::valueOf( n );
571 : 0 : }
572 : : }
573 : :
574 : : Reference< chart2::data::XDataSequence > xSeq(
575 [ + - ][ + - ]: 456 : new UncachedDataSequence( this, aRangeRepresentation ));
[ + - ][ + - ]
576 [ + - ]: 456 : lcl_addDataSequenceToMap( aRangeRepresentation, xSeq );
577 : 456 : return xSeq;
578 : : }
579 : :
580 : 72 : Reference< chart2::data::XDataSequence > InternalDataProvider::lcl_createDataSequenceAndAddToMap(
581 : : const OUString & rRangeRepresentation,
582 : : const OUString & rRole )
583 : : {
584 : : Reference< chart2::data::XDataSequence > xSeq(
585 [ + - ][ + - ]: 72 : new UncachedDataSequence( this, rRangeRepresentation, rRole ));
[ + - ]
586 [ + - ]: 72 : lcl_addDataSequenceToMap( rRangeRepresentation, xSeq );
587 : 72 : return xSeq;
588 : : }
589 : :
590 : 50 : void InternalDataProvider::createDefaultData()
591 : : {
592 : 50 : m_aInternalData.createDefaultData();
593 : 50 : }
594 : :
595 : : // ____ XDataProvider ____
596 : 0 : ::sal_Bool SAL_CALL InternalDataProvider::createDataSourcePossible( const Sequence< beans::PropertyValue >& /* aArguments */ )
597 : : throw (uno::RuntimeException)
598 : : {
599 : 0 : return true;
600 : : }
601 : :
602 : : namespace
603 : : {
604 : :
605 : 8988 : sal_Int32 lcl_getInnerLevelCount( const vector< vector< uno::Any > >& rLabels )
606 : : {
607 : 8988 : sal_Int32 nCount = 1;//minimum is 1!
608 : 8988 : vector< vector< uno::Any > >::const_iterator aLevelIt( rLabels.begin() );
609 : 8988 : vector< vector< uno::Any > >::const_iterator aLevelEnd( rLabels.end() );
610 [ + - ][ + + ]: 44990 : for( ;aLevelIt!=aLevelEnd; ++aLevelIt )
611 : : {
612 : 36002 : const vector< uno::Any >& rCurrentLevelLabels = *aLevelIt;
613 [ + - ]: 36002 : nCount = std::max<sal_Int32>( rCurrentLevelLabels.size(), nCount );
614 : : }
615 : 8988 : return nCount;
616 : : }
617 : :
618 : : }//end anonymous namespace
619 : :
620 : 4990 : Reference< chart2::data::XDataSource > SAL_CALL InternalDataProvider::createDataSource(
621 : : const Sequence< beans::PropertyValue >& aArguments )
622 : : throw (lang::IllegalArgumentException,
623 : : uno::RuntimeException)
624 : : {
625 : 4990 : OUString aRangeRepresentation;
626 : 4990 : bool bUseColumns = true;
627 : 4990 : bool bFirstCellAsLabel = true;
628 : 4990 : bool bHasCategories = true;
629 [ + - ]: 4990 : uno::Sequence< sal_Int32 > aSequenceMapping;
630 [ + - ]: 4990 : DataSourceHelper::readArguments( aArguments, aRangeRepresentation, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories );
631 : :
632 [ + + ]: 4990 : if( aRangeRepresentation.equals( lcl_aCategoriesRangeName ) )
633 : : {
634 : : //return split complex categories if we have any:
635 [ + - ]: 4920 : ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aComplexCategories;
636 [ + - ][ + - ]: 4920 : vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
[ # # ]
637 [ + + ]: 4920 : if( bUseColumns==m_bDataInColumns )
638 : : {
639 [ + - ]: 2460 : sal_Int32 nLevelCount = lcl_getInnerLevelCount( aCategories );
640 [ + + ]: 4920 : for( sal_Int32 nL=0; nL<nLevelCount; nL++ )
641 : : aComplexCategories.push_back( new LabeledDataSequence(
642 : : new UncachedDataSequence( this
643 : : , lcl_aCategoriesLevelRangeNamePrefix + OUString::valueOf( nL )
644 [ + - ][ + - ]: 2460 : , lcl_aCategoriesRoleName ) ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
645 : : }
646 : : else
647 : : {
648 [ + - ][ + - ]: 2460 : sal_Int32 nPointCount = m_bDataInColumns ? m_aInternalData.getRowCount() : m_aInternalData.getColumnCount();
[ # # ]
649 [ + + ]: 12300 : for( sal_Int32 nP=0; nP<nPointCount; nP++ )
650 : : aComplexCategories.push_back( new LabeledDataSequence(
651 : : new UncachedDataSequence( this
652 : : , lcl_aCategoriesPointRangeNamePrefix + OUString::valueOf( nP )
653 [ + - ][ + - ]: 9840 : , lcl_aCategoriesRoleName ) ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
654 : : }
655 : : //don't add the created sequences to the map as they are used temporarily only ...
656 [ + - ][ + - ]: 4920 : return new DataSource( ContainerHelper::ContainerToSequence(aComplexCategories) );
[ + - ][ + - ]
[ + - ]
657 : : }
658 : :
659 : : OSL_ASSERT( aRangeRepresentation.equals( lcl_aCompleteRange ));
660 : :
661 [ + - ]: 70 : ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aResultLSeqVec;
662 : :
663 : : // categories
664 [ + + ]: 70 : if( bHasCategories )
665 : : aResultLSeqVec.push_back(
666 [ + - ][ + - ]: 66 : new LabeledDataSequence( lcl_createDataSequenceAndAddToMap( lcl_aCategoriesRangeName, lcl_aCategoriesRoleName ) ) );
[ + - ][ + - ]
[ + - ]
667 : :
668 : : // data with labels
669 [ + - ]: 70 : ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aDataVec;
670 [ + - ][ + - ]: 70 : const sal_Int32 nCount = (bUseColumns ? m_aInternalData.getColumnCount() : m_aInternalData.getRowCount());
[ # # ]
671 [ + + ]: 280 : for( sal_Int32 nIdx=0; nIdx<nCount; ++nIdx )
672 : : {
673 : : aDataVec.push_back(
674 : : new LabeledDataSequence(
675 : : lcl_createDataSequenceAndAddToMap( OUString::valueOf( nIdx )),
676 [ + - ][ + - ]: 210 : lcl_createDataSequenceAndAddToMap( lcl_aLabelRangePrefix + OUString::valueOf( nIdx ))));
[ + - ][ + - ]
[ + - ][ + - ]
677 : : }
678 : :
679 : : // attention: this data provider has the limitation that it stores
680 : : // internally if data comes from columns or rows. It is intended for
681 : : // creating only one used data source.
682 : : // @todo: add this information in the range representation strings
683 : 70 : m_bDataInColumns = bUseColumns;
684 : :
685 : : //reorder labeled sequences according to aSequenceMapping; ignore categories
686 [ - + ]: 70 : for( sal_Int32 nNewIndex = 0; nNewIndex < aSequenceMapping.getLength(); nNewIndex++ )
687 : : {
688 [ # # ]: 0 : std::vector< LabeledDataSequence* >::size_type nOldIndex = aSequenceMapping[nNewIndex];
689 [ # # ]: 0 : if( nOldIndex < aDataVec.size() )
690 : : {
691 [ # # ]: 0 : if( aDataVec[nOldIndex].is() )
692 : : {
693 [ # # ]: 0 : aResultLSeqVec.push_back( aDataVec[nOldIndex] );
694 [ # # ]: 0 : aDataVec[nOldIndex] = 0;
695 : : }
696 : : }
697 : : }
698 : :
699 : : //add left over data sequences to result
700 : 70 : ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::iterator aIt(aDataVec.begin());
701 [ + - ]: 70 : const ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::const_iterator aEndIt(aDataVec.end());
702 [ + - ][ + + ]: 280 : for( ;aIt!=aEndIt; ++aIt)
703 : : {
704 [ + - ]: 210 : if( aIt->is() )
705 [ + - ]: 210 : aResultLSeqVec.push_back( *aIt );
706 : : }
707 : :
708 [ + - ][ + - ]: 4990 : return new DataSource( ContainerHelper::ContainerToSequence(aResultLSeqVec) );
[ + - ][ + - ]
[ + - ][ + - ]
709 : : }
710 : :
711 : 114 : Sequence< beans::PropertyValue > SAL_CALL InternalDataProvider::detectArguments(
712 : : const Reference< chart2::data::XDataSource >& /* xDataSource */ )
713 : : throw (uno::RuntimeException)
714 : : {
715 : 114 : Sequence< beans::PropertyValue > aArguments( 4 );
716 [ + - ]: 114 : aArguments[0] = beans::PropertyValue(
717 : : C2U("CellRangeRepresentation"), -1, uno::makeAny( lcl_aCompleteRange ),
718 [ + - ][ + - ]: 228 : beans::PropertyState_DIRECT_VALUE );
719 [ + - ]: 114 : aArguments[1] = beans::PropertyValue(
720 : : C2U("DataRowSource"), -1, uno::makeAny(
721 : : m_bDataInColumns
722 : : ? ::com::sun::star::chart::ChartDataRowSource_COLUMNS
723 : : : ::com::sun::star::chart::ChartDataRowSource_ROWS ),
724 [ + - ][ + - ]: 228 : beans::PropertyState_DIRECT_VALUE );
[ + - ]
725 : : // internal data always contains labels and categories
726 [ + - ]: 114 : aArguments[2] = beans::PropertyValue(
727 [ + - ][ + - ]: 228 : C2U("FirstCellAsLabel"), -1, uno::makeAny( true ), beans::PropertyState_DIRECT_VALUE );
728 [ + - ]: 114 : aArguments[3] = beans::PropertyValue(
729 [ + - ][ + - ]: 228 : C2U("HasCategories"), -1, uno::makeAny( true ), beans::PropertyState_DIRECT_VALUE );
730 : :
731 : : // #i85913# Sequence Mapping is not needed for internal data, as it is
732 : : // applied to the data when the data source is created.
733 : :
734 : 114 : return aArguments;
735 : : }
736 : :
737 : 0 : ::sal_Bool SAL_CALL InternalDataProvider::createDataSequenceByRangeRepresentationPossible( const OUString& /* aRangeRepresentation */ )
738 : : throw (uno::RuntimeException)
739 : : {
740 : 0 : return true;
741 : : }
742 : :
743 : 42 : Reference< chart2::data::XDataSequence > SAL_CALL InternalDataProvider::createDataSequenceByRangeRepresentation(
744 : : const OUString& aRangeRepresentation )
745 : : throw (lang::IllegalArgumentException,
746 : : uno::RuntimeException)
747 : : {
748 [ + + ]: 42 : if( aRangeRepresentation.match( lcl_aCategoriesRangeName ))
749 : : {
750 : : OSL_ASSERT( aRangeRepresentation.equals( lcl_aCategoriesRangeName ) );//it is not expected nor implmented that only parts of the categories are really requested
751 : :
752 : : // categories
753 : 6 : return lcl_createDataSequenceAndAddToMap( lcl_aCategoriesRangeName, lcl_aCategoriesRoleName );
754 : : }
755 [ + + ]: 36 : else if( aRangeRepresentation.match( lcl_aLabelRangePrefix ))
756 : : {
757 : : // label
758 : 18 : sal_Int32 nIndex = aRangeRepresentation.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
759 [ + - ]: 18 : return lcl_createDataSequenceAndAddToMap( lcl_aLabelRangePrefix + OUString::valueOf( nIndex ));
760 : : }
761 [ - + ]: 18 : else if ( aRangeRepresentation == "last" )
762 : : {
763 : : sal_Int32 nIndex = (m_bDataInColumns
764 : 0 : ? m_aInternalData.getColumnCount()
765 [ # # ]: 0 : : m_aInternalData.getRowCount()) - 1;
766 [ # # ]: 0 : return lcl_createDataSequenceAndAddToMap( OUString::valueOf( nIndex ));
767 : : }
768 [ + - ]: 18 : else if( !aRangeRepresentation.isEmpty())
769 : : {
770 : : // data
771 : 18 : return lcl_createDataSequenceAndAddToMap( aRangeRepresentation );
772 : : }
773 : :
774 : 42 : return Reference< chart2::data::XDataSequence >();
775 : : }
776 : :
777 : 0 : Reference< sheet::XRangeSelection > SAL_CALL InternalDataProvider::getRangeSelection()
778 : : throw (uno::RuntimeException)
779 : : {
780 : : // there is no range selection component
781 : 0 : return Reference< sheet::XRangeSelection >();
782 : : }
783 : :
784 : : // ____ XInternalDataProvider ____
785 : 0 : ::sal_Bool SAL_CALL InternalDataProvider::hasDataByRangeRepresentation( const OUString& aRange )
786 : : throw (uno::RuntimeException)
787 : : {
788 : 0 : sal_Bool bResult = false;
789 : :
790 [ # # ]: 0 : if( aRange.match( lcl_aCategoriesRangeName ))
791 : : {
792 : : OSL_ASSERT( aRange.equals( lcl_aCategoriesRangeName ) );//it is not expected nor implmented that only parts of the categories are really requested
793 : 0 : bResult = true;
794 : : }
795 [ # # ]: 0 : else if( aRange.match( lcl_aLabelRangePrefix ))
796 : : {
797 : 0 : sal_Int32 nIndex = aRange.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
798 [ # # ]: 0 : bResult = (nIndex < (m_bDataInColumns ? m_aInternalData.getColumnCount(): m_aInternalData.getRowCount()));
799 : : }
800 : : else
801 : : {
802 : 0 : sal_Int32 nIndex = aRange.toInt32();
803 [ # # ]: 0 : bResult = (nIndex < (m_bDataInColumns ? m_aInternalData.getColumnCount(): m_aInternalData.getRowCount()));
804 : : }
805 : :
806 : 0 : return bResult;
807 : : }
808 : :
809 : 22459 : Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation( const OUString& aRange )
810 : : throw (uno::RuntimeException)
811 : : {
812 : 22459 : Sequence< uno::Any > aResult;
813 : :
814 [ + + ]: 22459 : if( aRange.match( lcl_aLabelRangePrefix ) )
815 : : {
816 : 9277 : sal_Int32 nIndex = aRange.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
817 : : vector< uno::Any > aComplexLabel = m_bDataInColumns
818 : : ? m_aInternalData.getComplexColumnLabel( nIndex )
819 [ + - ][ # # ]: 9277 : : m_aInternalData.getComplexRowLabel( nIndex );
[ + - ]
820 [ + - ]: 9277 : if( !aComplexLabel.empty() )
821 [ + - ][ + - ]: 9277 : aResult = ContainerHelper::ContainerToSequence(aComplexLabel);
[ + - ]
822 : : }
823 [ - + ]: 13182 : else if( aRange.match( lcl_aCategoriesPointRangeNamePrefix ) )
824 : : {
825 : 0 : sal_Int32 nPointIndex = aRange.copy( lcl_aCategoriesPointRangeNamePrefix.getLength() ).toInt32();
826 : : vector< uno::Any > aComplexCategory = m_bDataInColumns
827 : : ? m_aInternalData.getComplexRowLabel( nPointIndex )
828 [ # # ][ # # ]: 0 : : m_aInternalData.getComplexColumnLabel( nPointIndex );
[ # # ]
829 [ # # ]: 0 : if( !aComplexCategory.empty() )
830 [ # # ][ # # ]: 0 : aResult = ContainerHelper::ContainerToSequence(aComplexCategory);
[ # # ]
831 : : }
832 [ + + ]: 13182 : else if( aRange.match( lcl_aCategoriesLevelRangeNamePrefix ) )
833 : : {
834 : 3235 : sal_Int32 nLevel = aRange.copy( lcl_aCategoriesLevelRangeNamePrefix.getLength() ).toInt32();
835 [ + - ][ # # ]: 3235 : vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
[ + - ]
836 [ + - ][ + - ]: 3235 : if( nLevel < lcl_getInnerLevelCount( aCategories ) )
837 : : {
838 [ + - ]: 3235 : aResult.realloc( aCategories.size() );
839 : : transform( aCategories.begin(), aCategories.end(),
840 [ + - ][ + - ]: 3235 : aResult.getArray(), lcl_copyFromLevel(nLevel) );
841 : 3235 : }
842 : : }
843 [ + + ]: 9947 : else if( aRange.equals( lcl_aCategoriesRangeName ) )
844 : : {
845 [ + - ][ + - ]: 3235 : vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
[ # # ]
846 [ + - ]: 3235 : sal_Int32 nLevelCount = lcl_getInnerLevelCount( aCategories );
847 [ + - ]: 3235 : if( nLevelCount == 1 )
848 : : {
849 : 3235 : sal_Int32 nL=0;
850 [ + - ][ + - ]: 3235 : aResult = this->getDataByRangeRepresentation( lcl_aCategoriesLevelRangeNamePrefix + OUString::valueOf( nL ) );
[ + - ]
851 : : }
852 : : else
853 : : {
854 [ # # ][ # # ]: 0 : Sequence< OUString > aLabels = m_bDataInColumns ? this->getRowDescriptions() : this->getColumnDescriptions();
[ # # ]
855 [ # # ]: 0 : aResult.realloc( aLabels.getLength() );
856 : 0 : transform( aLabels.getConstArray(), aLabels.getConstArray() + aLabels.getLength(),
857 [ # # # # ]: 0 : aResult.getArray(), CommonFunctors::makeAny< OUString >() );
[ # # ]
858 : 3235 : }
859 : : }
860 : : else
861 : : {
862 : 6712 : sal_Int32 nIndex = aRange.toInt32();
863 [ + - ]: 6712 : if( nIndex >= 0 )
864 : : {
865 [ + - ]: 6712 : Sequence< double > aData;
866 [ + - ]: 6712 : if( m_bDataInColumns )
867 [ + - ][ + - ]: 6712 : aData = m_aInternalData.getColumnValues(nIndex);
[ + - ]
868 : : else
869 [ # # ][ # # ]: 0 : aData = m_aInternalData.getRowValues(nIndex);
[ # # ]
870 [ + - ]: 6712 : if( aData.getLength() )
871 : : {
872 [ + - ]: 6712 : aResult.realloc( aData.getLength());
873 : 6712 : transform( aData.getConstArray(), aData.getConstArray() + aData.getLength(),
874 [ + - + - ]: 13424 : aResult.getArray(), CommonFunctors::makeAny< double >());
875 [ + - ]: 6712 : }
876 : : }
877 : : }
878 : :
879 : 22459 : return aResult;
880 : : }
881 : :
882 : 0 : void SAL_CALL InternalDataProvider::setDataByRangeRepresentation(
883 : : const OUString& aRange, const Sequence< uno::Any >& aNewData )
884 : : throw (uno::RuntimeException)
885 : : {
886 [ # # ]: 0 : vector< uno::Any > aNewVector( ContainerHelper::SequenceToVector(aNewData) );
887 [ # # ]: 0 : if( aRange.match( lcl_aLabelRangePrefix ) )
888 : : {
889 : 0 : sal_uInt32 nIndex = aRange.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
890 [ # # ]: 0 : if( m_bDataInColumns )
891 [ # # ]: 0 : m_aInternalData.setComplexColumnLabel( nIndex, aNewVector );
892 : : else
893 [ # # ]: 0 : m_aInternalData.setComplexRowLabel( nIndex, aNewVector );
894 : : }
895 [ # # ]: 0 : else if( aRange.match( lcl_aCategoriesPointRangeNamePrefix ) )
896 : : {
897 : 0 : sal_Int32 nPointIndex = aRange.copy( lcl_aCategoriesLevelRangeNamePrefix.getLength()).toInt32();
898 [ # # ]: 0 : if( m_bDataInColumns )
899 [ # # ]: 0 : m_aInternalData.setComplexRowLabel( nPointIndex, aNewVector );
900 : : else
901 [ # # ]: 0 : m_aInternalData.setComplexColumnLabel( nPointIndex, aNewVector );
902 : : }
903 [ # # ]: 0 : else if( aRange.match( lcl_aCategoriesLevelRangeNamePrefix ) )
904 : : {
905 : 0 : sal_Int32 nLevel = aRange.copy( lcl_aCategoriesLevelRangeNamePrefix.getLength()).toInt32();
906 [ # # ][ # # ]: 0 : vector< vector< uno::Any > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
[ # # ]
907 : :
908 : : //ensure equal length
909 [ # # ]: 0 : if( aNewVector.size() > aComplexCategories.size() )
910 [ # # ]: 0 : aComplexCategories.resize( aNewVector.size() );
911 [ # # ]: 0 : else if( aNewVector.size() < aComplexCategories.size() )
912 [ # # ]: 0 : aNewVector.resize( aComplexCategories.size() );
913 : :
914 : : transform( aComplexCategories.begin(), aComplexCategories.end(), aNewVector.begin(),
915 [ # # ]: 0 : aComplexCategories.begin(), lcl_setAnyAtLevel(nLevel) );
916 : :
917 [ # # ]: 0 : if( m_bDataInColumns )
918 [ # # ]: 0 : m_aInternalData.setComplexRowLabels( aComplexCategories );
919 : : else
920 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( aComplexCategories );
921 : : }
922 [ # # ]: 0 : else if( aRange.equals( lcl_aCategoriesRangeName ) )
923 : : {
924 [ # # ]: 0 : vector< vector< uno::Any > > aComplexCategories;
925 [ # # ]: 0 : aComplexCategories.resize( aNewVector.size() );
926 : : transform( aComplexCategories.begin(), aComplexCategories.end(), aNewVector.begin(),
927 [ # # ]: 0 : aComplexCategories.begin(), lcl_setAnyAtLevel(0) );
928 [ # # ]: 0 : if( m_bDataInColumns )
929 [ # # ]: 0 : m_aInternalData.setComplexRowLabels( aComplexCategories );
930 : : else
931 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( aComplexCategories );
932 : : }
933 : : else
934 : : {
935 : 0 : sal_Int32 nIndex = aRange.toInt32();
936 [ # # ]: 0 : if( nIndex>=0 )
937 : : {
938 [ # # ]: 0 : vector< double > aNewDataVec;
939 : 0 : transform( aNewData.getConstArray(), aNewData.getConstArray() + aNewData.getLength(),
940 [ # # # # ]: 0 : back_inserter( aNewDataVec ), CommonFunctors::AnyToDouble());
941 [ # # ]: 0 : if( m_bDataInColumns )
942 [ # # ]: 0 : m_aInternalData.setColumnValues( nIndex, aNewDataVec );
943 : : else
944 [ # # ]: 0 : m_aInternalData.setRowValues( nIndex, aNewDataVec );
945 : : }
946 : 0 : }
947 : 0 : }
948 : :
949 : 0 : void SAL_CALL InternalDataProvider::insertSequence( ::sal_Int32 nAfterIndex )
950 : : throw (uno::RuntimeException)
951 : : {
952 [ # # ]: 0 : if( m_bDataInColumns )
953 : : {
954 : 0 : lcl_increaseMapReferences( nAfterIndex + 1, m_aInternalData.getColumnCount());
955 : 0 : m_aInternalData.insertColumn( nAfterIndex );
956 : : }
957 : : else
958 : : {
959 : 0 : lcl_increaseMapReferences( nAfterIndex + 1, m_aInternalData.getRowCount());
960 : 0 : m_aInternalData.insertRow( nAfterIndex );
961 : : }
962 : 0 : }
963 : :
964 : 0 : void SAL_CALL InternalDataProvider::deleteSequence( ::sal_Int32 nAtIndex )
965 : : throw (uno::RuntimeException)
966 : : {
967 [ # # ]: 0 : lcl_deleteMapReferences( OUString::valueOf( nAtIndex ));
968 [ # # ]: 0 : lcl_deleteMapReferences( lcl_aLabelRangePrefix + OUString::valueOf( nAtIndex ));
969 [ # # ]: 0 : if( m_bDataInColumns )
970 : : {
971 : 0 : lcl_decreaseMapReferences( nAtIndex + 1, m_aInternalData.getColumnCount());
972 : 0 : m_aInternalData.deleteColumn( nAtIndex );
973 : : }
974 : : else
975 : : {
976 : 0 : lcl_decreaseMapReferences( nAtIndex + 1, m_aInternalData.getRowCount());
977 : 0 : m_aInternalData.deleteRow( nAtIndex );
978 : : }
979 : 0 : }
980 : :
981 : 0 : void SAL_CALL InternalDataProvider::appendSequence()
982 : : throw (uno::RuntimeException)
983 : : {
984 [ # # ]: 0 : if( m_bDataInColumns )
985 : 0 : m_aInternalData.appendColumn();
986 : : else
987 : 0 : m_aInternalData.appendRow();
988 : 0 : }
989 : :
990 : 0 : void SAL_CALL InternalDataProvider::insertComplexCategoryLevel( sal_Int32 nLevel )
991 : : throw (uno::RuntimeException)
992 : : {
993 : : OSL_ENSURE( nLevel> 0, "you can only insert category levels > 0" );//the first categories level cannot be deleted, check the calling code for error
994 [ # # ]: 0 : if( nLevel>0 )
995 : : {
996 [ # # ][ # # ]: 0 : vector< vector< uno::Any > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
[ # # ]
997 [ # # ]: 0 : ::std::for_each( aComplexCategories.begin(), aComplexCategories.end(), lcl_insertAnyAtLevel(nLevel) );
998 [ # # ]: 0 : if( m_bDataInColumns )
999 [ # # ]: 0 : m_aInternalData.setComplexRowLabels( aComplexCategories );
1000 : : else
1001 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( aComplexCategories );
1002 : :
1003 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( lcl_aCategoriesRangeName ));
1004 [ # # ]: 0 : ::std::for_each( aRange.first, aRange.second, lcl_setModified());
1005 : : }
1006 : 0 : }
1007 : 0 : void SAL_CALL InternalDataProvider::deleteComplexCategoryLevel( sal_Int32 nLevel )
1008 : : throw (uno::RuntimeException)
1009 : : {
1010 : : OSL_ENSURE( nLevel>0, "you can only delete category levels > 0" );//the first categories level cannot be deleted, check the calling code for error
1011 [ # # ]: 0 : if( nLevel>0 )
1012 : : {
1013 [ # # ][ # # ]: 0 : vector< vector< uno::Any > > aComplexCategories = m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels();
[ # # ]
1014 [ # # ]: 0 : ::std::for_each( aComplexCategories.begin(), aComplexCategories.end(), lcl_removeAnyAtLevel(nLevel) );
1015 [ # # ]: 0 : if( m_bDataInColumns )
1016 [ # # ]: 0 : m_aInternalData.setComplexRowLabels( aComplexCategories );
1017 : : else
1018 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( aComplexCategories );
1019 : :
1020 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( lcl_aCategoriesRangeName ));
1021 [ # # ]: 0 : ::std::for_each( aRange.first, aRange.second, lcl_setModified());
1022 : : }
1023 : 0 : }
1024 : :
1025 : 0 : void SAL_CALL InternalDataProvider::insertDataPointForAllSequences( ::sal_Int32 nAfterIndex )
1026 : : throw (uno::RuntimeException)
1027 : : {
1028 : 0 : sal_Int32 nMaxRep = 0;
1029 [ # # ]: 0 : if( m_bDataInColumns )
1030 : : {
1031 [ # # ]: 0 : m_aInternalData.insertRow( nAfterIndex );
1032 [ # # ]: 0 : nMaxRep = m_aInternalData.getColumnCount();
1033 : : }
1034 : : else
1035 : : {
1036 [ # # ]: 0 : m_aInternalData.insertColumn( nAfterIndex );
1037 [ # # ]: 0 : nMaxRep = m_aInternalData.getRowCount();
1038 : : }
1039 : :
1040 : : // notify change to all affected ranges
1041 [ # # ][ # # ]: 0 : tSequenceMap::const_iterator aBegin( m_aSequenceMap.lower_bound( C2U("0")));
1042 [ # # ]: 0 : tSequenceMap::const_iterator aEnd( m_aSequenceMap.upper_bound( OUString::valueOf( nMaxRep )));
1043 [ # # ]: 0 : ::std::for_each( aBegin, aEnd, lcl_setModified());
1044 : :
1045 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( lcl_aCategoriesRangeName ));
1046 [ # # ]: 0 : ::std::for_each( aRange.first, aRange.second, lcl_setModified());
1047 : 0 : }
1048 : :
1049 : 0 : void SAL_CALL InternalDataProvider::deleteDataPointForAllSequences( ::sal_Int32 nAtIndex )
1050 : : throw (uno::RuntimeException)
1051 : : {
1052 : 0 : sal_Int32 nMaxRep = 0;
1053 [ # # ]: 0 : if( m_bDataInColumns )
1054 : : {
1055 [ # # ]: 0 : m_aInternalData.deleteRow( nAtIndex );
1056 [ # # ]: 0 : nMaxRep = m_aInternalData.getColumnCount();
1057 : : }
1058 : : else
1059 : : {
1060 [ # # ]: 0 : m_aInternalData.deleteColumn( nAtIndex );
1061 [ # # ]: 0 : nMaxRep = m_aInternalData.getRowCount();
1062 : : }
1063 : :
1064 : : // notify change to all affected ranges
1065 [ # # ][ # # ]: 0 : tSequenceMap::const_iterator aBegin( m_aSequenceMap.lower_bound( C2U("0")));
1066 [ # # ]: 0 : tSequenceMap::const_iterator aEnd( m_aSequenceMap.upper_bound( OUString::valueOf( nMaxRep )));
1067 [ # # ]: 0 : ::std::for_each( aBegin, aEnd, lcl_setModified());
1068 : :
1069 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( lcl_aCategoriesRangeName ));
1070 [ # # ]: 0 : ::std::for_each( aRange.first, aRange.second, lcl_setModified());
1071 : 0 : }
1072 : :
1073 : 0 : void SAL_CALL InternalDataProvider::swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex )
1074 : : throw (uno::RuntimeException)
1075 : : {
1076 [ # # ]: 0 : if( m_bDataInColumns )
1077 [ # # ]: 0 : m_aInternalData.swapRowWithNext( nAtIndex );
1078 : : else
1079 [ # # ]: 0 : m_aInternalData.swapColumnWithNext( nAtIndex );
1080 : : sal_Int32 nMaxRep = (m_bDataInColumns
1081 : 0 : ? m_aInternalData.getColumnCount()
1082 [ # # ][ # # ]: 0 : : m_aInternalData.getRowCount());
[ # # ]
1083 : :
1084 : : // notify change to all affected ranges
1085 [ # # ][ # # ]: 0 : tSequenceMap::const_iterator aBegin( m_aSequenceMap.lower_bound( C2U("0")));
1086 [ # # ]: 0 : tSequenceMap::const_iterator aEnd( m_aSequenceMap.upper_bound( OUString::valueOf( nMaxRep )));
1087 [ # # ]: 0 : ::std::for_each( aBegin, aEnd, lcl_setModified());
1088 : :
1089 [ # # ]: 0 : tSequenceMapRange aRange( m_aSequenceMap.equal_range( lcl_aCategoriesRangeName ));
1090 [ # # ]: 0 : ::std::for_each( aRange.first, aRange.second, lcl_setModified());
1091 : 0 : }
1092 : :
1093 : 0 : void SAL_CALL InternalDataProvider::registerDataSequenceForChanges( const Reference< chart2::data::XDataSequence >& xSeq )
1094 : : throw (uno::RuntimeException)
1095 : : {
1096 [ # # ]: 0 : if( xSeq.is())
1097 [ # # ]: 0 : lcl_addDataSequenceToMap( xSeq->getSourceRangeRepresentation(), xSeq );
1098 : 0 : }
1099 : :
1100 : :
1101 : : // ____ XRangeXMLConversion ____
1102 : 136 : OUString SAL_CALL InternalDataProvider::convertRangeToXML( const OUString& aRangeRepresentation )
1103 : : throw (lang::IllegalArgumentException,
1104 : : uno::RuntimeException)
1105 : : {
1106 [ + - ]: 136 : XMLRangeHelper::CellRange aRange;
1107 [ + - ]: 136 : aRange.aTableName = OUString(RTL_CONSTASCII_USTRINGPARAM("local-table"));
1108 : :
1109 : : // attention: this data provider has the limitation that it stores
1110 : : // internally if data comes from columns or rows. It is intended for
1111 : : // creating only one used data source.
1112 : : // @todo: add this information in the range representation strings
1113 [ + + ]: 136 : if( aRangeRepresentation.match( lcl_aCategoriesRangeName ))
1114 : : {
1115 : : OSL_ASSERT( aRangeRepresentation.equals( lcl_aCategoriesRangeName ) );//it is not expected nor implmented that only parts of the categories are really requested
1116 : 16 : aRange.aUpperLeft.bIsEmpty = false;
1117 [ + - ]: 16 : if( m_bDataInColumns )
1118 : : {
1119 : 16 : aRange.aUpperLeft.nColumn = 0;
1120 : 16 : aRange.aUpperLeft.nRow = 1;
1121 : 16 : aRange.aLowerRight = aRange.aUpperLeft;
1122 [ + - ]: 16 : aRange.aLowerRight.nRow = m_aInternalData.getRowCount();
1123 : : }
1124 : : else
1125 : : {
1126 : 0 : aRange.aUpperLeft.nColumn = 1;
1127 : 0 : aRange.aUpperLeft.nRow = 0;
1128 : 0 : aRange.aLowerRight = aRange.aUpperLeft;
1129 [ # # ]: 0 : aRange.aLowerRight.nColumn = m_aInternalData.getColumnCount();
1130 : : }
1131 : : }
1132 [ + + ]: 120 : else if( aRangeRepresentation.match( lcl_aLabelRangePrefix ))
1133 : : {
1134 : 48 : sal_Int32 nIndex = aRangeRepresentation.copy( lcl_aLabelRangePrefix.getLength()).toInt32();
1135 : 48 : aRange.aUpperLeft.bIsEmpty = false;
1136 : 48 : aRange.aLowerRight.bIsEmpty = true;
1137 [ + - ]: 48 : if( m_bDataInColumns )
1138 : : {
1139 : 48 : aRange.aUpperLeft.nColumn = nIndex + 1;
1140 : 48 : aRange.aUpperLeft.nRow = 0;
1141 : : }
1142 : : else
1143 : : {
1144 : 0 : aRange.aUpperLeft.nColumn = 0;
1145 : 0 : aRange.aUpperLeft.nRow = nIndex + 1;
1146 : : }
1147 : : }
1148 [ + + ]: 72 : else if( aRangeRepresentation.equals( lcl_aCompleteRange ))
1149 : : {
1150 : 24 : aRange.aUpperLeft.bIsEmpty = false;
1151 : 24 : aRange.aLowerRight.bIsEmpty = false;
1152 : 24 : aRange.aUpperLeft.nColumn = 0;
1153 : 24 : aRange.aUpperLeft.nRow = 0;
1154 [ + - ]: 24 : aRange.aLowerRight.nColumn = m_aInternalData.getColumnCount();
1155 [ + - ]: 24 : aRange.aLowerRight.nRow = m_aInternalData.getRowCount();
1156 : : }
1157 : : else
1158 : : {
1159 : 48 : sal_Int32 nIndex = aRangeRepresentation.toInt32();
1160 : 48 : aRange.aUpperLeft.bIsEmpty = false;
1161 [ + - ]: 48 : if( m_bDataInColumns )
1162 : : {
1163 : 48 : aRange.aUpperLeft.nColumn = nIndex + 1;
1164 : 48 : aRange.aUpperLeft.nRow = 1;
1165 : 48 : aRange.aLowerRight = aRange.aUpperLeft;
1166 [ + - ]: 48 : aRange.aLowerRight.nRow = m_aInternalData.getRowCount();
1167 : : }
1168 : : else
1169 : : {
1170 : 0 : aRange.aUpperLeft.nColumn = 1;
1171 : 0 : aRange.aUpperLeft.nRow = nIndex + 1;
1172 : 0 : aRange.aLowerRight = aRange.aUpperLeft;
1173 [ # # ]: 0 : aRange.aLowerRight.nColumn = m_aInternalData.getColumnCount();
1174 : : }
1175 : : }
1176 : :
1177 [ + - ][ + - ]: 136 : return XMLRangeHelper::getXMLStringFromCellRange( aRange );
1178 : : }
1179 : :
1180 : 42 : OUString SAL_CALL InternalDataProvider::convertRangeFromXML( const OUString& aXMLRange )
1181 : : throw (lang::IllegalArgumentException,
1182 : : uno::RuntimeException)
1183 : : {
1184 [ + - ]: 42 : XMLRangeHelper::CellRange aRange( XMLRangeHelper::getCellRangeFromXMLString( aXMLRange ));
1185 [ - + ]: 42 : if( aRange.aUpperLeft.bIsEmpty )
1186 : : {
1187 : : OSL_ENSURE( aRange.aLowerRight.bIsEmpty, "Weird Range" );
1188 : 0 : return OUString();
1189 : : }
1190 : :
1191 : : // "all"
1192 [ + + ][ - + ]: 42 : if( !aRange.aLowerRight.bIsEmpty &&
[ # # ]
1193 : : ( aRange.aUpperLeft.nColumn != aRange.aLowerRight.nColumn ) &&
1194 : : ( aRange.aUpperLeft.nRow != aRange.aLowerRight.nRow ) )
1195 : 0 : return lcl_aCompleteRange;
1196 : :
1197 : : // attention: this data provider has the limitation that it stores
1198 : : // internally if data comes from columns or rows. It is intended for
1199 : : // creating only one used data source.
1200 : : // @todo: add this information in the range representation strings
1201 : :
1202 : : // data in columns
1203 [ + - ]: 42 : if( m_bDataInColumns )
1204 : : {
1205 [ + + ]: 42 : if( aRange.aUpperLeft.nColumn == 0 )
1206 : 6 : return lcl_aCategoriesRangeName;
1207 [ + + ]: 36 : if( aRange.aUpperLeft.nRow == 0 )
1208 : 18 : return lcl_aLabelRangePrefix + OUString::valueOf( aRange.aUpperLeft.nColumn - 1 );
1209 : :
1210 : 18 : return OUString::valueOf( aRange.aUpperLeft.nColumn - 1 );
1211 : : }
1212 : :
1213 : : // data in rows
1214 [ # # ]: 0 : if( aRange.aUpperLeft.nRow == 0 )
1215 : 0 : return lcl_aCategoriesRangeName;
1216 [ # # ]: 0 : if( aRange.aUpperLeft.nColumn == 0 )
1217 : 0 : return lcl_aLabelRangePrefix + OUString::valueOf( aRange.aUpperLeft.nRow - 1 );
1218 : :
1219 [ + - ]: 42 : return OUString::valueOf( aRange.aUpperLeft.nRow - 1 );
1220 : : }
1221 : :
1222 : : namespace
1223 : : {
1224 : :
1225 : : template< class Type >
1226 : 9 : Sequence< Sequence< Type > > lcl_convertVectorVectorToSequenceSequence( const vector< vector< Type > >& rIn )
1227 : : {
1228 : 9 : Sequence< Sequence< Type > > aRet;
1229 : 9 : sal_Int32 nOuterCount = rIn.size();
1230 [ + - ]: 9 : if( nOuterCount )
1231 : : {
1232 [ + - ]: 9 : aRet.realloc(nOuterCount);
1233 [ + + ]: 44 : for( sal_Int32 nN=0; nN<nOuterCount; nN++)
1234 [ + - ][ + - ]: 35 : aRet[nN]= ContainerHelper::ContainerToSequence( rIn[nN] );
[ + - ][ + - ]
1235 : : }
1236 : 9 : return aRet;
1237 : : }
1238 : :
1239 : : template< class Type >
1240 : 12 : vector< vector< Type > > lcl_convertSequenceSequenceToVectorVector( const Sequence< Sequence< Type > >& rIn )
1241 : : {
1242 : 12 : vector< vector< Type > > aRet;
1243 : 12 : sal_Int32 nOuterCount = rIn.getLength();
1244 [ + - ]: 12 : if( nOuterCount )
1245 : : {
1246 [ + - ]: 12 : aRet.resize(nOuterCount);
1247 [ + + ]: 54 : for( sal_Int32 nN=0; nN<nOuterCount; nN++)
1248 [ + - ]: 42 : aRet[nN]= ContainerHelper::SequenceToVector( rIn[nN] );
1249 : : }
1250 : 12 : return aRet;
1251 : : }
1252 : :
1253 : 0 : Sequence< Sequence< OUString > > lcl_convertComplexAnyVectorToStringSequence( const vector< vector< uno::Any > >& rIn )
1254 : : {
1255 : 0 : Sequence< Sequence< OUString > > aRet;
1256 : 0 : sal_Int32 nOuterCount = rIn.size();
1257 [ # # ]: 0 : if( nOuterCount )
1258 : : {
1259 [ # # ]: 0 : aRet.realloc(nOuterCount);
1260 [ # # ]: 0 : for( sal_Int32 nN=0; nN<nOuterCount; nN++)
1261 [ # # ][ # # ]: 0 : aRet[nN]= lcl_AnyToStringSequence( ContainerHelper::ContainerToSequence( rIn[nN] ) );
[ # # ][ # # ]
[ # # ][ # # ]
1262 : : }
1263 : 0 : return aRet;
1264 : : }
1265 : :
1266 : 0 : vector< vector< uno::Any > > lcl_convertComplexStringSequenceToAnyVector( const Sequence< Sequence< OUString > >& rIn )
1267 : : {
1268 : 0 : vector< vector< uno::Any > > aRet;
1269 : 0 : sal_Int32 nOuterCount = rIn.getLength();
1270 [ # # ]: 0 : for( sal_Int32 nN=0; nN<nOuterCount; nN++)
1271 [ # # ][ # # ]: 0 : aRet.push_back( ContainerHelper::SequenceToVector( lcl_StringToAnySequence( rIn[nN] ) ) );
[ # # ][ # # ]
1272 : 0 : return aRet;
1273 : : }
1274 : :
1275 : : class SplitCategoriesProvider_ForComplexDescriptions : public SplitCategoriesProvider
1276 : : {
1277 : : public:
1278 : :
1279 : 29 : explicit SplitCategoriesProvider_ForComplexDescriptions( const ::std::vector< ::std::vector< uno::Any > >& rComplexDescriptions )
1280 : 29 : : m_rComplexDescriptions( rComplexDescriptions )
1281 : 29 : {}
1282 : 29 : virtual ~SplitCategoriesProvider_ForComplexDescriptions()
1283 [ - + ]: 29 : {}
1284 : :
1285 : : virtual sal_Int32 getLevelCount() const;
1286 : : virtual uno::Sequence< rtl::OUString > getStringsForLevel( sal_Int32 nIndex ) const;
1287 : :
1288 : : private:
1289 : : const ::std::vector< ::std::vector< uno::Any > >& m_rComplexDescriptions;
1290 : : };
1291 : :
1292 : 29 : sal_Int32 SplitCategoriesProvider_ForComplexDescriptions::getLevelCount() const
1293 : : {
1294 : 29 : return lcl_getInnerLevelCount( m_rComplexDescriptions );
1295 : : }
1296 : 29 : uno::Sequence< rtl::OUString > SplitCategoriesProvider_ForComplexDescriptions::getStringsForLevel( sal_Int32 nLevel ) const
1297 : : {
1298 : 29 : uno::Sequence< rtl::OUString > aResult;
1299 [ + - ][ + - ]: 29 : if( nLevel < lcl_getInnerLevelCount( m_rComplexDescriptions ) )
1300 : : {
1301 [ + - ]: 29 : aResult.realloc( m_rComplexDescriptions.size() );
1302 : : transform( m_rComplexDescriptions.begin(), m_rComplexDescriptions.end(),
1303 [ + - ][ + - ]: 29 : aResult.getArray(), lcl_getStringFromLevelVector(nLevel) );
1304 : : }
1305 : 29 : return aResult;
1306 : : }
1307 : :
1308 : : }//anonymous namespace
1309 : :
1310 : : // ____ XDateCategories ____
1311 : 0 : Sequence< double > SAL_CALL InternalDataProvider::getDateCategories() throw (uno::RuntimeException)
1312 : : {
1313 : 0 : double fNan = InternalDataProvider::getNotANumber();
1314 : 0 : double fValue = fNan;
1315 [ # # ][ # # ]: 0 : vector< vector< uno::Any > > aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels());
[ # # ]
1316 : 0 : sal_Int32 nCount = aCategories.size();
1317 [ # # ]: 0 : Sequence< double > aDoubles( nCount );
1318 : 0 : vector< vector< uno::Any > >::iterator aIt( aCategories.begin() );
1319 [ # # ]: 0 : vector< vector< uno::Any > >::const_iterator aEnd( aCategories.end() );
1320 [ # # ][ # # ]: 0 : for(sal_Int32 nN=0; nN<nCount && aIt!=aEnd; ++nN, ++aIt )
[ # # ][ # # ]
1321 : : {
1322 [ # # ][ # # ]: 0 : if( !( !aIt->empty() && ((*aIt)[0]>>=fValue) ) )
[ # # ]
1323 : 0 : fValue = fNan;
1324 [ # # ]: 0 : aDoubles[nN]=fValue;
1325 : : }
1326 : 0 : return aDoubles;
1327 : : }
1328 : :
1329 : 0 : void SAL_CALL InternalDataProvider::setDateCategories( const Sequence< double >& rDates ) throw (uno::RuntimeException)
1330 : : {
1331 : 0 : sal_Int32 nCount = rDates.getLength();
1332 [ # # ]: 0 : vector< vector< uno::Any > > aNewCategories;
1333 [ # # ]: 0 : aNewCategories.reserve(nCount);
1334 [ # # ]: 0 : vector< uno::Any > aSingleLabel(1);
1335 : :
1336 [ # # ]: 0 : for(sal_Int32 nN=0; nN<nCount; ++nN )
1337 : : {
1338 [ # # ]: 0 : aSingleLabel[0]=uno::makeAny(rDates[nN]);
1339 [ # # ]: 0 : aNewCategories.push_back(aSingleLabel);
1340 : : }
1341 : :
1342 [ # # ]: 0 : if( m_bDataInColumns )
1343 [ # # ]: 0 : m_aInternalData.setComplexRowLabels( aNewCategories );
1344 : : else
1345 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( aNewCategories );
1346 : 0 : }
1347 : :
1348 : : // ____ XAnyDescriptionAccess ____
1349 : 9 : Sequence< Sequence< uno::Any > > SAL_CALL InternalDataProvider::getAnyRowDescriptions() throw (uno::RuntimeException)
1350 : : {
1351 [ + - ]: 9 : return lcl_convertVectorVectorToSequenceSequence( m_aInternalData.getComplexRowLabels() );
1352 : : }
1353 : 6 : void SAL_CALL InternalDataProvider::setAnyRowDescriptions( const Sequence< Sequence< uno::Any > >& aRowDescriptions ) throw (uno::RuntimeException)
1354 : : {
1355 [ + - ]: 6 : m_aInternalData.setComplexRowLabels( lcl_convertSequenceSequenceToVectorVector( aRowDescriptions ) );
1356 : 6 : }
1357 : 0 : Sequence< Sequence< uno::Any > > SAL_CALL InternalDataProvider::getAnyColumnDescriptions() throw (uno::RuntimeException)
1358 : : {
1359 [ # # ]: 0 : return lcl_convertVectorVectorToSequenceSequence( m_aInternalData.getComplexColumnLabels() );
1360 : : }
1361 : 6 : void SAL_CALL InternalDataProvider::setAnyColumnDescriptions( const Sequence< Sequence< uno::Any > >& aColumnDescriptions ) throw (uno::RuntimeException)
1362 : : {
1363 [ + - ]: 6 : m_aInternalData.setComplexColumnLabels( lcl_convertSequenceSequenceToVectorVector( aColumnDescriptions ) );
1364 : 6 : }
1365 : :
1366 : : // ____ XComplexDescriptionAccess ____
1367 : 0 : Sequence< Sequence< OUString > > SAL_CALL InternalDataProvider::getComplexRowDescriptions() throw (uno::RuntimeException)
1368 : : {
1369 [ # # ]: 0 : return lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexRowLabels() );
1370 : : }
1371 : 0 : void SAL_CALL InternalDataProvider::setComplexRowDescriptions( const Sequence< Sequence< ::rtl::OUString > >& aRowDescriptions ) throw (uno::RuntimeException)
1372 : : {
1373 [ # # ]: 0 : m_aInternalData.setComplexRowLabels( lcl_convertComplexStringSequenceToAnyVector(aRowDescriptions) );
1374 : 0 : }
1375 : 0 : Sequence< Sequence< ::rtl::OUString > > SAL_CALL InternalDataProvider::getComplexColumnDescriptions() throw (uno::RuntimeException)
1376 : : {
1377 [ # # ]: 0 : return lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexColumnLabels() );
1378 : : }
1379 : 0 : void SAL_CALL InternalDataProvider::setComplexColumnDescriptions( const Sequence< Sequence< ::rtl::OUString > >& aColumnDescriptions ) throw (uno::RuntimeException)
1380 : : {
1381 [ # # ]: 0 : m_aInternalData.setComplexColumnLabels( lcl_convertComplexStringSequenceToAnyVector(aColumnDescriptions) );
1382 : 0 : }
1383 : :
1384 : : // ____ XChartDataArray ____
1385 : 12 : Sequence< Sequence< double > > SAL_CALL InternalDataProvider::getData()
1386 : : throw (uno::RuntimeException)
1387 : : {
1388 : 12 : return m_aInternalData.getData();
1389 : : }
1390 : :
1391 : 16 : void SAL_CALL InternalDataProvider::setData( const Sequence< Sequence< double > >& rDataInRows )
1392 : : throw (uno::RuntimeException)
1393 : : {
1394 : 16 : return m_aInternalData.setData( rDataInRows );
1395 : : }
1396 : :
1397 : 2 : void SAL_CALL InternalDataProvider::setRowDescriptions( const Sequence< OUString >& aRowDescriptions )
1398 : : throw (uno::RuntimeException)
1399 : : {
1400 [ + - ]: 2 : vector< vector< uno::Any > > aComplexDescriptions( aRowDescriptions.getLength() );
1401 : : transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aRowDescriptions.getConstArray(),
1402 [ + - ]: 2 : aComplexDescriptions.begin(), lcl_setAnyAtLevelFromStringSequence(0) );
1403 [ + - ]: 2 : m_aInternalData.setComplexRowLabels( aComplexDescriptions );
1404 : 2 : }
1405 : :
1406 : 2 : void SAL_CALL InternalDataProvider::setColumnDescriptions( const Sequence< OUString >& aColumnDescriptions )
1407 : : throw (uno::RuntimeException)
1408 : : {
1409 [ + - ]: 2 : vector< vector< uno::Any > > aComplexDescriptions( aColumnDescriptions.getLength() );
1410 : : transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aColumnDescriptions.getConstArray(),
1411 [ + - ]: 2 : aComplexDescriptions.begin(), lcl_setAnyAtLevelFromStringSequence(0) );
1412 [ + - ]: 2 : m_aInternalData.setComplexColumnLabels( aComplexDescriptions );
1413 : 2 : }
1414 : :
1415 : 19 : Sequence< OUString > SAL_CALL InternalDataProvider::getRowDescriptions()
1416 : : throw (uno::RuntimeException)
1417 : : {
1418 [ + - ]: 19 : vector< vector< uno::Any > > aComplexLabels( m_aInternalData.getComplexRowLabels() );
1419 [ + - ]: 19 : SplitCategoriesProvider_ForComplexDescriptions aProvider( aComplexLabels );
1420 [ + - ][ + - ]: 19 : return ExplicitCategoriesProvider::getExplicitSimpleCategories( aProvider );
1421 : : }
1422 : :
1423 : 10 : Sequence< OUString > SAL_CALL InternalDataProvider::getColumnDescriptions()
1424 : : throw (uno::RuntimeException)
1425 : : {
1426 [ + - ]: 10 : vector< vector< uno::Any > > aComplexLabels( m_aInternalData.getComplexColumnLabels() );
1427 [ + - ]: 10 : SplitCategoriesProvider_ForComplexDescriptions aProvider( aComplexLabels );
1428 [ + - ][ + - ]: 10 : return ExplicitCategoriesProvider::getExplicitSimpleCategories( aProvider );
1429 : : }
1430 : :
1431 : : // ____ XChartData (base of XChartDataArray) ____
1432 : 0 : void SAL_CALL InternalDataProvider::addChartDataChangeEventListener(
1433 : : const Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& )
1434 : : throw (uno::RuntimeException)
1435 : : {
1436 : 0 : }
1437 : :
1438 : 0 : void SAL_CALL InternalDataProvider::removeChartDataChangeEventListener(
1439 : : const Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& )
1440 : : throw (uno::RuntimeException)
1441 : : {
1442 : 0 : }
1443 : :
1444 : 0 : double SAL_CALL InternalDataProvider::getNotANumber()
1445 : : throw (uno::RuntimeException)
1446 : : {
1447 : : double fNan;
1448 : 0 : ::rtl::math::setNan( & fNan );
1449 : 0 : return fNan;
1450 : : }
1451 : :
1452 : 0 : ::sal_Bool SAL_CALL InternalDataProvider::isNotANumber( double nNumber )
1453 : : throw (uno::RuntimeException)
1454 : : {
1455 : 0 : return ::rtl::math::isNan( nNumber )
1456 [ # # ][ # # ]: 0 : || ::rtl::math::isInf( nNumber );
1457 : : }
1458 : : // lang::XInitialization:
1459 : 50 : void SAL_CALL InternalDataProvider::initialize(const uno::Sequence< uno::Any > & _aArguments) throw (uno::RuntimeException, uno::Exception)
1460 : : {
1461 [ + - ]: 50 : comphelper::SequenceAsHashMap aArgs(_aArguments);
1462 [ + - ][ + - ]: 50 : if ( aArgs.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CreateDefaultData")),sal_False) )
[ + - ]
1463 [ + - ][ + - ]: 50 : createDefaultData();
1464 : 50 : }
1465 : : // ____ XCloneable ____
1466 : 0 : Reference< util::XCloneable > SAL_CALL InternalDataProvider::createClone()
1467 : : throw (uno::RuntimeException)
1468 : : {
1469 [ # # ][ # # ]: 0 : return Reference< util::XCloneable >( new InternalDataProvider( *this ));
1470 : : }
1471 : :
1472 : :
1473 : : // ================================================================================
1474 : :
1475 : 0 : Sequence< OUString > InternalDataProvider::getSupportedServiceNames_Static()
1476 : : {
1477 : 0 : Sequence< OUString > aServices( 1 );
1478 [ # # ][ # # ]: 0 : aServices[ 0 ] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.data.DataProvider" ));
1479 : 0 : return aServices;
1480 : : }
1481 : :
1482 : : // ================================================================================
1483 : :
1484 [ # # ][ # # ]: 46 : APPHELPER_XSERVICEINFO_IMPL( InternalDataProvider, lcl_aServiceName );
[ # # ][ # # ]
[ # # ]
1485 : :
1486 [ + - ][ + - ]: 48 : } // namespace chart
1487 : :
1488 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|