Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / inc / dpobject.hxx
blobea7fb3a5f1cd42fe6b6234d5d18dce8049e63443
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include "scdllapi.h"
24 #include "global.hxx"
25 #include "address.hxx"
26 #include "dpoutput.hxx"
27 #include "dptypes.hxx"
28 #include "pivot.hxx"
29 #include "dpmacros.hxx"
31 #include <com/sun/star/sheet/XDimensionsSupplier.hpp>
33 #include <set>
34 #include <vector>
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 {
43 namespace container {
44 class XIndexAccess;
47 namespace sdbc {
48 class XRowSet;
51 namespace sheet {
52 struct DataPilotTablePositionData;
53 struct DataPilotTableHeaderData;
54 struct DataPilotFieldFilter;
56 }}}
58 class Rectangle;
59 class ScDPSaveData;
60 class ScDPOutput;
61 struct ScPivotParam;
62 struct ScImportSourceDesc;
63 class ScSheetSourceDesc;
64 struct ScPivotField;
65 class ScDPTableData;
66 class ScDPDimensionSaveData;
68 struct ScDPServiceDesc
70 ::rtl::OUString aServiceName;
71 ::rtl::OUString aParSource;
72 ::rtl::OUString aParName;
73 ::rtl::OUString aParUser;
74 ::rtl::OUString aParPass;
76 ScDPServiceDesc( const ::rtl::OUString& rServ, const ::rtl::OUString& rSrc, const ::rtl::OUString& rNam,
77 const ::rtl::OUString& rUser, const ::rtl::OUString& rPass );
79 bool operator== ( const ScDPServiceDesc& rOther ) const;
83 class SC_DLLPUBLIC ScDPObject
85 private:
86 ScDocument* pDoc;
87 // settings
88 ScDPSaveData* pSaveData;
89 ::rtl::OUString aTableName;
90 ::rtl::OUString aTableTag;
91 ScRange aOutRange;
92 ScSheetSourceDesc* pSheetDesc; // for sheet data
93 ScImportSourceDesc* pImpDesc; // for database data
94 ScDPServiceDesc* pServDesc; // for external service
95 ::boost::shared_ptr<ScDPTableData> mpTableData;
96 // cached data
97 com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> xSource;
98 ScDPOutput* pOutput;
99 sal_uInt16 mnAutoFormatIndex;
100 long nHeaderRows; // page fields plus filter button
101 bool mbHeaderLayout:1; // true : grid, false : standard
102 bool bAllowMove:1;
103 bool bAlive:1; // false if only used to hold settings
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);
116 public:
117 ScDPObject(ScDocument* pD);
118 ScDPObject(const ScDPObject& r);
119 ~ScDPObject();
121 void EnableGetPivotData(bool b);
124 * When a DP object is "alive", it has table output on a sheet. This flag
125 * doesn't really change the behavior of the object, but is used only for
126 * testing purposes.
128 void SetAlive(bool bSet);
129 void SetAllowMove(bool bSet);
131 void InvalidateData();
132 void ClearTableData();
133 void ReloadGroupTableData();
135 void Output( const ScAddress& rPos );
136 ScRange GetNewOutputRange( bool& rOverflow );
137 const ScRange GetOutputRangeByType( sal_Int32 nType );
139 void SetSaveData(const ScDPSaveData& rData);
140 ScDPSaveData* GetSaveData() const { return pSaveData; }
142 void SetOutRange(const ScRange& rRange);
143 const ScRange& GetOutRange() const { return aOutRange; }
145 void SetHeaderLayout(bool bUseGrid);
146 bool GetHeaderLayout() const;
148 void SetSheetDesc(const ScSheetSourceDesc& rDesc, bool bFromRefUpdate = false);
149 void SetImportDesc(const ScImportSourceDesc& rDesc);
150 void SetServiceData(const ScDPServiceDesc& rDesc);
152 void WriteSourceDataTo( ScDPObject& rDest ) const;
153 void WriteTempDataTo( ScDPObject& rDest ) const;
155 const ScSheetSourceDesc* GetSheetDesc() const { return pSheetDesc; }
156 const ScImportSourceDesc* GetImportSourceDesc() const { return pImpDesc; }
157 const ScDPServiceDesc* GetDPServiceDesc() const { return pServDesc; }
159 com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier> GetSource();
161 bool IsSheetData() const;
162 bool IsImportData() const { return(pImpDesc != NULL); }
163 bool IsServiceData() const { return(pServDesc != NULL); }
165 void SetName(const ::rtl::OUString& rNew);
166 const ::rtl::OUString& GetName() const { return aTableName; }
167 void SetTag(const ::rtl::OUString& rNew);
168 const ::rtl::OUString& GetTag() const { return aTableTag; }
171 * Data description cell displays the description of a data dimension if
172 * and only if there is only one data dimension. It's usually located at
173 * the upper-left corner of the table output.
175 bool IsDataDescriptionCell(const ScAddress& rPos);
177 bool IsDimNameInUse(const ::rtl::OUString& rName) const;
178 ::rtl::OUString GetDimName( long nDim, bool& rIsDataLayout, sal_Int32* pFlags = NULL );
179 bool IsDuplicated( long nDim );
180 long GetDimCount();
181 void GetHeaderPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTableHeaderData& rData);
182 long GetHeaderDim( const ScAddress& rPos, sal_uInt16& rOrient );
183 bool GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMouseTop,
184 long nDragDim,
185 Rectangle& rPosRect, sal_uInt16& rOrient, long& rDimPos );
186 bool IsFilterButton( const ScAddress& rPos );
188 bool GetPivotData( ScDPGetPivotDataField& rTarget, /* returns result */
189 const std::vector< ScDPGetPivotDataField >& rFilters );
190 bool ParseFilters( ScDPGetPivotDataField& rTarget,
191 std::vector< ScDPGetPivotDataField >& rFilters,
192 const ::rtl::OUString& rFilterList );
194 void GetMemberResultNames(ScDPUniqueStringSet& rNames, long nDimension);
196 void FillPageList( std::vector<rtl::OUString>& rStrings, long nField );
198 void ToggleDetails(const ::com::sun::star::sheet::DataPilotTableHeaderData& rElemDesc, ScDPObject* pDestObj);
200 bool FillOldParam(ScPivotParam& rParam) const;
201 bool FillLabelData(sal_Int32 nDim, ScDPLabelData& Labels);
202 bool FillLabelData(ScPivotParam& rParam);
204 bool GetHierarchiesNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xHiers );
205 bool GetHierarchies( sal_Int32 nDim, com::sun::star::uno::Sequence< rtl::OUString >& rHiers );
207 sal_Int32 GetUsedHierarchy( sal_Int32 nDim );
209 bool GetMembersNA( sal_Int32 nDim, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
210 bool GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& xMembers );
212 bool GetMemberNames( sal_Int32 nDim, ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames );
213 bool GetMembers( sal_Int32 nDim, sal_Int32 nHier, ::std::vector<ScDPLabelData::Member>& rMembers );
215 void UpdateReference( UpdateRefMode eUpdateRefMode,
216 const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
217 bool RefsEqual( const ScDPObject& r ) const;
218 void WriteRefsTo( ScDPObject& r ) const;
220 void GetPositionData(const ScAddress& rPos, ::com::sun::star::sheet::DataPilotTablePositionData& rPosData);
222 bool GetDataFieldPositionData(const ScAddress& rPos,
223 ::com::sun::star::uno::Sequence<
224 ::com::sun::star::sheet::DataPilotFieldFilter >& rFilters);
226 void GetDrillDownData(const ScAddress& rPos,
227 ::com::sun::star::uno::Sequence<
228 ::com::sun::star::uno::Sequence<
229 ::com::sun::star::uno::Any > >& rTableData);
231 // apply drop-down attribute, initialize nHeaderRows, without accessing the source
232 // (button attribute must be present)
233 void RefreshAfterLoad();
235 void BuildAllDimensionMembers();
238 * Remove in the save data entries for members that don't exist anymore.
239 * This is called during pivot table refresh.
241 bool SyncAllDimensionMembers();
243 static bool HasRegisteredSources();
244 static com::sun::star::uno::Sequence<rtl::OUString> GetRegisteredSources();
245 static com::sun::star::uno::Reference<com::sun::star::sheet::XDimensionsSupplier>
246 CreateSource( const ScDPServiceDesc& rDesc );
248 static void ConvertOrientation(
249 ScDPSaveData& rSaveData,
250 const ScPivotFieldVector& rFields, sal_uInt16 nOrient,
251 const com::sun::star::uno::Reference<
252 com::sun::star::sheet::XDimensionsSupplier>& xSource,
253 const ScDPLabelDataVector& rLabels,
254 const ScPivotFieldVector* pRefColFields = NULL,
255 const ScPivotFieldVector* pRefRowFields = NULL,
256 const ScPivotFieldVector* pRefPageFields = NULL );
258 static bool IsOrientationAllowed( sal_uInt16 nOrient, sal_Int32 nDimFlags );
260 #if DEBUG_PIVOT_TABLE
261 void DumpCache() const;
262 #endif
266 class ScDPCollection
268 friend class ScDPCache;
269 public:
272 * Stores and manages all caches from internal sheets.
274 class SheetCaches
276 friend class ScDPCollection;
277 typedef boost::ptr_map<size_t, ScDPCache> CachesType;
278 typedef std::vector<ScRange> RangeIndexType;
279 CachesType maCaches;
280 RangeIndexType maRanges;
281 ScDocument* mpDoc;
282 public:
283 SheetCaches(ScDocument* pDoc);
284 bool hasCache(const ScRange& rRange) const;
285 const ScDPCache* getCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData);
286 size_t size() const;
288 void updateReference(
289 UpdateRefMode eMode, const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
291 private:
292 ScDPCache* getExistingCache(const ScRange& rRange);
294 void updateCache(const ScRange& rRange, const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
295 bool remove(const ScDPCache* p);
299 * Data caches for range name based source data.
301 class NameCaches
303 friend class ScDPCollection;
304 typedef ::boost::ptr_map<rtl::OUString, ScDPCache> CachesType;
305 CachesType maCaches;
306 ScDocument* mpDoc;
307 public:
308 NameCaches(ScDocument* pDoc);
309 bool hasCache(const rtl::OUString& rName) const;
310 const ScDPCache* getCache(
311 const ::rtl::OUString& rName, const ScRange& rRange, const ScDPDimensionSaveData* pDimData);
312 size_t size() const;
313 private:
314 ScDPCache* getExistingCache(const rtl::OUString& rName);
316 void updateCache(
317 const rtl::OUString& rName, const ScRange& rRange,
318 const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
319 bool remove(const ScDPCache* p);
323 * Defines connection type to external data source. Used as a key to look
324 * up database cache.
326 struct DBType
328 sal_Int32 mnSdbType;
329 ::rtl::OUString maDBName;
330 ::rtl::OUString maCommand;
331 DBType(sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand);
333 struct less : public ::std::binary_function<DBType, DBType, bool>
335 bool operator() (const DBType& left, const DBType& right) const;
340 * Data caches for external database sources.
342 class DBCaches
344 friend class ScDPCollection;
345 typedef ::boost::ptr_map<DBType, ScDPCache, DBType::less> CachesType;
346 CachesType maCaches;
347 ScDocument* mpDoc;
348 public:
349 DBCaches(ScDocument* pDoc);
350 bool hasCache(sal_Int32 nSdbType, const rtl::OUString& rDBName, const rtl::OUString& rCommand) const;
351 const ScDPCache* getCache(
352 sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand,
353 const ScDPDimensionSaveData* pDimData);
355 private:
356 ScDPCache* getExistingCache(
357 sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand);
359 com::sun::star::uno::Reference<com::sun::star::sdbc::XRowSet> createRowSet(
360 sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand);
362 void updateCache(sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand,
363 const ScDPDimensionSaveData* pDimData, std::set<ScDPObject*>& rRefs);
364 bool remove(const ScDPCache* p);
367 ScDPCollection(ScDocument* pDocument);
368 ScDPCollection(const ScDPCollection& r);
369 ~ScDPCollection();
371 sal_uLong ReloadCache(ScDPObject* pDPObj, std::set<ScDPObject*>& rRefs);
372 bool ReloadGroupsInCache(ScDPObject* pDPObj, std::set<ScDPObject*>& rRefs);
374 SC_DLLPUBLIC size_t GetCount() const;
375 SC_DLLPUBLIC ScDPObject* operator[](size_t nIndex);
376 SC_DLLPUBLIC const ScDPObject* operator[](size_t nIndex) const;
378 const ScDPObject* GetByName(const ::rtl::OUString& rName) const;
380 void DeleteOnTab( SCTAB nTab );
381 void UpdateReference( UpdateRefMode eUpdateRefMode,
382 const ScRange& r, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
383 void CopyToTab( SCTAB nOld, SCTAB nNew );
384 bool RefsEqual( const ScDPCollection& r ) const;
385 void WriteRefsTo( ScDPCollection& r ) const;
388 * Create a new name that's not yet used by any existing data pilot
389 * objects. All data pilot names are 'DataPilot' + <num>, and the nMin
390 * specifies the minimum number allowed.
392 * @param nMin minimum number allowed.
394 * @return new name for data pilot object.
396 ::rtl::OUString CreateNewName( sal_uInt16 nMin = 1 ) const;
398 void FreeTable(ScDPObject* pDPObj);
399 SC_DLLPUBLIC bool InsertNewTable(ScDPObject* pDPObj);
401 bool HasDPTable(SCCOL nCol, SCROW nRow, SCTAB nTab) const;
403 SheetCaches& GetSheetCaches();
404 NameCaches& GetNameCaches();
405 DBCaches& GetDBCaches();
407 private:
408 /** Only to be called from ScDPCache::RemoveReference(). */
409 void RemoveCache(const ScDPCache* pCache);
411 void GetAllTables(const ScRange& rSrcRange, std::set<ScDPObject*>& rRefs) const;
412 void GetAllTables(const rtl::OUString& rSrcName, std::set<ScDPObject*>& rRefs) const;
413 void GetAllTables(
414 sal_Int32 nSdbType, const ::rtl::OUString& rDBName, const ::rtl::OUString& rCommand,
415 std::set<ScDPObject*>& rRefs) const;
417 private:
418 typedef ::boost::ptr_vector<ScDPObject> TablesType;
420 ScDocument* mpDoc;
421 TablesType maTables;
422 SheetCaches maSheetCaches;
423 NameCaches maNameCaches;
424 DBCaches maDBCaches;
427 bool operator<(const ScDPCollection::DBType& left, const ScDPCollection::DBType& right);
429 #endif
431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */