LibreOffice Module sc (master) 1
chart2uno.hxx
Go to the documentation of this file.
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>
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
51namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
52
53class ScDocument;
54
55// DataProvider
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{
65public:
66
67 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
144
145private:
146
150};
151
152// DataSource
153class ScChart2DataSource final : public
154 ::cppu::WeakImplHelper<
155 css::chart2::data::XDataSource,
156 css::lang::XServiceInfo>,
157 public SfxListener
158{
159public:
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
178
179 // implementation
180
181 void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
182
183private:
184
186 std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
187
188};
189
190// DataSequence
191class 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{
203public:
205 ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
206
207 virtual ~ScChart2DataSequence() override;
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
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
285
286private:
287 void setDataChangedHint(bool b);
288
289 // Implementation
290 void RefChanged();
291 DECL_LINK( ValueListenerHdl, const SfxHint&, void );
292
293private:
295 {
296 public:
298 virtual ~ExternalRefListener() override;
301
302 virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
303 void addFileId(sal_uInt16 nFileId);
304 const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
305
306 private:
308 std::unordered_set<sal_uInt16> maFileIds;
310 };
311
316 void BuildDataCache();
317
318 void RebuildDataCache();
319
320 sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
321
322 void UpdateTokensFromRanges(const ScRangeList& rRanges);
323
325
327
328private:
329
330 // data array
331 struct Item
332 {
333 double mfValue;
334 OUString maString;
337 Item();
338 };
339
341 {
342 public:
344 virtual ~HiddenRangeListener() override;
345
346 virtual void notify() override;
347
348 private:
350 };
351
355 std::shared_ptr<std::vector<Item>> m_xDataArray;
356
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;
369
370 // internals
371 sal_Int64 m_nObjectId;
373 std::vector<ScTokenRef> m_aTokens;
374 std::optional<std::vector<sal_uInt32>>
376 std::unique_ptr<ExternalRefListener>
379
380 std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
381
382 std::unique_ptr<ScLinkListener> m_pValueListener;
384
387
392
393};
394
395/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< css::uno::Reference< css::util::XModifyListener > > XModifyListenerArr_Impl
Definition: cellsuno.hxx:129
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
ScDocument * m_pDocument
Definition: chart2uno.hxx:147
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:148
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
ExternalRefListener & operator=(const ExternalRefListener &)=delete
ExternalRefListener(const ExternalRefListener &)=delete
const std::unordered_set< sal_uInt16 > & getAllFileIds() const
Definition: chart2uno.hxx:304
ExternalRefListener(ScChart2DataSequence &rParent, ScDocument *pDoc)
Definition: chart2uno.cxx:2934
virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override
Definition: chart2uno.cxx:2951
std::unordered_set< sal_uInt16 > maFileIds
Definition: chart2uno.hxx:308
HiddenRangeListener(ScChart2DataSequence &rParent)
Definition: chart2uno.cxx:2402
css::chart2::data::DataSequenceRole m_aRole
Definition: chart2uno.hxx:367
void StopListeningToAllExternalRefs()
Definition: chart2uno.cxx:2791
std::unique_ptr< HiddenRangeListener > m_pHiddenListener
Definition: chart2uno.hxx:380
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
XModifyListenerArr_Impl m_aValueListeners
Definition: chart2uno.hxx:383
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: chart2uno.cxx:3254
virtual OUString SAL_CALL getSourceRangeRepresentation() override
Definition: chart2uno.cxx:3066
virtual OUString SAL_CALL getImplementationName() override
std::vector< ScTokenRef > m_aTokens
Definition: chart2uno.hxx:373
ScChart2DataSequence(ScDocument *pDoc, ::std::vector< ScTokenRef > &&rTokens, bool bIncludeHiddenCells)
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override
Definition: chart2uno.cxx:3173
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: chart2uno.cxx:3414
void setDataChangedHint(bool b)
Definition: chart2uno.cxx:3446
ExternalRefListener * GetExtRefListener()
Definition: chart2uno.cxx:2783
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: chart2uno.cxx:3351
std::unique_ptr< ExternalRefListener > m_pExtRefListener
Definition: chart2uno.hxx:377
css::uno::Sequence< css::uno::Any > m_aMixedDataCache
Cached data for getData.
Definition: chart2uno.hxx:362
ScDocument * m_pDocument
Definition: chart2uno.hxx:372
std::shared_ptr< std::vector< Item > > m_xDataArray
This vector contains the cached data which was calculated with BuildDataCache().
Definition: chart2uno.hxx:355
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3430
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
Definition: chart2uno.cxx:3422
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3264
virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override
Definition: chart2uno.cxx:3451
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
Definition: chart2uno.cxx:3035
ScChart2DataSequence(const ScChart2DataSequence &)=delete
void UpdateTokensFromRanges(const ScRangeList &rRanges)
Definition: chart2uno.cxx:2761
std::optional< std::vector< sal_uInt32 > > m_oRangeIndices
Definition: chart2uno.hxx:375
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
Definition: chart2uno.cxx:2976
virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override
Definition: chart2uno.cxx:3483
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: chart2uno.cxx:3378
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3438
virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override
Definition: chart2uno.cxx:3490
std::unique_ptr< ScLinkListener > m_pValueListener
Definition: chart2uno.hxx:382
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:378
DECL_LINK(ValueListenerHdl, const SfxHint &, void)
ScChart2DataSequence & operator=(const ScChart2DataSequence &)=delete
sal_Int32 FillCacheFromExternalRef(const ScTokenRef &pToken)
Definition: chart2uno.cxx:2676
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3302
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
void BuildDataCache()
Build an internal data array to cache the data ranges, and other information such as hidden values.
Definition: chart2uno.cxx:2547
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2805
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: chart2uno.cxx:3343
virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex(::sal_Int32 nIndex) override
Get the number format key for the n-th data entry If nIndex == -1, then you will get the number forma...
Definition: chart2uno.cxx:3221
css::uno::Sequence< sal_Int32 > m_aHiddenValues
Definition: chart2uno.hxx:364
virtual ~ScChart2DataSequence() override
Definition: chart2uno.cxx:2498
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
Definition: chart2uno.cxx:3013
std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences
Definition: chart2uno.hxx:186
ScChart2DataSource(ScDocument *pDoc)
Definition: chart2uno.cxx:2359
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2374
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void AddLabeledSequence(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xNew)
Definition: chart2uno.cxx:2389
virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override
Definition: chart2uno.cxx:2383
virtual ~ScChart2DataSource() override
Definition: chart2uno.cxx:2366
virtual OUString SAL_CALL getImplementationName() override
ScDocument * m_pDocument
Definition: chart2uno.hxx:185
Base class for objects that need to listen to link updates.
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
Sequence< PropertyValue > aArguments
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
unsigned char sal_Bool
sal_Int16 SCTAB
Definition: types.hxx:22
::boost::intrusive_ptr< formula::FormulaToken > ScTokenRef
Definition: types.hxx:29