Coverage Report

Created: 2025-12-31 10:39

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