1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <UncachedDataSequence.hxx>
21 #include <CommonFunctors.hxx>
22 #include <ModifyListenerHelper.hxx>
23 #include <InternalDataProvider.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 #include <strings.hrc>
31 using namespace ::com::sun::star
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Any
;
37 // necessary for MS compiler
38 using ::chart::impl::UncachedDataSequence_Base
;
42 constexpr OUString lcl_aServiceName
= u
"com.sun.star.comp.chart.UncachedDataSequence"_ustr
;
46 PROP_NUMBERFORMAT_KEY
,
50 } // anonymous namespace
55 UncachedDataSequence::UncachedDataSequence(
56 rtl::Reference
< InternalDataProvider
> xIntDataProv
,
57 OUString aRangeRepresentation
)
58 : m_nNumberFormatKey(0),
59 m_xDataProvider(std::move( xIntDataProv
)),
60 m_aSourceRepresentation(std::move( aRangeRepresentation
)),
61 m_xModifyEventForwarder( new ModifyEventForwarder() )
66 UncachedDataSequence::UncachedDataSequence(
67 rtl::Reference
< InternalDataProvider
> xIntDataProv
,
68 OUString aRangeRepresentation
,
69 const OUString
& rRole
)
70 : m_nNumberFormatKey(0),
71 m_xDataProvider(std::move( xIntDataProv
)),
72 m_aSourceRepresentation(std::move( aRangeRepresentation
)),
73 m_xModifyEventForwarder( new ModifyEventForwarder() )
76 std::unique_lock
<std::mutex
> aGuard
;
77 setFastPropertyValue_NoBroadcast( aGuard
, PROP_PROPOSED_ROLE
, uno::Any( rRole
));
80 UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence
& rSource
)
81 : m_nNumberFormatKey( rSource
.m_nNumberFormatKey
),
82 m_sRole( rSource
.m_sRole
),
83 m_xDataProvider( rSource
.m_xDataProvider
),
84 m_aSourceRepresentation( rSource
.m_aSourceRepresentation
),
85 m_xModifyEventForwarder( new ModifyEventForwarder() )
90 UncachedDataSequence::~UncachedDataSequence()
93 void UncachedDataSequence::registerProperties()
95 registerProperty( u
"NumberFormatKey"_ustr
,
96 PROP_NUMBERFORMAT_KEY
,
97 0, // PropertyAttributes
99 cppu::UnoType
<decltype(m_nNumberFormatKey
)>::get() );
101 registerProperty( u
"Role"_ustr
,
103 0, // PropertyAttributes
105 cppu::UnoType
<decltype(m_sRole
)>::get() );
107 registerProperty( u
"CachedXMLRange"_ustr
,
109 0, // PropertyAttributes
111 cppu::UnoType
<decltype(m_aXMLRange
)>::get() );
114 IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence
, UncachedDataSequence_Base
, comphelper::OPropertyContainer2
)
115 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence
, UncachedDataSequence_Base
, comphelper::OPropertyContainer2
)
117 // ____ XPropertySet ____
118 Reference
< beans::XPropertySetInfo
> SAL_CALL
UncachedDataSequence::getPropertySetInfo()
120 return createPropertySetInfo( getInfoHelper() );
123 // ____ ::comphelper::OPropertySetHelper ____
124 ::cppu::IPropertyArrayHelper
& UncachedDataSequence::getInfoHelper()
126 return *getArrayHelper();
129 // ____ ::comphelper::OPropertyArrayHelper ____
130 ::cppu::IPropertyArrayHelper
* UncachedDataSequence::createArrayHelper() const
132 Sequence
< beans::Property
> aProps
;
133 // describes all properties which have been registered in the ctor
134 describeProperties( aProps
);
136 return new ::cppu::OPropertyArrayHelper( aProps
);
139 OUString SAL_CALL
UncachedDataSequence::getImplementationName()
141 return lcl_aServiceName
;
144 sal_Bool SAL_CALL
UncachedDataSequence::supportsService( const OUString
& rServiceName
)
146 return cppu::supportsService(this, rServiceName
);
149 css::uno::Sequence
< OUString
> SAL_CALL
UncachedDataSequence::getSupportedServiceNames()
153 u
"com.sun.star.chart2.data.DataSequence"_ustr
,
154 u
"com.sun.star.chart2.data.NumericalDataSequence"_ustr
,
155 u
"com.sun.star.chart2.data.TextualDataSequence"_ustr
159 // ________ XNumericalDataSequence ________
160 Sequence
< double > SAL_CALL
UncachedDataSequence::getNumericalData()
162 std::unique_lock
<std::mutex
> aGuard
;
163 if( m_xDataProvider
.is())
165 const Sequence
< uno::Any
> aValues( m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
));
166 return CommonFunctors::convertToSequence(aValues
, CommonFunctors::ToDouble());
171 // ________ XTextualDataSequence ________
172 Sequence
< OUString
> SAL_CALL
UncachedDataSequence::getTextualData()
174 std::unique_lock
<std::mutex
> aGuard
;
175 if( m_xDataProvider
.is())
177 const Sequence
< uno::Any
> aValues( m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
));
178 return CommonFunctors::convertToSequence(aValues
, CommonFunctors::ToString());
183 // ________ XDataSequence ________
184 Sequence
< Any
> SAL_CALL
UncachedDataSequence::getData()
186 std::unique_lock
<std::mutex
> aGuard
;
187 if( m_xDataProvider
.is())
188 return m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
);
189 return Sequence
< Any
>();
192 OUString SAL_CALL
UncachedDataSequence::getSourceRangeRepresentation()
197 Sequence
< OUString
> SAL_CALL
UncachedDataSequence::generateLabel( chart2::data::LabelOrigin
)
199 // auto-generated label
200 sal_Int32 nSeries
= m_aSourceRepresentation
.toInt32() + 1;
201 OUString
aResString(::chart::SchResId(STR_DATA_UNNAMED_SERIES_WITH_INDEX
));
202 static constexpr OUString
aReplacementStr(u
"%NUMBER"_ustr
);
203 sal_Int32 nIndex
= aResString
.indexOf(aReplacementStr
);
206 aName
= aResString
.replaceAt(nIndex
, aReplacementStr
.getLength(), OUString::number(nSeries
));
207 return Sequence
< OUString
>( &aName
, 1 );
210 ::sal_Int32 SAL_CALL
UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32
)
212 return m_nNumberFormatKey
;
215 // ____ XIndexReplace ____
216 void SAL_CALL
UncachedDataSequence::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
)
218 std::unique_lock
<std::mutex
> aGuard
;
219 Sequence
< Any
> aData( getData());
220 if( Index
< aData
.getLength() &&
221 m_xDataProvider
.is() )
223 aData
.getArray()[Index
] = Element
;
224 m_xDataProvider
->setDataByRangeRepresentation( m_aSourceRepresentation
, aData
);
229 // ____ XIndexAccess (base of XIndexReplace) ____
230 ::sal_Int32 SAL_CALL
UncachedDataSequence::getCount()
232 OSL_FAIL( "Implement!" );
236 uno::Any SAL_CALL
UncachedDataSequence::getByIndex( ::sal_Int32
)
238 OSL_FAIL( "Implement!" );
242 // ____ XElementAccess (base of XIndexAccess) ____
243 uno::Type SAL_CALL
UncachedDataSequence::getElementType()
245 return cppu::UnoType
<uno::Any
>::get();
248 sal_Bool SAL_CALL
UncachedDataSequence::hasElements()
250 if( ! m_xDataProvider
.is())
252 return m_xDataProvider
->hasDataByRangeRepresentation( m_aSourceRepresentation
);
256 OUString SAL_CALL
UncachedDataSequence::getName()
258 return m_aSourceRepresentation
;
261 void SAL_CALL
UncachedDataSequence::setName( const OUString
& aName
)
263 m_aSourceRepresentation
= aName
;
267 Reference
< util::XCloneable
> SAL_CALL
UncachedDataSequence::createClone()
269 return new UncachedDataSequence( *this );
272 // ____ XModifiable ____
273 sal_Bool SAL_CALL
UncachedDataSequence::isModified()
278 void SAL_CALL
UncachedDataSequence::setModified( sal_Bool bModified
)
284 // ____ XModifyBroadcaster (base of XModifiable) ____
285 void SAL_CALL
UncachedDataSequence::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
287 m_xModifyEventForwarder
->addModifyListener( aListener
);
290 void SAL_CALL
UncachedDataSequence::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
292 m_xModifyEventForwarder
->removeModifyListener( aListener
);
295 void UncachedDataSequence::fireModifyEvent()
297 // @todo: currently never called, as data changes are not yet reported by
299 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */