LibreOffice Module chart2 (master) 1
UncachedDataSequence.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>
24
26#include <algorithm>
27#include <strings.hrc>
28#include <ResId.hxx>
29#include <utility>
30
31using namespace ::com::sun::star;
32
33using ::com::sun::star::uno::Sequence;
34using ::com::sun::star::uno::Reference;
35using ::com::sun::star::uno::Any;
36using ::osl::MutexGuard;
37
38// necessary for MS compiler
39using ::comphelper::OPropertyContainer;
41
42namespace
43{
44constexpr OUStringLiteral lcl_aServiceName = u"com.sun.star.comp.chart.UncachedDataSequence";
45
46enum
47{
48 PROP_NUMBERFORMAT_KEY,
49 PROP_PROPOSED_ROLE,
50 PROP_XML_RANGE
51};
52} // anonymous namespace
53
54namespace chart
55{
56
59 OUString aRangeRepresentation )
60 : OPropertyContainer( GetBroadcastHelper()),
61 UncachedDataSequence_Base( GetMutex()),
62 m_nNumberFormatKey(0),
63 m_xDataProvider(std::move( xIntDataProv )),
64 m_aSourceRepresentation(std::move( aRangeRepresentation )),
65 m_xModifyEventForwarder( new ModifyEventForwarder() )
66{
68}
69
72 OUString aRangeRepresentation,
73 const OUString & rRole )
74 : OPropertyContainer( GetBroadcastHelper()),
75 UncachedDataSequence_Base( GetMutex()),
76 m_nNumberFormatKey(0),
77 m_xDataProvider(std::move( xIntDataProv )),
78 m_aSourceRepresentation(std::move( aRangeRepresentation )),
79 m_xModifyEventForwarder( new ModifyEventForwarder() )
80{
82 setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE, uno::Any( rRole ));
83}
84
86 : OPropertyContainer( GetBroadcastHelper()),
87 UncachedDataSequence_Base( GetMutex()),
88 m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
89 m_sRole( rSource.m_sRole ),
90 m_xDataProvider( rSource.m_xDataProvider ),
91 m_aSourceRepresentation( rSource.m_aSourceRepresentation ),
92 m_xModifyEventForwarder( new ModifyEventForwarder() )
93{
95}
96
98{}
99
101{
102 registerProperty( "NumberFormatKey",
103 PROP_NUMBERFORMAT_KEY,
104 0, // PropertyAttributes
106 cppu::UnoType<decltype(m_nNumberFormatKey)>::get() );
107
108 registerProperty( "Role",
109 PROP_PROPOSED_ROLE,
110 0, // PropertyAttributes
111 & m_sRole,
112 cppu::UnoType<decltype(m_sRole)>::get() );
113
114 registerProperty( "CachedXMLRange",
115 PROP_XML_RANGE,
116 0, // PropertyAttributes
117 & m_aXMLRange,
118 cppu::UnoType<decltype(m_aXMLRange)>::get() );
119}
120
123
124// ____ XPropertySet ____
125Reference< beans::XPropertySetInfo > SAL_CALL UncachedDataSequence::getPropertySetInfo()
126{
127 return createPropertySetInfo( getInfoHelper() );
128}
129
130// ____ ::comphelper::OPropertySetHelper ____
132{
133 return *getArrayHelper();
134}
135
136// ____ ::comphelper::OPropertyArrayHelper ____
138{
140 // describes all properties which have been registered in the ctor
141 describeProperties( aProps );
142
143 return new ::cppu::OPropertyArrayHelper( aProps );
144}
145
147{
148 return lcl_aServiceName;
149}
150
151sal_Bool SAL_CALL UncachedDataSequence::supportsService( const OUString& rServiceName )
152{
153 return cppu::supportsService(this, rServiceName);
154}
155
156css::uno::Sequence< OUString > SAL_CALL UncachedDataSequence::getSupportedServiceNames()
157{
158 return {
159 lcl_aServiceName,
160 "com.sun.star.chart2.data.DataSequence",
161 "com.sun.star.chart2.data.NumericalDataSequence",
162 "com.sun.star.chart2.data.TextualDataSequence"
163 };
164}
165
166// ________ XNumericalDataSequence ________
168{
169 Sequence< double > aResult;
170 MutexGuard aGuard( GetMutex() );
171 if( m_xDataProvider.is())
172 {
173 const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
174 aResult.realloc( aValues.getLength());
175 std::transform( aValues.begin(), aValues.end(),
176 aResult.getArray(), CommonFunctors::AnyToDouble());
177 }
178 return aResult;
179}
180
181// ________ XTextualDataSequence ________
183{
184 Sequence< OUString > aResult;
185 MutexGuard aGuard( GetMutex() );
186 if( m_xDataProvider.is())
187 {
188 const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
189 aResult.realloc( aValues.getLength());
190 std::transform( aValues.begin(), aValues.end(),
191 aResult.getArray(), CommonFunctors::AnyToString());
192 }
193 return aResult;
194}
195
196// ________ XDataSequence ________
198{
199 MutexGuard aGuard( GetMutex() );
200 if( m_xDataProvider.is())
201 return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation );
202 return Sequence< Any >();
203}
204
206{
207 return getName();
208}
209
211{
212 // auto-generated label
213 sal_Int32 nSeries = m_aSourceRepresentation.toInt32() + 1;
214 OUString aResString(::chart::SchResId(STR_DATA_UNNAMED_SERIES_WITH_INDEX));
215 static constexpr OUStringLiteral aReplacementStr(u"%NUMBER");
216 sal_Int32 nIndex = aResString.indexOf(aReplacementStr);
217 OUString aName;
218 if( nIndex != -1 )
219 aName = aResString.replaceAt(nIndex, aReplacementStr.getLength(), OUString::number(nSeries));
220 return Sequence< OUString >( &aName, 1 );
221}
222
223::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 )
224{
225 return m_nNumberFormatKey;
226}
227
228// ____ XIndexReplace ____
229void SAL_CALL UncachedDataSequence::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
230{
231 MutexGuard aGuard( GetMutex() );
233 if( Index < aData.getLength() &&
234 m_xDataProvider.is() )
235 {
236 aData.getArray()[Index] = Element;
237 m_xDataProvider->setDataByRangeRepresentation( m_aSourceRepresentation, aData );
239 }
240}
241
242// ____ XIndexAccess (base of XIndexReplace) ____
243::sal_Int32 SAL_CALL UncachedDataSequence::getCount()
244{
245 OSL_FAIL( "Implement!" );
246 return 0;
247}
248
250{
251 OSL_FAIL( "Implement!" );
252 return uno::Any();
253}
254
255// ____ XElementAccess (base of XIndexAccess) ____
257{
259}
260
262{
263 if( ! m_xDataProvider.is())
264 return false;
265 return m_xDataProvider->hasDataByRangeRepresentation( m_aSourceRepresentation );
266}
267
268// ____ XNamed ____
270{
272}
273
274void SAL_CALL UncachedDataSequence::setName( const OUString& aName )
275{
278}
279
281{
282 return new UncachedDataSequence( *this );
283}
284
285// ____ XModifiable ____
287{
288 return false;
289}
290
292{
293 if( bModified )
295}
296
297// ____ XModifyBroadcaster (base of XModifiable) ____
299{
300 m_xModifyEventForwarder->addModifyListener( aListener );
301}
302
304{
305 m_xModifyEventForwarder->removeModifyListener( aListener );
306}
307
309{
310 // @todo: currently never called, as data changes are not yet reported by
311 // the data provider
312 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
313}
314
315} // namespace chart
316
317/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
This helper class serves as forwarder of modify events.
This sequence object does NOT store actual sequence data.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nLabelOrigin) override
UncachedDataSequence(rtl::Reference< InternalDataProvider > xIntDataProv, OUString aRangeRepresentation)
The referring data provider is held as uno reference to ensure its lifetime is at least as long as th...
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL setName(const OUString &aName) override
void registerProperties()
This method registers all properties.
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
virtual ~UncachedDataSequence() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL getByIndex(::sal_Int32 Index) override
virtual sal_Bool SAL_CALL isModified() override
virtual ::sal_Int32 SAL_CALL getCount() override
virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex(::sal_Int32 nIndex) override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL replaceByIndex(::sal_Int32 Index, const css::uno::Any &Element) override
virtual sal_Bool SAL_CALL hasElements() override
virtual void SAL_CALL setModified(sal_Bool bModified) override
rtl::Reference< InternalDataProvider > m_xDataProvider
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
virtual OUString SAL_CALL getSourceRangeRepresentation() override
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)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
css::uno::Type const & get()
float u
sal_Int32 nIndex
OUString aName
constexpr OUStringLiteral aData
::cppu::WeakComponentImplHelper< css::chart2::data::XDataSequence, css::chart2::data::XNumericalDataSequence, css::chart2::data::XTextualDataSequence, css::util::XCloneable, css::util::XModifiable, css::container::XIndexReplace, css::container::XNamed, css::lang::XServiceInfo > UncachedDataSequence_Base
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
unary function to convert css::uno::Any into a double number.
unary function to convert css::uno::Any into an OUString.
unsigned char sal_Bool