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