Coverage Report

Created: 2026-11-06 11:29

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