1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <PivotTableDataSequence.hxx>
#include <sal/config.h>
#include <sal/log.hxx>
#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <utility>
#include <vcl/svapp.hxx>
#include <miscuno.hxx>
#include <document.hxx>
#include <unonames.hxx>
using namespace css;
namespace sc
{
SC_SIMPLE_SERVICE_INFO( PivotTableDataSequence, "PivotTableDataSequence", "com.sun.star.chart2.data.DataSequence")
static std::span<const SfxItemPropertyMapEntry> lcl_GetDataSequencePropertyMap()
{
static const SfxItemPropertyMapEntry aDataSequencePropertyMap_Impl[] =
{
{ SC_UNONAME_HIDDENVALUES, 0, cppu::UnoType<uno::Sequence<sal_Int32>>::get(), 0, 0 },
{ SC_UNONAME_ROLE, 0, cppu::UnoType<css::chart2::data::DataSequenceRole>::get(), 0, 0 },
{ SC_UNONAME_INCLUDEHIDDENCELLS, 0, cppu::UnoType<bool>::get(), 0, 0 },
};
return aDataSequencePropertyMap_Impl;
}
PivotTableDataSequence::PivotTableDataSequence(ScDocument* pDocument, OUString sID,
std::vector<ValueAndFormat>&& rData)
: m_pDocument(pDocument)
, m_aID(std::move(sID))
, m_aData(std::move(rData))
, m_aPropSet(lcl_GetDataSequencePropertyMap())
{
if (m_pDocument)
m_pDocument->AddUnoObject(*this);
}
PivotTableDataSequence::~PivotTableDataSequence()
{
SolarMutexGuard g;
if (m_pDocument)
m_pDocument->RemoveUnoObject(*this);
}
void PivotTableDataSequence::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
{
if (rHint.GetId() == SfxHintId::Dying)
{
m_pDocument = nullptr;
}
}
uno::Sequence<uno::Any> SAL_CALL PivotTableDataSequence::getData()
{
SolarMutexGuard aGuard;
if (!m_pDocument)
throw uno::RuntimeException();
uno::Sequence<uno::Any> aSeq(m_aData.size());
auto pSeq = aSeq.getArray();
size_t i = 0;
for (ValueAndFormat const & rItem : m_aData)
{
if (rItem.m_eType == ValueType::Numeric)
pSeq[i] <<= double(rItem.m_fValue);
else if (rItem.m_eType == ValueType::String)
pSeq[i] <<= rItem.m_aString;
i++;
}
return aSeq;
}
// XNumericalDataSequence --------------------------------------------------
uno::Sequence<double> SAL_CALL PivotTableDataSequence::getNumericalData()
{
SolarMutexGuard aGuard;
if (!m_pDocument)
throw uno::RuntimeException();
uno::Sequence<double> aSeq(m_aData.size());
auto pSeq = aSeq.getArray();
size_t i = 0;
for (ValueAndFormat const & rItem : m_aData)
{
pSeq[i] = rItem.m_fValue;
i++;
}
return aSeq;
}
// XTextualDataSequence --------------------------------------------------
uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::getTextualData()
{
SolarMutexGuard aGuard;
if (!m_pDocument)
throw uno::RuntimeException();
uno::Sequence<OUString> aSeq(m_aData.size());
auto pSeq = aSeq.getArray();
size_t i = 0;
for (ValueAndFormat const & rItem : m_aData)
{
if (rItem.m_eType == ValueType::String)
pSeq[i] = rItem.m_aString;
i++;
}
return aSeq;
}
OUString SAL_CALL PivotTableDataSequence::getSourceRangeRepresentation()
{
return m_aID;
}
uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::generateLabel(chart2::data::LabelOrigin /*eOrigin*/)
{
SolarMutexGuard aGuard;
if (!m_pDocument)
throw uno::RuntimeException();
uno::Sequence<OUString> aSeq;
return aSeq;
}
sal_Int32 SAL_CALL PivotTableDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
if (nIndex == -1 && !m_aData.empty())
{
return m_aData[0].m_nNumberFormat;
}
else if (nIndex < 0 && o3tl::make_unsigned(nIndex) >= m_aData.size())
{
SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
return 0;
}
return m_aData[size_t(nIndex)].m_nNumberFormat;
}
// XCloneable ================================================================
uno::Reference<util::XCloneable> SAL_CALL PivotTableDataSequence::createClone()
{
SolarMutexGuard aGuard;
rtl::Reference<PivotTableDataSequence> pClone(new PivotTableDataSequence(m_pDocument, m_aID, std::vector(m_aData)));
pClone->setRole(m_aRole);
return pClone;
}
// XModifyBroadcaster ========================================================
void SAL_CALL PivotTableDataSequence::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
{
SolarMutexGuard aGuard;
m_aValueListeners.emplace_back(aListener);
}
void SAL_CALL PivotTableDataSequence::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener)
{
SolarMutexGuard aGuard;
sal_uInt16 nCount = m_aValueListeners.size();
for (sal_uInt16 n = nCount; n--; )
{
uno::Reference<util::XModifyListener>& rObj = m_aValueListeners[n];
if (rObj == aListener)
{
m_aValueListeners.erase(m_aValueListeners.begin() + n);
}
}
}
// DataSequence XPropertySet -------------------------------------------------
uno::Reference< beans::XPropertySetInfo> SAL_CALL PivotTableDataSequence::getPropertySetInfo()
{
SolarMutexGuard aGuard;
static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(m_aPropSet.getPropertyMap());
return aRef;
}
void SAL_CALL PivotTableDataSequence::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
{
if (rPropertyName == SC_UNONAME_ROLE)
{
if (!(rValue >>= m_aRole))
throw lang::IllegalArgumentException();
}
else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS
|| rPropertyName == SC_UNONAME_HIDDENVALUES
|| rPropertyName == SC_UNONAME_TIME_BASED
|| rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
{}
else
throw beans::UnknownPropertyException(rPropertyName);
}
uno::Any SAL_CALL PivotTableDataSequence::getPropertyValue(const OUString& rPropertyName)
{
uno::Any aReturn;
if (rPropertyName == SC_UNONAME_ROLE)
aReturn <<= m_aRole;
else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS)
aReturn <<= false;
else if (rPropertyName == SC_UNONAME_HIDDENVALUES)
{
css::uno::Sequence<sal_Int32> aHiddenValues;
aReturn <<= aHiddenValues;
}
else if (rPropertyName == SC_UNONAME_TIME_BASED)
{
aReturn <<= false;
}
else if (rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
{
aReturn <<= false;
}
else
throw beans::UnknownPropertyException(rPropertyName);
return aReturn;
}
void SAL_CALL PivotTableDataSequence::addPropertyChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/)
{
OSL_FAIL("Not yet implemented");
}
void SAL_CALL PivotTableDataSequence::removePropertyChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/)
{
OSL_FAIL("Not yet implemented");
}
void SAL_CALL PivotTableDataSequence::addVetoableChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
{
OSL_FAIL("Not yet implemented");
}
void SAL_CALL PivotTableDataSequence::removeVetoableChangeListener(
const OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
{
OSL_FAIL("Not yet implemented");
}
} // end sc namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|