Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/tools/UncachedDataSequence.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 <UncachedDataSequence.hxx>
21
#include <CommonFunctors.hxx>
22
#include <ModifyListenerHelper.hxx>
23
#include <InternalDataProvider.hxx>
24
25
#include <cppuhelper/supportsservice.hxx>
26
#include <strings.hrc>
27
#include <ResId.hxx>
28
#include <utility>
29
30
using namespace ::com::sun::star;
31
32
using ::com::sun::star::uno::Sequence;
33
using ::com::sun::star::uno::Reference;
34
using ::com::sun::star::uno::Any;
35
36
namespace
37
{
38
constexpr OUString lcl_aServiceName = u"com.sun.star.comp.chart.UncachedDataSequence"_ustr;
39
40
enum
41
{
42
    PROP_NUMBERFORMAT_KEY,
43
    PROP_PROPOSED_ROLE,
44
    PROP_XML_RANGE,
45
    PROP_CHARTEX_FORMULA,
46
    PROP_CHARTEX_NFORMULA,
47
    PROP_CHARTEX_DIM_TYPE
48
};
49
}  // anonymous namespace
50
51
namespace chart
52
{
53
54
UncachedDataSequence::UncachedDataSequence(
55
    rtl::Reference< InternalDataProvider > xIntDataProv,
56
    OUString aRangeRepresentation )
57
0
        : m_nNumberFormatKey(0),
58
0
          m_nChartExDimType(0),
59
0
          m_xDataProvider(std::move( xIntDataProv )),
60
0
          m_aSourceRepresentation(std::move( aRangeRepresentation )),
61
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
62
0
{
63
0
    registerProperties();
64
0
}
Unexecuted instantiation: chart::UncachedDataSequence::UncachedDataSequence(rtl::Reference<chart::InternalDataProvider>, rtl::OUString)
Unexecuted instantiation: chart::UncachedDataSequence::UncachedDataSequence(rtl::Reference<chart::InternalDataProvider>, rtl::OUString)
65
66
UncachedDataSequence::UncachedDataSequence(
67
    rtl::Reference< InternalDataProvider > xIntDataProv,
68
    OUString aRangeRepresentation,
69
    const OUString & rRole )
70
0
        : m_nNumberFormatKey(0),
71
0
          m_nChartExDimType(0),
72
0
          m_xDataProvider(std::move( xIntDataProv )),
73
0
          m_aSourceRepresentation(std::move( aRangeRepresentation )),
74
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
75
0
{
76
0
    registerProperties();
77
0
    std::unique_lock<std::mutex> aGuard;
78
0
    setFastPropertyValue_NoBroadcast( aGuard, PROP_PROPOSED_ROLE, uno::Any( rRole ));
79
0
}
Unexecuted instantiation: chart::UncachedDataSequence::UncachedDataSequence(rtl::Reference<chart::InternalDataProvider>, rtl::OUString, rtl::OUString const&)
Unexecuted instantiation: chart::UncachedDataSequence::UncachedDataSequence(rtl::Reference<chart::InternalDataProvider>, rtl::OUString, rtl::OUString const&)
80
81
UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence & rSource )
82
0
        : UncachedDataSequence_Base(),
83
0
          m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
84
0
          m_sRole( rSource.m_sRole ),
85
0
          m_aChartExFormula( rSource.m_aChartExFormula ),
86
0
          m_aChartExNFormula( rSource.m_aChartExNFormula ),
87
0
          m_nChartExDimType( rSource.m_nChartExDimType ),
88
0
          m_xDataProvider( rSource.m_xDataProvider ),
89
0
          m_aSourceRepresentation( rSource.m_aSourceRepresentation ),
90
0
          m_xModifyEventForwarder( new ModifyEventForwarder() )
