LibreOffice Module sc (master)  1
PivotTableDataProvider.hxx
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 #ifndef INCLUDED_SC_INC_PIVOTTABLEDATAPROVIDER_HXX
11 #define INCLUDED_SC_INC_PIVOTTABLEDATAPROVIDER_HXX
12 
13 #include <com/sun/star/chart2/data/XDataProvider.hpp>
14 #include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
15 #include <com/sun/star/chart2/data/PivotTableFieldEntry.hpp>
16 #include <com/sun/star/lang/XServiceInfo.hpp>
17 #include <com/sun/star/beans/XPropertySet.hpp>
18 #include <com/sun/star/util/XModifyBroadcaster.hpp>
19 
20 #include <svl/lstner.hxx>
21 #include <cppuhelper/implbase.hxx>
22 #include <rtl/ustring.hxx>
23 #include <svl/itemprop.hxx>
24 
25 #include <vector>
26 #include <unordered_map>
27 
28 namespace com::sun::star::chart2::data { class XDataSequence; }
29 namespace com::sun::star::chart2::data { class XDataSource; }
30 namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
31 namespace com::sun::star::uno { class XComponentContext; }
32 
33 class ScDocument;
34 
35 namespace sc
36 {
37 
39 
40 typedef cppu::WeakImplHelper<css::chart2::data::XDataProvider,
41  css::chart2::data::XPivotTableDataProvider,
42  css::beans::XPropertySet,
43  css::lang::XServiceInfo,
44  css::util::XModifyBroadcaster>
46 
47 class PivotTableDataProvider final : public PivotTableDataProvider_Base, public SfxListener
48 {
49 public:
50 
51  explicit PivotTableDataProvider(ScDocument* pDoc);
52  virtual ~PivotTableDataProvider() override;
53  virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
54 
55  // XDataProvider
56  virtual sal_Bool SAL_CALL
57  createDataSourcePossible(const css::uno::Sequence<css::beans::PropertyValue>& aArguments) override;
58 
59  virtual css::uno::Reference<css::chart2::data::XDataSource> SAL_CALL
60  createDataSource(const css::uno::Sequence<css::beans::PropertyValue>& aArguments) override;
61 
62  virtual css::uno::Sequence<css::beans::PropertyValue> SAL_CALL
63  detectArguments(const css::uno::Reference<css::chart2::data::XDataSource>& xDataSource) override;
64 
65  virtual sal_Bool SAL_CALL
66  createDataSequenceByRangeRepresentationPossible(const OUString& aRangeRepresentation) override;
67 
68  virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
69  createDataSequenceByRangeRepresentation(const OUString& aRangeRepresentation) override;
70 
71  virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
72  createDataSequenceByValueArray(const OUString& aRole, const OUString& aRangeRepresentation) override;
73 
74  virtual css::uno::Reference<css::sheet::XRangeSelection> SAL_CALL getRangeSelection() override;
75 
76  // XPivotTableDataProvider
77  virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL
78  getColumnFields() override;
79  virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL
80  getRowFields() override;
81  virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL
82  getPageFields() override;
83  virtual css::uno::Sequence<css::chart2::data::PivotTableFieldEntry> SAL_CALL
84  getDataFields() override;
85 
86  virtual OUString SAL_CALL getPivotTableName() override;
87 
88  virtual void SAL_CALL setPivotTableName(const OUString& sPivotTableName) override;
89 
90  virtual sal_Bool SAL_CALL hasPivotTable() override;
91 
92  virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
93  createDataSequenceOfValuesByIndex(sal_Int32 nIndex) override;
94  virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
95  createDataSequenceOfLabelsByIndex(sal_Int32 nIndex) override;
96  virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
98 
99  virtual OUString SAL_CALL getFieldOutputDescription(sal_Int32 nPageFieldIndex) override;
100 
101  // XPropertySet
102  virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
103 
104  virtual void SAL_CALL
105  setPropertyValue(const OUString& rPropertyName, const css::uno::Any& rValue) override;
106 
107  virtual css::uno::Any SAL_CALL
108  getPropertyValue(const OUString& rPropertyName) override;
109 
110  virtual void SAL_CALL addPropertyChangeListener(
111  const OUString& rPropertyName,
112  const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
113 
114  virtual void SAL_CALL removePropertyChangeListener(
115  const OUString& rPropertyName,
116  const css::uno::Reference<css::beans::XPropertyChangeListener>& rListener) override;
117 
118  virtual void SAL_CALL addVetoableChangeListener(
119  const OUString& rPropertyName,
120  const css::uno::Reference<css::beans::XVetoableChangeListener>& rListener) override;
121 
122  virtual void SAL_CALL removeVetoableChangeListener(
123  const OUString& rPropertyName,
124  const css::uno::Reference<css::beans::XVetoableChangeListener>& rListener) override;
125 
126  // XModifyBroadcaster
127  virtual void SAL_CALL
128  addModifyListener(const css::uno::Reference<css::util::XModifyListener>& aListener) override;
129 
130  virtual void SAL_CALL
131  removeModifyListener(const css::uno::Reference<css::util::XModifyListener>& aListener) override;
132 
133  // XServiceInfo
134  virtual OUString SAL_CALL getImplementationName() override;
135 
136  virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
137 
138  virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
139 
140 private:
141 
142  css::uno::Reference<css::chart2::data::XDataSource>
144 
145  css::uno::Reference<css::chart2::data::XDataSource>
146  createCategoriesDataSource(bool bOrientationIsColumn);
147 
148  css::uno::Reference<css::chart2::data::XLabeledDataSequence> newLabeledDataSequence();
149 
150  css::uno::Reference<css::chart2::data::XDataSequence> assignLabelsToDataSequence(size_t nIndex);
151 
152  css::uno::Reference<css::chart2::data::XDataSequence> assignValuesToDataSequence(size_t nIndex);
153 
154  css::uno::Reference<css::chart2::data::XDataSequence> assignFirstCategoriesToDataSequence();
155 
156  void collectPivotTableData();
157 
162 
163  std::vector<std::vector<ValueAndFormat>> m_aCategoriesColumnOrientation;
164  std::vector<std::vector<ValueAndFormat>> m_aCategoriesRowOrientation;
165  std::vector<std::vector<ValueAndFormat>> m_aLabels;
166  std::vector<std::vector<ValueAndFormat>> m_aDataRowVector;
167 
168  std::vector<css::chart2::data::PivotTableFieldEntry> m_aColumnFields;
169  std::vector<css::chart2::data::PivotTableFieldEntry> m_aRowFields;
170  std::vector<css::chart2::data::PivotTableFieldEntry> m_aPageFields;
171  std::vector<css::chart2::data::PivotTableFieldEntry> m_aDataFields;
172 
173  std::unordered_map<sal_Int32, OUString> m_aFieldOutputDescriptionMap;
174 
176 
177  css::uno::Reference<css::uno::XComponentContext> m_xContext;
178 
179  std::vector<css::uno::Reference<css::util::XModifyListener>> m_aValueListeners;
180 };
181 
182 }
183 
184 #endif // INCLUDED_SC_INC_PIVOTTABLEDATAPROVIDER_HXX
185 
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL addPropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
sal_Int32 nIndex
virtual css::uno::Sequence< css::chart2::data::PivotTableFieldEntry > SAL_CALL getPageFields() override
virtual OUString SAL_CALL getPivotTableName() override
virtual css::uno::Sequence< css::chart2::data::PivotTableFieldEntry > SAL_CALL getColumnFields() override
virtual sal_Bool SAL_CALL hasPivotTable() override
std::unordered_map< sal_Int32, OUString > m_aFieldOutputDescriptionMap
virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL createDataSource(const css::uno::Sequence< css::beans::PropertyValue > &aArguments) override
std::vector< css::chart2::data::PivotTableFieldEntry > m_aColumnFields
std::vector< css::chart2::data::PivotTableFieldEntry > m_aRowFields
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override
css::uno::Reference< css::chart2::data::XDataSequence > assignValuesToDataSequence(size_t nIndex)
css::uno::Any const & rValue
Sequence< PropertyValue > aArguments
virtual ~PivotTableDataProvider() override
std::vector< css::chart2::data::PivotTableFieldEntry > m_aPageFields
std::vector< css::chart2::data::PivotTableFieldEntry > m_aDataFields
virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceOfLabelsByIndex(sal_Int32 nIndex) override
virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByValueArray(const OUString &aRole, const OUString &aRangeRepresentation) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &rListener) override
std::vector< std::vector< ValueAndFormat > > m_aCategoriesColumnOrientation
css::uno::Reference< css::chart2::data::XDataSequence > assignFirstCategoriesToDataSequence()
std::vector< std::vector< ValueAndFormat > > m_aLabels
virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(const OUString &aRangeRepresentation) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
css::uno::Reference< css::chart2::data::XDataSequence > assignLabelsToDataSequence(size_t nIndex)
virtual void SAL_CALL setPivotTableName(const OUString &sPivotTableName) override
css::uno::Reference< css::chart2::data::XDataSource > createCategoriesDataSource(bool bOrientationIsColumn)
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual OUString SAL_CALL getFieldOutputDescription(sal_Int32 nPageFieldIndex) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &rPropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &rListener) override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL detectArguments(const css::uno::Reference< css::chart2::data::XDataSource > &xDataSource) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &rPropertyName) override
unsigned char sal_Bool
virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceOfCategories() override
std::vector< css::uno::Reference< css::util::XModifyListener > > m_aValueListeners
std::vector< std::vector< ValueAndFormat > > m_aCategoriesRowOrientation
virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(const OUString &aRangeRepresentation) override
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
virtual void SAL_CALL setPropertyValue(const OUString &rPropertyName, const css::uno::Any &rValue) override
virtual css::uno::Sequence< css::chart2::data::PivotTableFieldEntry > SAL_CALL getDataFields() override
cppu::WeakImplHelper< css::chart2::data::XDataProvider, css::chart2::data::XPivotTableDataProvider, css::beans::XPropertySet, css::lang::XServiceInfo, css::util::XModifyBroadcaster > PivotTableDataProvider_Base
std::vector< std::vector< ValueAndFormat > > m_aDataRowVector
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceOfValuesByIndex(sal_Int32 nIndex) override
css::uno::Reference< css::chart2::data::XLabeledDataSequence > newLabeledDataSequence()
css::uno::Reference< css::chart2::data::XDataSource > createValuesDataSource()
virtual sal_Bool SAL_CALL createDataSourcePossible(const css::uno::Sequence< css::beans::PropertyValue > &aArguments) override
virtual css::uno::Sequence< css::chart2::data::PivotTableFieldEntry > SAL_CALL getRowFields() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override