cid#1634585 Use of auto that causes a copy
[libreoffice.git] / chart2 / source / inc / InternalDataProvider.hxx
blob26a759c56865edab26d2a30773938e06d0aecd17
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 .
19 #pragma once
21 #include "InternalData.hxx"
22 #include <ChartModel.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/chart/XDateCategories.hpp>
26 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
27 #include <com/sun/star/chart2/XInternalDataProvider.hpp>
28 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/util/XCloneable.hpp>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/weakref.hxx>
33 #include <rtl/ref.hxx>
34 #include <unotools/weakref.hxx>
36 #include <map>
38 namespace com::sun::star::chart2 { class XChartDocument; }
40 namespace chart
42 class ChartModel;
43 class UncachedDataSequence;
45 namespace impl
48 typedef ::cppu::WeakImplHelper<
49 css::chart2::XInternalDataProvider,
50 css::chart2::data::XRangeXMLConversion,
51 css::chart2::XAnyDescriptionAccess,
52 css::chart::XDateCategories,
53 css::util::XCloneable,
54 css::lang::XInitialization,
55 css::lang::XServiceInfo >
56 InternalDataProvider_Base;
59 /** Data provider that handles data internally. This is used for charts with
60 their own data.
62 <p>The format for single ranges is "categories|label n|n" where n is a
63 non-negative number. Meaning return all categories, the label of sequence n,
64 or the data of sequence n.</p>
66 <p>The format for a complete range is "all". (Do we need more than
67 that?)</p>
69 class InternalDataProvider final :
70 public impl::InternalDataProvider_Base
72 public:
73 explicit InternalDataProvider();
75 // #i120559# allow handing over a default for data orientation
76 // (DataInColumns) that will be used when no data is available
77 explicit InternalDataProvider(
78 const rtl::Reference< ::chart::ChartModel > & xChartDoc,
79 bool bConnectToModel,
80 bool bDefaultDataInColumns );
81 explicit InternalDataProvider( const InternalDataProvider & rOther );
82 virtual ~InternalDataProvider() override;
84 /// declare XServiceInfo methods
85 virtual OUString SAL_CALL getImplementationName() override;
86 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
87 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
89 // ____ XInternalDataProvider ____
90 virtual sal_Bool SAL_CALL hasDataByRangeRepresentation( const OUString& aRange ) override;
91 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
92 getDataByRangeRepresentation( const OUString& aRange ) override;
93 virtual void SAL_CALL setDataByRangeRepresentation(
94 const OUString& aRange,
95 const css::uno::Sequence< css::uno::Any >& aNewData ) override;
96 virtual void SAL_CALL insertSequence( ::sal_Int32 nAfterIndex ) override;
97 virtual void SAL_CALL deleteSequence( ::sal_Int32 nAtIndex ) override;
98 virtual void SAL_CALL appendSequence() override;
99 virtual void SAL_CALL insertComplexCategoryLevel( ::sal_Int32 nLevel ) override;
100 virtual void SAL_CALL deleteComplexCategoryLevel( ::sal_Int32 nLevel ) override;
101 virtual void SAL_CALL insertDataPointForAllSequences( ::sal_Int32 nAfterIndex ) override;
102 virtual void SAL_CALL deleteDataPointForAllSequences( ::sal_Int32 nAtIndex ) override;
103 virtual void SAL_CALL swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex ) override;
104 virtual void SAL_CALL registerDataSequenceForChanges(
105 const css::uno::Reference< css::chart2::data::XDataSequence >& xSeq ) override;
106 virtual void SAL_CALL insertDataSeries( ::sal_Int32 nAfterIndex ) override;
108 // ____ XDataProvider (base of XInternalDataProvider) ____
109 virtual sal_Bool SAL_CALL createDataSourcePossible(
110 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
111 virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL createDataSource(
112 const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
113 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL detectArguments(
114 const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
115 virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
116 const OUString& aRangeRepresentation ) override;
117 virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
118 const OUString& aRangeRepresentation ) override;
120 virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
121 createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation,
122 const OUString& aRoleQualifier ) override;
124 virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
126 // ____ XRangeXMLConversion ____
127 virtual OUString SAL_CALL convertRangeToXML(
128 const OUString& aRangeRepresentation ) override;
129 virtual OUString SAL_CALL convertRangeFromXML(
130 const OUString& aXMLRange ) override;
132 // ____ XDateCategories ____
133 virtual css::uno::Sequence< double > SAL_CALL getDateCategories() override;
134 virtual void SAL_CALL setDateCategories( const css::uno::Sequence< double >& rDates ) override;
136 // ____ XAnyDescriptionAccess ____
137 virtual css::uno::Sequence< css::uno::Sequence< css::uno::Any > > SAL_CALL
138 getAnyRowDescriptions() override;
139 virtual void SAL_CALL setAnyRowDescriptions(
140 const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& aRowDescriptions ) override;
141 virtual css::uno::Sequence< css::uno::Sequence< css::uno::Any > > SAL_CALL
142 getAnyColumnDescriptions() override;
143 virtual void SAL_CALL setAnyColumnDescriptions(
144 const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& aColumnDescriptions ) override;
146 // ____ XComplexDescriptionAccess (base of XAnyDescriptionAccess) ____
147 virtual css::uno::Sequence< css::uno::Sequence< OUString > > SAL_CALL
148 getComplexRowDescriptions() override;
149 virtual void SAL_CALL setComplexRowDescriptions(
150 const css::uno::Sequence< css::uno::Sequence< OUString > >& aRowDescriptions ) override;
151 virtual css::uno::Sequence< css::uno::Sequence< OUString > > SAL_CALL
152 getComplexColumnDescriptions() override;
153 virtual void SAL_CALL setComplexColumnDescriptions(
154 const css::uno::Sequence< css::uno::Sequence< OUString > >& aColumnDescriptions ) override;
156 // ____ XChartDataArray (base of XComplexDescriptionAccess) ____
157 virtual css::uno::Sequence< css::uno::Sequence< double > > SAL_CALL getData() override;
158 virtual void SAL_CALL setData(
159 const css::uno::Sequence< css::uno::Sequence< double > >& aData ) override;
160 virtual css::uno::Sequence< OUString > SAL_CALL getRowDescriptions() override;
161 virtual void SAL_CALL setRowDescriptions(
162 const css::uno::Sequence< OUString >& aRowDescriptions ) override;
163 virtual css::uno::Sequence< OUString > SAL_CALL getColumnDescriptions() override;
164 virtual void SAL_CALL setColumnDescriptions(
165 const css::uno::Sequence< OUString >& aColumnDescriptions ) override;
167 // ____ XChartData (base of XChartDataArray) ____
168 virtual void SAL_CALL addChartDataChangeEventListener(
169 const css::uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) override;
170 virtual void SAL_CALL removeChartDataChangeEventListener(
171 const css::uno::Reference< css::chart::XChartDataChangeEventListener >& aListener ) override;
172 virtual double SAL_CALL getNotANumber() override;
173 virtual sal_Bool SAL_CALL isNotANumber(
174 double nNumber ) override;
176 // ____ XCloneable ____
177 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
178 // css::lang::XInitialization:
179 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > & aArguments) override;
181 void setChartModel(ChartModel* pChartModel);
183 private:
184 void addDataSequenceToMap(
185 const OUString & rRangeRepresentation,
186 const css::uno::Reference< css::chart2::data::XDataSequence > & xSequence );
188 css::uno::Reference< css::chart2::data::XDataSequence >
189 createDataSequenceAndAddToMap( const OUString & rRangeRepresentation,
190 const OUString & rRole );
191 rtl::Reference< UncachedDataSequence >
192 createDataSequenceAndAddToMap( const OUString & rRangeRepresentation );
194 rtl::Reference<UncachedDataSequence>
195 createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole,
196 std::u16string_view rRoleQualifier);
198 void deleteMapReferences( const OUString & rRangeRepresentation );
200 void adaptMapReferences(
201 const OUString & rOldRangeRepresentation,
202 const OUString & rNewRangeRepresentation );
204 void increaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
205 void decreaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
207 typedef std::multimap< OUString,
208 css::uno::WeakReference< css::chart2::data::XDataSequence > >
209 tSequenceMap;
210 typedef std::pair< tSequenceMap::iterator, tSequenceMap::iterator > tSequenceMapRange;
212 /** cache for all sequences that have been returned.
214 If the range-representation of a sequence changes and it is still
215 referred to by some component (weak reference is valid), the range will
216 be adapted.
218 tSequenceMap m_aSequenceMap;
219 InternalData m_aInternalData;
220 bool m_bDataInColumns;
222 // keep a weak reference to the owning m_xChartModel for insertDataSeries
223 unotools::WeakReference<ChartModel> m_xChartModel;
226 } // namespace chart
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */