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  { OUString(), 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> const & rData)
44  : m_pDocument(pDocument)
45  , m_aID(sID)
46  , m_aData(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 
78  size_t i = 0;
79  for (ValueAndFormat const & rItem : m_aData)
80  {
81  if (rItem.m_eType == ValueType::Numeric)
82  aSeq[i] <<= double(rItem.m_fValue);
83  else if (rItem.m_eType == ValueType::String)
84  aSeq[i] <<= rItem.m_aString;
85 
86  i++;
87  }
88  return aSeq;
89 }
90 
91 // XNumericalDataSequence --------------------------------------------------
92 
93 uno::Sequence<double> SAL_CALL PivotTableDataSequence::getNumericalData()
94 {
95  SolarMutexGuard aGuard;
96  if (!m_pDocument)
97  throw uno::RuntimeException();
98 
99  uno::Sequence<double> aSeq(m_aData.size());
100 
101  size_t i = 0;
102  for (ValueAndFormat const & rItem : m_aData)
103  {
104  aSeq[i] = rItem.m_fValue;
105  i++;
106  }
107  return aSeq;
108 }
109 
110 // XTextualDataSequence --------------------------------------------------
111 
112 uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::getTextualData()
113 {
114  SolarMutexGuard aGuard;
115  if (!m_pDocument)
116  throw uno::RuntimeException();
117 
118  uno::Sequence<OUString> aSeq(m_aData.size());
119 
120  size_t i = 0;
121  for (ValueAndFormat const & rItem : m_aData)
122  {
123  if (rItem.m_eType == ValueType::String)
124  aSeq[i] = rItem.m_aString;
125  i++;
126  }
127  return aSeq;
128 }
129 
131 {
132  SolarMutexGuard aGuard;
133 
134  return m_aID;
135 }
136 
137 uno::Sequence<OUString> SAL_CALL PivotTableDataSequence::generateLabel(chart2::data::LabelOrigin /*eOrigin*/)
138 {
139  SolarMutexGuard aGuard;
140  if (!m_pDocument)
141  throw uno::RuntimeException();
142 
143  uno::Sequence<OUString> aSeq;
144  return aSeq;
145 }
146 
147 sal_Int32 SAL_CALL PivotTableDataSequence::getNumberFormatKeyByIndex(sal_Int32 nIndex)
148 {
149  SolarMutexGuard aGuard;
150  if (nIndex == -1 && !m_aData.empty())
151  {
152  return m_aData[0].m_nNumberFormat;
153  }
154  else if (nIndex < 0 && o3tl::make_unsigned(nIndex) >= m_aData.size())
155  {
156  SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
157  return 0;
158  }
159  return m_aData[size_t(nIndex)].m_nNumberFormat;
160 }
161 
162 // XCloneable ================================================================
163 
164 uno::Reference<util::XCloneable> SAL_CALL PivotTableDataSequence::createClone()
165 {
166  SolarMutexGuard aGuard;
167 
168  std::unique_ptr<PivotTableDataSequence> pClone;
169  pClone.reset(new PivotTableDataSequence(m_pDocument, m_aID, m_aData));
170  pClone->setRole(m_aRole);
171 
172  uno::Reference<util::XCloneable> xClone(pClone.release());
173 
174  return xClone;
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:678
virtual OUString SAL_CALL getSourceRangeRepresentation() override
#define SC_UNONAME_TIME_BASED
Definition: unonames.hxx:681
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
PivotTableDataSequence(ScDocument *pDocument, OUString const &sID, std::vector< ValueAndFormat > const &rData)
sal_Int64 n
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:676
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
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)
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:64
#define SC_UNONAME_HAS_STRING_LABEL
Definition: unonames.hxx:680
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:879
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
static const SfxItemPropertyMapEntry * lcl_GetDataSequencePropertyMap()
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:887
virtual ~PivotTableDataSequence() override
Sequence< sal_Int8 > aSeq
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:677