LibreOffice Module chart2 (master) 1
CachedDataSequence.cxx
Go to the documentation of this file.
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
21#include <CommonFunctors.hxx>
23
26
27#include <algorithm>
28
29using namespace ::com::sun::star;
30
31using ::com::sun::star::uno::Sequence;
32using ::com::sun::star::uno::Reference;
33using ::com::sun::star::uno::Any;
34using ::osl::MutexGuard;
35
36// necessary for MS compiler
37using ::comphelper::OPropertyContainer;
39
40namespace
41{
42constexpr OUStringLiteral lcl_aServiceName = u"com.sun.star.comp.chart.CachedDataSequence";
43
44enum
45{
46// PROP_SOURCE_IDENTIFIER,
47 PROP_NUMBERFORMAT_KEY,
48 PROP_PROPOSED_ROLE
49};
50} // anonymous namespace
51
52namespace chart
53{
54
56 : OPropertyContainer( GetBroadcastHelper()),
57 CachedDataSequence_Base( GetMutex()),
58 m_eCurrentDataType( NUMERICAL ),
59 m_xModifyEventForwarder( new ModifyEventForwarder() )
60{
62}
64 : OPropertyContainer( GetBroadcastHelper()),
65 CachedDataSequence_Base( GetMutex()),
66 m_eCurrentDataType( MIXED ),
67 m_xModifyEventForwarder( new ModifyEventForwarder() )
68{
70}
71
72CachedDataSequence::CachedDataSequence( const OUString & rSingleText )
73 : OPropertyContainer( GetBroadcastHelper()),
74 CachedDataSequence_Base( GetMutex()),
75 m_eCurrentDataType( TEXTUAL ),
76 m_aTextualSequence({rSingleText}),
77 m_xModifyEventForwarder( new ModifyEventForwarder() )
78{
79 registerProperties();
80}
81
83 : OPropertyContainer( GetBroadcastHelper()),
84 CachedDataSequence_Base( GetMutex()),
85 m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
86 m_sRole( rSource.m_sRole ),
87 m_eCurrentDataType( rSource.m_eCurrentDataType ),
88 m_xModifyEventForwarder( new ModifyEventForwarder() )
89{
90 switch( m_eCurrentDataType )
91 {
92 case TEXTUAL:
94 break;
95 case NUMERICAL:
97 break;
98 case MIXED:
100 break;
101 }
102
104}
105
107{}
108
110{
111 registerProperty( "NumberFormatKey",
112 PROP_NUMBERFORMAT_KEY,
113 0, // PropertyAttributes
115 cppu::UnoType<decltype(m_nNumberFormatKey)>::get() );
116
117 registerProperty( "Role",
118 PROP_PROPOSED_ROLE,
119 0, // PropertyAttributes
120 & m_sRole,
121 cppu::UnoType<decltype(m_sRole)>::get() );
122}
123
125{
128
129 sal_Int32 nSize = ( m_eCurrentDataType == TEXTUAL )
130 ? m_aTextualSequence.getLength()
131 : m_aMixedSequence.getLength();
132
133 Sequence< double > aResult( nSize );
134 double * pResultArray = aResult.getArray();
135
137 {
138 const OUString * pTextArray = m_aTextualSequence.getConstArray();
139 std::transform( pTextArray, pTextArray + nSize,
140 pResultArray,
142 }
143 else
144 {
145 OSL_ASSERT( m_eCurrentDataType == MIXED );
146 const Any * pMixedArray = m_aMixedSequence.getConstArray();
147 std::transform( pMixedArray, pMixedArray + nSize,
148 pResultArray,
150 }
151 return aResult;
152}
153
155{
157 return m_aTextualSequence;
158
159 sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL )
160 ? m_aNumericalSequence.getLength()
161 : m_aMixedSequence.getLength();
162
163 Sequence< OUString > aResult( nSize );
164 OUString * pResultArray = aResult.getArray();
165
167 {
168 const double * pTextArray = m_aNumericalSequence.getConstArray();
169 std::transform( pTextArray, pTextArray + nSize,
170 pResultArray,
172 }
173 else
174 {
175 OSL_ASSERT( m_eCurrentDataType == MIXED );
176 const Any * pMixedArray = m_aMixedSequence.getConstArray();
177 std::transform( pMixedArray, pMixedArray + nSize,
178 pResultArray,
180 }
181
182 return aResult;
183}
184
186{
188 return m_aMixedSequence;
189
190 sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL )
191 ? m_aNumericalSequence.getLength()
192 : m_aTextualSequence.getLength();
193
194 Sequence< Any > aResult( nSize );
195 Any * pResultArray = aResult.getArray();
196
198 {
199 const double * pTextArray = m_aNumericalSequence.getConstArray();
200 std::transform( pTextArray, pTextArray + nSize,
201 pResultArray,
203 }
204 else
205 {
206 OSL_ASSERT( m_eCurrentDataType == TEXTUAL );
207 const OUString * pMixedArray = m_aTextualSequence.getConstArray();
208 std::transform( pMixedArray, pMixedArray + nSize,
209 pResultArray,
211 }
212
213 return aResult;
214}
215
218
219// ____ XPropertySet ____
220Reference< beans::XPropertySetInfo > SAL_CALL CachedDataSequence::getPropertySetInfo()
221{
222 return createPropertySetInfo( getInfoHelper() );
223}
224
225// ____ ::comphelper::OPropertySetHelper ____
227{
228 return *getArrayHelper();
229}
230
231// ____ ::comphelper::OPropertyArrayHelper ____
233{
235 // describes all properties which have been registered in the ctor
236 describeProperties( aProps );
237
238 return new ::cppu::OPropertyArrayHelper( aProps );
239}
240
242{
243 return lcl_aServiceName;
244}
245
246sal_Bool SAL_CALL CachedDataSequence::supportsService( const OUString& rServiceName )
247{
248 return cppu::supportsService(this, rServiceName);
249}
250
251css::uno::Sequence< OUString > SAL_CALL CachedDataSequence::getSupportedServiceNames()
252{
253 return {
254 lcl_aServiceName,
255 "com.sun.star.chart2.data.DataSequence",
256 "com.sun.star.chart2.data.NumericalDataSequence",
257 "com.sun.star.chart2.data.TextualDataSequence"
258 };
259}
260
261// ________ XNumericalDataSequence ________
263{
264 MutexGuard aGuard( GetMutex() );
265
268 else
269 return Impl_getNumericalData();
270}
271
272// ________ XTextualDataSequence ________
274{
275 MutexGuard aGuard( GetMutex() );
276
278 return m_aTextualSequence;
279 else
280 return Impl_getTextualData();
281}
282
283// ________ XDataSequence ________
285{
286 MutexGuard aGuard( GetMutex() );
287 return Impl_getMixedData();
288}
289
291{
292 return m_sRole;
293}
294
295Sequence< OUString > SAL_CALL CachedDataSequence::generateLabel( chart2::data::LabelOrigin /*eLabelOrigin*/ )
296{
297 // return empty label, as we have no range representations to determine something useful
298 return Sequence< OUString >();
299}
300
301::sal_Int32 SAL_CALL CachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 /*nIndex*/ )
302{
303 return 0;
304}
305
307{
308 return new CachedDataSequence( *this );
309}
310
312{
313 m_xModifyEventForwarder->addModifyListener( aListener );
314}
315
317{
318 m_xModifyEventForwarder->removeModifyListener( aListener );
319}
320
321// lang::XInitialization:
323{
325 m_aNumericalSequence = aMap.getUnpackedValueOrDefault( "DataSequence" ,m_aNumericalSequence);
326 if ( m_aNumericalSequence.hasElements() )
328 else
329 {
330 m_aTextualSequence = aMap.getUnpackedValueOrDefault( "DataSequence" ,m_aTextualSequence);
331 if ( m_aTextualSequence.hasElements() )
333 else
334 {
335 m_aMixedSequence = aMap.getUnpackedValueOrDefault( "DataSequence" ,m_aMixedSequence);
336 if ( m_aMixedSequence.hasElements() )
338 }
339 }
340}
341} // namespace chart
342
343extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
345 css::uno::Sequence<css::uno::Any> const &)
346{
347 return cppu::acquire(new ::chart::CachedDataSequence(context));
348}
349
350/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart_CachedDataSequence_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
This sequence object does store actual values within, hence "cached".
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
css::uno::Sequence< css::uno::Any > m_aMixedSequence
virtual OUString SAL_CALL getSourceRangeRepresentation() override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
css::uno::Sequence< double > m_aNumericalSequence
css::uno::Sequence< css::uno::Any > Impl_getMixedData() const
is used by interface method getData().
CachedDataSequence()
constructs an empty sequence
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
void registerProperties()
This method registers all properties.
virtual ~CachedDataSequence() override
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nLabelOrigin) override
css::uno::Sequence< OUString > Impl_getTextualData() const
is used by interface method getTextualData().
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex(::sal_Int32 nIndex) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
css::uno::Sequence< double > Impl_getNumericalData() const
is used by interface method getNumericalData().
css::uno::Sequence< OUString > m_aTextualSequence
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
This helper class serves as forwarder of modify events.
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
MIXED
float u
::cppu::WeakComponentImplHelper< css::chart2::data::XDataSequence, css::chart2::data::XNumericalDataSequence, css::chart2::data::XTextualDataSequence, css::util::XCloneable, css::util::XModifyBroadcaster, css::lang::XInitialization, css::lang::XServiceInfo > CachedDataSequence_Base
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
HashMap_OWString_Interface aMap
unary function to convert css::uno::Any into a double number.
unary function to convert css::uno::Any into an OUString.
unary function to convert a double number into an OUString.
unary function to convert an OUString into a double number.
unary function to convert any type T into a css::uno::Any.
unsigned char sal_Bool