LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sc / inc / chart2uno.hxx
bloba5e4f53b032fa166e6fe104451403a154f33a7e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include "cellsuno.hxx"
23 #include "rangelst.hxx"
24 #include "externalrefmgr.hxx"
25 #include "types.hxx"
26 #include "chartlis.hxx"
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>
46 #include <memory>
47 #include <optional>
48 #include <unordered_set>
49 #include <vector>
51 namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
53 class ScDocument;
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
65 public:
67 explicit ScChart2DataProvider( ScDocument* pDoc );
68 virtual ~ScChart2DataProvider() override;
69 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
71 // XDataProvider
72 virtual sal_Bool SAL_CALL createDataSourcePossible(
73 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
75 virtual css::uno::Reference<
76 css::chart2::data::XDataSource > SAL_CALL createDataSource(
77 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
79 virtual css::uno::Sequence<
80 css::beans::PropertyValue > SAL_CALL detectArguments(
81 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
83 virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
84 const OUString& aRangeRepresentation ) override;
86 virtual css::uno::Reference<
87 css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
88 const OUString& aRangeRepresentation ) override;
90 virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
91 createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation,
92 const OUString& aRoleQualifier ) override;
94 virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
96 // XSheetDataProvider
97 virtual sal_Bool SAL_CALL createDataSequenceByFormulaTokensPossible(
98 const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
100 virtual css::uno::Reference< css::chart2::data::XDataSequence >
101 SAL_CALL createDataSequenceByFormulaTokens(
102 const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
104 // XRangeXMLConversion
105 virtual OUString SAL_CALL convertRangeToXML( const OUString& sRangeRepresentation ) override;
107 virtual OUString SAL_CALL convertRangeFromXML( const OUString& sXMLRange ) override;
109 // XPropertySet
110 virtual css::uno::Reference< css::beans::XPropertySetInfo> SAL_CALL
111 getPropertySetInfo() override;
113 virtual void SAL_CALL setPropertyValue(
114 const OUString& rPropertyName,
115 const css::uno::Any& rValue) override;
117 virtual css::uno::Any SAL_CALL getPropertyValue(
118 const OUString& rPropertyName) override;
120 virtual void SAL_CALL addPropertyChangeListener(
121 const OUString& rPropertyName,
122 const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
124 virtual void SAL_CALL removePropertyChangeListener(
125 const OUString& rPropertyName,
126 const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
128 virtual void SAL_CALL addVetoableChangeListener(
129 const OUString& rPropertyName,
130 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
132 virtual void SAL_CALL removeVetoableChangeListener(
133 const OUString& rPropertyName,
134 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
136 // XServiceInfo
137 virtual OUString SAL_CALL getImplementationName() override;
139 virtual sal_Bool SAL_CALL supportsService( const OUString&
140 rServiceName) override;
142 virtual css::uno::Sequence< OUString> SAL_CALL
143 getSupportedServiceNames() override;
145 private:
147 ScDocument* m_pDocument;
148 SfxItemPropertySet m_aPropSet;
149 bool m_bIncludeHiddenCells;
152 // DataSource
153 class ScChart2DataSource final : public
154 ::cppu::WeakImplHelper<
155 css::chart2::data::XDataSource,
156 css::lang::XServiceInfo>,
157 public SfxListener
159 public:
161 explicit ScChart2DataSource( ScDocument* pDoc);
162 virtual ~ScChart2DataSource() override;
163 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
165 // XDataSource
166 virtual css::uno::Sequence< css::uno::Reference<
167 css::chart2::data::XLabeledDataSequence > > SAL_CALL
168 getDataSequences() override;
170 // XServiceInfo
171 virtual OUString SAL_CALL getImplementationName() override;
173 virtual sal_Bool SAL_CALL supportsService( const OUString&
174 rServiceName) override;
176 virtual css::uno::Sequence< OUString> SAL_CALL
177 getSupportedServiceNames() override;
179 // implementation
181 void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
183 private:
185 ScDocument* m_pDocument;
186 std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
190 // DataSequence
191 class 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
203 public:
204 explicit ScChart2DataSequence( ScDocument* pDoc,
205 ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
207 virtual ~ScChart2DataSequence() override;
208 ScChart2DataSequence(const ScChart2DataSequence&) = delete;
209 ScChart2DataSequence& operator=(const ScChart2DataSequence&) = delete;
211 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
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;
220 /** Get the number format key for the n-th data entry
221 * If nIndex == -1, then you will get the number format key for the first non-empty entry
223 virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
225 // XNumericalDataSequence
226 virtual css::uno::Sequence< double >
227 SAL_CALL getNumericalData() override;
229 // XTextualDataSequence
230 virtual css::uno::Sequence< OUString >
231 SAL_CALL getTextualData() override;
233 // XTimeBased
234 virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
235 virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
237 virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
239 // XPropertySet
240 virtual css::uno::Reference<
241 css::beans::XPropertySetInfo> SAL_CALL
242 getPropertySetInfo() override;
244 virtual void SAL_CALL setPropertyValue(
245 const OUString& rPropertyName,
246 const css::uno::Any& rValue) override;
248 virtual css::uno::Any SAL_CALL getPropertyValue(
249 const OUString& rPropertyName) override;
251 virtual void SAL_CALL addPropertyChangeListener(
252 const OUString& rPropertyName,
253 const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
255 virtual void SAL_CALL removePropertyChangeListener(
256 const OUString& rPropertyName,
257 const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
259 virtual void SAL_CALL addVetoableChangeListener(
260 const OUString& rPropertyName,
261 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
263 virtual void SAL_CALL removeVetoableChangeListener(
264 const OUString& rPropertyName,
265 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
267 // XCloneable
268 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
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;
276 // XServiceInfo
277 virtual OUString SAL_CALL getImplementationName() override;
279 virtual sal_Bool SAL_CALL supportsService( const OUString&
280 rServiceName) override;
282 virtual css::uno::Sequence< OUString> SAL_CALL
283 getSupportedServiceNames() override;
285 private:
286 void setDataChangedHint(bool b);
288 // Implementation
289 void RefChanged();
290 DECL_LINK( ValueListenerHdl, const SfxHint&, void );
292 private:
293 class ExternalRefListener final : public ScExternalRefManager::LinkListener
295 public:
296 ExternalRefListener(ScChart2DataSequence& rParent, ScDocument* pDoc);
297 virtual ~ExternalRefListener() override;
298 ExternalRefListener(const ExternalRefListener&) = delete;
299 ExternalRefListener& operator=(const ExternalRefListener&) = delete;
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;}
305 private:
306 ScChart2DataSequence& mrParent;
307 std::unordered_set<sal_uInt16> maFileIds;
308 ScDocument* mpDoc;
312 * Build an internal data array to cache the data ranges, and other
313 * information such as hidden values.
315 void BuildDataCache();
317 void RebuildDataCache();
319 sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
321 void UpdateTokensFromRanges(const ScRangeList& rRanges);
323 ExternalRefListener* GetExtRefListener();
325 void StopListeningToAllExternalRefs();
327 void CopyData(const ScChart2DataSequence& r);
329 private:
331 // data array
332 struct Item
334 double mfValue;
335 OUString maString;
336 bool mbIsValue;
337 ScAddress mAddress;
338 Item();
341 class HiddenRangeListener final : public ScChartHiddenRangeListener
343 public:
344 HiddenRangeListener(ScChart2DataSequence& rParent);
345 virtual ~HiddenRangeListener() override;
347 virtual void notify() override;
349 private:
350 ScChart2DataSequence& mrParent;
353 /** This vector contains the cached data which was calculated with BuildDataCache(). */
354 std::vector<Item> m_aDataArray;
357 * Cached data for getData. We may also need to cache data for the
358 * numerical and textural data series if they turn out to be bottlenecks
359 * under certain scenarios.
361 css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
363 css::uno::Sequence<sal_Int32> m_aHiddenValues;
365 // properties
366 css::chart2::data::DataSequenceRole m_aRole;
367 bool m_bIncludeHiddenCells;
369 // internals
370 sal_Int64 m_nObjectId;
371 ScDocument* m_pDocument;
372 std::vector<ScTokenRef> m_aTokens;
373 std::optional<std::vector<sal_uInt32>>
374 m_oRangeIndices;
375 std::unique_ptr<ExternalRefListener>
376 m_pExtRefListener;
377 SfxItemPropertySet m_aPropSet;
379 std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
381 std::unique_ptr<ScLinkListener> m_pValueListener;
382 XModifyListenerArr_Impl m_aValueListeners;
384 bool m_bGotDataChangedHint;
385 bool m_bExtDataRebuildQueued;
387 bool mbTimeBased;
388 SCTAB mnTimeBasedStart;
389 SCTAB mnTimeBasedEnd;
390 SCTAB mnCurrentTab;
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */