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>
38 namespace com
{ namespace sun
{ namespace star
{
50 struct DataPilotTablePositionData
;
51 struct DataPilotTableHeaderData
;
52 struct DataPilotFieldFilter
;
56 namespace tools
{ class Rectangle
; }
59 struct ScImportSourceDesc
;
60 class ScSheetSourceDesc
;
62 class ScDPDimensionSaveData
;
65 struct ScDPServiceDesc
67 OUString aServiceName
;
73 ScDPServiceDesc( const OUString
& rServ
, const OUString
& rSrc
, const OUString
& rNam
,
74 const OUString
& rUser
, const OUString
& rPass
);
76 bool operator== ( const ScDPServiceDesc
& rOther
) const;
79 class SC_DLLPUBLIC ScDPObject
84 ScDPSaveData
* pSaveData
;
88 ScSheetSourceDesc
* pSheetDesc
; // for sheet data
89 ScImportSourceDesc
* pImpDesc
; // for database data
90 ScDPServiceDesc
* pServDesc
; // for external service
91 std::shared_ptr
<ScDPTableData
> mpTableData
;
93 css::uno::Reference
<css::sheet::XDimensionsSupplier
> xSource
;
95 long nHeaderRows
; // page fields plus filter button
96 bool mbHeaderLayout
:1; // true : grid, false : standard
98 bool bSettingsChanged
:1;
99 bool mbEnableGetPivotData
:1;
101 SAL_DLLPRIVATE ScDPTableData
* GetTableData();
102 SAL_DLLPRIVATE
void CreateObjects();
103 SAL_DLLPRIVATE
void CreateOutput();
104 SAL_DLLPRIVATE
void ClearSource();
105 SAL_DLLPRIVATE
void FillLabelDataForDimension(
106 const css::uno::Reference
< css::container::XIndexAccess
>& xDims
,
107 sal_Int32 nDim
, ScDPLabelData
& rLabelData
);
110 ScDPObject(ScDocument
* pD
);
111 ScDPObject(const ScDPObject
& r
);
114 ScDPObject
& operator= (const ScDPObject
& r
);
116 void EnableGetPivotData(bool b
);
118 void SetAllowMove(bool bSet
);
120 void InvalidateData();
122 void ClearTableData();
123 void ReloadGroupTableData();
125 void Output( const ScAddress
& rPos
);
126 ScRange
GetNewOutputRange( bool& rOverflow
);
128 ScRange
GetOutputRangeByType( sal_Int32 nType
);
129 ScRange
GetOutputRangeByType( sal_Int32 nType
) const;
131 void SetSaveData(const ScDPSaveData
& rData
);
132 ScDPSaveData
* GetSaveData() const { return pSaveData
; }
134 void SetOutRange(const ScRange
& rRange
);
135 const ScRange
& GetOutRange() const;
137 void SetHeaderLayout(bool bUseGrid
);
138 bool GetHeaderLayout() const { return mbHeaderLayout
;}
140 void SetSheetDesc(const ScSheetSourceDesc
& rDesc
);
141 void SetImportDesc(const ScImportSourceDesc
& rDesc
);
142 void SetServiceData(const ScDPServiceDesc
& rDesc
);
144 void WriteSourceDataTo( ScDPObject
& rDest
) const;
145 void WriteTempDataTo( ScDPObject
& rDest
) const;
147 const ScSheetSourceDesc
* GetSheetDesc() const { return pSheetDesc
; }
148 const ScImportSourceDesc
* GetImportSourceDesc() const { return pImpDesc
; }
149 const ScDPServiceDesc
* GetDPServiceDesc() const { return pServDesc
; }
151 css::uno::Reference
<css::sheet::XDimensionsSupplier
> const & GetSource();
153 bool IsSheetData() const;
154 bool IsImportData() const { return(pImpDesc
!= nullptr); }
155 bool IsServiceData() const { return(pServDesc
!= nullptr); }
157 void SetName(const OUString
& rNew
);
158 const OUString
& GetName() const { return aTableName
; }
159 void SetTag(const OUString
& rNew
);
160 const OUString
& GetTag() const { return aTableTag
; }
163 * Data description cell displays the description of a data dimension if
164 * and only if there is only one data dimension. It's usually located at
165 * the upper-left corner of the table output.
167 bool IsDataDescriptionCell(const ScAddress
& rPos
);
169 bool IsDimNameInUse(const OUString
& rName
) const;
170 OUString
GetDimName( long nDim
, bool& rIsDataLayout
, sal_Int32
* pFlags
= nullptr );
171 bool IsDuplicated( long nDim
);
173 void GetHeaderPositionData(const ScAddress
& rPos
, css::sheet::DataPilotTableHeaderData
& rData
);
174 long GetHeaderDim( const ScAddress
& rPos
, css::sheet::DataPilotFieldOrientation
& rOrient
);
175 bool GetHeaderDrag( const ScAddress
& rPos
, bool bMouseLeft
, bool bMouseTop
,
177 tools::Rectangle
& rPosRect
, css::sheet::DataPilotFieldOrientation
& rOrient
, long& rDimPos
);
178 bool IsFilterButton( const ScAddress
& rPos
);
180 OUString
GetFormattedString( const OUString
& rDimName
, const double fValue
);
183 const OUString
& rDataFieldName
,
184 std::vector
<css::sheet::DataPilotFieldFilter
>& rFilters
);
187 OUString
& rDataFieldName
,
188 std::vector
<css::sheet::DataPilotFieldFilter
>& rFilters
,
189 std::vector
<sal_Int16
>& rFilterFuncs
,
190 const OUString
& rFilterList
);
192 void GetMemberResultNames(ScDPUniqueStringSet
& rNames
, long nDimension
);
194 void ToggleDetails(const css::sheet::DataPilotTableHeaderData
& rElemDesc
, ScDPObject
* pDestObj
);
196 void FillOldParam(ScPivotParam
& rParam
) const;
197 void FillLabelData(sal_Int32 nDim
, ScDPLabelData
& Labels
);
198 void FillLabelData(ScPivotParam
& rParam
);
200 bool GetHierarchiesNA( sal_Int32 nDim
, css::uno::Reference
< css::container::XNameAccess
>& xHiers
);
201 void GetHierarchies( sal_Int32 nDim
, css::uno::Sequence
< OUString
>& rHiers
);
203 sal_Int32
GetUsedHierarchy( sal_Int32 nDim
);
205 bool GetMembersNA( sal_Int32 nDim
, css::uno::Reference
< css::sheet::XMembersAccess
>& xMembers
);
206 bool GetMembersNA( sal_Int32 nDim
, sal_Int32 nHier
, css::uno::Reference
< css::sheet::XMembersAccess
>& xMembers
);
208 bool GetMemberNames( sal_Int32 nDim
, css::uno::Sequence
< OUString
>& rNames
);
209 bool GetMembers( sal_Int32 nDim
, sal_Int32 nHier
, ::std::vector
<ScDPLabelData::Member
>& rMembers
);
211 void UpdateReference( UpdateRefMode eUpdateRefMode
,
212 const ScRange
& r
, SCCOL nDx
, SCROW nDy
, SCTAB nDz
);
213 bool RefsEqual( const ScDPObject
& r
) const;
214 void WriteRefsTo( ScDPObject
& r
) const;
216 void GetPositionData(const ScAddress
& rPos
, css::sheet::DataPilotTablePositionData
& rPosData
);
218 bool GetDataFieldPositionData(const ScAddress
& rPos
,
220 css::sheet::DataPilotFieldFilter
>& rFilters
);
222 void GetDrillDownData(const ScAddress
& rPos
,
223 css::uno::Sequence
< css::uno::Sequence
< css::uno::Any
> >& rTableData
);
225 // apply drop-down attribute, initialize nHeaderRows, without accessing the source
226 // (button attribute must be present)
227 void RefreshAfterLoad();
229 void BuildAllDimensionMembers();
232 * Remove in the save data entries for members that don't exist anymore.
233 * This is called during pivot table refresh.
235 bool SyncAllDimensionMembers();
237 static bool HasRegisteredSources();
238 static std::vector
<OUString
> GetRegisteredSources();
239 static css::uno::Reference
<css::sheet::XDimensionsSupplier
>
240 CreateSource( const ScDPServiceDesc
& rDesc
);
242 static void ConvertOrientation(
243 ScDPSaveData
& rSaveData
,
244 const ScPivotFieldVector
& rFields
, css::sheet::DataPilotFieldOrientation nOrient
,
245 const css::uno::Reference
< css::sheet::XDimensionsSupplier
>& xSource
,
246 const ScDPLabelDataVector
& rLabels
,
247 const ScPivotFieldVector
* pRefColFields
= nullptr,
248 const ScPivotFieldVector
* pRefRowFields
= nullptr,
249 const ScPivotFieldVector
* pRefPageFields
= nullptr );
251 static bool IsOrientationAllowed( css::sheet::DataPilotFieldOrientation nOrient
, sal_Int32 nDimFlags
);
255 void DumpCache() const;
261 friend class ScDPCache
;
265 * Stores and manages all caches from internal sheets.
269 friend class ScDPCollection
;
270 typedef std::map
<size_t, std::unique_ptr
<ScDPCache
>> CachesType
;
271 typedef std::vector
<ScRange
> RangeIndexType
;
273 RangeIndexType maRanges
;
276 SheetCaches(ScDocument
* pDoc
);
277 bool hasCache(const ScRange
& rRange
) const;
278 const ScDPCache
* getCache(const ScRange
& rRange
, const ScDPDimensionSaveData
* pDimData
);
279 SC_DLLPUBLIC
size_t size() const;
281 void updateReference(
282 UpdateRefMode eMode
, const ScRange
& r
, SCCOL nDx
, SCROW nDy
, SCTAB nDz
);
284 SC_DLLPUBLIC ScDPCache
* getExistingCache(const ScRange
& rRange
);
285 SC_DLLPUBLIC
const ScDPCache
* getExistingCache(const ScRange
& rRange
) const;
287 void updateCache(const ScRange
& rRange
, std::set
<ScDPObject
*>& rRefs
);
288 bool remove(const ScDPCache
* p
);
290 SC_DLLPUBLIC
const std::vector
<ScRange
>& getAllRanges() const;
294 * Data caches for range name based source data.
298 friend class ScDPCollection
;
299 typedef ::std::map
<OUString
, std::unique_ptr
<ScDPCache
>> CachesType
;
303 NameCaches(ScDocument
* pDoc
);
304 bool hasCache(const OUString
& rName
) const;
305 const ScDPCache
* getCache(
306 const OUString
& rName
, const ScRange
& rRange
, const ScDPDimensionSaveData
* pDimData
);
309 ScDPCache
* getExistingCache(const OUString
& rName
);
312 const OUString
& rName
, const ScRange
& rRange
, std::set
<ScDPObject
*>& rRefs
);
313 bool remove(const ScDPCache
* p
);
317 * Defines connection type to external data source. Used as a key to look
325 DBType(sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
329 bool operator() (const DBType
& left
, const DBType
& right
) const;
334 * Data caches for external database sources.
338 friend class ScDPCollection
;
339 typedef ::std::map
<DBType
, std::unique_ptr
<ScDPCache
>, DBType::less
> CachesType
;
343 DBCaches(ScDocument
* pDoc
);
344 bool hasCache(sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
) const;
345 const ScDPCache
* getCache(
346 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
347 const ScDPDimensionSaveData
* pDimData
);
350 ScDPCache
* getExistingCache(
351 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
353 static css::uno::Reference
<css::sdbc::XRowSet
> createRowSet(
354 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
);
357 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
358 std::set
<ScDPObject
*>& rRefs
);
359 bool remove(const ScDPCache
* p
);
362 ScDPCollection(ScDocument
* pDocument
);
363 ScDPCollection(const ScDPCollection
& r
);
366 const char* ReloadCache(const ScDPObject
* pDPObj
, std::set
<ScDPObject
*>& rRefs
);
367 bool ReloadGroupsInCache(const ScDPObject
* pDPObj
, std::set
<ScDPObject
*>& rRefs
);
368 SC_DLLPUBLIC
bool GetReferenceGroups(const ScDPObject
& rDPObj
, const ScDPDimensionSaveData
** pGroups
) const;
370 SC_DLLPUBLIC
size_t GetCount() const;
371 SC_DLLPUBLIC ScDPObject
& operator[](size_t nIndex
);
372 SC_DLLPUBLIC
const ScDPObject
& operator[](size_t nIndex
) const;
374 ScDPObject
* GetByName(const OUString
& rName
) const;
376 void DeleteOnTab( SCTAB nTab
);
377 void UpdateReference( UpdateRefMode eUpdateRefMode
,
378 const ScRange
& r
, SCCOL nDx
, SCROW nDy
, SCTAB nDz
);
379 void CopyToTab( SCTAB nOld
, SCTAB nNew
);
380 bool RefsEqual( const ScDPCollection
& r
) const;
381 void WriteRefsTo( ScDPCollection
& r
) const;
384 * Create a new name that's not yet used by any existing data pilot
385 * objects. All data pilot names are 'DataPilot' + <num>
387 * @return new name for data pilot object.
389 OUString
CreateNewName() const;
391 void FreeTable(const ScDPObject
* pDPObj
);
392 SC_DLLPUBLIC
bool InsertNewTable(ScDPObject
* pDPObj
);
393 SC_DLLPUBLIC
bool HasTable(const ScDPObject
* pDPObj
) const;
395 SC_DLLPUBLIC SheetCaches
& GetSheetCaches();
396 SC_DLLPUBLIC
const SheetCaches
& GetSheetCaches() const;
397 NameCaches
& GetNameCaches();
398 SC_DLLPUBLIC
const NameCaches
& GetNameCaches() const;
399 DBCaches
& GetDBCaches();
400 SC_DLLPUBLIC
const DBCaches
& GetDBCaches() const;
402 ScRangeList
GetAllTableRanges( SCTAB nTab
) const;
403 bool IntersectsTableByColumns( SCCOL nCol1
, SCCOL nCol2
, SCROW nRow
, SCTAB nTab
) const;
404 bool IntersectsTableByRows( SCCOL nCol
, SCROW nRow1
, SCROW nRow2
, SCTAB nTab
) const;
405 bool HasTable( const ScRange
& rRange
) const;
407 #if DEBUG_PIVOT_TABLE
408 void DumpTables() const;
412 /** Only to be called from ScDPCache::RemoveReference(). */
413 void RemoveCache(const ScDPCache
* pCache
);
415 void GetAllTables(const ScRange
& rSrcRange
, std::set
<ScDPObject
*>& rRefs
) const;
416 void GetAllTables(const OUString
& rSrcName
, std::set
<ScDPObject
*>& rRefs
) const;
418 sal_Int32 nSdbType
, const OUString
& rDBName
, const OUString
& rCommand
,
419 std::set
<ScDPObject
*>& rRefs
) const;
422 typedef std::vector
< std::unique_ptr
<ScDPObject
> > TablesType
;
426 SheetCaches maSheetCaches
;
427 NameCaches maNameCaches
;
431 bool operator<(const ScDPCollection::DBType
& left
, const ScDPCollection::DBType
& right
);
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */