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 <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, "PivotTableDataSequence", "com.sun.star.chart2.data.DataSequence")
29 
31 {
32  static const SfxItemPropertyMapEntry aDataSequencePropertyMap_Impl[] =
33  {
37  { u"", 0, css::uno::Type(), 0, 0 }
38  };
39  return aDataSequencePropertyMap_Impl;
40 }
41 
42 PivotTableDataSequence::PivotTableDataSequence(ScDocument* pDocument, OUString const & sID,
43  std::vector<ValueAndFormat>&& rData)
44  : m_pDocument(pDocument)
45  , m_aID(sID)
46  , m_aData(std::move(rData))
47  , m_aPropSet(lcl_GetDataSequencePropertyMap())
48 {
49  if (m_pDocument)
50  m_pDocument->AddUnoObject(*this);
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 
69 uno::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 
94 uno::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 
114 uno::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 
140 uno::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 
150 sal_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 
167 uno::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 
179 void SAL_CALL PivotTableDataSequence::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
180 {
181  SolarMutexGuard aGuard;
182  m_aValueListeners.emplace_back(aListener);
183 }
184 
185 void 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 
202 uno::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 
209 void 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 
225 uno::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: */
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
#define SC_UNONAME_INCLUDEHIDDENCELLS
Definition: unonames.hxx:687
virtual OUString SAL_CALL getSourceRangeRepresentation() override
#define SC_UNONAME_TIME_BASED
Definition: unonames.hxx:690
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< OUString > SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override
sal_Int64 n
const ContentProperties & rData
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
std::vector< ValueAndFormat > m_aData
SfxHintId GetId() const
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
#define SC_UNONAME_ROLE
Definition: unonames.hxx:685
MapData m_aData
int nCount
virtual sal_Int32 SAL_CALL getNumberFormatKeyByIndex(sal_Int32 nIndex) override
std::vector< css::uno::Reference< css::util::XModifyListener > > m_aValueListeners
int i
CAUTION! The following defines must be in the same namespace as the respective type.
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
float u
css::chart2::data::DataSequenceRole m_aRole
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Type const & get()
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
Definition: miscuno.hxx:63
#define SC_UNONAME_HAS_STRING_LABEL
Definition: unonames.hxx:689
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
static const SfxItemPropertyMapEntry * lcl_GetDataSequencePropertyMap()
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
virtual ~PivotTableDataSequence() override
Sequence< sal_Int8 > aSeq
PivotTableDataSequence(ScDocument *pDocument, OUString const &sID, std::vector< ValueAndFormat > &&rData)
virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override
#define SAL_WARN(area, stream)
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
#define SC_UNONAME_HIDDENVALUES
Definition: unonames.hxx:686