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;
210
211 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
212
213 // XDataSequence
214 virtual css::uno::Sequence< css::uno::Any >
215 SAL_CALL getData() override;
216 virtual OUString SAL_CALL getSourceRangeRepresentation() override;
217 virtual css::uno::Sequence< OUString >
218 SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override;
219
223 virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
224
225 // XNumericalDataSequence
226 virtual css::uno::Sequence< double >
227 SAL_CALL getNumericalData() override;
228
229 // XTextualDataSequence
230 virtual css::uno::Sequence< OUString >
231 SAL_CALL getTextualData() override;
232
233 // XTimeBased
234 virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
235 virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
236
237 virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
238
239 // XPropertySet
240 virtual css::uno::Reference<
241 css::beans::XPropertySetInfo> SAL_CALL
242 getPropertySetInfo() override;
243
244 virtual void SAL_CALL setPropertyValue(
245 const OUString& rPropertyName,
246 const css::uno::Any& rValue) override;
247
248 virtual css::uno::Any SAL_CALL getPropertyValue(
249 const OUString& rPropertyName) override;
250
251 virtual void SAL_CALL addPropertyChangeListener(
252 const OUString& rPropertyName,
253 const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
254
255 virtual void SAL_CALL removePropertyChangeListener(
256 const OUString& rPropertyName,
257 const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
258
259 virtual void SAL_CALL addVetoableChangeListener(
260 const OUString& rPropertyName,
261 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
262
263 virtual void SAL_CALL removeVetoableChangeListener(
264 const OUString& rPropertyName,
265 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
266
267 // XCloneable
268 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
269
270 // XModifyBroadcaster
271 virtual void SAL_CALL addModifyListener(
272 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
273 virtual void SAL_CALL removeModifyListener(
274 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
275
276 // XServiceInfo
277 virtual OUString SAL_CALL getImplementationName() override;
278
279 virtual sal_Bool SAL_CALL supportsService( const OUString&
280 rServiceName) override;
281
282 virtual css::uno::Sequence< OUString> SAL_CALL
284
285private:
286 void setDataChangedHint(bool b);
287
288 // Implementation
289 void RefChanged();
290 DECL_LINK( ValueListenerHdl, const SfxHint&, void );
291
292private:
294 {
295 public:
297 virtual ~ExternalRefListener() override;
300
301 virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
302 void addFileId(sal_uInt16 nFileId);
303 const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
304
305 private:
307 std::unordered_set<sal_uInt16> maFileIds;
309 };
310
315 void BuildDataCache();
316
317 void RebuildDataCache();
318
319 sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
320
321 void UpdateTokensFromRanges(const ScRangeList& rRanges);
322
324
326
327 void CopyData(const ScChart2DataSequence& r);
328
329private:
330
331 // data array
332 struct Item
333 {
334 double mfValue;
335 OUString maString;
338 Item();
339 };
340
342 {
343 public:
345 virtual ~HiddenRangeListener() override;
346
347 virtual void notify() override;
348
349 private:
351 };
352
354 std::vector<Item> m_aDataArray;
355
361 css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
362
363 css::uno::Sequence<sal_Int32> m_aHiddenValues;
364
365 // properties
366 css::chart2::data::DataSequenceRole m_aRole;
368
369 // internals
370 sal_Int64 m_nObjectId;
372 std::vector<ScTokenRef> m_aTokens;
373 std::optional<std::vector<sal_uInt32>>
375 std::unique_ptr<ExternalRefListener>
378
379 std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
380
381 std::unique_ptr<ScLinkListener> m_pValueListener;
383
386
391
392};
393
394/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< css::uno::Reference< css::util::XModifyListener > > XModifyListenerArr_Impl
Definition: cellsuno.hxx:130
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:303
ExternalRefListener(ScChart2DataSequence &rParent, ScDocument *pDoc)
Definition: chart2uno.cxx:2889
virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override
Definition: chart2uno.cxx:2906
std::unordered_set< sal_uInt16 > maFileIds
Definition: chart2uno.hxx:307
HiddenRangeListener(ScChart2DataSequence &rParent)
Definition: chart2uno.cxx:2395
css::chart2::data::DataSequenceRole m_aRole
Definition: chart2uno.hxx:366
void StopListeningToAllExternalRefs()
Definition: chart2uno.cxx:2714
std::unique_ptr< HiddenRangeListener > m_pHiddenListener
Definition: chart2uno.hxx:379
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
XModifyListenerArr_Impl m_aValueListeners
Definition: chart2uno.hxx:382
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: chart2uno.cxx:3209
virtual OUString SAL_CALL getSourceRangeRepresentation() override
Definition: chart2uno.cxx:3021
virtual OUString SAL_CALL getImplementationName() override
std::vector< ScTokenRef > m_aTokens
Definition: chart2uno.hxx:372
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:3128
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: chart2uno.cxx:3379
void setDataChangedHint(bool b)
Definition: chart2uno.cxx:3411
ExternalRefListener * GetExtRefListener()
Definition: chart2uno.cxx:2706
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: chart2uno.cxx:3316
std::unique_ptr< ExternalRefListener > m_pExtRefListener
Definition: chart2uno.hxx:376
css::uno::Sequence< css::uno::Any > m_aMixedDataCache
Cached data for getData.
Definition: chart2uno.hxx:361
ScDocument * m_pDocument
Definition: chart2uno.hxx:371
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3395
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
Definition: chart2uno.cxx:3387
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3229
virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override
Definition: chart2uno.cxx:3416
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
Definition: chart2uno.cxx:2990
ScChart2DataSequence(const ScChart2DataSequence &)=delete
void UpdateTokensFromRanges(const ScRangeList &rRanges)
Definition: chart2uno.cxx:2684
std::optional< std::vector< sal_uInt32 > > m_oRangeIndices
Definition: chart2uno.hxx:374
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
Definition: chart2uno.cxx:2931
std::vector< Item > m_aDataArray
This vector contains the cached data which was calculated with BuildDataCache().
Definition: chart2uno.hxx:354
virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override
Definition: chart2uno.cxx:3448
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: chart2uno.cxx:3343
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3403
virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override
Definition: chart2uno.cxx:3455
std::unique_ptr< ScLinkListener > m_pValueListener
Definition: chart2uno.hxx:381
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:377
DECL_LINK(ValueListenerHdl, const SfxHint &, void)
ScChart2DataSequence & operator=(const ScChart2DataSequence &)=delete
sal_Int32 FillCacheFromExternalRef(const ScTokenRef &pToken)
Definition: chart2uno.cxx:2600
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3267
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:2491
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2760
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: chart2uno.cxx:3308
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:3176
void CopyData(const ScChart2DataSequence &r)
Definition: chart2uno.cxx:2727
css::uno::Sequence< sal_Int32 > m_aHiddenValues
Definition: chart2uno.hxx:363
virtual ~ScChart2DataSequence() override
Definition: chart2uno.cxx:2442
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
Definition: chart2uno.cxx:2968
std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences
Definition: chart2uno.hxx:186
ScChart2DataSource(ScDocument *pDoc)
Definition: chart2uno.cxx:2352
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2367
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void AddLabeledSequence(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xNew)
Definition: chart2uno.cxx:2382
virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override
Definition: chart2uno.cxx:2376
virtual ~ScChart2DataSource() override
Definition: chart2uno.cxx:2359
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