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 INCLUDED_SC_INC_DPOBJECT_HXX
21 #define INCLUDED_SC_INC_DPOBJECT_HXX
25 #include "address.hxx"
26 #include "dpoutput.hxx"
27 #include "dptypes.hxx"
29 #include "calcmacros.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 SAL_DLLPRIVATE ScDPTableData
* GetTableData();
108 SAL_DLLPRIVATE
void CreateObjects();
109 SAL_DLLPRIVATE
void CreateOutput();
110 SAL_DLLPRIVATE
void ClearSource();
111 SAL_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
);
285 SC_DLLPUBLIC
size_t size() const;
287 void updateReference(
288 UpdateRefMode eMode
, const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
290 SC_DLLPUBLIC ScDPCache
* getExistingCache(const ScRange
& rRange
);
292 void updateCache(const ScRange
& rRange
, std::set
<ScDPObject
*>& rRefs
);
293 bool remove(const ScDPCache
* p
);
297 * Data caches for range name based source data.
301 friend class ScDPCollection
;
302 typedef ::boost::ptr_map
<OUString
, ScDPCache
> CachesType
;
306 NameCaches(ScDocument
* pDoc
);
307 bool hasCache(const OUString
& rName
) const;
308 const ScDPCache
* getCache(
309 const OUString
& rName
, const ScRange
& rRange
, const ScDPDimensionSaveData
* pDimData
);
312 ScDPCache
* getExistingCache(const OUString
& rName
);
315 const OUString
& rName
, const ScRange
& rRange
, std::set
<ScDPObject
*>& rRefs
);
316 bool remove(const ScDPCache
* p
);
320 * Defines connection type to external data source. Used as a key to look
328 DBType(sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
330 struct less
: public ::std::binary_function
<DBType
, DBType
, bool>
332 bool operator() (const DBType
& left
, const DBType
& right
) const;
337 * Data caches for external database sources.
341 friend class ScDPCollection
;
342 typedef ::boost::ptr_map
<DBType
, ScDPCache
, DBType::less
> CachesType
;
346 DBCaches(ScDocument
* pDoc
);
347 bool hasCache(sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
) const;
348 const ScDPCache
* getCache(
349 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
350 const ScDPDimensionSaveData
* pDimData
);
353 ScDPCache
* getExistingCache(
354 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
356 com::sun::star::uno::Reference
<com::sun::star::sdbc::XRowSet
> createRowSet(
357 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
360 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
361 std::set
<ScDPObject
*>& rRefs
);
362 bool remove(const ScDPCache
* p
);
365 ScDPCollection(ScDocument
* pDocument
);
366 ScDPCollection(const ScDPCollection
& r
);
369 sal_uLong
ReloadCache(ScDPObject
* pDPObj
, std::set
<ScDPObject
*>& rRefs
);
370 bool ReloadGroupsInCache(ScDPObject
* pDPObj
, std::set
<ScDPObject
*>& rRefs
);
372 SC_DLLPUBLIC
size_t GetCount() const;
373 SC_DLLPUBLIC ScDPObject
* operator[](size_t nIndex
);
374 SC_DLLPUBLIC
const ScDPObject
* operator[](size_t nIndex
) const;
376 const ScDPObject
* GetByName(const OUString
& rName
) const;
378 void DeleteOnTab( SCTAB nTab
);
379 void UpdateReference( UpdateRefMode eUpdateRefMode
,
380 const ScRange
& r
, SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
381 void CopyToTab( SCTAB nOld
, SCTAB nNew
);
382 bool RefsEqual( const ScDPCollection
& r
) const;
383 void WriteRefsTo( ScDPCollection
& r
) const;
386 * Create a new name that's not yet used by any existing data pilot
387 * objects. All data pilot names are 'DataPilot' + <num>, and the nMin
388 * specifies the minimum number allowed.
390 * @param nMin minimum number allowed.
392 * @return new name for data pilot object.
394 OUString
CreateNewName( sal_uInt16 nMin
= 1 ) const;
396 void FreeTable(ScDPObject
* pDPObj
);
397 SC_DLLPUBLIC
bool InsertNewTable(ScDPObject
* pDPObj
);
399 SC_DLLPUBLIC SheetCaches
& GetSheetCaches();
400 NameCaches
& GetNameCaches();
401 DBCaches
& GetDBCaches();
403 ScRangeList
GetAllTableRanges( SCTAB nTab
) const;
404 bool IntersectsTableByColumns( SCCOL nCol1
, SCCOL nCol2
, SCROW nRow
, SCTAB nTab
) const;
405 bool IntersectsTableByRows( SCCOL nCol
, SCROW nRow1
, SCROW nRow2
, SCTAB nTab
) const;
406 bool HasTable( const ScRange
& rRange
) const;
408 #if DEBUG_PIVOT_TABLE
409 void DumpTables() const;
413 /** Only to be called from ScDPCache::RemoveReference(). */
414 void RemoveCache(const ScDPCache
* pCache
);
416 void GetAllTables(const ScRange
& rSrcRange
, std::set
<ScDPObject
*>& rRefs
) const;
417 void GetAllTables(const OUString
& rSrcName
, std::set
<ScDPObject
*>& rRefs
) const;
419 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
420 std::set
<ScDPObject
*>& rRefs
) const;
423 typedef ::boost::ptr_vector
<ScDPObject
> TablesType
;
427 SheetCaches maSheetCaches
;
428 NameCaches maNameCaches
;
432 bool operator<(const ScDPCollection::DBType
& left
, const ScDPCollection::DBType
& right
);
436 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */