Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_INC_DPTABSRC_HXX
21 : #define INCLUDED_SC_INC_DPTABSRC_HXX
22 :
23 : #include "global.hxx"
24 : #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
25 : #include <com/sun/star/sheet/XHierarchiesSupplier.hpp>
26 : #include <com/sun/star/sheet/XLevelsSupplier.hpp>
27 : #include <com/sun/star/sheet/XMembersSupplier.hpp>
28 : #include <com/sun/star/sheet/XDataPilotResults.hpp>
29 : #include <com/sun/star/sheet/XDataPilotMemberResults.hpp>
30 : #include <com/sun/star/sheet/MemberResult.hpp>
31 : #include <com/sun/star/sheet/GeneralFunction.hpp>
32 : #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp>
33 : #include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp>
34 : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
35 : #include <com/sun/star/sheet/DataPilotFieldReference.hpp>
36 : #include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp>
37 : #include <com/sun/star/util/XRefreshable.hpp>
38 : #include <com/sun/star/sheet/XDrillDownDataSupplier.hpp>
39 : #include <com/sun/star/util/XCloneable.hpp>
40 : #include <com/sun/star/beans/XPropertySet.hpp>
41 : #include <com/sun/star/lang/XServiceInfo.hpp>
42 : #include <com/sun/star/container/XNamed.hpp>
43 : #include <cppuhelper/implbase2.hxx>
44 : #include <cppuhelper/implbase3.hxx>
45 : #include <cppuhelper/implbase5.hxx>
46 : #include <cppuhelper/implbase6.hxx>
47 : #include <rtl/ref.hxx>
48 :
49 : #include "dptabdat.hxx"
50 : #include "dpglobal.hxx"
51 : #include "dpresfilter.hxx"
52 :
53 : #include <boost/noncopyable.hpp>
54 : #include <boost/scoped_ptr.hpp>
55 : #include <list>
56 : #include <unordered_map>
57 : #include <unordered_set>
58 : #include <vector>
59 :
60 : namespace com { namespace sun { namespace star {
61 : namespace sheet {
62 : struct DataPilotFieldFilter;
63 : }
64 : namespace table {
65 : struct CellAddress;
66 : }
67 : }}}
68 :
69 : class ScDPResultMember;
70 : class ScDPResultData;
71 : class ScDPItemData;
72 : class ScDPTableData;
73 :
74 : // implementation of DataPilotSource using ScDPTableData
75 :
76 : class ScDPDimensions;
77 : class ScDPDimension;
78 : class ScDPHierarchies;
79 : class ScDPHierarchy;
80 : class ScDPLevels;
81 : class ScDPLevel;
82 : class ScDPMembers;
83 : class ScDPMember;
84 :
85 : class ScDPSource : public cppu::WeakImplHelper6<
86 : com::sun::star::sheet::XDimensionsSupplier,
87 : com::sun::star::sheet::XDataPilotResults,
88 : com::sun::star::util::XRefreshable,
89 : com::sun::star::sheet::XDrillDownDataSupplier,
90 : com::sun::star::beans::XPropertySet,
91 : com::sun::star::lang::XServiceInfo >
92 : {
93 : private:
94 : ScDPTableData* pData; // data source (ScDPObject manages its life time)
95 : ScDPDimensions* pDimensions; // api objects
96 : // settings:
97 :
98 : std::vector<long> maColDims;
99 : std::vector<long> maRowDims;
100 : std::vector<long> maDataDims;
101 : std::vector<long> maPageDims;
102 : ScDPResultTree maResFilterSet;
103 :
104 : bool bColumnGrand;
105 : bool bRowGrand;
106 : bool bIgnoreEmptyRows;
107 : bool bRepeatIfEmpty;
108 :
109 : long nDupCount;
110 :
111 : // results:
112 : ScDPResultData* pResData; // keep the rest in this!
113 : ScDPResultMember* pColResRoot;
114 : ScDPResultMember* pRowResRoot;
115 : com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>* pColResults;
116 : com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>* pRowResults;
117 : std::vector<ScDPLevel*> aColLevelList;
118 : std::vector<ScDPLevel*> aRowLevelList;
119 : bool bResultOverflow;
120 : bool bPageFiltered; // set if page field filters have been applied to cache table
121 :
122 : ::std::unique_ptr<OUString> mpGrandTotalName;
123 :
124 : void CreateRes_Impl();
125 : void FillMemberResults();
126 : void FillLevelList( sal_uInt16 nOrientation, std::vector<ScDPLevel*> &rList );
127 : void FillCalcInfo(bool bIsRow, ScDPTableData::CalcInfo& rInfo, bool &bHasAutoShow);
128 :
129 : /**
130 : * Compile a list of dimension indices that are either, column, row or
131 : * page dimensions (i.e. all but data dimensions).
132 : */
133 : void GetCategoryDimensionIndices(std::unordered_set<sal_Int32>& rCatDims);
134 :
135 : /**
136 : * Set visibilities of individual rows in the cache table based on the
137 : * page field data.
138 : */
139 : void FilterCacheByPageDimensions();
140 :
141 : void SetDupCount( long nNew );
142 :
143 : OUString getDataDescription(); //! ???
144 :
145 : void setIgnoreEmptyRows(bool bSet);
146 : void setRepeatIfEmpty(bool bSet);
147 :
148 : void disposeData();
149 :
150 : public:
151 : ScDPSource( ScDPTableData* pD );
152 : virtual ~ScDPSource();
153 :
154 46385 : ScDPTableData* GetData() { return pData; }
155 2188 : const ScDPTableData* GetData() const { return pData; }
156 :
157 : const OUString* GetGrandTotalName() const;
158 :
159 : sal_uInt16 GetOrientation(long nColumn);
160 : void SetOrientation(long nColumn, sal_uInt16 nNew);
161 : long GetPosition(long nColumn);
162 :
163 : long GetDataDimensionCount();
164 : ScDPDimension* GetDataDimension(long nIndex);
165 : OUString GetDataDimName(long nIndex);
166 : const ScDPCache* GetCache();
167 : const ScDPItemData* GetItemDataById( long nDim, long nId );
168 : long GetDataLayoutDim(){ return pData->GetColumnCount(); }
169 : SCROW GetMemberId( long nDim, const ScDPItemData& rData );
170 : bool IsDataLayoutDimension(long nDim);
171 : sal_uInt16 GetDataLayoutOrientation();
172 :
173 : bool IsDateDimension(long nDim);
174 :
175 : bool SubTotalAllowed(long nColumn); //! move to ScDPResultData
176 :
177 : ScDPDimension* AddDuplicated(long nSource, const OUString& rNewName);
178 136 : long GetDupCount() const { return nDupCount; }
179 :
180 : long GetSourceDim(long nDim);
181 :
182 : const com::sun::star::uno::Sequence<com::sun::star::sheet::MemberResult>*
183 : GetMemberResults( ScDPLevel* pLevel );
184 :
185 : ScDPDimensions* GetDimensionsObject();
186 :
187 : // XDimensionsSupplier
188 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
189 : SAL_CALL getDimensions( )
190 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
191 :
192 : // XDataPilotResults
193 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence<
194 : ::com::sun::star::sheet::DataResult > > SAL_CALL getResults( )
195 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
196 :
197 : virtual com::sun::star::uno::Sequence<double> SAL_CALL
198 : getFilteredResults(
199 : const com::sun::star::uno::Sequence<com::sun::star::sheet::DataPilotFieldFilter>& aFilters )
200 : throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
201 :
202 : // XRefreshable
203 : virtual void SAL_CALL refresh() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
204 : virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
205 : ::com::sun::star::util::XRefreshListener >& l )
206 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
207 : virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
208 : ::com::sun::star::util::XRefreshListener >& l )
209 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
210 :
211 : // XDrillDownDataSupplier
212 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >
213 : SAL_CALL getDrillDownData(const ::com::sun::star::uno::Sequence<
214 : ::com::sun::star::sheet::DataPilotFieldFilter >& aFilters )
215 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
216 :
217 : // XPropertySet
218 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
219 : SAL_CALL getPropertySetInfo( )
220 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
221 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
222 : const ::com::sun::star::uno::Any& aValue )
223 : throw(::com::sun::star::beans::UnknownPropertyException,
224 : ::com::sun::star::beans::PropertyVetoException,
225 : ::com::sun::star::lang::IllegalArgumentException,
226 : ::com::sun::star::lang::WrappedTargetException,
227 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
228 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
229 : const OUString& PropertyName )
230 : throw(::com::sun::star::beans::UnknownPropertyException,
231 : ::com::sun::star::lang::WrappedTargetException,
232 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
233 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
234 : const ::com::sun::star::uno::Reference<
235 : ::com::sun::star::beans::XPropertyChangeListener >& xListener )
236 : throw(::com::sun::star::beans::UnknownPropertyException,
237 : ::com::sun::star::lang::WrappedTargetException,
238 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
239 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
240 : const ::com::sun::star::uno::Reference<
241 : ::com::sun::star::beans::XPropertyChangeListener >& aListener )
242 : throw(::com::sun::star::beans::UnknownPropertyException,
243 : ::com::sun::star::lang::WrappedTargetException,
244 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
245 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
246 : const ::com::sun::star::uno::Reference<
247 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
248 : throw(::com::sun::star::beans::UnknownPropertyException,
249 : ::com::sun::star::lang::WrappedTargetException,
250 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
251 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
252 : const ::com::sun::star::uno::Reference<
253 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
254 : throw(::com::sun::star::beans::UnknownPropertyException,
255 : ::com::sun::star::lang::WrappedTargetException,
256 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
257 :
258 : // XServiceInfo
259 : virtual OUString SAL_CALL getImplementationName( )
260 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
261 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
262 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
264 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
265 :
266 : #if DEBUG_PIVOT_TABLE
267 : void DumpResults() const;
268 : #endif
269 : };
270 :
271 : class ScDPDimensions : public cppu::WeakImplHelper2<
272 : com::sun::star::container::XNameAccess,
273 : com::sun::star::lang::XServiceInfo >
274 : {
275 : private:
276 : ScDPSource* pSource;
277 : long nDimCount;
278 : ScDPDimension** ppDims;
279 :
280 : public:
281 : ScDPDimensions( ScDPSource* pSrc );
282 : virtual ~ScDPDimensions();
283 :
284 : void CountChanged();
285 :
286 : // XNameAccess
287 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
288 : throw(::com::sun::star::container::NoSuchElementException,
289 : ::com::sun::star::lang::WrappedTargetException,
290 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
291 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames()
292 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
293 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
294 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
295 :
296 : // XElementAccess
297 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
298 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
299 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
300 :
301 : // XServiceInfo
302 : virtual OUString SAL_CALL getImplementationName( )
303 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
304 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
305 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
306 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
307 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
308 :
309 : long getCount() const;
310 : ScDPDimension* getByIndex(long nIndex) const;
311 : };
312 :
313 : class ScDPDimension : boost::noncopyable, public cppu::WeakImplHelper5<
314 : com::sun::star::sheet::XHierarchiesSupplier,
315 : com::sun::star::container::XNamed,
316 : com::sun::star::util::XCloneable,
317 : com::sun::star::beans::XPropertySet,
318 : com::sun::star::lang::XServiceInfo >
319 : {
320 : ScDPSource* pSource;
321 : long nDim; // dimension index (== column ID)
322 : ScDPHierarchies* pHierarchies;
323 : long nUsedHier;
324 : sal_uInt16 nFunction; // enum GeneralFunction
325 : OUString aName; // if empty, take from source
326 : boost::scoped_ptr<OUString> mpLayoutName;
327 : boost::scoped_ptr<OUString> mpSubtotalName;
328 : long nSourceDim; // >=0 if dup'ed
329 : ::com::sun::star::sheet::DataPilotFieldReference
330 : aReferenceValue; // settings for "show data as" / "displayed value"
331 : bool bHasSelectedPage;
332 : OUString aSelectedPage;
333 : ScDPItemData* pSelectedData; // internal, temporary, created from aSelectedPage
334 : bool mbHasHiddenMember;
335 :
336 : public:
337 : ScDPDimension( ScDPSource* pSrc, long nD );
338 : virtual ~ScDPDimension();
339 :
340 3381 : long GetDimension() const { return nDim; } // dimension index in source
341 126 : long GetSourceDim() const { return nSourceDim; } // >=0 if dup'ed
342 :
343 : ScDPDimension* CreateCloneObject();
344 : ScDPHierarchies* GetHierarchiesObject();
345 :
346 : SC_DLLPUBLIC const OUString* GetLayoutName() const;
347 : const OUString* GetSubtotalName() const;
348 :
349 : // XNamed
350 : virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
351 : virtual void SAL_CALL setName( const OUString& aName )
352 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
353 :
354 : // XHierarchiesSupplier
355 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
356 : getHierarchies() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
357 :
358 : // XCloneable
359 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL
360 : createClone() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
361 :
362 : // XPropertySet
363 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
364 : SAL_CALL getPropertySetInfo( )
365 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
366 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
367 : const ::com::sun::star::uno::Any& aValue )
368 : throw(::com::sun::star::beans::UnknownPropertyException,
369 : ::com::sun::star::beans::PropertyVetoException,
370 : ::com::sun::star::lang::IllegalArgumentException,
371 : ::com::sun::star::lang::WrappedTargetException,
372 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
373 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
374 : const OUString& PropertyName )
375 : throw(::com::sun::star::beans::UnknownPropertyException,
376 : ::com::sun::star::lang::WrappedTargetException,
377 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
378 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
379 : const ::com::sun::star::uno::Reference<
380 : ::com::sun::star::beans::XPropertyChangeListener >& xListener )
381 : throw(::com::sun::star::beans::UnknownPropertyException,
382 : ::com::sun::star::lang::WrappedTargetException,
383 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
384 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
385 : const ::com::sun::star::uno::Reference<
386 : ::com::sun::star::beans::XPropertyChangeListener >& aListener )
387 : throw(::com::sun::star::beans::UnknownPropertyException,
388 : ::com::sun::star::lang::WrappedTargetException,
389 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
390 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
391 : const ::com::sun::star::uno::Reference<
392 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
393 : throw(::com::sun::star::beans::UnknownPropertyException,
394 : ::com::sun::star::lang::WrappedTargetException,
395 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
396 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
397 : const ::com::sun::star::uno::Reference<
398 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
399 : throw(::com::sun::star::beans::UnknownPropertyException,
400 : ::com::sun::star::lang::WrappedTargetException,
401 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
402 :
403 : // XServiceInfo
404 : virtual OUString SAL_CALL getImplementationName( )
405 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
406 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
407 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
408 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
409 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
410 :
411 : sal_uInt16 getOrientation() const;
412 : void setOrientation(sal_uInt16 nNew);
413 : long getPosition() const;
414 : bool getIsDataLayoutDimension() const;
415 1053 : sal_uInt16 getFunction() const { return nFunction;}
416 : void setFunction(sal_uInt16 nNew); // for data dimension
417 789 : long getUsedHierarchy() const { return nUsedHier;}
418 :
419 54 : bool HasSelectedPage() const { return bHasSelectedPage; }
420 : const ScDPItemData& GetSelectedData();
421 :
422 89 : const ::com::sun::star::sheet::DataPilotFieldReference& GetReferenceValue() const { return aReferenceValue;}
423 : };
424 :
425 : class ScDPHierarchies : public cppu::WeakImplHelper2<
426 : com::sun::star::container::XNameAccess,
427 : com::sun::star::lang::XServiceInfo >
428 : {
429 : private:
430 : ScDPSource* pSource;
431 : long nDim;
432 : long nHierCount;
433 : ScDPHierarchy** ppHiers;
434 :
435 : public:
436 : ScDPHierarchies( ScDPSource* pSrc, long nD );
437 : virtual ~ScDPHierarchies();
438 :
439 : // XNameAccess
440 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
441 : throw(::com::sun::star::container::NoSuchElementException,
442 : ::com::sun::star::lang::WrappedTargetException,
443 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
444 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames()
445 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
446 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
447 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
448 :
449 : // XElementAccess
450 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
451 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
452 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
453 :
454 : // XServiceInfo
455 : virtual OUString SAL_CALL getImplementationName( )
456 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
457 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
458 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
459 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
460 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
461 :
462 : long getCount() const;
463 : ScDPHierarchy* getByIndex(long nIndex) const;
464 : };
465 :
466 : class ScDPHierarchy : public cppu::WeakImplHelper3<
467 : com::sun::star::sheet::XLevelsSupplier,
468 : com::sun::star::container::XNamed,
469 : com::sun::star::lang::XServiceInfo >
470 : {
471 : private:
472 : ScDPSource* pSource;
473 : long nDim;
474 : long nHier;
475 : ScDPLevels* pLevels;
476 :
477 : public:
478 : ScDPHierarchy( ScDPSource* pSrc, long nD, long nH );
479 : virtual ~ScDPHierarchy();
480 :
481 : ScDPLevels* GetLevelsObject();
482 :
483 : // XNamed
484 : virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
485 : virtual void SAL_CALL setName( const OUString& aName )
486 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
487 :
488 : // XLevelsSupplier
489 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
490 : getLevels() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
491 :
492 : // XServiceInfo
493 : virtual OUString SAL_CALL getImplementationName( )
494 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
495 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
496 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
497 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
498 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
499 : };
500 :
501 : class ScDPLevels : public cppu::WeakImplHelper2<
502 : com::sun::star::container::XNameAccess,
503 : com::sun::star::lang::XServiceInfo >
504 : {
505 : private:
506 : ScDPSource* pSource;
507 : long nDim;
508 : long nHier;
509 : long nLevCount;
510 : ScDPLevel** ppLevs;
511 :
512 : public:
513 : ScDPLevels( ScDPSource* pSrc, long nD, long nH );
514 : virtual ~ScDPLevels();
515 :
516 : // XNameAccess
517 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
518 : throw(::com::sun::star::container::NoSuchElementException,
519 : ::com::sun::star::lang::WrappedTargetException,
520 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
521 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames()
522 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
523 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
524 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
525 :
526 : // XElementAccess
527 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
528 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
529 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
530 :
531 : // XServiceInfo
532 : virtual OUString SAL_CALL getImplementationName( )
533 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
534 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
535 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
536 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
537 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
538 :
539 : long getCount() const;
540 : ScDPLevel* getByIndex(long nIndex) const;
541 : };
542 :
543 : class ScDPLevel : public cppu::WeakImplHelper5<
544 : com::sun::star::sheet::XMembersSupplier,
545 : com::sun::star::container::XNamed,
546 : com::sun::star::sheet::XDataPilotMemberResults,
547 : com::sun::star::beans::XPropertySet,
548 : com::sun::star::lang::XServiceInfo >
549 : {
550 : private:
551 : ScDPSource* pSource;
552 : long nDim;
553 : long nHier;
554 : long nLev;
555 : ScDPMembers* pMembers;
556 : com::sun::star::uno::Sequence<com::sun::star::sheet::GeneralFunction> aSubTotals;
557 : ::com::sun::star::sheet::DataPilotFieldSortInfo aSortInfo; // stored user settings
558 : ::com::sun::star::sheet::DataPilotFieldAutoShowInfo aAutoShowInfo; // stored user settings
559 : ::com::sun::star::sheet::DataPilotFieldLayoutInfo aLayoutInfo; // stored user settings
560 : // valid only from result calculation:
561 : ::std::vector<sal_Int32> aGlobalOrder; // result of sorting by name or position
562 : long nSortMeasure; // measure (index of data dimension) to sort by
563 : long nAutoMeasure; // measure (index of data dimension) for AutoShow
564 : bool bShowEmpty:1;
565 : bool bEnableLayout:1; // enabled only for row fields, not for the innermost one
566 : bool bRepeatItemLabels:1;
567 :
568 : public:
569 : ScDPLevel( ScDPSource* pSrc, long nD, long nH, long nL );
570 : virtual ~ScDPLevel();
571 :
572 : ScDPMembers* GetMembersObject();
573 :
574 : // XNamed
575 : virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
576 : virtual void SAL_CALL setName( const OUString& aName )
577 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
578 :
579 : // XMembersSupplier
580 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL
581 : getMembers() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
582 :
583 : // XDataPilotMemberResults
584 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::MemberResult > SAL_CALL
585 : getResults() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
586 :
587 : // XPropertySet
588 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
589 : SAL_CALL getPropertySetInfo( )
590 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
591 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
592 : const ::com::sun::star::uno::Any& aValue )
593 : throw(::com::sun::star::beans::UnknownPropertyException,
594 : ::com::sun::star::beans::PropertyVetoException,
595 : ::com::sun::star::lang::IllegalArgumentException,
596 : ::com::sun::star::lang::WrappedTargetException,
597 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
598 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
599 : const OUString& PropertyName )
600 : throw(::com::sun::star::beans::UnknownPropertyException,
601 : ::com::sun::star::lang::WrappedTargetException,
602 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
603 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
604 : const ::com::sun::star::uno::Reference<
605 : ::com::sun::star::beans::XPropertyChangeListener >& xListener )
606 : throw(::com::sun::star::beans::UnknownPropertyException,
607 : ::com::sun::star::lang::WrappedTargetException,
608 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
609 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
610 : const ::com::sun::star::uno::Reference<
611 : ::com::sun::star::beans::XPropertyChangeListener >& aListener )
612 : throw(::com::sun::star::beans::UnknownPropertyException,
613 : ::com::sun::star::lang::WrappedTargetException,
614 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
615 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
616 : const ::com::sun::star::uno::Reference<
617 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
618 : throw(::com::sun::star::beans::UnknownPropertyException,
619 : ::com::sun::star::lang::WrappedTargetException,
620 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
621 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
622 : const ::com::sun::star::uno::Reference<
623 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
624 : throw(::com::sun::star::beans::UnknownPropertyException,
625 : ::com::sun::star::lang::WrappedTargetException,
626 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
627 :
628 : // XServiceInfo
629 : virtual OUString SAL_CALL getImplementationName( )
630 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
631 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
632 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
633 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
634 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
635 :
636 : com::sun::star::uno::Sequence<com::sun::star::sheet::GeneralFunction> getSubTotals() const;
637 931 : bool getShowEmpty() const { return bShowEmpty;}
638 590 : bool getRepeatItemLabels() const { return bRepeatItemLabels; }
639 :
640 201 : const ::com::sun::star::sheet::DataPilotFieldSortInfo& GetSortInfo() const { return aSortInfo; }
641 346 : const ::com::sun::star::sheet::DataPilotFieldAutoShowInfo& GetAutoShow() const { return aAutoShowInfo; }
642 :
643 : void EvaluateSortOrder();
644 : void SetEnableLayout(bool bSet);
645 :
646 : const ::std::vector<sal_Int32>& GetGlobalOrder() const { return aGlobalOrder; }
647 430 : ::std::vector<sal_Int32>& GetGlobalOrder() { return aGlobalOrder; }
648 0 : long GetSortMeasure() const { return nSortMeasure; }
649 1 : long GetAutoMeasure() const { return nAutoMeasure; }
650 :
651 2939 : bool IsOutlineLayout() const
652 : {
653 3534 : return bEnableLayout &&
654 595 : aLayoutInfo.LayoutMode !=
655 2939 : ::com::sun::star::sheet::DataPilotFieldLayoutMode::TABULAR_LAYOUT;
656 : }
657 :
658 0 : bool IsSubtotalsAtTop() const
659 : {
660 0 : return bEnableLayout &&
661 0 : aLayoutInfo.LayoutMode ==
662 0 : ::com::sun::star::sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
663 : }
664 :
665 6472 : bool IsAddEmpty() const
666 : {
667 6472 : return bEnableLayout && aLayoutInfo.AddEmptyLines;
668 : }
669 :
670 : //! number format (for data fields and date fields)
671 : };
672 :
673 : // hash map from name to index in the member array, for fast name access
674 : typedef std::unordered_map< OUString, sal_Int32, OUStringHash > ScDPMembersHashMap;
675 :
676 : class ScDPMembers : public cppu::WeakImplHelper2<
677 : com::sun::star::container::XNameAccess,
678 : com::sun::star::lang::XServiceInfo >
679 : {
680 : private:
681 : typedef std::vector<rtl::Reference<ScDPMember> > MembersType;
682 : ScDPSource* pSource;
683 : long nDim;
684 : long nHier;
685 : long nLev;
686 : long nMbrCount;
687 : mutable MembersType maMembers;
688 : mutable ScDPMembersHashMap aHashMap;
689 :
690 : public:
691 : ScDPMembers( ScDPSource* pSrc, long nD, long nH, long nL );
692 : virtual ~ScDPMembers();
693 :
694 : // XNameAccess
695 : virtual ::com::sun::star::uno::Any SAL_CALL getByName( const OUString& aName )
696 : throw(::com::sun::star::container::NoSuchElementException,
697 : ::com::sun::star::lang::WrappedTargetException,
698 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
699 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames()
700 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
701 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName )
702 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
703 :
704 : // XElementAccess
705 : virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
706 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
707 : virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
708 :
709 : // XServiceInfo
710 : virtual OUString SAL_CALL getImplementationName( )
711 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
712 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
713 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
714 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
715 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
716 :
717 1366 : long getCount() const { return nMbrCount;}
718 : ScDPMember* getByIndex(long nIndex) const;
719 :
720 : long getMinMembers() const;
721 :
722 : sal_Int32 GetIndexFromName( const OUString& rName ) const; // <0 if not found
723 : const std::vector<sal_Int32>& GetGlobalOrder();
724 : const ScDPItemData* GetSrcItemDataByIndex( SCROW nIndex);
725 : SCROW GetSrcItemsCount();
726 : };
727 :
728 : class ScDPMember : boost::noncopyable, public cppu::WeakImplHelper3<
729 : com::sun::star::container::XNamed,
730 : com::sun::star::beans::XPropertySet,
731 : com::sun::star::lang::XServiceInfo >
732 : {
733 : private:
734 : ScDPSource* pSource;
735 : long nDim;
736 : long nHier;
737 : long nLev;
738 :
739 : SCROW mnDataId;
740 : boost::scoped_ptr<OUString> mpLayoutName;
741 :
742 : sal_Int32 nPosition; // manual sorting
743 : bool bVisible;
744 : bool bShowDet;
745 :
746 : public:
747 : ScDPMember(ScDPSource* pSrc, long nD, long nH, long nL, SCROW nIndex);
748 : virtual ~ScDPMember();
749 :
750 : OUString GetNameStr() const;
751 : void FillItemData( ScDPItemData& rData ) const;
752 : const ScDPItemData* GetItemData() const;
753 4733 : SCROW GetItemDataId() const { return mnDataId; }
754 : bool IsNamedItem(SCROW nIndex) const;
755 :
756 : SC_DLLPUBLIC const OUString* GetLayoutName() const;
757 0 : long GetDim() const { return nDim;}
758 :
759 : sal_Int32 Compare( const ScDPMember& rOther ) const; // visible order
760 :
761 : // XNamed
762 : virtual OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
763 : virtual void SAL_CALL setName( const OUString& aName )
764 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
765 :
766 : // XPropertySet
767 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
768 : SAL_CALL getPropertySetInfo( )
769 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
770 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
771 : const ::com::sun::star::uno::Any& aValue )
772 : throw(::com::sun::star::beans::UnknownPropertyException,
773 : ::com::sun::star::beans::PropertyVetoException,
774 : ::com::sun::star::lang::IllegalArgumentException,
775 : ::com::sun::star::lang::WrappedTargetException,
776 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
777 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
778 : const OUString& PropertyName )
779 : throw(::com::sun::star::beans::UnknownPropertyException,
780 : ::com::sun::star::lang::WrappedTargetException,
781 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
782 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
783 : const ::com::sun::star::uno::Reference<
784 : ::com::sun::star::beans::XPropertyChangeListener >& xListener )
785 : throw(::com::sun::star::beans::UnknownPropertyException,
786 : ::com::sun::star::lang::WrappedTargetException,
787 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
788 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
789 : const ::com::sun::star::uno::Reference<
790 : ::com::sun::star::beans::XPropertyChangeListener >& aListener )
791 : throw(::com::sun::star::beans::UnknownPropertyException,
792 : ::com::sun::star::lang::WrappedTargetException,
793 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
794 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
795 : const ::com::sun::star::uno::Reference<
796 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
797 : throw(::com::sun::star::beans::UnknownPropertyException,
798 : ::com::sun::star::lang::WrappedTargetException,
799 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
800 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
801 : const ::com::sun::star::uno::Reference<
802 : ::com::sun::star::beans::XVetoableChangeListener >& aListener )
803 : throw(::com::sun::star::beans::UnknownPropertyException,
804 : ::com::sun::star::lang::WrappedTargetException,
805 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
806 :
807 : // XServiceInfo
808 : virtual OUString SAL_CALL getImplementationName( )
809 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
810 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
811 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
812 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
813 : throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
814 :
815 16185 : bool isVisible() const { return bVisible;}
816 1416 : bool getShowDetails() const { return bShowDet;}
817 : };
818 :
819 : #endif
820 :
821 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|