1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_CHART2UNO_HXX
21 #define INCLUDED_SC_INC_CHART2UNO_HXX
23 #include "cellsuno.hxx"
24 #include "rangelst.hxx"
25 #include "externalrefmgr.hxx"
27 #include "chartlis.hxx"
29 #include <svl/lstner.hxx>
30 #include <com/sun/star/chart/ChartDataRowSource.hpp>
31 #include <com/sun/star/chart2/data/XDataProvider.hpp>
32 #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
33 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
34 #include <com/sun/star/chart2/data/XDataSource.hpp>
35 #include <com/sun/star/chart2/data/XDataSequence.hpp>
36 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
37 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
38 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
39 #include <com/sun/star/chart2/data/DataSequenceRole.hpp>
40 #include <com/sun/star/chart2/XTimeBased.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/util/XCloneable.hpp>
44 #include <com/sun/star/util/XModifyBroadcaster.hpp>
45 #include <cppuhelper/implbase.hxx>
46 #include <rtl/ustring.hxx>
47 #include <svl/itemprop.hxx>
51 #include <unordered_set>
57 class ScChart2DataProvider
: public
58 ::cppu::WeakImplHelper
<
59 css::chart2::data::XDataProvider
,
60 css::chart2::data::XSheetDataProvider
,
61 css::chart2::data::XRangeXMLConversion
,
62 css::beans::XPropertySet
,
63 css::lang::XServiceInfo
>,
68 explicit ScChart2DataProvider( ScDocument
* pDoc
);
69 virtual ~ScChart2DataProvider() override
;
70 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
73 virtual sal_Bool SAL_CALL
createDataSourcePossible(
74 const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
)
75 throw (css::uno::RuntimeException
, std::exception
) override
;
77 virtual css::uno::Reference
<
78 css::chart2::data::XDataSource
> SAL_CALL
createDataSource(
79 const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
)
80 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
82 virtual css::uno::Sequence
<
83 css::beans::PropertyValue
> SAL_CALL
detectArguments(
84 const css::uno::Reference
< css::chart2::data::XDataSource
>& xDataSource
)
85 throw (css::uno::RuntimeException
, std::exception
) override
;
87 virtual sal_Bool SAL_CALL
createDataSequenceByRangeRepresentationPossible(
88 const OUString
& aRangeRepresentation
)
89 throw (css::uno::RuntimeException
, std::exception
) override
;
91 virtual css::uno::Reference
<
92 css::chart2::data::XDataSequence
> SAL_CALL
createDataSequenceByRangeRepresentation(
93 const OUString
& aRangeRepresentation
)
94 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
96 virtual css::uno::Reference
<css::chart2::data::XDataSequence
> SAL_CALL
97 createDataSequenceByValueArray( const OUString
& aRole
, const OUString
& aRangeRepresentation
)
98 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
100 virtual css::uno::Reference
< css::sheet::XRangeSelection
> SAL_CALL
getRangeSelection()
101 throw (css::uno::RuntimeException
, std::exception
) override
;
103 // XSheetDataProvider
104 virtual sal_Bool SAL_CALL
createDataSequenceByFormulaTokensPossible(
105 const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
)
106 throw (css::uno::RuntimeException
, std::exception
) override
;
108 virtual css::uno::Reference
< css::chart2::data::XDataSequence
>
109 SAL_CALL
createDataSequenceByFormulaTokens(
110 const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
)
111 throw (css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
) override
;
113 // XRangeXMLConversion
114 virtual OUString SAL_CALL
convertRangeToXML( const OUString
& sRangeRepresentation
)
115 throw ( css::uno::RuntimeException
, css::lang::IllegalArgumentException
, std::exception
) override
;
117 virtual OUString SAL_CALL
convertRangeFromXML( const OUString
& sXMLRange
)
118 throw ( css::uno::RuntimeException
, css::lang::IllegalArgumentException
, std::exception
) override
;
121 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
122 getPropertySetInfo() throw( css::uno::RuntimeException
, std::exception
) override
;
124 virtual void SAL_CALL
setPropertyValue(
125 const OUString
& rPropertyName
,
126 const css::uno::Any
& rValue
)
127 throw( css::beans::UnknownPropertyException
,
128 css::beans::PropertyVetoException
,
129 css::lang::IllegalArgumentException
,
130 css::lang::WrappedTargetException
,
131 css::uno::RuntimeException
, std::exception
) override
;
133 virtual css::uno::Any SAL_CALL
getPropertyValue(
134 const OUString
& rPropertyName
)
135 throw( css::beans::UnknownPropertyException
,
136 css::lang::WrappedTargetException
,
137 css::uno::RuntimeException
, std::exception
) override
;
139 virtual void SAL_CALL
addPropertyChangeListener(
140 const OUString
& rPropertyName
,
141 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
)
142 throw( css::beans::UnknownPropertyException
,
143 css::lang::WrappedTargetException
,
144 css::uno::RuntimeException
, std::exception
) override
;
146 virtual void SAL_CALL
removePropertyChangeListener(
147 const OUString
& rPropertyName
,
148 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& rListener
)
149 throw( css::beans::UnknownPropertyException
,
150 css::lang::WrappedTargetException
,
151 css::uno::RuntimeException
, std::exception
) override
;
153 virtual void SAL_CALL
addVetoableChangeListener(
154 const OUString
& rPropertyName
,
155 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
)
156 throw( css::beans::UnknownPropertyException
,
157 css::lang::WrappedTargetException
,
158 css::uno::RuntimeException
, std::exception
) override
;
160 virtual void SAL_CALL
removeVetoableChangeListener(
161 const OUString
& rPropertyName
,
162 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
)
163 throw( css::beans::UnknownPropertyException
,
164 css::lang::WrappedTargetException
,
165 css::uno::RuntimeException
, std::exception
) override
;
168 virtual OUString SAL_CALL
getImplementationName() throw(
169 css::uno::RuntimeException
, std::exception
) override
;
171 virtual sal_Bool SAL_CALL
supportsService( const OUString
&
172 rServiceName
) throw( css::uno::RuntimeException
, std::exception
) override
;
174 virtual css::uno::Sequence
< OUString
> SAL_CALL
175 getSupportedServiceNames() throw(
176 css::uno::RuntimeException
, std::exception
) override
;
180 ScDocument
* m_pDocument
;
181 SfxItemPropertySet m_aPropSet
;
182 bool m_bIncludeHiddenCells
;
186 class ScChart2DataSource
: public
187 ::cppu::WeakImplHelper
<
188 css::chart2::data::XDataSource
,
189 css::lang::XServiceInfo
>,
194 explicit ScChart2DataSource( ScDocument
* pDoc
);
195 virtual ~ScChart2DataSource() override
;
196 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
199 virtual css::uno::Sequence
< css::uno::Reference
<
200 css::chart2::data::XLabeledDataSequence
> > SAL_CALL
201 getDataSequences() throw (css::uno::RuntimeException
, std::exception
) override
;
204 virtual OUString SAL_CALL
getImplementationName() throw(
205 css::uno::RuntimeException
, std::exception
) override
;
207 virtual sal_Bool SAL_CALL
supportsService( const OUString
&
208 rServiceName
) throw( css::uno::RuntimeException
, std::exception
) override
;
210 virtual css::uno::Sequence
< OUString
> SAL_CALL
211 getSupportedServiceNames() throw(
212 css::uno::RuntimeException
, std::exception
) override
;
216 void AddLabeledSequence(const css::uno::Reference
< css::chart2::data::XLabeledDataSequence
>& xNew
);
220 ScDocument
* m_pDocument
;
221 typedef std::list
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > LabeledList
;
222 LabeledList m_aLabeledSequences
;
227 class ScChart2DataSequence
: public
228 ::cppu::WeakImplHelper
<
229 css::chart2::data::XDataSequence
,
230 css::chart2::data::XTextualDataSequence
,
231 css::chart2::data::XNumericalDataSequence
,
232 css::chart2::XTimeBased
,
233 css::util::XCloneable
,
234 css::util::XModifyBroadcaster
,
235 css::beans::XPropertySet
,
236 css::lang::XServiceInfo
>,
240 explicit ScChart2DataSequence( ScDocument
* pDoc
,
241 const css::uno::Reference
< css::chart2::data::XDataProvider
>& xDP
,
242 ::std::vector
<ScTokenRef
>&& rTokens
, bool bIncludeHiddenCells
);
244 virtual ~ScChart2DataSequence() override
;
245 ScChart2DataSequence(const ScChart2DataSequence
&) = delete;
246 ScChart2DataSequence
& operator=(const ScChart2DataSequence
&) = delete;
248 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
251 virtual css::uno::Sequence
< css::uno::Any
>
253 throw (css::uno::RuntimeException
,
254 std::exception
) override
;
255 virtual OUString SAL_CALL
getSourceRangeRepresentation()
256 throw (css::uno::RuntimeException
, std::exception
) override
;
257 virtual css::uno::Sequence
< OUString
>
258 SAL_CALL
generateLabel(css::chart2::data::LabelOrigin nOrigin
)
259 throw (css::uno::RuntimeException
, std::exception
) override
;
261 /** Get the number format key for the n-th data entry
262 * If nIndex == -1, then you will get the number format key for the first non-empty entry
264 virtual ::sal_Int32 SAL_CALL
getNumberFormatKeyByIndex( ::sal_Int32 nIndex
)
265 throw (css::lang::IndexOutOfBoundsException
,
266 css::uno::RuntimeException
,
267 std::exception
) override
;
269 // XNumericalDataSequence
270 virtual css::uno::Sequence
< double >
271 SAL_CALL
getNumericalData()
272 throw (css::uno::RuntimeException
,
273 std::exception
) override
;
275 // XTextualDataSequence
276 virtual css::uno::Sequence
< OUString
>
277 SAL_CALL
getTextualData()
278 throw (css::uno::RuntimeException
,
279 std::exception
) override
;
282 virtual sal_Bool SAL_CALL
switchToNext(sal_Bool bWrap
) throw (css::uno::RuntimeException
, std::exception
) override
;
283 virtual sal_Bool SAL_CALL
setToPointInTime(sal_Int32 nPoint
) throw (css::uno::RuntimeException
, std::exception
) override
;
285 virtual void SAL_CALL
setRange(sal_Int32 nStart
, sal_Int32 nEnd
) throw (css::uno::RuntimeException
, std::exception
) override
;
288 virtual css::uno::Reference
<
289 css::beans::XPropertySetInfo
> SAL_CALL
290 getPropertySetInfo() throw( css::uno::RuntimeException
, std::exception
) override
;
292 virtual void SAL_CALL
setPropertyValue(
293 const OUString
& rPropertyName
,
294 const css::uno::Any
& rValue
)
295 throw( css::beans::UnknownPropertyException
,
296 css::beans::PropertyVetoException
,
297 css::lang::IllegalArgumentException
,
298 css::lang::WrappedTargetException
,
299 css::uno::RuntimeException
, std::exception
) override
;
301 virtual css::uno::Any SAL_CALL
getPropertyValue(
302 const OUString
& rPropertyName
)
303 throw(css::beans::UnknownPropertyException
,
304 css::lang::WrappedTargetException
,
305 css::uno::RuntimeException
,
306 std::exception
) override
;
308 virtual void SAL_CALL
addPropertyChangeListener(
309 const OUString
& rPropertyName
,
310 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
)
311 throw( css::beans::UnknownPropertyException
,
312 css::lang::WrappedTargetException
,
313 css::uno::RuntimeException
, std::exception
) override
;
315 virtual void SAL_CALL
removePropertyChangeListener(
316 const OUString
& rPropertyName
,
317 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& rListener
)
318 throw( css::beans::UnknownPropertyException
,
319 css::lang::WrappedTargetException
,
320 css::uno::RuntimeException
, std::exception
) override
;
322 virtual void SAL_CALL
addVetoableChangeListener(
323 const OUString
& rPropertyName
,
324 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
)
325 throw( css::beans::UnknownPropertyException
,
326 css::lang::WrappedTargetException
,
327 css::uno::RuntimeException
, std::exception
) override
;
329 virtual void SAL_CALL
removeVetoableChangeListener(
330 const OUString
& rPropertyName
,
331 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
)
332 throw( css::beans::UnknownPropertyException
,
333 css::lang::WrappedTargetException
,
334 css::uno::RuntimeException
, std::exception
) override
;
337 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone()
338 throw (css::uno::RuntimeException
, std::exception
) override
;
340 // XModifyBroadcaster
341 virtual void SAL_CALL
addModifyListener(
342 const css::uno::Reference
< css::util::XModifyListener
>& aListener
)
343 throw (css::uno::RuntimeException
,
344 std::exception
) override
;
345 virtual void SAL_CALL
removeModifyListener(
346 const css::uno::Reference
< css::util::XModifyListener
>& aListener
)
347 throw (css::uno::RuntimeException
, std::exception
) override
;
350 virtual OUString SAL_CALL
getImplementationName() throw(
351 css::uno::RuntimeException
, std::exception
) override
;
353 virtual sal_Bool SAL_CALL
supportsService( const OUString
&
354 rServiceName
) throw( css::uno::RuntimeException
, std::exception
) override
;
356 virtual css::uno::Sequence
< OUString
> SAL_CALL
357 getSupportedServiceNames() throw(
358 css::uno::RuntimeException
, std::exception
) override
;
361 void setDataChangedHint(bool b
);
365 DECL_LINK( ValueListenerHdl
, const SfxHint
&, void );
368 class ExternalRefListener
: public ScExternalRefManager::LinkListener
371 ExternalRefListener(ScChart2DataSequence
& rParent
, ScDocument
* pDoc
);
372 virtual ~ExternalRefListener() override
;
373 ExternalRefListener(const ExternalRefListener
&) = delete;
374 ExternalRefListener
& operator=(const ExternalRefListener
&) = delete;
376 virtual void notify(sal_uInt16 nFileId
, ScExternalRefManager::LinkUpdateType eType
) override
;
377 void addFileId(sal_uInt16 nFileId
);
378 const std::unordered_set
<sal_uInt16
>& getAllFileIds() { return maFileIds
;}
381 ScChart2DataSequence
& mrParent
;
382 std::unordered_set
<sal_uInt16
> maFileIds
;
387 * Build an internal data array to cache the data ranges, and other
388 * information such as hidden values.
390 void BuildDataCache();
392 void RebuildDataCache();
394 sal_Int32
FillCacheFromExternalRef(const ScTokenRef
& pToken
);
396 void UpdateTokensFromRanges(const ScRangeList
& rRanges
);
398 ExternalRefListener
* GetExtRefListener();
400 void StopListeningToAllExternalRefs();
402 void CopyData(const ScChart2DataSequence
& r
);
416 class HiddenRangeListener
: public ScChartHiddenRangeListener
419 HiddenRangeListener(ScChart2DataSequence
& rParent
);
420 virtual ~HiddenRangeListener() override
;
422 virtual void notify() override
;
425 ScChart2DataSequence
& mrParent
;
428 /** This vector contains the cached data which was calculated with BuildDataCache(). */
429 std::vector
<Item
> m_aDataArray
;
432 * Cached data for getData. We may also need to cache data for the
433 * numerical and textural data series if they turn out to be bottlenecks
434 * under certain scenarios.
436 css::uno::Sequence
< css::uno::Any
> m_aMixedDataCache
;
438 css::uno::Sequence
<sal_Int32
> m_aHiddenValues
;
441 css::chart2::data::DataSequenceRole m_aRole
;
442 bool m_bIncludeHiddenCells
;
445 typedef std::unique_ptr
<std::vector
<sal_uInt32
> > RangeIndexMapPtr
;
446 typedef std::unique_ptr
<ExternalRefListener
> ExtRefListenerPtr
;
448 sal_Int64 m_nObjectId
;
449 ScDocument
* m_pDocument
;
450 std::vector
<ScTokenRef
> m_aTokens
;
451 RangeIndexMapPtr m_pRangeIndices
;
452 ExtRefListenerPtr m_pExtRefListener
;
453 css::uno::Reference
< css::chart2::data::XDataProvider
> m_xDataProvider
;
454 SfxItemPropertySet m_aPropSet
;
456 std::unique_ptr
<HiddenRangeListener
> m_pHiddenListener
;
458 ScLinkListener
* m_pValueListener
;
459 XModifyListenerArr_Impl m_aValueListeners
;
461 bool m_bGotDataChangedHint
;
462 bool m_bExtDataRebuildQueued
;
465 SCTAB mnTimeBasedStart
;
466 SCTAB mnTimeBasedEnd
;
471 #endif // INCLUDED_SC_INC_CHART2UNO_HXX
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */