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 #pragma once
21 
22 #include "scdllapi.h"
23 #include "refreshtimer.hxx"
24 #include "address.hxx"
25 #include "global.hxx"
26 #include "rangelst.hxx"
27 
28 #include <svl/listener.hxx>
29 
30 #include <memory>
31 #include <set>
32 #include <vector>
33 
34 class ScDocument;
35 struct ScSortParam;
36 struct ScQueryParam;
37 struct ScSubTotalParam;
38 
40 enum class ScDBDataPortion
41 {
42  TOP_LEFT,
43  AREA
44 };
45 
48 {
49 public:
52  ScDocument& GetDocument() const;
54 
55 protected:
58 };
59 
60 class SAL_DLLPUBLIC_RTTI ScDBData final : public SvtListener, public ScRefreshTimer
61 {
62 private:
63  std::unique_ptr<ScSortParam> mpSortParam;
64  std::unique_ptr<ScQueryParam> mpQueryParam;
65  std::unique_ptr<ScSubTotalParam> mpSubTotal;
66  std::unique_ptr<ScImportParam> mpImportParam;
67 
69 
71  const OUString aName;
72  OUString aUpper;
78  bool bByRow;
79  bool bHasHeader;
80  bool bHasTotals;
81  bool bDoSize;
82  bool bKeepFmt;
83  bool bStripData;
84 
86  bool bIsAdvanced;
88 
89  bool bDBSelection;
90 
91  sal_uInt16 nIndex;
92  bool bAutoFilter;
93  bool bModified;
94 
95  ::std::vector< OUString > maTableColumnNames;
98 
99  using ScRefreshTimer::operator==;
100 
101 public:
102  struct less
103  {
104  bool operator() (const std::unique_ptr<ScDBData>& left, const std::unique_ptr<ScDBData>& right) const;
105  };
106 
107  SC_DLLPUBLIC ScDBData(const OUString& rName,
108  SCTAB nTab,
109  SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
110  bool bByR = true, bool bHasH = true, bool bTotals = false);
111  ScDBData(const ScDBData& rData);
112  ScDBData(const OUString& rName, const ScDBData& rData);
113  SC_DLLPUBLIC virtual ~ScDBData() override;
114 
115  virtual void Notify( const SfxHint& rHint ) override;
116 
117  ScDBData& operator= (const ScDBData& rData) ;
118 
119  bool operator== (const ScDBData& rData) const;
120 
121  const OUString& GetName() const { return aName; }
122  const OUString& GetUpperName() const { return aUpper; }
123  SCTAB GetTab() const { return nTable; }
124  void GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2) const;
125  SC_DLLPUBLIC void GetArea(ScRange& rRange) const;
126  void SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
127  void MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
128  SCCOL nUpdateCol = -1);
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( ::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  SC_DLLPUBLIC void GetSortParam(ScSortParam& rSortParam) const;
176  SC_DLLPUBLIC 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  bool UpdateReference(const ScDocument* pDoc, UpdateRefMode eUpdateRefMode, SCCOL nCol1,
212  SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
213  SCCOL nDx, SCROW nDy, SCTAB nDz);
214 
215  void ExtendDataArea(const ScDocument& rDoc);
216  void CalcSaveFilteredCount(SCSIZE nNonFilteredRowCount);
217  void GetFilterSelCount(SCSIZE& nSelected, SCSIZE& nTotal);
218 
219 private:
220 
221  void AdjustTableColumnNames( UpdateRefMode eUpdateRefMode, SCCOL nDx, SCCOL nCol1,
222  SCCOL nOldCol1, SCCOL nOldCol2, SCCOL nNewCol1, SCCOL nNewCol2 );
223  void InvalidateTableColumnNames( bool bSwapToEmptyNames );
224 };
225 
227 {
228 public:
229  enum RangeType { GlobalNamed, GlobalAnonymous, SheetAnonymous };
230 
235  {
236  friend class ScDBCollection;
237 
238  typedef ::std::set<std::unique_ptr<ScDBData>, ScDBData::less> DBsType;
239  DBsType m_DBs;
242  NamedDBs(const NamedDBs& r, ScDBCollection& rParent);
243  NamedDBs(const NamedDBs&) = delete;
244  virtual ~NamedDBs() override;
245  NamedDBs & operator=(NamedDBs const&) = delete;
246  void initInserted( ScDBData* p );
247 
248  public:
249  typedef DBsType::iterator iterator;
250  typedef DBsType::const_iterator const_iterator;
251 
252  iterator begin();
253  iterator end();
254  const_iterator begin() const;
255  const_iterator end() const;
256  ScDBData* findByIndex(sal_uInt16 nIndex);
257  ScDBData* findByUpperName(const OUString& rName);
258  iterator findByUpperName2(const OUString& rName);
259 
264  bool insert(std::unique_ptr<ScDBData> p);
265 
266  iterator erase(const iterator& itr);
267  bool empty() const;
268  size_t size() const;
269  bool operator== (const NamedDBs& r) const;
270  };
271 
275  class SAL_DLLPRIVATE AnonDBs
276  {
277  typedef ::std::vector<std::unique_ptr<ScDBData>> DBsType;
278  DBsType m_DBs;
279 
280  AnonDBs& operator=(AnonDBs const&) = delete;
281 
282  public:
283  AnonDBs();
284  AnonDBs(AnonDBs const&);
285 
286  typedef DBsType::iterator iterator;
287  typedef DBsType::const_iterator const_iterator;
288 
289  iterator begin();
290  iterator end();
291  const_iterator begin() const;
292  const_iterator end() const;
293  const ScDBData* findAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const;
294  const ScDBData* findByRange(const ScRange& rRange) const;
295  void deleteOnTab(SCTAB nTab);
296  ScDBData* getByRange(const ScRange& rRange);
297  void insert(ScDBData* p);
298  iterator erase(const iterator& itr);
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& rDocument);
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 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:519
ScDocument & mrDoc
Definition: dbdata.hxx:56
ScRefreshTimer & operator=(const ScRefreshTimer &r)
SCTAB GetTab() const
Definition: dbdata.hxx:123
ScRange aAdvSource
source range
Definition: dbdata.hxx:87
ScRangeList maDirtyTableColumnNames
Definition: dbdata.hxx:57
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:47
sal_uInt64 left
void SetImportSelection(bool bSet)
Definition: dbdata.hxx:202
bool HasHeader() const
Definition: dbdata.hxx:130
bool bIsAdvanced
QueryParam.
Definition: dbdata.hxx:86
void SetDoSize(bool bSet)
Definition: dbdata.hxx:137
void SetKeepFmt(bool bSet)
Definition: dbdata.hxx:139
bool mbTableColumnNamesDirty
Definition: dbdata.hxx:96
SCCOL nStartCol
Definition: dbdata.hxx:74
bool bDoSize
Definition: dbdata.hxx:81
bool IsDoSize() const
Definition: dbdata.hxx:136
std::unique_ptr< ScSortParam > mpSortParam
Definition: dbdata.hxx:63
sal_uInt16 nEntryIndex
counter for unique indices
Definition: dbdata.hxx:307
void SetModified(bool bMod)
Definition: dbdata.hxx:208
ScDocument & rDoc
Definition: dbdata.hxx:306
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:44
AnonDBs & getAnonDBs()
Definition: dbdata.hxx:318
::std::vector< std::unique_ptr< ScDBData > > DBsType
Definition: dbdata.hxx:277
ScDBCollection & mrParent
Definition: dbdata.hxx:240
SCROW nStartRow
Definition: dbdata.hxx:75
void SetIndex(sal_uInt16 nInd)
Definition: dbdata.hxx:134
::std::vector< OUString > maTableColumnNames
names of table columns
Definition: dbdata.hxx:95
void SetRefreshHandler(const Link< Timer *, void > &rLink)
Definition: dbdata.hxx:336
sal_uInt16 GetIndex() const
Definition: dbdata.hxx:135
virtual ~ScDBDataContainerBase()
Definition: dbdata.hxx:51
Stores global anonymous database ranges.
Definition: dbdata.hxx:275
ScDBDataPortion
Enum used to indicate which portion of the DBArea is to be considered.
Definition: dbdata.hxx:40
bool bKeepFmt
Definition: dbdata.hxx:82
bool bAutoFilter
AutoFilter? (not saved)
Definition: dbdata.hxx:92
def right
SC_DLLPUBLIC const ::std::vector< OUString > & GetTableColumnNames() const
Definition: dbdata.hxx:149
SCROW nEndRow
Definition: dbdata.hxx:77
SCCOL nEndCol
Definition: dbdata.hxx:76
const AnonDBs & getAnonDBs() const
Definition: dbdata.hxx:319
const OUString aName
DBParam.
Definition: dbdata.hxx:71
bool bHasTotals
Definition: dbdata.hxx:80
void SetContainer(ScDBDataContainerBase *pContainer)
Definition: dbdata.hxx:143
bool empty() const
Definition: dbdata.cxx:1513
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:483
sal_Int16 SCCOL
Definition: types.hxx:21
OUString aUpper
Definition: dbdata.hxx:72
SCSIZE nFilteredRowCount
Definition: dbdata.hxx:97
DBsType::iterator iterator
Definition: dbdata.hxx:249
const OUString & GetName() const
Definition: dbdata.hxx:121
std::unique_ptr< ScQueryParam > mpQueryParam
Definition: dbdata.hxx:64
bool IsKeepFmt() const
Definition: dbdata.hxx:138
size
SCTAB nTable
Definition: dbdata.hxx:73
bool bByRow
Definition: dbdata.hxx:78
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:286
Stores global named database ranges.
Definition: dbdata.hxx:234
UpdateRefMode
Definition: global.hxx:310
sal_Int32 SCROW
Definition: types.hxx:17
ScDBDataContainerBase * mpContainer
Definition: dbdata.hxx:68
const OUString & GetUpperName() const
Definition: dbdata.hxx:122
ScRangeList & GetDirtyTableColumnNames()
Definition: dbdata.cxx:1067
DBsType::const_iterator const_iterator
Definition: dbdata.hxx:287
DBsType::const_iterator const_iterator
Definition: dbdata.hxx:250
AnonDBs maAnonDBs
Definition: dbdata.hxx:309
bool bDBSelection
not in Param: if selection, block update
Definition: dbdata.hxx:89
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:66
bool bHasHeader
Definition: dbdata.hxx:79
bool bModified
is set/cleared for/by(?) UpdateReference
Definition: dbdata.hxx:93
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
ScDocument & GetDocument() const
Definition: dbdata.cxx:1062
std::unique_ptr< ScSubTotalParam > mpSubTotal
Definition: dbdata.hxx:65
bool bStripData
Definition: dbdata.hxx:83
const NamedDBs & getNamedDBs() const
Definition: dbdata.hxx:316
ScDBDataContainerBase(ScDocument &rDoc)
Definition: dbdata.hxx:50
::std::set< std::unique_ptr< ScDBData >, ScDBData::less > DBsType
Definition: dbdata.hxx:238
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
bool operator==(const ScRefreshTimer &r) const
bool HasTotals() const
Definition: dbdata.hxx:132
sal_Int16 SCTAB
Definition: types.hxx:22
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:91
bool IsModified() const
Definition: dbdata.hxx:207