LibreOffice Module sc (master)  1
dbdata.hxx
Go to the documentation of this file.
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_DBDATA_HXX
21 #define INCLUDED_SC_INC_DBDATA_HXX
22 
23 #include "scdllapi.h"
24 #include "refreshtimer.hxx"
25 #include "address.hxx"
26 #include "global.hxx"
27 #include "rangelst.hxx"
28 
29 #include <svl/listener.hxx>
30 
31 #include <memory>
32 #include <set>
33 #include <vector>
34 
35 class ScDocument;
36 struct ScSortParam;
37 struct ScQueryParam;
38 struct ScSubTotalParam;
39 
41 enum class ScDBDataPortion
42 {
43  TOP_LEFT,
44  AREA
45 };
46 
49 {
50 public:
53  ScDocument& GetDocument() const;
55 
56 protected:
59 };
60 
61 class SAL_DLLPUBLIC_RTTI ScDBData final : public SvtListener, public ScRefreshTimer
62 {
63 private:
64  std::unique_ptr<ScSortParam> mpSortParam;
65  std::unique_ptr<ScQueryParam> mpQueryParam;
66  std::unique_ptr<ScSubTotalParam> mpSubTotal;
67  std::unique_ptr<ScImportParam> mpImportParam;
68 
70 
72  const OUString aName;
73  OUString aUpper;
79  bool bByRow;
80  bool bHasHeader;
81  bool bHasTotals;
82  bool bDoSize;
83  bool bKeepFmt;
84  bool bStripData;
85 
87  bool bIsAdvanced;
89 
90  bool bDBSelection;
91 
92  sal_uInt16 nIndex;
93  bool bAutoFilter;
94  bool bModified;
95 
96  ::std::vector< OUString > maTableColumnNames;
99 
100  using ScRefreshTimer::operator==;
101 
102 public:
103  struct less
104  {
105  bool operator() (const std::unique_ptr<ScDBData>& left, const std::unique_ptr<ScDBData>& right) const;
106  };
107 
108  SC_DLLPUBLIC ScDBData(const OUString& rName,
109  SCTAB nTab,
110  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
111  bool bByR = true, bool bHasH = true, bool bTotals = false);
112  ScDBData(const ScDBData& rData);
113  ScDBData(const OUString& rName, const ScDBData& rData);
114  SC_DLLPUBLIC virtual ~ScDBData() override;
115 
116  virtual void Notify( const SfxHint& rHint ) override;
117 
118  ScDBData& operator= (const ScDBData& rData) ;
119 
120  bool operator== (const ScDBData& rData) const;
121 
122  const OUString& GetName() const { return aName; }
123  const OUString& GetUpperName() const { return aUpper; }
124  SCTAB GetTab() const { return nTable; }
125  void GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const;
126  SC_DLLPUBLIC void GetArea(ScRange& rRange) const;
127  void SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
128  void MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
129  void SetByRow(bool bByR) { bByRow = bByR; }
130  bool HasHeader() const { return bHasHeader; }
131  void SetHeader(bool bHasH) { bHasHeader = bHasH; }
132  bool HasTotals() const { return bHasTotals; }
133  void SetTotals(bool bTotals) { bHasTotals = bTotals; }
134  void SetIndex(sal_uInt16 nInd) { nIndex = nInd; }
135  sal_uInt16 GetIndex() const { return nIndex; }
136  bool IsDoSize() const { return bDoSize; }
137  void SetDoSize(bool bSet) { bDoSize = bSet; }
138  bool IsKeepFmt() const { return bKeepFmt; }
139  void SetKeepFmt(bool bSet) { bKeepFmt = bSet; }
140  bool IsStripData() const { return bStripData; }
141  void SetStripData(bool bSet) { bStripData = bSet; }
142 
143  void SetContainer( ScDBDataContainerBase* pContainer ) { mpContainer = pContainer; }
145  ScRange GetHeaderArea() const;
146  void StartTableColumnNamesListener();
147  void EndTableColumnNamesListener();
148  SC_DLLPUBLIC void SetTableColumnNames( const ::std::vector< OUString >& rNames );
149  SC_DLLPUBLIC const ::std::vector< OUString >& GetTableColumnNames() const { return maTableColumnNames; }
150  bool AreTableColumnNamesDirty() const { return mbTableColumnNamesDirty; }
151 
153  SC_DLLPUBLIC void RefreshTableColumnNames( ScDocument* pDoc );
154 
157  void RefreshTableColumnNames( ScDocument* pDoc, const ScRange& rRange );
158 
166  sal_Int32 GetColumnNameOffset( const OUString& rName ) const;
167 
170  const OUString& GetTableColumnName( SCCOL nCol ) const;
171 
172  OUString GetSourceString() const;
173  OUString GetOperations() const;
174 
175  void GetSortParam(ScSortParam& rSortParam) const;
176  void SetSortParam(const ScSortParam& rSortParam);
177 
180  void UpdateFromSortParam( const ScSortParam& rSortParam );
181 
182  SC_DLLPUBLIC void GetQueryParam(ScQueryParam& rQueryParam) const;
183  SC_DLLPUBLIC void SetQueryParam(const ScQueryParam& rQueryParam);
184  SC_DLLPUBLIC bool GetAdvancedQuerySource(ScRange& rSource) const;
185  SC_DLLPUBLIC void SetAdvancedQuerySource(const ScRange* pSource);
186 
187  void GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const;
188  void SetSubTotalParam(const ScSubTotalParam& rSubTotalParam);
189 
190  void GetImportParam(ScImportParam& rImportParam) const;
191  void SetImportParam(const ScImportParam& rImportParam);
192 
193  bool IsDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const;
194  bool IsDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
195 
196  bool HasImportParam() const;
197  SC_DLLPUBLIC bool HasQueryParam() const;
198  bool HasSortParam() const;
199  bool HasSubTotalParam() const;
200 
201  bool HasImportSelection() const { return bDBSelection; }
202  void SetImportSelection(bool bSet) { bDBSelection = bSet; }
203 
204  bool HasAutoFilter() const { return bAutoFilter; }
205  void SetAutoFilter(bool bSet) { bAutoFilter = bSet; }
206 
207  bool IsModified() const { return bModified; }
208  void SetModified(bool bMod) { bModified = bMod; }
209 
210  void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
211  void UpdateReference(const ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
212  SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
213  SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
214  SCCOL nDx, SCROW nDy, SCTAB nDz);
215 
216  void ExtendDataArea(const ScDocument* pDoc);
217  void CalcSaveFilteredCount(SCSIZE nNonFilteredRowCount);
218  void GetFilterSelCount(SCSIZE& nSelected, SCSIZE& nTotal);
219 
220 private:
221 
222  void AdjustTableColumnNames( UpdateRefMode eUpdateRefMode, SCCOL nDx, SCCOL nCol1,
223  SCCOL nOldCol1, SCCOL nOldCol2, SCCOL nNewCol1, SCCOL nNewCol2 );
224  void InvalidateTableColumnNames( bool bSwapToEmptyNames );
225 };
226 
228 {
229 public:
230  enum RangeType { GlobalNamed, GlobalAnonymous, SheetAnonymous };
231 
236  {
237  friend class ScDBCollection;
238 
239  typedef ::std::set<std::unique_ptr<ScDBData>, ScDBData::less> DBsType;
240  DBsType m_DBs;
242  NamedDBs(ScDBCollection& rParent, ScDocument& rDoc);
243  NamedDBs(const NamedDBs& r, ScDBCollection& rParent);
244  NamedDBs(const NamedDBs&) = delete;
245  virtual ~NamedDBs() override;
246  NamedDBs & operator=(NamedDBs const&) = delete;
247  void initInserted( ScDBData* p );
248 
249  public:
250  typedef DBsType::iterator iterator;
251  typedef DBsType::const_iterator const_iterator;
252 
253  iterator begin();
254  iterator end();
255  const_iterator begin() const;
256  const_iterator end() const;
257  ScDBData* findByIndex(sal_uInt16 nIndex);
258  ScDBData* findByUpperName(const OUString& rName);
259  iterator findByUpperName2(const OUString& rName);
260 
265  bool insert(std::unique_ptr<ScDBData> p);
266 
267  void erase(const iterator& itr);
268  bool empty() const;
269  size_t size() const;
270  bool operator== (const NamedDBs& r) const;
271  };
272 
276  class SAL_DLLPRIVATE AnonDBs
277  {
278  typedef ::std::vector<std::unique_ptr<ScDBData>> DBsType;
279  DBsType m_DBs;
280 
281  AnonDBs& operator=(AnonDBs const&) = delete;
282 
283  public:
284  AnonDBs();
285  AnonDBs(AnonDBs const&);
286 
287  typedef DBsType::iterator iterator;
288  typedef DBsType::const_iterator const_iterator;
289 
290  iterator begin();
291  iterator end();
292  const_iterator begin() const;
293  const_iterator end() const;
294  const ScDBData* findAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const;
295  const ScDBData* findByRange(const ScRange& rRange) const;
296  void deleteOnTab(SCTAB nTab);
297  ScDBData* getByRange(const ScRange& rRange);
298  void insert(ScDBData* p);
299  bool empty() const;
300  bool has( const ScDBData* p ) const;
301  bool operator== (const AnonDBs& r) const;
302  };
303 
304 private:
307  sal_uInt16 nEntryIndex;
310 
311 public:
312  ScDBCollection(ScDocument* pDocument);
313  ScDBCollection(const ScDBCollection& r);
314 
315  NamedDBs& getNamedDBs() { return maNamedDBs;}
316  const NamedDBs& getNamedDBs() const { return maNamedDBs;}
317 
318  AnonDBs& getAnonDBs() { return maAnonDBs;}
319  const AnonDBs& getAnonDBs() const { return maAnonDBs;}
320 
321  const ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const;
322  ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion);
323  const ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
324  ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
325  ScDBData* GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab );
326 
327  void RefreshDirtyTableColumnNames();
328 
329  void DeleteOnTab( SCTAB nTab );
330  void UpdateReference(UpdateRefMode eUpdateRefMode,
331  SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
332  SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
333  SCCOL nDx, SCROW nDy, SCTAB nDz);
334  void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
335 
337  { aRefreshHandler = rLink; }
338  const Link<Timer *, void>& GetRefreshHandler() const { return aRefreshHandler; }
339 
340  bool empty() const;
341  bool operator== (const ScDBCollection& r) const;
342 };
343 
344 #endif
345 
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:517
ScDocument & mrDoc
Definition: dbdata.hxx:57
ScRefreshTimer & operator=(const ScRefreshTimer &r)
SCTAB GetTab() const
Definition: dbdata.hxx:124
ScRange aAdvSource
source range
Definition: dbdata.hxx:88
ScRangeList maDirtyTableColumnNames
Definition: dbdata.hxx:58
const Link< Timer *, void > & GetRefreshHandler() const
Definition: dbdata.hxx:338
bool HasAutoFilter() const
Definition: dbdata.hxx:204
Container base class to provide selected access for ScDBData.
Definition: dbdata.hxx:48
sal_uInt64 left
void SetImportSelection(bool bSet)
Definition: dbdata.hxx:202
bool HasHeader() const
Definition: dbdata.hxx:130
bool bIsAdvanced
QueryParam.
Definition: dbdata.hxx:87
void SetDoSize(bool bSet)
Definition: dbdata.hxx:137
void SetKeepFmt(bool bSet)
Definition: dbdata.hxx:139
bool mbTableColumnNamesDirty
Definition: dbdata.hxx:97
SCCOL nStartCol
Definition: dbdata.hxx:75
bool bDoSize
Definition: dbdata.hxx:82
bool IsDoSize() const
Definition: dbdata.hxx:136
std::unique_ptr< ScSortParam > mpSortParam
Definition: dbdata.hxx:64
sal_uInt16 nEntryIndex
counter for unique indices
Definition: dbdata.hxx:307
void SetModified(bool bMod)
Definition: dbdata.hxx:208
enumrange< T >::Iterator begin(enumrange< T >)
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:45
AnonDBs & getAnonDBs()
Definition: dbdata.hxx:318
::std::vector< std::unique_ptr< ScDBData > > DBsType
Definition: dbdata.hxx:278
ScDBCollection & mrParent
Definition: dbdata.hxx:241
SCROW nStartRow
Definition: dbdata.hxx:76
void SetIndex(sal_uInt16 nInd)
Definition: dbdata.hxx:134
::std::vector< OUString > maTableColumnNames
names of table columns
Definition: dbdata.hxx:96
void SetRefreshHandler(const Link< Timer *, void > &rLink)
Definition: dbdata.hxx:336
sal_uInt16 GetIndex() const
Definition: dbdata.hxx:135
virtual ~ScDBDataContainerBase()
Definition: dbdata.hxx:52
Stores global anonymous database ranges.
Definition: dbdata.hxx:276
ScDBDataPortion
Enum used to indicate which portion of the DBArea is to be considered.
Definition: dbdata.hxx:41
bool bKeepFmt
Definition: dbdata.hxx:83
bool bAutoFilter
AutoFilter? (not saved)
Definition: dbdata.hxx:93
def right
SC_DLLPUBLIC const ::std::vector< OUString > & GetTableColumnNames() const
Definition: dbdata.hxx:149
SCROW nEndRow
Definition: dbdata.hxx:78
SCCOL nEndCol
Definition: dbdata.hxx:77
const AnonDBs & getAnonDBs() const
Definition: dbdata.hxx:319
const OUString aName
DBParam.
Definition: dbdata.hxx:72
bool bHasTotals
Definition: dbdata.hxx:81
void SetContainer(ScDBDataContainerBase *pContainer)
Definition: dbdata.hxx:143
bool empty() const
Definition: dbdata.cxx:1495
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
Definition: docsh.hxx:477
sal_Int16 SCCOL
Definition: types.hxx:22
OUString aUpper
Definition: dbdata.hxx:73
SCSIZE nFilteredRowCount
Definition: dbdata.hxx:98
DBsType::iterator iterator
Definition: dbdata.hxx:250
const OUString & GetName() const
Definition: dbdata.hxx:122
std::unique_ptr< ScQueryParam > mpQueryParam
Definition: dbdata.hxx:65
bool IsKeepFmt() const
Definition: dbdata.hxx:138
size
SCTAB nTable
Definition: dbdata.hxx:74
bool bByRow
Definition: dbdata.hxx:79
void SetHeader(bool bHasH)
Definition: dbdata.hxx:131
bool IsStripData() const
Definition: dbdata.hxx:140
enumrange< T >::Iterator end(enumrange< T >)
void SetByRow(bool bByR)
Definition: dbdata.hxx:129
void SetStripData(bool bSet)
Definition: dbdata.hxx:141
top left cell of area
DBsType::iterator iterator
Definition: dbdata.hxx:287
Stores global named database ranges.
Definition: dbdata.hxx:235
UpdateRefMode
Definition: global.hxx:310
sal_Int32 SCROW
Definition: types.hxx:18
ScDBDataContainerBase * mpContainer
Definition: dbdata.hxx:69
const OUString & GetUpperName() const
Definition: dbdata.hxx:123
ScRangeList & GetDirtyTableColumnNames()
Definition: dbdata.cxx:1070
DBsType::const_iterator const_iterator
Definition: dbdata.hxx:288
DBsType::const_iterator const_iterator
Definition: dbdata.hxx:251
AnonDBs maAnonDBs
Definition: dbdata.hxx:309
bool bDBSelection
not in Param: if selection, block update
Definition: dbdata.hxx:90
bool AreTableColumnNamesDirty() const
Definition: dbdata.hxx:150
bool HasImportSelection() const
Definition: dbdata.hxx:201
void SetTotals(bool bTotals)
Definition: dbdata.hxx:133
std::unique_ptr< ScImportParam > mpImportParam
Definition: dbdata.hxx:67
bool bHasHeader
Definition: dbdata.hxx:80
bool bModified
is set/cleared for/by(?) UpdateReference
Definition: dbdata.hxx:94
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
ScDocument & GetDocument() const
Definition: dbdata.cxx:1065
ScDocument * pDoc
Definition: dbdata.hxx:306
std::unique_ptr< ScSubTotalParam > mpSubTotal
Definition: dbdata.hxx:66
bool bStripData
Definition: dbdata.hxx:84
const NamedDBs & getNamedDBs() const
Definition: dbdata.hxx:316
ScDBDataContainerBase(ScDocument &rDoc)
Definition: dbdata.hxx:51
::std::set< std::unique_ptr< ScDBData >, ScDBData::less > DBsType
Definition: dbdata.hxx:239
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
bool operator==(const ScRefreshTimer &r) const
bool HasTotals() const
Definition: dbdata.hxx:132
sal_Int16 SCTAB
Definition: types.hxx:23
Link< Timer *, void > aRefreshHandler
Definition: dbdata.hxx:305
void SetAutoFilter(bool bSet)
Definition: dbdata.hxx:205
NamedDBs maNamedDBs
Definition: dbdata.hxx:308
sal_uInt16 nIndex
unique index formulas
Definition: dbdata.hxx:92
bool IsModified() const
Definition: dbdata.hxx:207