Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "UncachedDataSequence.hxx"
22 : : #include "macros.hxx"
23 : : #include "PropertyHelper.hxx"
24 : : #include "CommonFunctors.hxx"
25 : : #include "ModifyListenerHelper.hxx"
26 : :
27 : : #include <algorithm>
28 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : : #include <rtl/math.hxx>
30 : :
31 : : using namespace ::com::sun::star;
32 : :
33 : : using ::com::sun::star::uno::Sequence;
34 : : using ::com::sun::star::uno::Reference;
35 : : using ::com::sun::star::uno::Any;
36 : : using ::rtl::OUString;
37 : : using ::osl::MutexGuard;
38 : :
39 : : // necessary for MS compiler
40 : : using ::comphelper::OPropertyContainer;
41 : : using ::chart::impl::UncachedDataSequence_Base;
42 : :
43 : : namespace
44 : : {
45 : 16 : static const OUString lcl_aServiceName(
46 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.UncachedDataSequence" ));
47 : :
48 : : enum
49 : : {
50 : : PROP_NUMBERFORMAT_KEY,
51 : : PROP_PROPOSED_ROLE,
52 : : PROP_XML_RANGE
53 : : };
54 : : } // anonymous namespace
55 : :
56 : :
57 : : // ____________________
58 : : namespace chart
59 : : {
60 : :
61 : 456 : UncachedDataSequence::UncachedDataSequence(
62 : : const Reference< chart2::XInternalDataProvider > & xIntDataProv,
63 : : const OUString & rRangeRepresentation )
64 : 456 : : OPropertyContainer( GetBroadcastHelper()),
65 : 456 : UncachedDataSequence_Base( GetMutex()),
66 : : m_nNumberFormatKey(0),
67 : : m_xDataProvider( xIntDataProv ),
68 : : m_aSourceRepresentation( rRangeRepresentation ),
69 [ + - ]: 1368 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ + - + - ]
[ + - ]
70 : : {
71 [ + - ]: 456 : registerProperties();
72 : 456 : }
73 : :
74 : 12372 : UncachedDataSequence::UncachedDataSequence(
75 : : const Reference< chart2::XInternalDataProvider > & xIntDataProv,
76 : : const OUString & rRangeRepresentation,
77 : : const OUString & rRole )
78 : 12372 : : OPropertyContainer( GetBroadcastHelper()),
79 : 12372 : UncachedDataSequence_Base( GetMutex()),
80 : : m_nNumberFormatKey(0),
81 : : m_xDataProvider( xIntDataProv ),
82 : : m_aSourceRepresentation( rRangeRepresentation ),
83 [ + - ]: 37116 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ + - + - ]
[ + - ]
84 : : {
85 [ + - ]: 12372 : registerProperties();
86 [ + - ][ + - ]: 12372 : setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE, uno::makeAny( rRole ));
87 : 12372 : }
88 : :
89 : 70 : UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence & rSource )
90 : : : ::comphelper::OMutexAndBroadcastHelper(),
91 : 70 : OPropertyContainer( GetBroadcastHelper()),
92 : : ::comphelper::OPropertyArrayUsageHelper< UncachedDataSequence >(),
93 : 70 : UncachedDataSequence_Base( GetMutex()),
94 : : m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
95 : : m_sRole( rSource.m_sRole ),
96 : : m_xDataProvider( rSource.m_xDataProvider ),
97 : : m_aSourceRepresentation( rSource.m_aSourceRepresentation ),
98 [ + - ]: 210 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
[ + - + - ]
[ + - ]
99 : : {
100 [ + - ]: 70 : registerProperties();
101 : 70 : }
102 : :
103 [ + - ][ + - ]: 12898 : UncachedDataSequence::~UncachedDataSequence()
[ + - ][ + - ]
104 [ - + ]: 25796 : {}
105 : :
106 : 12898 : void UncachedDataSequence::registerProperties()
107 : : {
108 : : registerProperty( C2U( "NumberFormatKey" ),
109 : : PROP_NUMBERFORMAT_KEY,
110 : : 0, // PropertyAttributes
111 : : & m_nNumberFormatKey,
112 [ + - ]: 12898 : ::getCppuType( & m_nNumberFormatKey ) );
113 : :
114 : : registerProperty( C2U( "Role" ),
115 : : PROP_PROPOSED_ROLE,
116 : : 0, // PropertyAttributes
117 : : & m_sRole,
118 [ + - ]: 12898 : ::getCppuType( & m_sRole ) );
119 : :
120 : : registerProperty( C2U( "CachedXMLRange" ),
121 : : PROP_XML_RANGE,
122 : : 0, // PropertyAttributes
123 : : & m_aXMLRange,
124 [ + - ]: 12898 : ::getCppuType( & m_aXMLRange ) );
125 : 12898 : }
126 : :
127 : : // ================================================================================
128 : :
129 : 0 : Sequence< OUString > UncachedDataSequence::getSupportedServiceNames_Static()
130 : : {
131 : 0 : Sequence< OUString > aServices( 4 );
132 [ # # ]: 0 : aServices[ 0 ] = lcl_aServiceName;
133 [ # # ][ # # ]: 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.data.DataSequence" );
134 [ # # ][ # # ]: 0 : aServices[ 2 ] = C2U( "com.sun.star.chart2.data.NumericalDataSequence" );
135 [ # # ][ # # ]: 0 : aServices[ 3 ] = C2U( "com.sun.star.chart2.data.TextualDataSequence" );
136 : 0 : return aServices;
137 : : }
138 : :
139 [ + + ][ + - ]: 419181 : IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
140 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
[ # # ]
141 : :
142 : : // ____ XPropertySet ____
143 : 84 : Reference< beans::XPropertySetInfo > SAL_CALL UncachedDataSequence::getPropertySetInfo()
144 : : throw(uno::RuntimeException)
145 : : {
146 : 84 : return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) );
147 : : }
148 : :
149 : : // ____ ::comphelper::OPropertySetHelper ____
150 : : // __________________________________________
151 : 41752 : ::cppu::IPropertyArrayHelper& UncachedDataSequence::getInfoHelper()
152 : : {
153 : 41752 : return *getArrayHelper();
154 : : }
155 : :
156 : : // ____ ::comphelper::OPropertyArrayHelper ____
157 : : // ____________________________________________
158 : 24 : ::cppu::IPropertyArrayHelper* UncachedDataSequence::createArrayHelper() const
159 : : {
160 [ + - ]: 24 : Sequence< beans::Property > aProps;
161 : : // describes all properties which have been registered in the ctor
162 [ + - ]: 24 : describeProperties( aProps );
163 : :
164 [ + - ][ + - ]: 24 : return new ::cppu::OPropertyArrayHelper( aProps );
165 : : }
166 : :
167 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
168 [ # # ][ # # ]: 0 : APPHELPER_XSERVICEINFO_IMPL( UncachedDataSequence, lcl_aServiceName )
[ # # ][ # # ]
[ # # ]
169 : :
170 : : // ================================================================================
171 : :
172 : : // ________ XNumericalDataSequence ________
173 : 2706 : Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData()
174 : : throw (uno::RuntimeException)
175 : : {
176 [ + - ]: 2706 : Sequence< double > aResult;
177 [ + - ]: 2706 : MutexGuard aGuard( GetMutex() );
178 [ + - ]: 2706 : if( m_xDataProvider.is())
179 : : {
180 [ + - ][ + - ]: 2706 : Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
181 [ + - ]: 2706 : aResult.realloc( aValues.getLength());
182 : 2706 : ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
183 [ + - + - ]: 5412 : aResult.getArray(), CommonFunctors::AnyToDouble());
184 : : }
185 [ + - ]: 2706 : return aResult;
186 : : }
187 : :
188 : : // ________ XTextualDataSequence ________
189 : 9277 : Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData()
190 : : throw (uno::RuntimeException)
191 : : {
192 [ + - ]: 9277 : Sequence< OUString > aResult;
193 [ + - ]: 9277 : MutexGuard aGuard( GetMutex() );
194 [ + - ]: 9277 : if( m_xDataProvider.is())
195 : : {
196 [ + - ][ + - ]: 9277 : Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
197 [ + - ]: 9277 : aResult.realloc( aValues.getLength());
198 : 9277 : ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
199 [ + - + - ]: 18554 : aResult.getArray(), CommonFunctors::AnyToString());
200 : : }
201 [ + - ]: 9277 : return aResult;
202 : : }
203 : :
204 : : // ________ XDataSequence ________
205 : 7241 : Sequence< Any > SAL_CALL UncachedDataSequence::getData()
206 : : throw (uno::RuntimeException)
207 : : {
208 [ + - ]: 7241 : MutexGuard aGuard( GetMutex() );
209 [ + - ]: 7241 : if( m_xDataProvider.is())
210 [ + - ][ + - ]: 7241 : return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation );
211 [ # # ][ + - ]: 7241 : return Sequence< Any >();
212 : : }
213 : :
214 : 2612 : OUString SAL_CALL UncachedDataSequence::getSourceRangeRepresentation()
215 : : throw (uno::RuntimeException)
216 : : {
217 : 2612 : return getName();
218 : : }
219 : :
220 : :
221 : 5 : Sequence< OUString > SAL_CALL UncachedDataSequence::generateLabel( chart2::data::LabelOrigin )
222 : : throw (uno::RuntimeException)
223 : : {
224 : : // auto-generated label is an empty string
225 : 5 : return Sequence< OUString >(1);
226 : : }
227 : :
228 : 1879 : ::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 )
229 : : throw (lang::IndexOutOfBoundsException,
230 : : uno::RuntimeException)
231 : : {
232 : 1879 : return m_nNumberFormatKey;
233 : : }
234 : :
235 : : // ____ XIndexReplace ____
236 : 0 : void SAL_CALL UncachedDataSequence::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
237 : : throw (lang::IllegalArgumentException,
238 : : lang::IndexOutOfBoundsException,
239 : : lang::WrappedTargetException,
240 : : uno::RuntimeException)
241 : : {
242 [ # # ]: 0 : MutexGuard aGuard( GetMutex() );
243 [ # # ]: 0 : Sequence< Any > aData( getData());
244 [ # # # # ]: 0 : if( Index < aData.getLength() &&
[ # # ]
245 : 0 : m_xDataProvider.is() )
246 : : {
247 [ # # ]: 0 : aData[Index] = Element;
248 [ # # ][ # # ]: 0 : m_xDataProvider->setDataByRangeRepresentation( m_aSourceRepresentation, aData );
249 [ # # ]: 0 : fireModifyEvent();
250 [ # # ][ # # ]: 0 : }
251 : 0 : }
252 : :
253 : : // ____ XIndexAccess (base of XIndexReplace) ____
254 : 0 : ::sal_Int32 SAL_CALL UncachedDataSequence::getCount()
255 : : throw (uno::RuntimeException)
256 : : {
257 : : OSL_FAIL( "Implement!" );
258 : 0 : return 0;
259 : : }
260 : :
261 : 0 : uno::Any SAL_CALL UncachedDataSequence::getByIndex( ::sal_Int32 )
262 : : throw (lang::IndexOutOfBoundsException,
263 : : lang::WrappedTargetException,
264 : : uno::RuntimeException)
265 : : {
266 : : OSL_FAIL( "Implement!" );
267 : 0 : return uno::Any();
268 : : }
269 : :
270 : : // ____ XElementAccess (base of XIndexAccess) ____
271 : 0 : uno::Type SAL_CALL UncachedDataSequence::getElementType()
272 : : throw (uno::RuntimeException)
273 : : {
274 : 0 : return ::getCppuType( reinterpret_cast< uno::Any * >(0));
275 : : }
276 : :
277 : 0 : ::sal_Bool SAL_CALL UncachedDataSequence::hasElements()
278 : : throw (uno::RuntimeException)
279 : : {
280 [ # # ]: 0 : if( ! m_xDataProvider.is())
281 : 0 : return sal_False;
282 : 0 : return m_xDataProvider->hasDataByRangeRepresentation( m_aSourceRepresentation );
283 : : }
284 : :
285 : : // ____ XNamed ____
286 : 2612 : ::rtl::OUString SAL_CALL UncachedDataSequence::getName()
287 : : throw (uno::RuntimeException)
288 : : {
289 : 2612 : return m_aSourceRepresentation;
290 : : }
291 : :
292 : 0 : void SAL_CALL UncachedDataSequence::setName( const OUString& aName )
293 : : throw (uno::RuntimeException)
294 : : {
295 : 0 : m_aSourceRepresentation = aName;
296 : 0 : fireModifyEvent();
297 : 0 : }
298 : :
299 : :
300 : :
301 : 70 : Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone()
302 : : throw (uno::RuntimeException)
303 : : {
304 [ + - ]: 70 : UncachedDataSequence * pNewSeq = new UncachedDataSequence( *this );
305 [ + - ]: 70 : return Reference< util::XCloneable >( pNewSeq );
306 : : }
307 : :
308 : :
309 : : // ____ XModifiable ____
310 : 0 : ::sal_Bool SAL_CALL UncachedDataSequence::isModified()
311 : : throw (uno::RuntimeException)
312 : : {
313 : 0 : return sal_False;
314 : : }
315 : :
316 : 0 : void SAL_CALL UncachedDataSequence::setModified( ::sal_Bool bModified )
317 : : throw (beans::PropertyVetoException,
318 : : uno::RuntimeException)
319 : : {
320 [ # # ]: 0 : if( bModified )
321 : 0 : fireModifyEvent();
322 : 0 : }
323 : :
324 : : // ____ XModifyBroadcaster (base of XModifiable) ____
325 : 12898 : void SAL_CALL UncachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
326 : : throw (uno::RuntimeException)
327 : : {
328 : : try
329 : : {
330 [ + - ]: 12898 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
331 [ + - ][ + - ]: 12898 : xBroadcaster->addModifyListener( aListener );
[ # # ]
332 : : }
333 : 0 : catch( const uno::Exception & ex )
334 : : {
335 : : ASSERT_EXCEPTION( ex );
336 : : }
337 : 12898 : }
338 : :
339 : 12898 : void SAL_CALL UncachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
340 : : throw (uno::RuntimeException)
341 : : {
342 : : try
343 : : {
344 [ + - ]: 12898 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
345 [ + - ][ + - ]: 12898 : xBroadcaster->removeModifyListener( aListener );
[ # # ]
346 : : }
347 : 0 : catch( const uno::Exception & ex )
348 : : {
349 : : ASSERT_EXCEPTION( ex );
350 : : }
351 : 12898 : }
352 : :
353 : 0 : void UncachedDataSequence::fireModifyEvent()
354 : : {
355 : : // @todo: currently never called, as data changes are not yet reported by
356 : : // the data provider
357 [ # # ][ # # ]: 0 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
[ # # ]
358 : 0 : }
359 : :
360 [ + - ][ + - ]: 48 : } // namespace chart
361 : :
362 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|