Coverage Report

Created: 2026-06-30 11:14

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