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 #ifndef INCLUDED_SC_INC_CHART2UNO_HXX
21 #define INCLUDED_SC_INC_CHART2UNO_HXX
22 
23 #include "cellsuno.hxx"
24 #include "rangelst.hxx"
25 #include "externalrefmgr.hxx"
26 #include "types.hxx"
27 #include "chartlis.hxx"
28 
29 #include <svl/lstner.hxx>
30 #include <com/sun/star/chart2/data/XDataProvider.hpp>
31 #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
32 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
33 #include <com/sun/star/chart2/data/XDataSource.hpp>
34 #include <com/sun/star/chart2/data/XDataSequence.hpp>
35 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
36 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
37 #include <com/sun/star/chart2/data/DataSequenceRole.hpp>
38 #include <com/sun/star/chart2/XTimeBased.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/util/XCloneable.hpp>
42 #include <com/sun/star/util/XModifyBroadcaster.hpp>
43 #include <cppuhelper/implbase.hxx>
44 #include <rtl/ustring.hxx>
45 #include <svl/itemprop.hxx>
46 
47 #include <memory>
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 ) override;
92 
93  virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
94 
95  // XSheetDataProvider
96  virtual sal_Bool SAL_CALL createDataSequenceByFormulaTokensPossible(
97  const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
98 
99  virtual css::uno::Reference< css::chart2::data::XDataSequence >
100  SAL_CALL createDataSequenceByFormulaTokens(
101  const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
102 
103  // XRangeXMLConversion
104  virtual OUString SAL_CALL convertRangeToXML( const OUString& sRangeRepresentation ) override;
105 
106  virtual OUString SAL_CALL convertRangeFromXML( const OUString& sXMLRange ) override;
107 
108  // XPropertySet
109  virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL
110  getPropertySetInfo() override;
111 
112  virtual void SAL_CALL setPropertyValue(
113  const OUString& rPropertyName,
114  const css::uno::Any& rValue) override;
115 
116  virtual css::uno::Any SAL_CALL getPropertyValue(
117  const OUString& rPropertyName) override;
118 
119  virtual void SAL_CALL addPropertyChangeListener(
120  const OUString& rPropertyName,
121  const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
122 
123  virtual void SAL_CALL removePropertyChangeListener(
124  const OUString& rPropertyName,
125  const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
126 
127  virtual void SAL_CALL addVetoableChangeListener(
128  const OUString& rPropertyName,
129  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
130 
131  virtual void SAL_CALL removeVetoableChangeListener(
132  const OUString& rPropertyName,
133  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
134 
135  // XServiceInfo
136  virtual OUString SAL_CALL getImplementationName() override;
137 
138  virtual sal_Bool SAL_CALL supportsService( const OUString&
139  rServiceName) override;
140 
141  virtual css::uno::Sequence< OUString> SAL_CALL
142  getSupportedServiceNames() override;
143 
144 private:
145 
149 };
150 
151 // DataSource
152 class ScChart2DataSource final : public
153  ::cppu::WeakImplHelper<
154  css::chart2::data::XDataSource,
155  css::lang::XServiceInfo>,
156  public SfxListener
157 {
158 public:
159 
160  explicit ScChart2DataSource( ScDocument* pDoc);
161  virtual ~ScChart2DataSource() override;
162  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
163 
164  // XDataSource
165  virtual css::uno::Sequence< css::uno::Reference<
166  css::chart2::data::XLabeledDataSequence > > SAL_CALL
167  getDataSequences() override;
168 
169  // XServiceInfo
170  virtual OUString SAL_CALL getImplementationName() override;
171 
172  virtual sal_Bool SAL_CALL supportsService( const OUString&
173  rServiceName) override;
174 
175  virtual css::uno::Sequence< OUString> SAL_CALL
176  getSupportedServiceNames() override;
177 
178  // implementation
179 
180  void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
181 
182 private:
183 
185  std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
186 
187 };
188 
189 // DataSequence
190 class ScChart2DataSequence final : public
191  ::cppu::WeakImplHelper<
192  css::chart2::data::XDataSequence,
193  css::chart2::data::XTextualDataSequence,
194  css::chart2::data::XNumericalDataSequence,
195  css::chart2::XTimeBased,
196  css::util::XCloneable,
197  css::util::XModifyBroadcaster,
198  css::beans::XPropertySet,
199  css::lang::XServiceInfo>,
200  public SfxListener
201 {
202 public:
203  explicit ScChart2DataSequence( ScDocument* pDoc,
204  ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
205 
206  virtual ~ScChart2DataSequence() override;
209 
210  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
211 
212  // XDataSequence
213  virtual css::uno::Sequence< css::uno::Any >
214  SAL_CALL getData() override;
215  virtual OUString SAL_CALL getSourceRangeRepresentation() override;
216  virtual css::uno::Sequence< OUString >
217  SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override;
218 
222  virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
223 
224  // XNumericalDataSequence
225  virtual css::uno::Sequence< double >
226  SAL_CALL getNumericalData() override;
227 
228  // XTextualDataSequence
229  virtual css::uno::Sequence< OUString >
230  SAL_CALL getTextualData() override;
231 
232  // XTimeBased
233  virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
234  virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
235 
236  virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
237 
238  // XPropertySet
239  virtual css::uno::Reference<
240  css::beans::XPropertySetInfo> SAL_CALL
241  getPropertySetInfo() override;
242 
243  virtual void SAL_CALL setPropertyValue(
244  const OUString& rPropertyName,
245  const css::uno::Any& rValue) override;
246 
247  virtual css::uno::Any SAL_CALL getPropertyValue(
248  const OUString& rPropertyName) override;
249 
250  virtual void SAL_CALL addPropertyChangeListener(
251  const OUString& rPropertyName,
252  const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
253 
254  virtual void SAL_CALL removePropertyChangeListener(
255  const OUString& rPropertyName,
256  const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
257 
258  virtual void SAL_CALL addVetoableChangeListener(
259  const OUString& rPropertyName,
260  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
261 
262  virtual void SAL_CALL removeVetoableChangeListener(
263  const OUString& rPropertyName,
264  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
265 
266  // XCloneable
267  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
268 
269  // XModifyBroadcaster
270  virtual void SAL_CALL addModifyListener(
271  const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
272  virtual void SAL_CALL removeModifyListener(
273  const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
274 
275  // XServiceInfo
276  virtual OUString SAL_CALL getImplementationName() override;
277 
278  virtual sal_Bool SAL_CALL supportsService( const OUString&
279  rServiceName) override;
280 
281  virtual css::uno::Sequence< OUString> SAL_CALL
282  getSupportedServiceNames() override;
283 
284 private:
285  void setDataChangedHint(bool b);
286 
287  // Implementation
288  void RefChanged();
289  DECL_LINK( ValueListenerHdl, const SfxHint&, void );
290 
291 private:
293  {
294  public:
296  virtual ~ExternalRefListener() override;
297  ExternalRefListener(const ExternalRefListener&) = delete;
299 
300  virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
301  void addFileId(sal_uInt16 nFileId);
302  const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
303 
304  private:
306  std::unordered_set<sal_uInt16> maFileIds;
308  };
309 
314  void BuildDataCache();
315 
316  void RebuildDataCache();
317 
318  sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
319 
320  void UpdateTokensFromRanges(const ScRangeList& rRanges);
321 
323 
325 
326  void CopyData(const ScChart2DataSequence& r);
327 
328 private:
329 
330  // data array
331  struct Item
332  {
333  double mfValue;
334  OUString maString;
335  bool mbIsValue;
337  Item();
338  };
339 
341  {
342  public:
344  virtual ~HiddenRangeListener() override;
345 
346  virtual void notify() override;
347 
348  private:
350  };
351 
353  std::vector<Item> m_aDataArray;
354 
360  css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
361 
362  css::uno::Sequence<sal_Int32> m_aHiddenValues;
363 
364  // properties
365  css::chart2::data::DataSequenceRole m_aRole;
367 
368  // internals
369  typedef std::unique_ptr<std::vector<sal_uInt32> > RangeIndexMapPtr;
370  typedef std::unique_ptr<ExternalRefListener> ExtRefListenerPtr;
371 
372  sal_Int64 m_nObjectId;
374  std::vector<ScTokenRef> m_aTokens;
375  RangeIndexMapPtr m_pRangeIndices;
376  ExtRefListenerPtr m_pExtRefListener;
378 
379  std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
380 
381  std::unique_ptr<ScLinkListener> m_pValueListener;
383 
386 
391 
392 };
393 
394 #endif // INCLUDED_SC_INC_CHART2UNO_HXX
395 
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< sal_Int32 > m_aHiddenValues
Definition: chart2uno.hxx:362
std::unique_ptr< ExternalRefListener > ExtRefListenerPtr
Definition: chart2uno.hxx:370
std::unique_ptr< HiddenRangeListener > m_pHiddenListener
Definition: chart2uno.hxx:379
ExtRefListenerPtr m_pExtRefListener
Definition: chart2uno.hxx:376
ExternalRefListener & operator=(const ExternalRefListener &)=delete
ExternalRefListener * GetExtRefListener()
Definition: chart2uno.cxx:2641
sal_Int32 nIndex
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
Definition: chart2uno.cxx:2927
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:147
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3207
ScDocument * m_pDocument
Definition: chart2uno.hxx:184
virtual ~ScChart2DataSource() override
Definition: chart2uno.cxx:2294
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2302
RangeIndexMapPtr m_pRangeIndices
Definition: chart2uno.hxx:375
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3169
std::vector< ScTokenRef > m_aTokens
Definition: chart2uno.hxx:374
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
std::unique_ptr< std::vector< sal_uInt32 > > RangeIndexMapPtr
Definition: chart2uno.hxx:369
virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override
Definition: chart2uno.cxx:2843
css::uno::Sequence< css::uno::Any > m_aMixedDataCache
Cached data for getData.
Definition: chart2uno.hxx:360
void StopListeningToAllExternalRefs()
Definition: chart2uno.cxx:2649
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:377
css::uno::Any const & rValue
css::chart2::data::DataSequenceRole m_aRole
Definition: chart2uno.hxx:365
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:3319
ScDocument * m_pDocument
Definition: chart2uno.hxx:373
virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override
Definition: chart2uno.cxx:3356
DocumentType eType
virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override
Definition: chart2uno.cxx:3388
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
ScDocument * m_pDocument
Definition: chart2uno.hxx:146
HiddenRangeListener(ScChart2DataSequence &rParent)
Definition: chart2uno.cxx:2330
ScChart2DataSource(ScDocument *pDoc)
Definition: chart2uno.cxx:2287
Base class for objects that need to listen to link updates.
const std::unordered_set< sal_uInt16 > & getAllFileIds() const
Definition: chart2uno.hxx:302
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3343
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2695
ExternalRefListener(ScChart2DataSequence &rParent, ScDocument *pDoc)
Definition: chart2uno.cxx:2825
unsigned char sal_Bool
virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override
Definition: chart2uno.cxx:3395
void BuildDataCache()
Build an internal data array to cache the data ranges, and other information such as hidden values...
Definition: chart2uno.cxx:2426
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: chart2uno.cxx:3283
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
std::vector< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences
Definition: chart2uno.hxx:185
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
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:3114
std::unordered_set< sal_uInt16 > maFileIds
Definition: chart2uno.hxx:306
void setDataChangedHint(bool b)
Definition: chart2uno.cxx:3351
void CopyData(const ScChart2DataSequence &r)
Definition: chart2uno.cxx:2662
std::vector< Item > m_aDataArray
This vector contains the cached data which was calculated with BuildDataCache().
Definition: chart2uno.hxx:353
DECL_LINK(ValueListenerHdl, const SfxHint &, void)
XModifyListenerArr_Impl m_aValueListeners
Definition: chart2uno.hxx:382
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3335
::boost::intrusive_ptr< formula::FormulaToken > ScTokenRef
Definition: types.hxx:30
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
Definition: chart2uno.cxx:3327
std::unique_ptr< ScLinkListener > m_pValueListener
Definition: chart2uno.hxx:381
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
Definition: chart2uno.cxx:2902
void UpdateTokensFromRanges(const ScRangeList &rRanges)
Definition: chart2uno.cxx:2619
virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override
Definition: chart2uno.cxx:2311
virtual OUString SAL_CALL getSourceRangeRepresentation() override
Definition: chart2uno.cxx:2959
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: chart2uno.cxx:3147
sal_Int32 FillCacheFromExternalRef(const ScTokenRef &pToken)
Definition: chart2uno.cxx:2535
virtual ~ScChart2DataSequence() override
Definition: chart2uno.cxx:2377
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
Definition: chart2uno.cxx:2865
void AddLabeledSequence(const css::uno::Reference< css::chart2::data::XLabeledDataSequence > &xNew)
Definition: chart2uno.cxx:2317
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: chart2uno.cxx:3256
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: chart2uno.cxx:3248
sal_Int16 SCTAB
Definition: types.hxx:23
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override
Definition: chart2uno.cxx:3066