LibreOffice Module sc (master) 1
PivotTableDataSequence.cxx
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
10#include <memory>
12
13#include <sal/config.h>
14#include <sal/log.hxx>
15#include <o3tl/safeint.hxx>
16#include <osl/diagnose.h>
17#include <utility>
18#include <vcl/svapp.hxx>
19
20#include <miscuno.hxx>
21#include <document.hxx>
22#include <unonames.hxx>
23
24using namespace css;
25
26namespace sc
27{
28
29SC_SIMPLE_SERVICE_INFO( PivotTableDataSequence, "PivotTableDataSequence", "com.sun.star.chart2.data.DataSequence")
30
32{
33 static const SfxItemPropertyMapEntry aDataSequencePropertyMap_Impl[] =
34 {
38 };
39 return aDataSequencePropertyMap_Impl;
40}
41
43 std::vector<ValueAndFormat>&& rData)
44 : m_pDocument(pDocument)
45 , m_aID(std::move(sID))
46 , m_aData(std::move(rData))
47 , m_aPropSet(lcl_GetDataSequencePropertyMap())
48{
49 if (m_pDocument)
51}
52
54{
56
57 if (m_pDocument)
59}
60
62{
63 if (rHint.GetId() == SfxHintId::Dying)
64 {
65 m_pDocument = nullptr;
66 }
67}
68
69uno::Sequence<uno::Any> SAL_CALL PivotTableDataSequence::getData()
70{
71 SolarMutexGuard aGuard;
72
73 if (!m_pDocument)
74 throw uno::RuntimeException();
75
76 uno::Sequence<uno::Any> aSeq(m_aData.size());
77 auto pSeq = aSeq.getArray();
78
79 size_t i = 0;
80 for (ValueAndFormat const & rItem : m_aData)
81 {
82 if (rItem.m_eType == ValueType::Numeric)
83 pSeq[i] <<= double(rItem.m_fValue);
84 else if (rItem.m_eType == ValueType::String)
85 pSeq[i] <<= rItem.m_aString;
86
87 i++;
88 }
89 return aSeq;
90}
91
92// XNumericalDataSequence --------------------------------------------------
93
94uno::Sequence<double> SAL_CALL PivotTableDataSequence::getNumericalData()
95{
96 SolarMutexGuard aGuard;
97 if (!m_pDocument)
98 throw uno::RuntimeException();
99
100 uno::Sequence<double> aSeq(m_aData.size());
101 auto pSeq = aSeq.getArray();
102
103 size_t i = 0;
104 for (ValueAndFormat const & rItem : m_aData)
105 {
106 pSeq[i] = rItem.m_fValue;
107 i++;
108 }
109 return aSeq;
110}
111
112// XTextualDataSequence --------------------------------------------------
113
114uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::getTextualData()
115{
116 SolarMutexGuard aGuard;
117 if (!m_pDocument)
118 throw uno::RuntimeException();
119
120 uno::Sequence<OUString> aSeq(m_aData.size());
121 auto pSeq = aSeq.getArray();
122
123 size_t i = 0;
124 for (ValueAndFormat const & rItem : m_aData)
125 {
126 if (rItem.m_eType == ValueType::String)
127 pSeq[i] = rItem.m_aString;
128 i++;
129 }
130 return aSeq;
131}
132
134{
135 SolarMutexGuard aGuard;
136
137 return m_aID;
138}
139
140uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::generateLabel(chart2::data::LabelOrigin /*eOrigin*/)
141{
142 SolarMutexGuard aGuard;
143 if (!m_pDocument)
144 throw uno::RuntimeException();
145
146 uno::Sequence<OUString> aSeq;
147 return aSeq;
148}
149
150sal_Int32 SAL_CALL PivotTableDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex)
151{
152 SolarMutexGuard aGuard;
153 if (nIndex == -1 && !m_aData.empty())
154 {
155 return m_aData[0].m_nNumberFormat;
156 }
157 else if (nIndex < 0 && o3tl::make_unsigned(nIndex) >= m_aData.size())
158 {
159 SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
160 return 0;
161 }
162 return m_aData[size_t(nIndex)].m_nNumberFormat;
163}
164
165// XCloneable ================================================================
166
167uno::Reference<util::XCloneable> SAL_CALL PivotTableDataSequence::createClone()
168{
169 SolarMutexGuard aGuard;
170
172 pClone->setRole(m_aRole);
173
174 return pClone;
175}
176
177// XModifyBroadcaster ========================================================
178
179void SAL_CALL PivotTableDataSequence::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
180{
181 SolarMutexGuard aGuard;
182 m_aValueListeners.emplace_back(aListener);
183}
184
185void SAL_CALL PivotTableDataSequence::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener)
186{
187 SolarMutexGuard aGuard;
188
189 sal_uInt16 nCount = m_aValueListeners.size();
190 for (sal_uInt16 n = nCount; n--; )
191 {
192 uno::Reference<util::XModifyListener>& rObj = m_aValueListeners[n];
193 if (rObj == aListener)
194 {
195 m_aValueListeners.erase(m_aValueListeners.begin() + n);
196 }
197 }
198}
199
200// DataSequence XPropertySet -------------------------------------------------
201
202uno::Reference< beans::XPropertySetInfo> SAL_CALL PivotTableDataSequence::getPropertySetInfo()
203{
204 SolarMutexGuard aGuard;
205 static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(m_aPropSet.getPropertyMap());
206 return aRef;
207}
208
209void SAL_CALL PivotTableDataSequence::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
210{
211 if (rPropertyName == SC_UNONAME_ROLE)
212 {
213 if (!(rValue >>= m_aRole))
214 throw lang::IllegalArgumentException();
215 }
216 else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS
217 || rPropertyName == SC_UNONAME_HIDDENVALUES
218 || rPropertyName == SC_UNONAME_TIME_BASED
219 || rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
220 {}
221 else
222 throw beans::UnknownPropertyException(rPropertyName);
223}
224
225uno::Any SAL_CALL PivotTableDataSequence::getPropertyValue(const OUString& rPropertyName)
226{
227 uno::Any aReturn;
228 if (rPropertyName == SC_UNONAME_ROLE)
229 aReturn <<= m_aRole;
230 else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS)
231 aReturn <<= false;
232 else if (rPropertyName == SC_UNONAME_HIDDENVALUES)
233 {
234 css::uno::Sequence<sal_Int32> aHiddenValues;
235 aReturn <<= aHiddenValues;
236 }
237 else if (rPropertyName == SC_UNONAME_TIME_BASED)
238 {
239 aReturn <<= false;
240 }
241 else if (rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
242 {
243 aReturn <<= false;
244 }
245 else
246 throw beans::UnknownPropertyException(rPropertyName);
247 return aReturn;
248}
249
251 const OUString& /*rPropertyName*/,
252 const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/)
253{
254 OSL_FAIL("Not yet implemented");
255}
256
258 const OUString& /*rPropertyName*/,
259 const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/)
260{
261 OSL_FAIL("Not yet implemented");
262}
263
265 const OUString& /*rPropertyName*/,
266 const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
267{
268 OSL_FAIL("Not yet implemented");
269}
270
272 const OUString& /*rPropertyName*/,
273 const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
274{
275 OSL_FAIL("Not yet implemented");
276}
277
278} // end sc namespace
279
280/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
SfxHintId GetId() const
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Type const & get()
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
virtual sal_Int32 SAL_CALL getNumberFormatKeyByIndex(sal_Int32 nIndex) override
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
std::vector< css::uno::Reference< css::util::XModifyListener > > m_aValueListeners
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
std::vector< ValueAndFormat > m_aData
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
css::chart2::data::DataSequenceRole m_aRole
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
virtual ~PivotTableDataSequence() override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual OUString SAL_CALL getSourceRangeRepresentation() override
PivotTableDataSequence(ScDocument *pDocument, OUString sID, std::vector< ValueAndFormat > &&rData)
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
int nCount
MapData m_aData
sal_Int32 nIndex
sal_Int64 n
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
static o3tl::span< const SfxItemPropertyMapEntry > lcl_GetDataSequencePropertyMap()
constexpr OUStringLiteral SC_UNONAME_TIME_BASED
Definition: unonames.hxx:699
constexpr OUStringLiteral SC_UNONAME_HIDDENVALUES
Definition: unonames.hxx:695
constexpr OUStringLiteral SC_UNONAME_ROLE
Definition: unonames.hxx:694
constexpr OUStringLiteral SC_UNONAME_INCLUDEHIDDENCELLS
Definition: unonames.hxx:696
constexpr OUStringLiteral SC_UNONAME_HAS_STRING_LABEL
Definition: unonames.hxx:698