91
0
{
92
0
    registerProperties();
93
0
}
Unexecuted instantiation: chart::UncachedDataSequence::UncachedDataSequence(chart::UncachedDataSequence const&)
Unexecuted instantiation: chart::UncachedDataSequence::UncachedDataSequence(chart::UncachedDataSequence const&)
94
95
UncachedDataSequence::~UncachedDataSequence()
96
0
{}
97
98
void UncachedDataSequence::registerProperties()
99
0
{
100
0
    registerProperty( u"NumberFormatKey"_ustr,
101
0
                      PROP_NUMBERFORMAT_KEY,
102
0
                      0,   // PropertyAttributes
103
0
                      & m_nNumberFormatKey,
104
0
                      cppu::UnoType<decltype(m_nNumberFormatKey)>::get() );
105
106
0
    registerProperty( u"Role"_ustr,
107
0
                      PROP_PROPOSED_ROLE,
108
0
                      0,   // PropertyAttributes
109
0
                      & m_sRole,
110
0
                      cppu::UnoType<decltype(m_sRole)>::get() );
111
112
0
    registerProperty( u"CachedXMLRange"_ustr,
113
0
                      PROP_XML_RANGE,
114
0
                      0,   // PropertyAttributes
115
0
                      & m_aXMLRange,
116
0
                      cppu::UnoType<decltype(m_aXMLRange)>::get() );
117
118
0
    registerProperty( u"ChartExFormula"_ustr,
119
0
                      PROP_CHARTEX_FORMULA,
120
0
                      0,
121
0
                      & m_aChartExFormula,
122
0
                      cppu::UnoType<decltype(m_aChartExFormula)>::get() );
123
124
0
    registerProperty( u"ChartExNFormula"_ustr,
125
0
                      PROP_CHARTEX_NFORMULA,
126
0
                      0,
127
0
                      & m_aChartExNFormula,
128
0
                      cppu::UnoType<decltype(m_aChartExNFormula)>::get() );
129
130
0
    registerProperty( u"ChartExDimType"_ustr,
131
0
                      PROP_CHARTEX_DIM_TYPE,
132
0
                      0,
133
0
                      & m_nChartExDimType,
134
0
                      cppu::UnoType<decltype(m_nChartExDimType)>::get() );
135
0
}
136
137
::cppu::IPropertyArrayHelper* UncachedDataSequence::createArrayHelper() const
138
0
{
139
0
    Sequence< beans::Property > aProps;
140
    // describes all properties which have been registered in the ctor
141
0
    describeProperties( aProps );
142
143
0
    return new ::cppu::OPropertyArrayHelper( aProps );
144
0
}
145
146
OUString SAL_CALL UncachedDataSequence::getImplementationName()
147
0
{
148
0
    return lcl_aServiceName;
149
0
}
150
151
sal_Bool SAL_CALL UncachedDataSequence::supportsService( const OUString& rServiceName )
152
0
{
153
0
    return cppu::supportsService(this, rServiceName);
154
0
}
155
156
css::uno::Sequence< OUString > SAL_CALL UncachedDataSequence::getSupportedServiceNames()
157
0
{
158
0
    return {
159
0
        lcl_aServiceName,
160
0
        u"com.sun.star.chart2.data.DataSequence"_ustr,
161
0
        u"com.sun.star.chart2.data.NumericalDataSequence"_ustr,
162
0
        u"com.sun.star.chart2.data.TextualDataSequence"_ustr
163
0
    };
164
0
}
165
166
// ________ XNumericalDataSequence ________
167
Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData()
168
0
{
169
0
    std::unique_lock<std::mutex> aGuard;
170
0
    if( m_xDataProvider.is())
171
0
    {
172
0
        const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
173
0
        return CommonFunctors::convertToSequence(aValues, CommonFunctors::ToDouble());
174
0
    }
175
0
    return {};
176
0
}
177
178
// ________ XTextualDataSequence ________
179
Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData()
180
0
{
181
0
    std::unique_lock<std::mutex> aGuard;
182
0
    if( m_xDataProvider.is())
183
0
    {
184
0
        const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
185
0
        return CommonFunctors::convertToSequence(aValues, CommonFunctors::ToString());
186
0
    }
187
0
    return {};
188
0
}
189
190
// ________ XDataSequence  ________
191
Sequence< Any > SAL_CALL UncachedDataSequence::getData()
192
0
{
193
0
    std::unique_lock<std::mutex> aGuard;
194
0
    if( m_xDataProvider.is())
195
0
        return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation );
196
0
    return Sequence< Any >();
