1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_DPOBJECT_HXX
21 #define SC_DPOBJECT_HXX
25 #include "address.hxx"
26 #include "dpoutput.hxx"
27 #include "dptypes.hxx"
29 #include "dpmacros.hxx"
31 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
36 #include <boost/ptr_container/ptr_list.hpp>
37 #include <boost/ptr_container/ptr_vector.hpp>
38 #include <boost/ptr_container/ptr_map.hpp>
39 #include <boost/shared_ptr.hpp>
41 namespace com
{ namespace sun
{ namespace star
{
52 struct DataPilotTablePositionData
;
53 struct DataPilotTableHeaderData
;
54 struct DataPilotFieldFilter
;
62 struct ScImportSourceDesc
;
63 class ScSheetSourceDesc
;
66 class ScDPDimensionSaveData
;
69 struct ScDPServiceDesc
71 OUString aServiceName
;
77 ScDPServiceDesc( const OUString
& rServ
, const OUString
& rSrc
, const OUString
& rNam
,
78 const OUString
& rUser
, const OUString
& rPass
);
80 bool operator== ( const ScDPServiceDesc
& rOther
) const;
84 class SC_DLLPUBLIC ScDPObject
89 ScDPSaveData
* pSaveData
;
93 ScSheetSourceDesc
* pSheetDesc
; // for sheet data
94 ScImportSourceDesc
* pImpDesc
; // for database data
95 ScDPServiceDesc
* pServDesc
; // for external service
96 ::boost::shared_ptr
<ScDPTableData
> mpTableData
;
98 com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
> xSource
;
100 sal_uInt16 mnAutoFormatIndex
;
101 long nHeaderRows
; // page fields plus filter button
102 bool mbHeaderLayout
:1; // true : grid, false : standard
104 bool bSettingsChanged
:1;
105 bool mbEnableGetPivotData
:1;
107 SC_DLLPRIVATE ScDPTableData
* GetTableData();
108 SC_DLLPRIVATE
void CreateObjects();
109 SC_DLLPRIVATE
void CreateOutput();
110 SC_DLLPRIVATE
void ClearSource();
111 SC_DLLPRIVATE
bool FillLabelDataForDimension(
112 const com::sun::star::uno::Reference
<
113 com::sun::star::container::XIndexAccess
>& xDims
,
114 sal_Int32 nDim
, ScDPLabelData
& rLabelData
);
117 ScDPObject(ScDocument
* pD
);
118 ScDPObject(const ScDPObject
& r
);
121 ScDPObject
& operator= (const ScDPObject
& r
);
123 void EnableGetPivotData(bool b
);
125 void SetAllowMove(bool bSet
);
127 void InvalidateData();
129 void ClearTableData();
130 void ReloadGroupTableData();
132 void Output( const ScAddress
& rPos
);
133 ScRange
GetNewOutputRange( bool& rOverflow
);
134 const ScRange
GetOutputRangeByType( sal_Int32 nType
);
136 void SetSaveData(const ScDPSaveData
& rData
);
137 ScDPSaveData
* GetSaveData() const { return pSaveData
; }
139 void SetOutRange(const ScRange
& rRange
);
140 const ScRange
& GetOutRange() const { return aOutRange
; }
142 void SetHeaderLayout(bool bUseGrid
);
143 bool GetHeaderLayout() const;
145 void SetSheetDesc(const ScSheetSourceDesc
& rDesc
, bool bFromRefUpdate
= false);
146 void SetImportDesc(const ScImportSourceDesc
& rDesc
);
147 void SetServiceData(const ScDPServiceDesc
& rDesc
);
149 void WriteSourceDataTo( ScDPObject
& rDest
) const;
150 void WriteTempDataTo( ScDPObject
& rDest
) const;
152 const ScSheetSourceDesc
* GetSheetDesc() const { return pSheetDesc
; }
153 const ScImportSourceDesc
* GetImportSourceDesc() const { return pImpDesc
; }
154 const ScDPServiceDesc
* GetDPServiceDesc() const { return pServDesc
; }
156 com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
> GetSource();
158 bool IsSheetData() const;
159 bool IsImportData() const { return(pImpDesc
!= NULL
); }
160 bool IsServiceData() const { return(pServDesc
!= NULL
); }
162 void SetName(const OUString
& rNew
);
163 const OUString
& GetName() const { return aTableName
; }
164 void SetTag(const OUString
& rNew
);
165 const OUString
& GetTag() const { return aTableTag
; }
168 * Data description cell displays the description of a data dimension if
169 * and only if there is only one data dimension. It's usually located at
170 * the upper-left corner of the table output.
172 bool IsDataDescriptionCell(const ScAddress
& rPos
);
174 bool IsDimNameInUse(const OUString
& rName
) const;
175 OUString
GetDimName( long nDim
, bool& rIsDataLayout
, sal_Int32
* pFlags
= NULL
);
176 bool IsDuplicated( long nDim
);
178 void GetHeaderPositionData(const ScAddress
& rPos
, ::com::sun::star::sheet::DataPilotTableHeaderData
& rData
);
179 long GetHeaderDim( const ScAddress
& rPos
, sal_uInt16
& rOrient
);
180 bool GetHeaderDrag( const ScAddress
& rPos
, bool bMouseLeft
, bool bMouseTop
,
182 Rectangle
& rPosRect
, sal_uInt16
& rOrient
, long& rDimPos
);
183 bool IsFilterButton( const ScAddress
& rPos
);
186 const OUString
& rDataFieldName
,
187 std::vector
<com::sun::star::sheet::DataPilotFieldFilter
>& rFilters
);
190 OUString
& rDataFieldName
,
191 std::vector
<com::sun::star::sheet::DataPilotFieldFilter
>& rFilters
,
192 std::vector
<com::sun::star::sheet::GeneralFunction
>& rFilterFuncs
,
193 const OUString
& rFilterList
);
195 void GetMemberResultNames(ScDPUniqueStringSet
& rNames
, long nDimension
);
197 void ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData
& rElemDesc
, ScDPObject
* pDestObj
);
199 bool FillOldParam(ScPivotParam
& rParam
) const;
200 bool FillLabelData(sal_Int32 nDim
, ScDPLabelData
& Labels
);
201 bool FillLabelData(ScPivotParam
& rParam
);
203 bool GetHierarchiesNA( sal_Int32 nDim
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xHiers
);
204 bool GetHierarchies( sal_Int32 nDim
, com::sun::star::uno::Sequence
< OUString
>& rHiers
);
206 sal_Int32
GetUsedHierarchy( sal_Int32 nDim
);
208 bool GetMembersNA( sal_Int32 nDim
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xMembers
);
209 bool GetMembersNA( sal_Int32 nDim
, sal_Int32 nHier
, com::sun::star::uno::Reference
< com::sun::star::container::XNameAccess
>& xMembers
);
211 bool GetMemberNames( sal_Int32 nDim
, ::com::sun::star::uno::Sequence
< OUString
>& rNames
);
212 bool GetMembers( sal_Int32 nDim
, sal_Int32 nHier
, ::std::vector
<ScDPLabelData::Member
>& rMembers
);
214 void UpdateReference( UpdateRefMode eUpdateRefMode
,
215 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
216 bool RefsEqual( const ScDPObject
& r
) const;
217 void WriteRefsTo( ScDPObject
& r
) const;
219 void GetPositionData(const ScAddress
& rPos
, ::com::sun::star::sheet::DataPilotTablePositionData
& rPosData
);
221 bool GetDataFieldPositionData(const ScAddress
& rPos
,
222 ::com::sun::star::uno::Sequence
<
223 ::com::sun::star::sheet::DataPilotFieldFilter
>& rFilters
);
225 void GetDrillDownData(const ScAddress
& rPos
,
226 ::com::sun::star::uno::Sequence
<
227 ::com::sun::star::uno::Sequence
<
228 ::com::sun::star::uno::Any
> >& rTableData
);
230 // apply drop-down attribute, initialize nHeaderRows, without accessing the source
231 // (button attribute must be present)
232 void RefreshAfterLoad();
234 void BuildAllDimensionMembers();
237 * Remove in the save data entries for members that don't exist anymore.
238 * This is called during pivot table refresh.
240 bool SyncAllDimensionMembers();
242 static bool HasRegisteredSources();
243 static com::sun::star::uno::Sequence
<OUString
> GetRegisteredSources();
244 static com::sun::star::uno::Reference
<com::sun::star::sheet::XDimensionsSupplier
>
245 CreateSource( const ScDPServiceDesc
& rDesc
);
247 static void ConvertOrientation(
248 ScDPSaveData
& rSaveData
,
249 const ScPivotFieldVector
& rFields
, sal_uInt16 nOrient
,
250 const com::sun::star::uno::Reference
<
251 com::sun::star::sheet::XDimensionsSupplier
>& xSource
,
252 const ScDPLabelDataVector
& rLabels
,
253 const ScPivotFieldVector
* pRefColFields
= NULL
,
254 const ScPivotFieldVector
* pRefRowFields
= NULL
,
255 const ScPivotFieldVector
* pRefPageFields
= NULL
);
257 static bool IsOrientationAllowed( sal_uInt16 nOrient
, sal_Int32 nDimFlags
);
259 #if DEBUG_PIVOT_TABLE
260 void DumpCache() const;
267 friend class ScDPCache
;
271 * Stores and manages all caches from internal sheets.
275 friend class ScDPCollection
;
276 typedef boost::ptr_map
<size_t, ScDPCache
> CachesType
;
277 typedef std::vector
<ScRange
> RangeIndexType
;
279 RangeIndexType maRanges
;
282 SheetCaches(ScDocument
* pDoc
);
283 bool hasCache(const ScRange
& rRange
) const;
284 const ScDPCache
* getCache(const ScRange
& rRange
, const ScDPDimensionSaveData
* pDimData
);
287 void updateReference(
288 UpdateRefMode eMode
, const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
291 ScDPCache
* getExistingCache(const ScRange
& rRange
);
293 void updateCache(const ScRange
& rRange
, std::set
<ScDPObject
*>& rRefs
);
294 bool remove(const ScDPCache
* p
);
298 * Data caches for range name based source data.
302 friend class ScDPCollection
;
303 typedef ::boost::ptr_map
<OUString
, ScDPCache
> CachesType
;
307 NameCaches(ScDocument
* pDoc
);
308 bool hasCache(const OUString
& rName
) const;
309 const ScDPCache
* getCache(
310 const OUString
& rName
, const ScRange
& rRange
, const ScDPDimensionSaveData
* pDimData
);
313 ScDPCache
* getExistingCache(const OUString
& rName
);
316 const OUString
& rName
, const ScRange
& rRange
, std::set
<ScDPObject
*>& rRefs
);
317 bool remove(const ScDPCache
* p
);
321 * Defines connection type to external data source. Used as a key to look
329 DBType(sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
331 struct less
: public ::std::binary_function
<DBType
, DBType
, bool>
333 bool operator() (const DBType
& left
, const DBType
& right
) const;
338 * Data caches for external database sources.
342 friend class ScDPCollection
;
343 typedef ::boost::ptr_map
<DBType
, ScDPCache
, DBType::less
> CachesType
;
347 DBCaches(ScDocument
* pDoc
);
348 bool hasCache(sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
) const;
349 const ScDPCache
* getCache(
350 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
351 const ScDPDimensionSaveData
* pDimData
);
354 ScDPCache
* getExistingCache(
355 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
357 com::sun::star::uno::Reference
<com::sun::star::sdbc::XRowSet
> createRowSet(
358 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
361 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
362 std::set
<ScDPObject
*>& rRefs
);
363 bool remove(const ScDPCache
* p
);
366 ScDPCollection(ScDocument
* pDocument
);
367 ScDPCollection(const ScDPCollection
& r
);
370 sal_uLong
ReloadCache(ScDPObject
* pDPObj
, std::set
<ScDPObject
*>& rRefs
);
371 bool ReloadGroupsInCache(ScDPObject
* pDPObj
, std::set
<ScDPObject
*>& rRefs
);
373 SC_DLLPUBLIC
size_t GetCount() const;
374 SC_DLLPUBLIC ScDPObject
* operator[](size_t nIndex
);
375 SC_DLLPUBLIC
const ScDPObject
* operator[](size_t nIndex
) const;
377 const ScDPObject
* GetByName(const OUString
& rName
) const;
379 void DeleteOnTab( SCTAB nTab
);
380 void UpdateReference( UpdateRefMode eUpdateRefMode
,
381 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
382 void CopyToTab( SCTAB nOld
, SCTAB nNew
);
383 bool RefsEqual( const ScDPCollection
& r
) const;
384 void WriteRefsTo( ScDPCollection
& r
) const;
387 * Create a new name that's not yet used by any existing data pilot
388 * objects. All data pilot names are 'DataPilot' + <num>, and the nMin
389 * specifies the minimum number allowed.
391 * @param nMin minimum number allowed.
393 * @return new name for data pilot object.
395 OUString
CreateNewName( sal_uInt16 nMin
= 1 ) const;
397 void FreeTable(ScDPObject
* pDPObj
);
398 SC_DLLPUBLIC
bool InsertNewTable(ScDPObject
* pDPObj
);
400 SheetCaches
& GetSheetCaches();
401 NameCaches
& GetNameCaches();
402 DBCaches
& GetDBCaches();
404 ScRangeList
GetAllTableRanges( SCTAB nTab
) const;
405 bool IntersectsTableByColumns( SCCOL nCol1
, SCCOL nCol2
, SCROW nRow
, SCTAB nTab
) const;
406 bool IntersectsTableByRows( SCCOL nCol
, SCROW nRow1
, SCROW nRow2
, SCTAB nTab
) const;
407 bool HasTable( const ScRange
& rRange
) const;
410 /** Only to be called from ScDPCache::RemoveReference(). */
411 void RemoveCache(const ScDPCache
* pCache
);
413 void GetAllTables(const ScRange
& rSrcRange
, std::set
<ScDPObject
*>& rRefs
) const;
414 void GetAllTables(const OUString
& rSrcName
, std::set
<ScDPObject
*>& rRefs
) const;
416 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
417 std::set
<ScDPObject
*>& rRefs
) const;
420 typedef ::boost::ptr_vector
<ScDPObject
> TablesType
;
424 SheetCaches maSheetCaches
;
425 NameCaches maNameCaches
;
429 bool operator<(const ScDPCollection::DBType
& left
, const ScDPCollection::DBType
& right
);
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */