Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/inc/chart2uno.hxx
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
#pragma once
21
22
#include "cellsuno.hxx"
23
#include "rangelst.hxx"
24
#include "externalrefmgr.hxx"
25
#include "types.hxx"
26
#include "chartlis.hxx"
27
28
#include <svl/lstner.hxx>
29
#include <com/sun/star/chart2/data/XDataProvider.hpp>
30
#include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
31
#include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
32
#include <com/sun/star/chart2/data/XDataSource.hpp>
33
#include <com/sun/star/chart2/data/XDataSequence.hpp>
34
#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
35
#include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
36
#include <com/sun/star/chart2/data/DataSequenceRole.hpp>
37
#include <com/sun/star/chart2/XTimeBased.hpp>
38
#include <com/sun/star/lang/XServiceInfo.hpp>
39
#include <com/sun/star/beans/XPropertySet.hpp>
40
#include <com/sun/star/util/XCloneable.hpp>
41
#include <com/sun/star/util/XModifyBroadcaster.hpp>
42
#include <cppuhelper/implbase.hxx>
43
#include <rtl/ustring.hxx>
44
#include <svl/itemprop.hxx>
45
46
#include <memory>
47
#include <optional>
48
#include <unordered_set>
49
#include <vector>
50
51
namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
52
53
class ScDocument;
54
55
// DataProvider
56
class ScChart2DataProvider final : public
57
                ::cppu::WeakImplHelper<
58
                    css::chart2::data::XDataProvider,
59
                    css::chart2::data::XSheetDataProvider,
60
                    css::chart2::data::XRangeXMLConversion,
61
                    css::beans::XPropertySet,
62
                    css::lang::XServiceInfo>,
63
                public SfxListener
64
{
65
public:
66
67
    SC_DLLPUBLIC explicit ScChart2DataProvider( ScDocument* pDoc );
68
    virtual ~ScChart2DataProvider() override;
69
    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
70
71
    // XDataProvider
72
    virtual sal_Bool SAL_CALL createDataSourcePossible(
73
        const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
74
75
    virtual css::uno::Reference<
76
        css::chart2::data::XDataSource > SAL_CALL createDataSource(
77
            const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
78
79
    virtual css::uno::Sequence<
80
        css::beans::PropertyValue > SAL_CALL detectArguments(
81
            const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
82
83
    virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
84
        const OUString& aRangeRepresentation ) override;
85
86
    virtual css::uno::Reference<
87
        css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
88
            const OUString& aRangeRepresentation ) override;
89
90
    virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
91
        createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation,
92
            const OUString& aRoleQualifier ) override;
93
94
    virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
95
96
    // XSheetDataProvider
97
    virtual sal_Bool SAL_CALL createDataSequenceByFormulaTokensPossible(
98
        const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
99
100
    virtual css::uno::Reference< css::chart2::data::XDataSequence >
101
        SAL_CALL createDataSequenceByFormulaTokens(
102
            const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
103
104
    // XRangeXMLConversion
105
    virtual OUString SAL_CALL convertRangeToXML( const OUString& sRangeRepresentation ) override;
106
107
    virtual OUString SAL_CALL convertRangeFromXML( const OUString& sXMLRange ) override;
108
109
    // XPropertySet
110
    virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL
111
        getPropertySetInfo() override;
112
113
    virtual void SAL_CALL setPropertyValue(
114
            const OUString& rPropertyName,
115
            const css::uno::Any& rValue) override;
116
117
    virtual css::uno::Any SAL_CALL getPropertyValue(
118
            const OUString& rPropertyName) override;
119
120
    virtual void SAL_CALL addPropertyChangeListener(
121
            const OUString& rPropertyName,
122
            const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
123
124
    virtual void SAL_CALL removePropertyChangeListener(
125
            const OUString& rPropertyName,
126
            const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
127
128
    virtual void SAL_CALL addVetoableChangeListener(
129
            const OUString& rPropertyName,
130
            const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
131
132
    virtual void SAL_CALL removeVetoableChangeListener(
133
            const OUString& rPropertyName,
134
            const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
135
136
    // XServiceInfo
137
    virtual OUString SAL_CALL getImplementationName() override;
138
139
    virtual sal_Bool SAL_CALL supportsService( const OUString&
140
            rServiceName) override;
141
142
    virtual css::uno::Sequence< OUString> SAL_CALL
143
        getSupportedServiceNames() override;
144
145
private:
146
147
    ScDocument*                 m_pDocument;
148
    SfxItemPropertySet          m_aPropSet;
149
    bool                        m_bIncludeHiddenCells;
150
};
151
152
// DataSource
153
class ScChart2DataSource final : public
154
                ::cppu::WeakImplHelper<
155
                    css::chart2::data::XDataSource,
156
                    css::lang::XServiceInfo>,
157
                public SfxListener
158
{
159
public:
160
161
    explicit ScChart2DataSource( ScDocument* pDoc);
162
    virtual ~ScChart2DataSource() override;
163
    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
164
165
    // XDataSource
166
    virtual css::uno::Sequence< css::uno::Reference<
167
            css::chart2::data::XLabeledDataSequence > > SAL_CALL
168
        getDataSequences() override;
169
170
    // XServiceInfo
171
    virtual OUString SAL_CALL getImplementationName() override;
172
173
    virtual sal_Bool SAL_CALL supportsService( const OUString&
174
            rServiceName) override;
175
176
    virtual css::uno::Sequence< OUString> SAL_CALL
177
        getSupportedServiceNames() override;
178
179
    // implementation
180
181
    void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
182
183
private:
184
185
    ScDocument*                 m_pDocument;
186
    std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
187
188
};
189
190
// DataSequence
191
class ScChart2DataSequence final : public
192
                ::cppu::WeakImplHelper<
193
                    css::chart2::data::XDataSequence,
194
                    css::chart2::data::XTextualDataSequence,
195
                    css::chart2::data::XNumericalDataSequence,
196
                    css::chart2::XTimeBased,
197
                    css::util::XCloneable,
198
                    css::util::XModifyBroadcaster,
199
                    css::beans::XPropertySet,
200
                    css::lang::XServiceInfo>,
201
                public SfxListener
202
{
203
public:
204
    explicit ScChart2DataSequence( ScDocument* pDoc,
205
            ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
206
207
    virtual ~ScChart2DataSequence() override;
208
    ScChart2DataSequence(ScDocument* pDoc, const ScChart2DataSequence&);
209
    ScChart2DataSequence(const ScChart2DataSequence&) = delete;
210
    ScChart2DataSequence& operator=(const ScChart2DataSequence&) = delete;
211
212
    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
213
214
    // XDataSequence
215
    virtual css::uno::Sequence< css::uno::Any >
216
        SAL_CALL getData() override;
217
    virtual OUString SAL_CALL getSourceRangeRepresentation() override;
218
    virtual css::uno::Sequence< OUString >
219
        SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override;
220
221
    /** Get the number format key for the n-th data entry
222
     * If nIndex == -1, then you will get the number format key for the first non-empty entry
223
     */
224
    virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
225
226
    // XNumericalDataSequence
227
    virtual css::uno::Sequence< double >
228
        SAL_CALL getNumericalData() override;
229
230
    // XTextualDataSequence
231
    virtual css::uno::Sequence< OUString >
232
        SAL_CALL getTextualData() override;
233
234
    // XTimeBased
235
    virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
236
    virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
237
238
    virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
239
240
    // XPropertySet
241
    virtual css::uno::Reference<
242
        css::beans::XPropertySetInfo> SAL_CALL
243
        getPropertySetInfo() override;
244
245
    virtual void SAL_CALL setPropertyValue(
246
            const OUString& rPropertyName,
247
            const css::uno::Any& rValue) override;
248
249
    virtual css::uno::Any SAL_CALL getPropertyValue(
250
            const OUString& rPropertyName) override;
251
252
    virtual void SAL_CALL addPropertyChangeListener(
253
            const OUString& rPropertyName,
254
            const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
255
256
    virtual void SAL_CALL removePropertyChangeListener(
257
            const OUString& rPropertyName,
258
            const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
259
260
    virtual void SAL_CALL addVetoableChangeListener(
261
            const OUString& rPropertyName,
262
            const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
263
264
    virtual void SAL_CALL removeVetoableChangeListener(
265
            const OUString& rPropertyName,
266
            const css::uno::Reference<  css::beans::XVetoableChangeListener>& rListener) override;
267
268
    // XCloneable
269
    virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
270
271
    // XModifyBroadcaster
272
    virtual void SAL_CALL addModifyListener(
273
        const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
274
    virtual void SAL_CALL removeModifyListener(
275
        const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
276
277
    // XServiceInfo
278
    virtual OUString SAL_CALL getImplementationName() override;
279
280
    virtual sal_Bool SAL_CALL supportsService( const OUString&
281
            rServiceName) override;
282
283
    virtual css::uno::Sequence< OUString> SAL_CALL
284
        getSupportedServiceNames() override;
285
286
private:
287
    void setDataChangedHint(bool b);
288
289
    // Implementation
290
    void    RefChanged();
291
    DECL_LINK( ValueListenerHdl, const SfxHint&, void );
292
293
private:
294
    class ExternalRefListener final : public ScExternalRefManager::LinkListener
295
    {
296
    public:
297
        ExternalRefListener(ScChart2DataSequence& rParent, ScDocument* pDoc);
298
        virtual ~ExternalRefListener() override;
299
        ExternalRefListener(const ExternalRefListener&) = delete;
300
        ExternalRefListener& operator=(const ExternalRefListener&) = delete;
301
302
        virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
303
        void addFileId(sal_uInt16 nFileId);
304
0
        const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
305
306
    private:
307
        ScChart2DataSequence&       mrParent;
308
        std::unordered_set<sal_uInt16> maFileIds;
309
        ScDocument*                 mpDoc;
310
    };
311
312
    /**
313
     * Build an internal data array to cache the data ranges, and other
314
     * information such as hidden values.
315
     */
316
    void BuildDataCache();
317
318
    void RebuildDataCache();
319
320
    sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
321
322
    void UpdateTokensFromRanges(const ScRangeList& rRanges);
323
324
    ExternalRefListener* GetExtRefListener();
325
326
    void StopListeningToAllExternalRefs();
327
328
private:
329
330
    // data array
331
    struct Item
332
    {
333
        double              mfValue;
334
        OUString     maString;
335
        bool                mbIsValue;
336
        ScAddress   mAddress;
337
        Item();
338
    };
339
340
    class HiddenRangeListener final : public ScChartHiddenRangeListener
341
    {
342
    public:
343
        HiddenRangeListener(ScChart2DataSequence& rParent);
344
        virtual ~HiddenRangeListener() override;
345
346
        virtual void notify() override;
347
348
    private:
349
        ScChart2DataSequence& mrParent;
350
    };
351
352
    /** This vector contains the cached data which was calculated with BuildDataCache().
353
        We use a shared_ptr because chart likes to Clone this class, which is very
354
        expensive when we have lots of data. */
355
    std::shared_ptr<std::vector<Item>> m_xDataArray;
356
357
    /**
358
     * Cached data for getData.  We may also need to cache data for the
359
     * numerical and textural data series if they turn out to be bottlenecks
360
     * under certain scenarios.
361
     */
362
    css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
363
364
    css::uno::Sequence<sal_Int32>  m_aHiddenValues;
365
366
    // properties
367
    css::chart2::data::DataSequenceRole  m_aRole;
368
    bool                        m_bIncludeHiddenCells;
369
370
    // internals
371
    sal_Int64                   m_nObjectId;
372
    ScDocument*                 m_pDocument;
373
    std::vector<ScTokenRef>     m_aTokens;
374
    std::optional<std::vector<sal_uInt32>>
375
                                m_oRangeIndices;
376
    std::unique_ptr<ExternalRefListener>
377
                                m_pExtRefListener;
378
    SfxItemPropertySet          m_aPropSet;
379
380
    std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
381
382
    std::unique_ptr<ScLinkListener>      m_pValueListener;
383
    XModifyListenerArr_Impl     m_aValueListeners;
384
385
    bool                        m_bGotDataChangedHint;
386
    bool                        m_bExtDataRebuildQueued;
387
388
    bool mbTimeBased;
389
    SCTAB mnTimeBasedStart;
390
    SCTAB mnTimeBasedEnd;
391
    SCTAB mnCurrentTab;
392
393
};
394
395
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */