tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / PivotTableDataSequence.cxx
blob352e4b80e7fd3bc0edf677bbc5140a355ba6e058
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/.
8 */
10 #include <PivotTableDataSequence.hxx>
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>
19 #include <miscuno.hxx>
20 #include <document.hxx>
21 #include <unonames.hxx>
23 using namespace css;
25 namespace sc
28 SC_SIMPLE_SERVICE_INFO( PivotTableDataSequence, u"PivotTableDataSequence"_ustr, u"com.sun.star.chart2.data.DataSequence"_ustr)
30 static std::span<const SfxItemPropertyMapEntry> lcl_GetDataSequencePropertyMap()
32 static const SfxItemPropertyMapEntry aDataSequencePropertyMap_Impl[] =
34 { SC_UNONAME_HIDDENVALUES, 0, cppu::UnoType<uno::Sequence<sal_Int32>>::get(), 0, 0 },
35 { SC_UNONAME_ROLE, 0, cppu::UnoType<css::chart2::data::DataSequenceRole>::get(), 0, 0 },
36 { SC_UNONAME_INCLUDEHIDDENCELLS, 0, cppu::UnoType<bool>::get(), 0, 0 },
38 return aDataSequencePropertyMap_Impl;
41 PivotTableDataSequence::PivotTableDataSequence(ScDocument* pDocument, OUString sID,
42 std::vector<ValueAndFormat>&& rData)
43 : m_pDocument(pDocument)
44 , m_aID(std::move(sID))
45 , m_aData(std::move(rData))
46 , m_aPropSet(lcl_GetDataSequencePropertyMap())
48 if (m_pDocument)
49 m_pDocument->AddUnoObject(*this);
52 PivotTableDataSequence::~PivotTableDataSequence()
54 SolarMutexGuard g;
56 if (m_pDocument)
57 m_pDocument->RemoveUnoObject(*this);
60 void PivotTableDataSequence::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
62 if (rHint.GetId() == SfxHintId::Dying)
64 m_pDocument = nullptr;
68 uno::Sequence<uno::Any> SAL_CALL PivotTableDataSequence::getData()
70 SolarMutexGuard aGuard;
72 if (!m_pDocument)
73 throw uno::RuntimeException();
75 uno::Sequence<uno::Any> aSeq(m_aData.size());
76 auto pSeq = aSeq.getArray();
78 size_t i = 0;
79 for (ValueAndFormat const & rItem : m_aData)
81 if (rItem.m_eType == ValueType::Numeric)
82 pSeq[i] <<= double(rItem.m_fValue);
83 else if (rItem.m_eType == ValueType::String)
84 pSeq[i] <<= rItem.m_aString;
86 i++;
88 return aSeq;
91 // XNumericalDataSequence --------------------------------------------------
93 uno::Sequence<double> SAL_CALL PivotTableDataSequence::getNumericalData()
95 SolarMutexGuard aGuard;
96 if (!m_pDocument)
97 throw uno::RuntimeException();
99 uno::Sequence<double> aSeq(m_aData.size());
100 auto pSeq = aSeq.getArray();
102 size_t i = 0;
103 for (ValueAndFormat const & rItem : m_aData)
105 pSeq[i] = rItem.m_fValue;
106 i++;
108 return aSeq;
111 // XTextualDataSequence --------------------------------------------------
113 uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::getTextualData()
115 SolarMutexGuard aGuard;
116 if (!m_pDocument)
117 throw uno::RuntimeException();
119 uno::Sequence<OUString> aSeq(m_aData.size());
120 auto pSeq = aSeq.getArray();
122 size_t i = 0;
123 for (ValueAndFormat const & rItem : m_aData)
125 if (rItem.m_eType == ValueType::String)
126 pSeq[i] = rItem.m_aString;
127 i++;
129 return aSeq;
132 OUString SAL_CALL PivotTableDataSequence::getSourceRangeRepresentation()
134 return m_aID;
137 uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::generateLabel(chart2::data::LabelOrigin /*eOrigin*/)
139 SolarMutexGuard aGuard;
140 if (!m_pDocument)
141 throw uno::RuntimeException();
143 uno::Sequence<OUString> aSeq;
144 return aSeq;
147 sal_Int32 SAL_CALL PivotTableDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex)
149 SolarMutexGuard aGuard;
150 if (nIndex == -1 && !m_aData.empty())
152 return m_aData[0].m_nNumberFormat;
154 else if (nIndex < 0 && o3tl::make_unsigned(nIndex) >= m_aData.size())
156 SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
157 return 0;
159 return m_aData[size_t(nIndex)].m_nNumberFormat;
162 // XCloneable ================================================================
164 uno::Reference<util::XCloneable> SAL_CALL PivotTableDataSequence::createClone()
166 SolarMutexGuard aGuard;
168 rtl::Reference<PivotTableDataSequence> pClone(new PivotTableDataSequence(m_pDocument, m_aID, std::vector(m_aData)));
169 pClone->setRole(m_aRole);
171 return pClone;
174 // XModifyBroadcaster ========================================================
176 void SAL_CALL PivotTableDataSequence::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
178 SolarMutexGuard aGuard;
179 m_aValueListeners.emplace_back(aListener);
182 void SAL_CALL PivotTableDataSequence::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener)
184 SolarMutexGuard aGuard;
186 sal_uInt16 nCount = m_aValueListeners.size();
187 for (sal_uInt16 n = nCount; n--; )
189 uno::Reference<util::XModifyListener>& rObj = m_aValueListeners[n];
190 if (rObj == aListener)
192 m_aValueListeners.erase(m_aValueListeners.begin() + n);
197 // DataSequence XPropertySet -------------------------------------------------
199 uno::Reference< beans::XPropertySetInfo> SAL_CALL PivotTableDataSequence::getPropertySetInfo()
201 SolarMutexGuard aGuard;
202 static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(m_aPropSet.getPropertyMap());
203 return aRef;
206 void SAL_CALL PivotTableDataSequence::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
208 if (rPropertyName == SC_UNONAME_ROLE)
210 if (!(rValue >>= m_aRole))
211 throw lang::IllegalArgumentException();
213 else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS
214 || rPropertyName == SC_UNONAME_HIDDENVALUES
215 || rPropertyName == SC_UNONAME_TIME_BASED
216 || rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
218 else
219 throw beans::UnknownPropertyException(rPropertyName);
222 uno::Any SAL_CALL PivotTableDataSequence::getPropertyValue(const OUString& rPropertyName)
224 uno::Any aReturn;
225 if (rPropertyName == SC_UNONAME_ROLE)
226 aReturn <<= m_aRole;
227 else if (rPropertyName == SC_UNONAME_INCLUDEHIDDENCELLS)
228 aReturn <<= false;
229 else if (rPropertyName == SC_UNONAME_HIDDENVALUES)
231 css::uno::Sequence<sal_Int32> aHiddenValues;
232 aReturn <<= aHiddenValues;
234 else if (rPropertyName == SC_UNONAME_TIME_BASED)
236 aReturn <<= false;
238 else if (rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
240 aReturn <<= false;
242 else
243 throw beans::UnknownPropertyException(rPropertyName);
244 return aReturn;
247 void SAL_CALL PivotTableDataSequence::addPropertyChangeListener(
248 const OUString& /*rPropertyName*/,
249 const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/)
251 OSL_FAIL("Not yet implemented");
254 void SAL_CALL PivotTableDataSequence::removePropertyChangeListener(
255 const OUString& /*rPropertyName*/,
256 const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/)
258 OSL_FAIL("Not yet implemented");
261 void SAL_CALL PivotTableDataSequence::addVetoableChangeListener(
262 const OUString& /*rPropertyName*/,
263 const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
265 OSL_FAIL("Not yet implemented");
268 void SAL_CALL PivotTableDataSequence::removeVetoableChangeListener(
269 const OUString& /*rPropertyName*/,
270 const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
272 OSL_FAIL("Not yet implemented");
275 } // end sc namespace
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */