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