1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef CHART2_INTERNALDATAPROVIDER_HXX
24 #define CHART2_INTERNALDATAPROVIDER_HXX
25 
26 #include "InternalData.hxx"
27 
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/chart/XDateCategories.hpp>
30 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
31 #include <com/sun/star/chart2/data/XDataProvider.hpp>
32 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
33 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
34 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
35 #include <com/sun/star/chart2/XChartDocument.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/util/XCloneable.hpp>
38 #include <cppuhelper/implbase7.hxx>
39 #include "ServiceMacros.hxx"
40 
41 #include "CachedDataSequence.hxx"
42 
43 #include <map>
44 #include <memory>
45 
46 namespace chart
47 {
48 
49 namespace impl
50 {
51 
52 typedef ::cppu::WeakImplHelper7<
53         ::com::sun::star::chart2::XInternalDataProvider,
54         ::com::sun::star::chart2::data::XRangeXMLConversion,
55         ::com::sun::star::chart2::XAnyDescriptionAccess,
56         ::com::sun::star::chart::XDateCategories,
57         ::com::sun::star::util::XCloneable,
58 		::com::sun::star::lang::XInitialization,
59         ::com::sun::star::lang::XServiceInfo >
60     InternalDataProvider_Base;
61 }
62 
63 /** Data provider that handles data internally.  This is used for charts with
64     their own data.
65 
66     <p>The format for single ranges is "categories|label n|n" where n is a
67     non-negative number. Meaning return all categories, the label of sequence n,
68     or the data of sequence n.</p>
69 
70     <p>The format for a complete range is "all". (Do we need more than
71     that?)</p>
72  */
73 class InternalDataProvider :
74         public impl::InternalDataProvider_Base
75 {
76 public:
77     explicit InternalDataProvider(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & _xContext);
78 
79     // #120559# allow handing over a default for data orientation (DataInColumns) that will
80     // be used when no data is available
81     explicit InternalDataProvider(
82         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > & xChartDoc,
83         bool bConnectToModel,
84         bool bDefaultDataInColumns );
85     explicit InternalDataProvider( const InternalDataProvider & rOther );
86 	virtual ~InternalDataProvider();
87 
88     void createDefaultData();
89 
90     /// declare XServiceInfo methods
91     APPHELPER_XSERVICEINFO_DECL()
92     APPHELPER_SERVICE_FACTORY_HELPER(InternalDataProvider)
93 
94     // ____ XInternalDataProvider ____
95     virtual ::sal_Bool SAL_CALL hasDataByRangeRepresentation( const ::rtl::OUString& aRange )
96         throw (::com::sun::star::uno::RuntimeException);
97     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL
98         getDataByRangeRepresentation( const ::rtl::OUString& aRange )
99         throw (::com::sun::star::uno::RuntimeException);
100     virtual void SAL_CALL setDataByRangeRepresentation(
101         const ::rtl::OUString& aRange,
102         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aNewData )
103         throw (::com::sun::star::uno::RuntimeException);
104     virtual void SAL_CALL insertSequence( ::sal_Int32 nAfterIndex )
105         throw (::com::sun::star::uno::RuntimeException);
106     virtual void SAL_CALL deleteSequence( ::sal_Int32 nAtIndex )
107         throw (::com::sun::star::uno::RuntimeException);
108     virtual void SAL_CALL appendSequence()
109         throw (::com::sun::star::uno::RuntimeException);
110     virtual void SAL_CALL insertComplexCategoryLevel( ::sal_Int32 nLevel )
111         throw (::com::sun::star::uno::RuntimeException);
112     virtual void SAL_CALL deleteComplexCategoryLevel( ::sal_Int32 nLevel )
113         throw (::com::sun::star::uno::RuntimeException);
114     virtual void SAL_CALL insertDataPointForAllSequences( ::sal_Int32 nAfterIndex )
115         throw (::com::sun::star::uno::RuntimeException);
116     virtual void SAL_CALL deleteDataPointForAllSequences( ::sal_Int32 nAtIndex )
117         throw (::com::sun::star::uno::RuntimeException);
118     virtual void SAL_CALL swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex )
119         throw (::com::sun::star::uno::RuntimeException);
120     virtual void SAL_CALL registerDataSequenceForChanges(
121         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xSeq )
122         throw (::com::sun::star::uno::RuntimeException);
123 
124     // ____ XDataProvider (base of XInternalDataProvider) ____
125     virtual ::sal_Bool SAL_CALL createDataSourcePossible(
126         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
127         throw (::com::sun::star::uno::RuntimeException);
128     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > SAL_CALL createDataSource(
129         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
130         throw (::com::sun::star::lang::IllegalArgumentException,
131                ::com::sun::star::uno::RuntimeException);
132     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL detectArguments(
133         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource )
134         throw (::com::sun::star::uno::RuntimeException);
135     virtual ::sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
136         const ::rtl::OUString& aRangeRepresentation )
137         throw (::com::sun::star::uno::RuntimeException);
138     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
139         const ::rtl::OUString& aRangeRepresentation )
140         throw (::com::sun::star::lang::IllegalArgumentException,
141                ::com::sun::star::uno::RuntimeException);
142     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XRangeSelection > SAL_CALL getRangeSelection()
143         throw (::com::sun::star::uno::RuntimeException);
144 
145     // ____ XRangeXMLConversion ____
146     virtual ::rtl::OUString SAL_CALL convertRangeToXML(
147         const ::rtl::OUString& aRangeRepresentation )
148         throw (::com::sun::star::lang::IllegalArgumentException,
149                ::com::sun::star::uno::RuntimeException);
150     virtual ::rtl::OUString SAL_CALL convertRangeFromXML(
151         const ::rtl::OUString& aXMLRange )
152         throw (::com::sun::star::lang::IllegalArgumentException,
153                ::com::sun::star::uno::RuntimeException);
154 
155     // ____ XDateCategories ____
156     virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getDateCategories() throw (::com::sun::star::uno::RuntimeException);
157     virtual void SAL_CALL setDateCategories( const ::com::sun::star::uno::Sequence< double >& rDates ) throw (::com::sun::star::uno::RuntimeException);
158 
159     // ____ XAnyDescriptionAccess ____
160     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL
161         getAnyRowDescriptions() throw (::com::sun::star::uno::RuntimeException);
162     virtual void SAL_CALL setAnyRowDescriptions(
163         const ::com::sun::star::uno::Sequence<
164         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aRowDescriptions )
165         throw (::com::sun::star::uno::RuntimeException);
166     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL
167         getAnyColumnDescriptions() throw (::com::sun::star::uno::RuntimeException);
168     virtual void SAL_CALL setAnyColumnDescriptions(
169         const ::com::sun::star::uno::Sequence<
170         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aColumnDescriptions )
171         throw (::com::sun::star::uno::RuntimeException);
172 
173     // ____ XComplexDescriptionAccess (base of XAnyDescriptionAccess) ____
174     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL
175         getComplexRowDescriptions() throw (::com::sun::star::uno::RuntimeException);
176     virtual void SAL_CALL setComplexRowDescriptions(
177         const ::com::sun::star::uno::Sequence<
178         ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aRowDescriptions )
179         throw (::com::sun::star::uno::RuntimeException);
180     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL
181         getComplexColumnDescriptions() throw (::com::sun::star::uno::RuntimeException);
182     virtual void SAL_CALL setComplexColumnDescriptions(
183         const ::com::sun::star::uno::Sequence<
184         ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aColumnDescriptions )
185         throw (::com::sun::star::uno::RuntimeException);
186 
187     // ____ XChartDataArray (base of XComplexDescriptionAccess) ____
188     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > SAL_CALL getData()
189         throw (::com::sun::star::uno::RuntimeException);
190     virtual void SAL_CALL setData(
191         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& aData )
192         throw (::com::sun::star::uno::RuntimeException);
193     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRowDescriptions()
194         throw (::com::sun::star::uno::RuntimeException);
195     virtual void SAL_CALL setRowDescriptions(
196         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRowDescriptions )
197         throw (::com::sun::star::uno::RuntimeException);
198     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getColumnDescriptions()
199         throw (::com::sun::star::uno::RuntimeException);
200     virtual void SAL_CALL setColumnDescriptions(
201         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aColumnDescriptions )
202         throw (::com::sun::star::uno::RuntimeException);
203 
204     // ____ XChartData (base of XChartDataArray) ____
205     virtual void SAL_CALL addChartDataChangeEventListener(
206         const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
207         throw (::com::sun::star::uno::RuntimeException);
208     virtual void SAL_CALL removeChartDataChangeEventListener(
209         const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
210         throw (::com::sun::star::uno::RuntimeException);
211     virtual double SAL_CALL getNotANumber()
212         throw (::com::sun::star::uno::RuntimeException);
213     virtual ::sal_Bool SAL_CALL isNotANumber(
214         double nNumber )
215         throw (::com::sun::star::uno::RuntimeException);
216 
217     // ____ XCloneable ____
218     virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
219         throw (::com::sun::star::uno::RuntimeException);
220 	// ::com::sun::star::lang::XInitialization:
221     virtual void SAL_CALL initialize(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > & aArguments)
222 		throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception);
223 
224 private:
225     void lcl_addDataSequenceToMap(
226         const ::rtl::OUString & rRangeRepresentation,
227         const ::com::sun::star::uno::Reference<
228             ::com::sun::star::chart2::data::XDataSequence > & xSequence );
229 
230     ::com::sun::star::uno::Reference<
231             ::com::sun::star::chart2::data::XDataSequence >
232         lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation,
233                                        const ::rtl::OUString & rRole );
234     ::com::sun::star::uno::Reference<
235             ::com::sun::star::chart2::data::XDataSequence >
236         lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation );
237 
238     void lcl_deleteMapReferences( const ::rtl::OUString & rRangeRepresentation );
239 
240     void lcl_adaptMapReferences(
241         const ::rtl::OUString & rOldRangeRepresentation,
242         const ::rtl::OUString & rNewRangeRepresentation );
243 
244     void lcl_increaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
245     void lcl_decreaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
246 
247     typedef ::std::multimap< ::rtl::OUString,
248             ::com::sun::star::uno::WeakReference< ::com::sun::star::chart2::data::XDataSequence > >
249         tSequenceMap;
250     typedef ::std::pair< tSequenceMap::iterator, tSequenceMap::iterator > tSequenceMapRange;
251     typedef ::std::pair< tSequenceMap::const_iterator, tSequenceMap::const_iterator > tConstSequenceMapRange;
252 
253     /** cache for all sequences that have been returned.
254 
255         If the range-representation of a sequence changes and it is still
256         referred to by some component (weak reference is valid), the range will
257         be adapted.
258      */
259     tSequenceMap m_aSequenceMap;
260     InternalData m_aInternalData;
261     bool m_bDataInColumns;
262 };
263 
264 } //  namespace chart
265 
266 // CHART2_INTERNALDATAPROVIDER_HXX
267 #endif
268