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 <unordered_set>
48 #include <vector>
49 
50 namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
51 
52 class ScDocument;
53 
54 // DataProvider
55 class SC_DLLPUBLIC ScChart2DataProvider final : public
56  ::cppu::WeakImplHelper<
57  css::chart2::data::XDataProvider,
58  css::chart2::data::XSheetDataProvider,
59  css::chart2::data::XRangeXMLConversion,
60  css::beans::XPropertySet,
61  css::lang::XServiceInfo>,
62  public SfxListener
63 {
64 public:
65 
66  explicit ScChart2DataProvider( ScDocument* pDoc );
67  virtual ~ScChart2DataProvider() override;
68  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
69 
70  // XDataProvider
71  virtual sal_Bool SAL_CALL createDataSourcePossible(
72  const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
73 
74  virtual css::uno::Reference<
75  css::chart2::data::XDataSource > SAL_CALL createDataSource(
76  const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
77 
78  virtual css::uno::Sequence<
79  css::beans::PropertyValue > SAL_CALL detectArguments(
80  const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
81 
82  virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
83  const OUString& aRangeRepresentation ) override;
84 
85  virtual css::uno::Reference<
86  css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
87  const OUString& aRangeRepresentation ) override;
88 
89  virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
90  createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation ) override;
91 
92  virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
93 
94  // XSheetDataProvider
95  virtual sal_Bool SAL_CALL createDataSequenceByFormulaTokensPossible(
96  const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
97 
98  virtual css::uno::Reference< css::chart2::data::XDataSequence >
99  SAL_CALL createDataSequenceByFormulaTokens(
100  const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
101 
102  // XRangeXMLConversion
103  virtual OUString SAL_CALL convertRangeToXML( const OUString& sRangeRepresentation ) override;
104 
105  virtual OUString SAL_CALL convertRangeFromXML( const OUString& sXMLRange ) override;
106 
107  // XPropertySet
108  virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL
109  getPropertySetInfo() override;
110 
111  virtual void SAL_CALL setPropertyValue(
112  const OUString& rPropertyName,
113  const css::uno::Any& rValue) override;
114 
115  virtual css::uno::Any SAL_CALL getPropertyValue(
116  const OUString& rPropertyName) override;
117 
118  virtual void SAL_CALL addPropertyChangeListener(
119  const OUString& rPropertyName,
120  const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
121 
122  virtual void SAL_CALL removePropertyChangeListener(
123  const OUString& rPropertyName,
124  const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
125 
126  virtual void SAL_CALL addVetoableChangeListener(
127  const OUString& rPropertyName,
128  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
129 
130  virtual void SAL_CALL removeVetoableChangeListener(
131  const OUString& rPropertyName,
132  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
133 
134  // XServiceInfo
135  virtual OUString SAL_CALL getImplementationName() override;
136 
137  virtual sal_Bool SAL_CALL supportsService( const OUString&
138  rServiceName) override;
139 
140  virtual css::uno::Sequence< OUString> SAL_CALL
141  getSupportedServiceNames() override;
142 
143 private:
144 
148 };
149 
150 // DataSource
151 class ScChart2DataSource final : public
152  ::cppu::WeakImplHelper<
153  css::chart2::data::XDataSource,
154  css::lang::XServiceInfo>,
155  public SfxListener
156 {
157 public:
158 
159  explicit ScChart2DataSource( ScDocument* pDoc);
160  virtual ~ScChart2DataSource() override;
161  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
162 
163  // XDataSource
164  virtual css::uno::Sequence< css::uno::Reference<
165  css::chart2::data::XLabeledDataSequence > > SAL_CALL
166  getDataSequences() override;
167 
168  // XServiceInfo
169  virtual OUString SAL_CALL getImplementationName() override;
170 
171  virtual sal_Bool SAL_CALL supportsService( const OUString&
172  rServiceName) override;
173 
174  virtual css::uno::Sequence< OUString> SAL_CALL
175  getSupportedServiceNames() override;
176 
177  // implementation
178 
179  void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
180 
181 private:
182 
184  std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
185 
186 };
187 
188 // DataSequence
189 class ScChart2DataSequence final : public
190  ::cppu::WeakImplHelper<
191  css::chart2::data::XDataSequence,
192  css::chart2::data::XTextualDataSequence,
193  css::chart2::data::XNumericalDataSequence,
194  css::chart2::XTimeBased,
195  css::util::XCloneable,
196  css::util::XModifyBroadcaster,
197  css::beans::XPropertySet,
198  css::lang::XServiceInfo>,
199  public SfxListener
200 {
201 public:
202  explicit ScChart2DataSequence( ScDocument* pDoc,
203  ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
204 
205  virtual ~ScChart2DataSequence() override;
208 
209  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
210 
211  // XDataSequence
212  virtual css::uno::Sequence< css::uno::Any >
213  SAL_CALL getData() override;
214  virtual OUString SAL_CALL getSourceRangeRepresentation() override;
215  virtual css::uno::Sequence< OUString >
216  SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override;
217 
221  virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
222 
223  // XNumericalDataSequence
224  virtual css::uno::Sequence< double >
225  SAL_CALL getNumericalData() override;
226 
227  // XTextualDataSequence
228  virtual css::uno::Sequence< OUString >
229  SAL_CALL getTextualData() override;
230 
231  // XTimeBased
232  virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
233  virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
234 
235  virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
236 
237  // XPropertySet
238  virtual css::uno::Reference<
239  css::beans::XPropertySetInfo> SAL_CALL
240  getPropertySetInfo() override;
241 
242  virtual void SAL_CALL setPropertyValue(
243  const OUString& rPropertyName,
244  const css::uno::Any& rValue) override;
245 
246  virtual css::uno::Any SAL_CALL getPropertyValue(
247  const OUString& rPropertyName) override;
248 
249  virtual void SAL_CALL addPropertyChangeListener(
250  const OUString& rPropertyName,
251  const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
252 
253  virtual void SAL_CALL removePropertyChangeListener(
254  const OUString& rPropertyName,
255  const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
256 
257  virtual void SAL_CALL addVetoableChangeListener(
258  const OUString& rPropertyName,
259  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
260 
261  virtual void SAL_CALL removeVetoableChangeListener(
262  const OUString& rPropertyName,
263  const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
264 
265  // XCloneable
266  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
267 
268  // XModifyBroadcaster
269  virtual void SAL_CALL addModifyListener(
270  const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
271  virtual void SAL_CALL removeModifyListener(
272  const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
273 
274  // XServiceInfo
275  virtual OUString SAL_CALL getImplementationName() override;
276 
277  virtual sal_Bool SAL_CALL supportsService( const OUString&
278  rServiceName) override;
279 
280  virtual css::uno::Sequence< OUString> SAL_CALL
281  getSupportedServiceNames() override;
282 
283 private:
284  void setDataChangedHint(bool b);
285 
286  // Implementation
287  void RefChanged();
288  DECL_LINK( ValueListenerHdl, const SfxHint&, void );
289 
290 private:
292  {
293  public:
295  virtual ~ExternalRefListener() override;
296  ExternalRefListener(const ExternalRefListener&) = delete;
298 
299  virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
300  void addFileId(sal_uInt16 nFileId);
301  const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
302 
303  private:
305  std::unordered_set<sal_uInt16> maFileIds;
307  };
308 
313  void BuildDataCache();
314 
315  void RebuildDataCache();
316 
317  sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
318 
319  void UpdateTokensFromRanges(const ScRangeList& rRanges);
320 
322 
324 
325  void CopyData(const ScChart2DataSequence& r);
326 
327 private:
328 
329  // data array
330  struct Item
331  {
332  double mfValue;
333  OUString maString;
334  bool mbIsValue;
336  Item();
337  };
338 
340  {
341  public:
343  virtual ~HiddenRangeListener() override;
344 
345  virtual void notify() override;
346 
347  private:
349  };
350 
352  std::vector<Item> m_aDataArray;
353 
359  css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
360 
361  css::uno::Sequence<sal_Int32> m_aHiddenValues;
362 
363  // properties
364  css::chart2::data::DataSequenceRole m_aRole;
366 
367  // internals
368  typedef std::unique_ptr<std::vector<sal_uInt32> > RangeIndexMapPtr;
369 
370  sal_Int64 m_nObjectId;
372  std::vector<ScTokenRef> m_aTokens;
373  RangeIndexMapPtr m_pRangeIndices;
374  std::unique_ptr<ExternalRefListener>
377 
378  std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
379 
380  std::unique_ptr<ScLinkListener> m_pValueListener;
382 
385 
390 
391 };
392 
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< sal_Int32 > m_aHiddenValues
Definition: chart2uno.hxx:361
std::unique_ptr< HiddenRangeListener > m_pHiddenListener
Definition: chart2uno.hxx:378
ExternalRefListener & operator=(const ExternalRefListener &)=delete
ExternalRefListener * GetExtRefListener()
Definition: chart2uno.cxx:2643
sal_Int32 nIndex
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
Definition: chart2uno.cxx:2924
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:146
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3201
ScDocument * m_pDocument
Definition: chart2uno.hxx:183
virtual ~ScChart2DataSource() override
Definition: chart2uno.cxx:2296
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2304
RangeIndexMapPtr m_pRangeIndices
Definition: chart2uno.hxx:373
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: chart2uno.cxx:3163
std::vector< ScTokenRef > m_aTokens
Definition: chart2uno.hxx:372
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:368
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:359
void StopListeningToAllExternalRefs()
Definition: chart2uno.cxx:2651
SfxItemPropertySet m_aPropSet
Definition: chart2uno.hxx:376
css::uno::Any const & rValue
css::chart2::data::DataSequenceRole m_aRole
Definition: chart2uno.hxx:364
std::vector< css::uno::Reference< css::util::XModifyListener > > XModifyListenerArr_Impl
Definition: cellsuno.hxx:129
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:3313
ScDocument * m_pDocument
Definition: chart2uno.hxx:371
virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override
Definition: chart2uno.cxx:3350
DocumentType eType
virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override
Definition: chart2uno.cxx:3382
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
ScDocument * m_pDocument
Definition: chart2uno.hxx:145
HiddenRangeListener(ScChart2DataSequence &rParent)
Definition: chart2uno.cxx:2332
ScChart2DataSource(ScDocument *pDoc)
Definition: chart2uno.cxx:2289
Base class for objects that need to listen to link updates.
const std::unordered_set< sal_uInt16 > & getAllFileIds() const
Definition: chart2uno.hxx:301
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3337
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: chart2uno.cxx:2697
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:3389
void BuildDataCache()
Build an internal data array to cache the data ranges, and other information such as hidden values...
Definition: chart2uno.cxx:2428
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
Definition: chart2uno.cxx:3277
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:184
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:375
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:3110
std::unordered_set< sal_uInt16 > maFileIds
Definition: chart2uno.hxx:305
void setDataChangedHint(bool b)
Definition: chart2uno.cxx:3345
void CopyData(const ScChart2DataSequence &r)
Definition: chart2uno.cxx:2664
std::vector< Item > m_aDataArray
This vector contains the cached data which was calculated with BuildDataCache().
Definition: chart2uno.hxx:352
DECL_LINK(ValueListenerHdl, const SfxHint &, void)
XModifyListenerArr_Impl m_aValueListeners
Definition: chart2uno.hxx:381
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
Definition: chart2uno.cxx:3329
::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:3321
std::unique_ptr< ScLinkListener > m_pValueListener
Definition: chart2uno.hxx:380
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
Definition: chart2uno.cxx:2902
void UpdateTokensFromRanges(const ScRangeList &rRanges)
Definition: chart2uno.cxx:2621
virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() override
Definition: chart2uno.cxx:2313
virtual OUString SAL_CALL getSourceRangeRepresentation() override
Definition: chart2uno.cxx:2955
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: chart2uno.cxx:3143
sal_Int32 FillCacheFromExternalRef(const ScTokenRef &pToken)
Definition: chart2uno.cxx:2537
virtual ~ScChart2DataSequence() override
Definition: chart2uno.cxx:2379
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:2319
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
Definition: chart2uno.cxx:3250
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: chart2uno.cxx:3242
sal_Int16 SCTAB
Definition: types.hxx:22
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override
Definition: chart2uno.cxx:3062