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>
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 SC_DLLPUBLIC 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  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 
150  css::uno::Reference< css::chart2::data::XDataSource > mxCachedDataSource;
151  css::uno::Sequence< css::beans::PropertyValue > maCachedArguments;
152  css::uno::Sequence< css::beans::PropertyValue > maCreateDataSourceArguments;
153  css::uno::Reference< css::chart2::data::XDataSource > mxCreatedDataSource;
154 };
155 
156 // DataSource
157 class ScChart2DataSource final : public
158  ::cppu::WeakImplHelper<
159  css::chart2::data::XDataSource,
160  css::lang::XServiceInfo>,
161  public SfxListener
162 {
163 public:
164 
165  explicit ScChart2DataSource( ScDocument* pDoc);
166  virtual ~ScChart2DataSource() override;
167  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
168 
169  // XDataSource
170  virtual css::uno::Sequence< css::uno::Reference<
171  css::chart2::data::XLabeledDataSequence > > SAL_CALL
172  getDataSequences() override;
173 
174  // XServiceInfo
175  virtual OUString SAL_CALL getImplementationName() override;
176 
177  virtual sal_Bool SAL_CALL supportsService( const OUString&
178  rServiceName) override;
179 
180  virtual css::uno::Sequence< OUString> SAL_CALL
181  getSupportedServiceNames() override;
182 
183  // implementation
184 
185  void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
186 
187 private:
188 
190  std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
191 
192 };
193 
194 // DataSequence
195 class ScChart2DataSequence final : public
196  ::cppu::WeakImplHelper<
197  css::chart2::data::XDataSequence,
198  css::chart2::data::XTextualDataSequence,
199  css::chart2::data::XNumericalDataSequence,
200  css::chart2::XTimeBased,
201  css::util::XCloneable,
202  css::util::XModifyBroadcaster,
203  css::beans::XPropertySet,
204  css::lang::XServiceInfo>,
205  public SfxListener
206 {
207 public:
208  explicit ScChart2DataSequence( ScDocument* pDoc,
209  ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
210 
211  virtual ~ScChart2DataSequence() override;
214 
215  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
216 
217  // XDataSequence
218  virtual css::uno::Sequence< css::uno::Any >
219  SAL_CALL getData() override;
220  virtual OUString SAL_CALL getSourceRangeRepresentation() override;
221  virtual css::uno::Sequence< OUString >
222  SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override;
223 
227  virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
228 
229  // XNumericalDataSequence
230  virtual css::uno::Sequence< double >
231  SAL_CALL getNumericalData() override;
232 
233  // XTextualDataSequence
234  virtual css::uno::Sequence< OUString >
235  SAL_CALL getTextualData() override;
236 
237  // XTimeBased
238  virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
239  virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
240 
241  virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
242 
243  // XPropertySet
244  virtual css::uno::Reference<
245  css::beans::XPropertySetInfo> SAL_CALL
246  getPropertySetInfo() override;
247 
248  virtual void SAL_CALL setPropertyValue(
249  const OUString& rPropertyName,
250  const css::uno::Any& rValue) override;
251 
252  virtual css::uno::Any SAL_CALL getPropertyValue(
253  const OUString& rPropertyName) override;
254 
255  virtual void SAL_CALL addPropertyChangeListener(
256  const OUString& rPropertyName,
257  const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
258 
259  virtual void SAL_CALL removePropertyChangeListener(
260  const OUString& rPropertyName,
261  const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
262 
263  virtual void SAL_CALL addVetoableChangeListener(
264  const OUString& rPropertyName,
265  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
266 
267  virtual void SAL_CALL removeVetoableChangeListener(
268  const OUString& rPropertyName,
269  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
270 
271  // XCloneable
272  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
273 
274  // XModifyBroadcaster
275  virtual void SAL_CALL addModifyListener(
276  const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
277  virtual void SAL_CALL removeModifyListener(
278  const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
279 
280  // XServiceInfo
281  virtual OUString SAL_CALL getImplementationName() override;
282 
283  virtual sal_Bool SAL_CALL supportsService( const OUString&
284  rServiceName) override;
285 
286  virtual css::uno::Sequence< OUString> SAL_CALL
287  getSupportedServiceNames() override;
288 
289 private:
290  void setDataChangedHint(bool b);
291 
292  // Implementation
293  void RefChanged();
294  DECL_LINK( ValueListenerHdl, const SfxHint&, void );
295 
296 private:
298  {
299  public:
301  virtual ~ExternalRefListener() override;
302  ExternalRefListener(const ExternalRefListener&) = delete;
304 
305  virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
306  void addFileId(sal_uInt16 nFileId);
307  const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
308 
309  private:
311  std::unordered_set<sal_uInt16> maFileIds;
313  };
314 
319  void BuildDataCache();
320 
321  void RebuildDataCache();
322 
323  sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
324 
325  void UpdateTokensFromRanges(const ScRangeList& rRanges);
326 
328 
330 
331  void CopyData(const ScChart2DataSequence& r);
332 
333 private:
334 
335  // data array
336  struct Item
337  {
338  double mfValue;
339  OUString maString;
340  bool mbIsValue;
342  Item();
343  };
344 
346  {
347  public:
349  virtual ~HiddenRangeListener() override;
350 
351  virtual void notify() override;
352 
353  private:
355  };
356 
358  std::vector<Item> m_aDataArray;
359 
365  css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
366 
367  css::uno::Sequence<sal_Int32> m_aHiddenValues;
368 
369  // properties
370  css::chart2::data::DataSequenceRole m_aRole;
372 
373  // internals
374  sal_Int64 m_nObjectId;
376  std::vector<ScTokenRef> m_aTokens;
377  std::optional<std::vector<sal_uInt32>>
379  std::unique_ptr<ExternalRefListener>
382 
383  std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
384 
385  std::unique_ptr<ScLinkListener> m_pValueListener;
387 
390 
395 
396 };
397 
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< sal_Int32 > m_aHiddenValues
Definition: chart2uno.hxx:367
std::unique_ptr< HiddenRangeListener > m_pHiddenListener
Definition: chart2uno.hxx:383
ExternalRefListener & operator=(const ExternalRefListener &)=delete
ExternalRefListener * GetExtRefListener()
Definition: chart2uno.cxx:2716
sal_Int32 nIndex
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
Definition: chart2uno.cxx:3000
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:148
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3277
ScDocument * m_pDocument
Definition: chart2uno.hxx:189
virtual ~ScChart2DataSource() override
Definition: chart2uno.cxx:2369
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2377
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3239
std::optional< std::vector< sal_uInt32 > > m_oRangeIndices
Definition: chart2uno.hxx:378
std::vector< ScTokenRef > m_aTokens
Definition: chart2uno.hxx:376
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override
Definition: chart2uno.cxx:2916
css::uno::Sequence< css::uno::Any > m_aMixedDataCache
Cached data for getData.
Definition: chart2uno.hxx:365
void StopListeningToAllExternalRefs()
Definition: chart2uno.cxx:2724
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:381
css::chart2::data::DataSequenceRole m_aRole
Definition: chart2uno.hxx:370
std::vector< css::uno::Reference< css::util::XModifyListener > > XModifyListenerArr_Impl
Definition: cellsuno.hxx:130
ScChart2DataSequence & operator=(const ScChart2DataSequence &)=delete
Sequence< PropertyValue > aArguments
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
ScChart2DataSequence(ScDocument *pDoc,::std::vector< ScTokenRef > &&rTokens, bool bIncludeHiddenCells)
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: chart2uno.cxx:3389
ScDocument * m_pDocument
Definition: chart2uno.hxx:375
virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override
Definition: chart2uno.cxx:3426
DocumentType eType
virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override
Definition: chart2uno.cxx:3458
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
ScDocument * m_pDocument
Definition: chart2uno.hxx:147
HiddenRangeListener(ScChart2DataSequence &rParent)
Definition: chart2uno.cxx:2405
ScChart2DataSource(ScDocument *pDoc)
Definition: chart2uno.cxx:2362
Base class for objects that need to listen to link updates.
const std::unordered_set< sal_uInt16 > & getAllFileIds() const
Definition: chart2uno.hxx:307
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3413
css::uno::Reference< css::chart2::data::XDataSource > mxCachedDataSource
Definition: chart2uno.hxx:150
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2770
ExternalRefListener(ScChart2DataSequence &rParent, ScDocument *pDoc)
Definition: chart2uno.cxx:2899
unsigned char sal_Bool
virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override
Definition: chart2uno.cxx:3465
void BuildDataCache()
Build an internal data array to cache the data ranges, and other information such as hidden values...
Definition: chart2uno.cxx:2501
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: chart2uno.cxx:3353
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
css::uno::Reference< css::chart2::data::XDataSource > mxCreatedDataSource
Definition: chart2uno.hxx:153
std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences
Definition: chart2uno.hxx:190
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
std::unique_ptr< ExternalRefListener > m_pExtRefListener
Definition: chart2uno.hxx:380
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:3186
std::unordered_set< sal_uInt16 > maFileIds
Definition: chart2uno.hxx:311
css::uno::Sequence< css::beans::PropertyValue > maCreateDataSourceArguments
Definition: chart2uno.hxx:152
void setDataChangedHint(bool b)
Definition: chart2uno.cxx:3421
void CopyData(const ScChart2DataSequence &r)
Definition: chart2uno.cxx:2737
std::vector< Item > m_aDataArray
This vector contains the cached data which was calculated with BuildDataCache().
Definition: chart2uno.hxx:358
DECL_LINK(ValueListenerHdl, const SfxHint &, void)
XModifyListenerArr_Impl m_aValueListeners
Definition: chart2uno.hxx:386
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3405
::boost::intrusive_ptr< formula::FormulaToken > ScTokenRef
Definition: types.hxx:29
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
Definition: chart2uno.cxx:3397
std::unique_ptr< ScLinkListener > m_pValueListener
Definition: chart2uno.hxx:385
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
Definition: chart2uno.cxx:2978
void UpdateTokensFromRanges(const ScRangeList &rRanges)
Definition: chart2uno.cxx:2694
virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override
Definition: chart2uno.cxx:2386
virtual OUString SAL_CALL getSourceRangeRepresentation() override
Definition: chart2uno.cxx:3031
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: chart2uno.cxx:3219
sal_Int32 FillCacheFromExternalRef(const ScTokenRef &pToken)
Definition: chart2uno.cxx:2610
css::uno::Sequence< css::beans::PropertyValue > maCachedArguments
Definition: chart2uno.hxx:151
virtual ~ScChart2DataSequence() override
Definition: chart2uno.cxx:2452
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
Definition: chart2uno.cxx:2941
void AddLabeledSequence(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xNew)
Definition: chart2uno.cxx:2392
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: chart2uno.cxx:3326
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: chart2uno.cxx:3318
sal_Int16 SCTAB
Definition: types.hxx:22
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override
Definition: chart2uno.cxx:3138