197
0
}
198
199
OUString SAL_CALL UncachedDataSequence::getSourceRangeRepresentation()
200
0
{
201
0
    return getName();
202
0
}
203
204
Sequence< OUString > SAL_CALL UncachedDataSequence::generateLabel( chart2::data::LabelOrigin )
205
0
{
206
    // auto-generated label
207
0
    sal_Int32 nSeries = m_aSourceRepresentation.toInt32() + 1;
208
0
    OUString aResString(::chart::SchResId(STR_DATA_UNNAMED_SERIES_WITH_INDEX));
209
0
    static constexpr OUString aReplacementStr(u"%NUMBER"_ustr);
210
0
    sal_Int32 nIndex = aResString.indexOf(aReplacementStr);
211
0
    OUString aName;
212
0
    if( nIndex != -1 )
213
0
        aName = aResString.replaceAt(nIndex, aReplacementStr.getLength(), OUString::number(nSeries));
214
0
    return Sequence< OUString >( &aName, 1 );
215
0
}
216
217
::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 )
218
0
{
219
0
    return m_nNumberFormatKey;
220
0
}
221
222
// ____ XIndexReplace ____
223
void SAL_CALL UncachedDataSequence::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
224
0
{
225
0
    std::unique_lock<std::mutex> aGuard;
226
0
    Sequence< Any > aData( getData());
227
0
    if( Index < aData.getLength() &&
228
0
        m_xDataProvider.is() )
229
0
    {
230
0
        aData.getArray()[Index] = Element;
231
0
        m_xDataProvider->setDataByRangeRepresentation( m_aSourceRepresentation, aData );
232
0
        fireModifyEvent();
233
0
    }
234
0
}
235
236
// ____ XIndexAccess (base of XIndexReplace) ____
237
::sal_Int32 SAL_CALL UncachedDataSequence::getCount()
238
0
{
239
0
    OSL_FAIL( "Implement!" );
240
0
    return 0;
241
0
}
242
243
uno::Any SAL_CALL UncachedDataSequence::getByIndex( ::sal_Int32 )
244
0
{
245
0
    OSL_FAIL( "Implement!" );
246
0
    return uno::Any();
247
0
}
248
249
// ____ XElementAccess (base of XIndexAccess) ____
250
uno::Type SAL_CALL UncachedDataSequence::getElementType()
251
0
{
252
0
    return cppu::UnoType<uno::Any>::get();
253
0
}
254
255
sal_Bool SAL_CALL UncachedDataSequence::hasElements()
256
0
{
257
0
    if( ! m_xDataProvider.is())
258
0
        return false;
259
0
    return m_xDataProvider->hasDataByRangeRepresentation( m_aSourceRepresentation );
260
0
}
261
262
// ____ XNamed ____
263
OUString SAL_CALL UncachedDataSequence::getName()
264
0
{
265
0
    return m_aSourceRepresentation;
266
0
}
267
268
void SAL_CALL UncachedDataSequence::setName( const OUString& aName )
269
0
{
270
0
    m_aSourceRepresentation = aName;
271
0
    fireModifyEvent();
272
0
}
273
274
Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone()
275
0
{
276
0
    return new UncachedDataSequence( *this );
277
0
}
278
279
// ____ XModifiable ____
280
sal_Bool SAL_CALL UncachedDataSequence::isModified()
281
0
{
282
0
    return false;
283
0
}
284
285
void SAL_CALL UncachedDataSequence::setModified( sal_Bool bModified )
286
0
{
287
0
    if( bModified )
288
0
        fireModifyEvent();
289
0
}
290
291
// ____ XModifyBroadcaster (base of XModifiable) ____
292
void SAL_CALL UncachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
293
0
{
294
0
    m_xModifyEventForwarder->addModifyListener( aListener );
295
0
}
296
297
void SAL_CALL UncachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
298
0
{
299
0
    m_xModifyEventForwarder->removeModifyListener( aListener );
300
0
}
301
302
void UncachedDataSequence::fireModifyEvent()
303
0
{
304
    // @todo: currently never called, as data changes are not yet reported by
305
    // the data provider
306
0
    m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
307
0
}
308
309
}  // namespace chart
310
311
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */