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 
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 
169  pClone->setRole(m_aRole);
170 
171  return pClone;
172 }
173 
174 // XModifyBroadcaster ========================================================
175 
176 void SAL_CALL PivotTableDataSequence::addModifyListener(const uno::Reference<util::XModifyListener>& aListener)
177 {
178  SolarMutexGuard aGuard;
179  m_aValueListeners.emplace_back(aListener);
180 }
181 
182 void SAL_CALL PivotTableDataSequence::removeModifyListener(const uno::Reference<util::XModifyListener>& aListener)
183 {
184  SolarMutexGuard aGuard;
185 
186  sal_uInt16 nCount = m_aValueListeners.size();
187  for (sal_uInt16 n = nCount; n--; )
188  {
189  uno::Reference<util::XModifyListener>& rObj = m_aValueListeners[n];
190  if (rObj == aListener)
191  {
192  m_aValueListeners.erase(m_aValueListeners.begin() + n);
193  }
194  }
195 }
196 
197 // DataSequence XPropertySet -------------------------------------------------
198 
199 uno::Reference< beans::XPropertySetInfo> SAL_CALL PivotTableDataSequence::getPropertySetInfo()
200 {
201  SolarMutexGuard aGuard;
202  static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(m_aPropSet.getPropertyMap());
203  return aRef;
204 }
205 
206 void SAL_CALL PivotTableDataSequence::setPropertyValue(const OUString& rPropertyName, const uno::Any& rValue)
207 {
208  if (rPropertyName == SC_UNONAME_ROLE)
209  {
210  if (!(rValue >>= m_aRole))
211  throw lang::IllegalArgumentException();
212  }
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)
217  {}
218  else
219  throw beans::UnknownPropertyException(rPropertyName);
220 }
221 
222 uno::Any SAL_CALL PivotTableDataSequence::getPropertyValue(const OUString& rPropertyName)
223 {
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)
230  {
231  css::uno::Sequence<sal_Int32> aHiddenValues;
232  aReturn <<= aHiddenValues;
233  }
234  else if (rPropertyName == SC_UNONAME_TIME_BASED)
235  {
236  aReturn <<= false;
237  }
238  else if (rPropertyName == SC_UNONAME_HAS_STRING_LABEL)
239  {
240  aReturn <<= false;
241  }
242  else
243  throw beans::UnknownPropertyException(rPropertyName);
244  return aReturn;
245 }
246 
248  const OUString& /*rPropertyName*/,
249  const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/)
250 {
251  OSL_FAIL("Not yet implemented");
252 }
253 
255  const OUString& /*rPropertyName*/,
256  const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/)
257 {
258  OSL_FAIL("Not yet implemented");
259 }
260 
262  const OUString& /*rPropertyName*/,
263  const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
264 {
265  OSL_FAIL("Not yet implemented");
266 }
267 
269  const OUString& /*rPropertyName*/,
270  const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/)
271 {
272  OSL_FAIL("Not yet implemented");
273 }
274 
275 } // end sc namespace
276 
277 /* 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:683
virtual OUString SAL_CALL getSourceRangeRepresentation() override
#define SC_UNONAME_TIME_BASED
Definition: unonames.hxx:686
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:681
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
#define static
Definition: arraysum.hxx:27
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:685
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:898
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override
static const SfxItemPropertyMapEntry * lcl_GetDataSequencePropertyMap()
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:906
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:682