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