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 <CachedDataSequence.hxx>
21 #include <CommonFunctors.hxx>
22 #include <ModifyListenerHelper.hxx>
24 #include <comphelper/sequenceashashmap.hxx>
25 #include <cppuhelper/supportsservice.hxx>
29 using namespace ::com::sun::star
;
31 using ::com::sun::star::uno::Sequence
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::Any
;
35 // necessary for MS compiler
36 using ::chart::impl::CachedDataSequence_Base
;
40 constexpr OUString lcl_aServiceName
= u
"com.sun.star.comp.chart.CachedDataSequence"_ustr
;
44 // PROP_SOURCE_IDENTIFIER,
45 PROP_NUMBERFORMAT_KEY
,
48 } // anonymous namespace
53 CachedDataSequence::CachedDataSequence()
54 : m_eCurrentDataType( NUMERICAL
),
55 m_xModifyEventForwarder( new ModifyEventForwarder() )
59 CachedDataSequence::CachedDataSequence( const Reference
< uno::XComponentContext
> & /*xContext*/ )
60 : m_eCurrentDataType( MIXED
),
61 m_xModifyEventForwarder( new ModifyEventForwarder() )
66 CachedDataSequence::CachedDataSequence( const OUString
& rSingleText
)
67 : m_eCurrentDataType( TEXTUAL
),
68 m_aTextualSequence({rSingleText
}),
69 m_xModifyEventForwarder( new ModifyEventForwarder() )
74 CachedDataSequence::CachedDataSequence( const CachedDataSequence
& rSource
)
75 : m_nNumberFormatKey( rSource
.m_nNumberFormatKey
),
76 m_sRole( rSource
.m_sRole
),
77 m_eCurrentDataType( rSource
.m_eCurrentDataType
),
78 m_xModifyEventForwarder( new ModifyEventForwarder() )
80 switch( m_eCurrentDataType
)
83 m_aTextualSequence
= rSource
.m_aTextualSequence
;
86 m_aNumericalSequence
= rSource
.m_aNumericalSequence
;
89 m_aMixedSequence
= rSource
.m_aMixedSequence
;
96 CachedDataSequence::~CachedDataSequence()
99 void CachedDataSequence::registerProperties()
101 registerProperty( u
"NumberFormatKey"_ustr
,
102 PROP_NUMBERFORMAT_KEY
,
103 0, // PropertyAttributes
104 & m_nNumberFormatKey
,
105 cppu::UnoType
<decltype(m_nNumberFormatKey
)>::get() );
107 registerProperty( u
"Role"_ustr
,
109 0, // PropertyAttributes
111 cppu::UnoType
<decltype(m_sRole
)>::get() );
114 Sequence
< double > CachedDataSequence::Impl_getNumericalData() const
116 if( m_eCurrentDataType
== NUMERICAL
)
117 return m_aNumericalSequence
;
119 if( m_eCurrentDataType
== TEXTUAL
)
120 return CommonFunctors::convertToSequence(m_aTextualSequence
, CommonFunctors::ToDouble());
122 OSL_ASSERT(m_eCurrentDataType
== MIXED
);
123 return CommonFunctors::convertToSequence(m_aMixedSequence
, CommonFunctors::ToDouble());
126 Sequence
< OUString
> CachedDataSequence::Impl_getTextualData() const
128 if( m_eCurrentDataType
== TEXTUAL
)
129 return m_aTextualSequence
;
131 if( m_eCurrentDataType
== NUMERICAL
)
132 return CommonFunctors::convertToSequence(m_aNumericalSequence
, CommonFunctors::ToString());
134 OSL_ASSERT(m_eCurrentDataType
== MIXED
);
135 return CommonFunctors::convertToSequence(m_aMixedSequence
, CommonFunctors::ToString());
138 Sequence
< Any
> CachedDataSequence::Impl_getMixedData() const
140 if( m_eCurrentDataType
== MIXED
)
141 return m_aMixedSequence
;
143 if( m_eCurrentDataType
== NUMERICAL
)
144 return CommonFunctors::convertToSequence(m_aNumericalSequence
, CommonFunctors::makeAny());
146 OSL_ASSERT(m_eCurrentDataType
== TEXTUAL
);
147 return CommonFunctors::convertToSequence(m_aTextualSequence
, CommonFunctors::makeAny());
150 IMPLEMENT_FORWARD_XINTERFACE2( CachedDataSequence
, CachedDataSequence_Base
, comphelper::OPropertyContainer2
)
151 IMPLEMENT_FORWARD_XTYPEPROVIDER2( CachedDataSequence
, CachedDataSequence_Base
, comphelper::OPropertyContainer2
)
153 // ____ XPropertySet ____
154 Reference
< beans::XPropertySetInfo
> SAL_CALL
CachedDataSequence::getPropertySetInfo()
156 return createPropertySetInfo( getInfoHelper() );
159 // ____ ::comphelper::OPropertySetHelper ____
160 ::cppu::IPropertyArrayHelper
& CachedDataSequence::getInfoHelper()
162 return *getArrayHelper();
165 // ____ ::comphelper::OPropertyArrayHelper ____
166 ::cppu::IPropertyArrayHelper
* CachedDataSequence::createArrayHelper() const
168 Sequence
< beans::Property
> aProps
;
169 // describes all properties which have been registered in the ctor
170 describeProperties( aProps
);
172 return new ::cppu::OPropertyArrayHelper( aProps
);
175 OUString SAL_CALL
CachedDataSequence::getImplementationName()
177 return lcl_aServiceName
;
180 sal_Bool SAL_CALL
CachedDataSequence::supportsService( const OUString
& rServiceName
)
182 return cppu::supportsService(this, rServiceName
);
185 css::uno::Sequence
< OUString
> SAL_CALL
CachedDataSequence::getSupportedServiceNames()
189 u
"com.sun.star.chart2.data.DataSequence"_ustr
,
190 u
"com.sun.star.chart2.data.NumericalDataSequence"_ustr
,
191 u
"com.sun.star.chart2.data.TextualDataSequence"_ustr
195 // ________ XNumericalDataSequence ________
196 Sequence
< double > SAL_CALL
CachedDataSequence::getNumericalData()
198 std::unique_lock
aGuard( m_aMutex
);
200 if( m_eCurrentDataType
== NUMERICAL
)
201 return m_aNumericalSequence
;
203 return Impl_getNumericalData();
206 // ________ XTextualDataSequence ________
207 Sequence
< OUString
> SAL_CALL
CachedDataSequence::getTextualData()
209 std::unique_lock
aGuard( m_aMutex
);
211 if( m_eCurrentDataType
== TEXTUAL
)
212 return m_aTextualSequence
;
214 return Impl_getTextualData();
217 // ________ XDataSequence ________
218 Sequence
< Any
> SAL_CALL
CachedDataSequence::getData()
220 std::unique_lock
aGuard( m_aMutex
);
221 return Impl_getMixedData();
224 OUString SAL_CALL
CachedDataSequence::getSourceRangeRepresentation()
229 Sequence
< OUString
> SAL_CALL
CachedDataSequence::generateLabel( chart2::data::LabelOrigin
/*eLabelOrigin*/ )
231 // return empty label, as we have no range representations to determine something useful
232 return Sequence
< OUString
>();
235 ::sal_Int32 SAL_CALL
CachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32
/*nIndex*/ )
240 Reference
< util::XCloneable
> SAL_CALL
CachedDataSequence::createClone()
242 return new CachedDataSequence( *this );
245 void SAL_CALL
CachedDataSequence::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
247 m_xModifyEventForwarder
->addModifyListener( aListener
);
250 void SAL_CALL
CachedDataSequence::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
252 m_xModifyEventForwarder
->removeModifyListener( aListener
);
255 // lang::XInitialization:
256 void SAL_CALL
CachedDataSequence::initialize(const uno::Sequence
< uno::Any
> & _aArguments
)
258 ::comphelper::SequenceAsHashMap
aMap(_aArguments
);
259 m_aNumericalSequence
= aMap
.getUnpackedValueOrDefault( u
"DataSequence"_ustr
,m_aNumericalSequence
);
260 if ( m_aNumericalSequence
.hasElements() )
261 m_eCurrentDataType
= NUMERICAL
;
264 m_aTextualSequence
= aMap
.getUnpackedValueOrDefault( u
"DataSequence"_ustr
,m_aTextualSequence
);
265 if ( m_aTextualSequence
.hasElements() )
266 m_eCurrentDataType
= TEXTUAL
;
269 m_aMixedSequence
= aMap
.getUnpackedValueOrDefault( u
"DataSequence"_ustr
,m_aMixedSequence
);
270 if ( m_aMixedSequence
.hasElements() )
271 m_eCurrentDataType
= MIXED
;
277 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
278 com_sun_star_comp_chart_CachedDataSequence_get_implementation(css::uno::XComponentContext
*context
,
279 css::uno::Sequence
<css::uno::Any
> const &)
281 return cppu::acquire(new ::chart::CachedDataSequence(context
));
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */