Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/tools/CachedDataSequence.cxx
Line
Count
Source
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
#include <CachedDataSequence.hxx>
21
#include <CommonFunctors.hxx>
22
#include <ModifyListenerHelper.hxx>
23
24
#include <comphelper/sequenceashashmap.hxx>
25
#include <cppuhelper/supportsservice.hxx>
26
27
using namespace ::com::sun::star;
28
29
using ::com::sun::star::uno::Sequence;
30
using ::com::sun::star::uno::Reference;
31
using ::com::sun::star::uno::Any;
32
33
// necessary for MS compiler
34
using ::chart::impl::CachedDataSequence_Base;
35
36
namespace
37
{
38
constexpr OUString lcl_aServiceName = u"com.sun.star.comp.chart.CachedDataSequence"_ustr;
39
40
enum
41
{
42
//     PROP_SOURCE_IDENTIFIER,
43
    PROP_NUMBERFORMAT_KEY,
44
    PROP_PROPOSED_ROLE
45
};
46
}  // anonymous namespace
47
48
namespace chart
49
{
50
51
CachedDataSequence::CachedDataSequence()
52
0
        : m_eCurrentDataType( NUMERICAL ),
53
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
54
0
{
55
0
    registerProperties();
56
0
}
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence()
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence()
57
CachedDataSequence::CachedDataSequence( const Reference< uno::XComponentContext > & /*xContext*/ )
58
0
        : m_eCurrentDataType( MIXED ),
59
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
60
0
{
61
0
    registerProperties();
62
0
}
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&)
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&)
63
64
CachedDataSequence::CachedDataSequence( const OUString & rSingleText )
65
0
        : m_eCurrentDataType( TEXTUAL ),
66
0
          m_aTextualSequence({rSingleText}),
67
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
68
0
{
69
0
    registerProperties();
70
0
}
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence(rtl::OUString const&)
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence(rtl::OUString const&)
71
72
CachedDataSequence::CachedDataSequence( const CachedDataSequence & rSource )
73
0
        : m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
74
0
          m_sRole( rSource.m_sRole ),
75
0
          m_eCurrentDataType( rSource.m_eCurrentDataType ),
76
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
77
0
{
78
0
    switch( m_eCurrentDataType )
79
0
    {
80
0
        case TEXTUAL:
81
0
            m_aTextualSequence = rSource.m_aTextualSequence;
82
0
            break;
83
0
        case NUMERICAL:
84
0
            m_aNumericalSequence = rSource.m_aNumericalSequence;
85
0
            break;
86
0
        case MIXED:
87
0
            m_aMixedSequence = rSource.m_aMixedSequence;
88
0
            break;
89
0
    }
90
91
0
    registerProperties();
92
0
}
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence(chart::CachedDataSequence const&)
Unexecuted instantiation: chart::CachedDataSequence::CachedDataSequence(chart::CachedDataSequence const&)
93
94
CachedDataSequence::~CachedDataSequence()
95
0
{}
96
97
void CachedDataSequence::registerProperties()
98
0
{
99
0
    registerProperty( u"NumberFormatKey"_ustr,
100
0
                      PROP_NUMBERFORMAT_KEY,
101
0
                      0,   // PropertyAttributes
102
0
                      & m_nNumberFormatKey,
103
0
                      cppu::UnoType<decltype(m_nNumberFormatKey)>::get() );
104
105
0
    registerProperty( u"Role"_ustr,
106
0
                      PROP_PROPOSED_ROLE,
107
0
                      0,   // PropertyAttributes
108
0
                      & m_sRole,
109
0
                      cppu::UnoType<decltype(m_sRole)>::get() );
110
0
}
111
112
Sequence< double > CachedDataSequence::Impl_getNumericalData() const
113
0
{
114
0
    if( m_eCurrentDataType == NUMERICAL )
115
0
        return m_aNumericalSequence;
116
117
0
    if( m_eCurrentDataType == TEXTUAL )
118
0
        return CommonFunctors::convertToSequence(m_aTextualSequence, CommonFunctors::ToDouble());
119
120
0
    OSL_ASSERT(m_eCurrentDataType == MIXED);
121
0
    return CommonFunctors::convertToSequence(m_aMixedSequence, CommonFunctors::ToDouble());
122
0
}
123
124
Sequence< OUString > CachedDataSequence::Impl_getTextualData() const
125
0
{
126
0
    if( m_eCurrentDataType == TEXTUAL )
127
0
        return m_aTextualSequence;
128
129
0
    if( m_eCurrentDataType == NUMERICAL )
130
0
        return CommonFunctors::convertToSequence(m_aNumericalSequence, CommonFunctors::ToString());
131
132
0
    OSL_ASSERT(m_eCurrentDataType == MIXED);
133
0
    return CommonFunctors::convertToSequence(m_aMixedSequence, CommonFunctors::ToString());
134
0
}
135
136
Sequence< Any > CachedDataSequence::Impl_getMixedData() const
137
0
{
138
0
    if( m_eCurrentDataType == MIXED )
139
0
        return m_aMixedSequence;
140
141
0
    if( m_eCurrentDataType == NUMERICAL )
142
0
        return CommonFunctors::convertToSequence(m_aNumericalSequence, CommonFunctors::makeAny());
143
144
0
    OSL_ASSERT(m_eCurrentDataType == TEXTUAL);
145
0
    return CommonFunctors::convertToSequence(m_aTextualSequence, CommonFunctors::makeAny());
146
0
}
147
148
IMPLEMENT_FORWARD_XINTERFACE2( CachedDataSequence, CachedDataSequence_Base, comphelper::OPropertyContainer2 )
149
IMPLEMENT_FORWARD_XTYPEPROVIDER2( CachedDataSequence, CachedDataSequence_Base, comphelper::OPropertyContainer2 )
150
151
// ____ XPropertySet ____
152
Reference< beans::XPropertySetInfo > SAL_CALL CachedDataSequence::getPropertySetInfo()
153
0
{
154
0
    return createPropertySetInfo( getInfoHelper() );
155
0
}
156
157
// ____ ::comphelper::OPropertySetHelper ____
158
::cppu::IPropertyArrayHelper& CachedDataSequence::getInfoHelper()
159
0
{
160
0
    return *getArrayHelper();
161
0
}
162
163
// ____ ::comphelper::OPropertyArrayHelper ____
164
::cppu::IPropertyArrayHelper* CachedDataSequence::createArrayHelper() const
165
0
{
166
0
    Sequence< beans::Property > aProps;
167
    // describes all properties which have been registered in the ctor
168
0
    describeProperties( aProps );
169
170
0
    return new ::cppu::OPropertyArrayHelper( aProps );
171
0
}
172
173
OUString SAL_CALL CachedDataSequence::getImplementationName()
174
0
{
175
0
    return lcl_aServiceName;
176
0
}
177
178
sal_Bool SAL_CALL CachedDataSequence::supportsService( const OUString& rServiceName )
179
0
{
180
0
    return cppu::supportsService(this, rServiceName);
181
0
}
182
183
css::uno::Sequence< OUString > SAL_CALL CachedDataSequence::getSupportedServiceNames()
184
0
{
185
0
    return {
186
0
        lcl_aServiceName,
187
0
        u"com.sun.star.chart2.data.DataSequence"_ustr,
188
0
        u"com.sun.star.chart2.data.NumericalDataSequence"_ustr,
189
0
        u"com.sun.star.chart2.data.TextualDataSequence"_ustr
190
0
    };
191
0
}
192
193
// ________ XNumericalDataSequence ________
194
Sequence< double > SAL_CALL CachedDataSequence::getNumericalData()
195
0
{
196
0
    std::unique_lock aGuard( m_aMutex );
197
198
0
    if( m_eCurrentDataType == NUMERICAL )
199
0
        return m_aNumericalSequence;
200
0
    else
201
0
        return Impl_getNumericalData();
202
0
}
203
204
// ________ XTextualDataSequence ________
205
Sequence< OUString > SAL_CALL CachedDataSequence::getTextualData()
206
0
{
207
0
    std::unique_lock aGuard( m_aMutex );
208
209
0
    if( m_eCurrentDataType == TEXTUAL )
210
0
        return m_aTextualSequence;
211
0
    else
212
0
        return Impl_getTextualData();
213
0
}
214
215
// ________ XDataSequence  ________
216
Sequence< Any > SAL_CALL CachedDataSequence::getData()
217
0
{
218
0
    std::unique_lock aGuard( m_aMutex );
219
0
    return Impl_getMixedData();
220
0
}
221
222
OUString SAL_CALL CachedDataSequence::getSourceRangeRepresentation()
223
0
{
224
0
    return m_sRole;
225
0
}
226
227
Sequence< OUString > SAL_CALL CachedDataSequence::generateLabel( chart2::data::LabelOrigin  /*eLabelOrigin*/ )
228
0
{
229
    // return empty label, as we have no range representations to determine something useful
230
0
    return Sequence< OUString >();
231
0
}
232
233
::sal_Int32 SAL_CALL CachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 /*nIndex*/ )
234
0
{
235
0
    return 0;
236
0
}
237
238
Reference< util::XCloneable > SAL_CALL CachedDataSequence::createClone()
239
0
{
240
0
    return new CachedDataSequence( *this );
241
0
}
242
243
void SAL_CALL CachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
244
0
{
245
0
    m_xModifyEventForwarder->addModifyListener( aListener );
246
0
}
247
248
void SAL_CALL CachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
249
0
{
250
0
    m_xModifyEventForwarder->removeModifyListener( aListener );
251
0
}
252
253
// lang::XInitialization:
254
void SAL_CALL CachedDataSequence::initialize(const uno::Sequence< uno::Any > & _aArguments)
255
0
{
256
0
    ::comphelper::SequenceAsHashMap aMap(_aArguments);
257
0
    m_aNumericalSequence = aMap.getUnpackedValueOrDefault( u"DataSequence"_ustr ,m_aNumericalSequence);
258
0
    if ( m_aNumericalSequence.hasElements() )
259
0
        m_eCurrentDataType = NUMERICAL;
260
0
    else
261
0
    {
262
0
        m_aTextualSequence = aMap.getUnpackedValueOrDefault( u"DataSequence"_ustr ,m_aTextualSequence);
263
0
        if ( m_aTextualSequence.hasElements() )
264
0
            m_eCurrentDataType = TEXTUAL;
265
0
        else
266
0
        {
267
0
            m_aMixedSequence = aMap.getUnpackedValueOrDefault( u"DataSequence"_ustr ,m_aMixedSequence);
268
0
            if ( m_aMixedSequence.hasElements() )
269
0
                m_eCurrentDataType = MIXED;
270
0
        }
271
0
    }
272
0
}
273
}  // namespace chart
274
275
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
276
com_sun_star_comp_chart_CachedDataSequence_get_implementation(css::uno::XComponentContext *context,
277
        css::uno::Sequence<css::uno::Any> const &)
278
0
{
279
0
    return cppu::acquire(new ::chart::CachedDataSequence(context));
280
0
}
281
282
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */