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
48{
49public:
52 ScDocument& GetDocument() const;
54
55protected:
58};
59
60class SAL_DLLPUBLIC_RTTI ScDBData final : public SvtListener, public ScRefreshTimer
61{
62private:
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;
81 bool bDoSize;
84
88
90
91 sal_uInt16 nIndex;
93 bool bModified;
94
95 ::std::vector< OUString > maTableColumnNames;
98
99 using ScRefreshTimer::operator==;
100
101public:
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 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
219private:
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{
228public:
229 enum RangeType { GlobalNamed, GlobalAnonymous, SheetAnonymous };
230
235 {
236 friend class ScDBCollection;
237
238 typedef ::std::set<std::unique_ptr<ScDBData>, ScDBData::less> DBsType;
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 ScDBData* findByName(const OUString& rName);
260
265 bool insert(std::unique_ptr<ScDBData> p);
266
267 iterator 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;
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 iterator erase(const iterator& itr);
300 bool empty() const;
301 bool has( const ScDBData* p ) const;
302 bool operator== (const AnonDBs& r) const;
303 };
304
305private:
308 sal_uInt16 nEntryIndex;
311
312public:
313 ScDBCollection(ScDocument& rDocument);
315
316 NamedDBs& getNamedDBs() { return maNamedDBs;}
317 const NamedDBs& getNamedDBs() const { return maNamedDBs;}
318
319 AnonDBs& getAnonDBs() { return maAnonDBs;}
320 const AnonDBs& getAnonDBs() const { return maAnonDBs;}
321
322 const ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion) const;
323 ScDBData* GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, ScDBDataPortion ePortion);
324 const ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const;
325 ScDBData* GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
326 ScDBData* GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab );
327 std::vector<ScDBData*> GetAllDBsFromTab(SCTAB nTab);
328
329 void RefreshDirtyTableColumnNames();
330
331 void DeleteOnTab( SCTAB nTab );
332 void UpdateReference(UpdateRefMode eUpdateRefMode,
333 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
334 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
335 SCCOL nDx, SCROW nDy, SCTAB nDz);
336 void UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos );
337 void CopyToTable(SCTAB nOldPos, SCTAB nNewPos);
338
340 { aRefreshHandler = rLink; }
341 const Link<Timer *, void>& GetRefreshHandler() const { return aRefreshHandler; }
342
343 bool empty() const;
344 bool operator== (const ScDBCollection& r) const;
345};
346
347/* 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:277
AnonDBs & operator=(AnonDBs const &)=delete
DBsType::const_iterator const_iterator
Definition: dbdata.hxx:288
DBsType::iterator iterator
Definition: dbdata.hxx:287
::std::vector< std::unique_ptr< ScDBData > > DBsType
Definition: dbdata.hxx:278
Stores global named database ranges.
Definition: dbdata.hxx:235
DBsType::const_iterator const_iterator
Definition: dbdata.hxx:250
NamedDBs & operator=(NamedDBs const &)=delete
NamedDBs(const NamedDBs &)=delete
ScDBCollection & mrParent
Definition: dbdata.hxx:240
::std::set< std::unique_ptr< ScDBData >, ScDBData::less > DBsType
Definition: dbdata.hxx:238
DBsType::iterator iterator
Definition: dbdata.hxx:249
AnonDBs maAnonDBs
Definition: dbdata.hxx:310
Link< Timer *, void > aRefreshHandler
Definition: dbdata.hxx:306
NamedDBs maNamedDBs
Definition: dbdata.hxx:309
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:316
const NamedDBs & getNamedDBs() const
Definition: dbdata.hxx:317
const Link< Timer *, void > & GetRefreshHandler() const
Definition: dbdata.hxx:341
bool empty() const
Definition: dbdata.cxx:1603
const AnonDBs & getAnonDBs() const
Definition: dbdata.hxx:320
sal_uInt16 nEntryIndex
counter for unique indices
Definition: dbdata.hxx:308
AnonDBs & getAnonDBs()
Definition: dbdata.hxx:319
void SetRefreshHandler(const Link< Timer *, void > &rLink)
Definition: dbdata.hxx:339
ScDocument & rDoc
Definition: dbdata.hxx:307
Container base class to provide selected access for ScDBData.
Definition: dbdata.hxx:48
ScDocument & mrDoc
Definition: dbdata.hxx:56
ScRangeList & GetDirtyTableColumnNames()
Definition: dbdata.cxx:1121
ScRangeList maDirtyTableColumnNames
Definition: dbdata.hxx:57
ScDBDataContainerBase(ScDocument &rDoc)
Definition: dbdata.hxx:50
virtual ~ScDBDataContainerBase()
Definition: dbdata.hxx:51
ScDocument & GetDocument() const
Definition: dbdata.cxx:1116
std::unique_ptr< ScSortParam > mpSortParam
Definition: dbdata.hxx:63
void SetByRow(bool bByR)
Definition: dbdata.hxx:129
bool IsDoSize() const
Definition: dbdata.hxx:136
bool HasAutoFilter() const
Definition: dbdata.hxx:204
bool HasHeader() const
Definition: dbdata.hxx:130
void SetIndex(sal_uInt16 nInd)
Definition: dbdata.hxx:134
const OUString & GetName() const
Definition: dbdata.hxx:121
std::unique_ptr< ScImportParam > mpImportParam
Definition: dbdata.hxx:66
bool bModified
is set/cleared for/by(?) UpdateReference
Definition: dbdata.hxx:93
SCROW nEndRow
Definition: dbdata.hxx:77
SCCOL nEndCol
Definition: dbdata.hxx:76
bool HasTotals() const
Definition: dbdata.hxx:132
bool bByRow
Definition: dbdata.hxx:78
const OUString & GetUpperName() const
Definition: dbdata.hxx:122
bool IsModified() const
Definition: dbdata.hxx:207
bool bDBSelection
not in Param: if selection, block update
Definition: dbdata.hxx:89
void SetAutoFilter(bool bSet)
Definition: dbdata.hxx:205
const OUString aName
DBParam.
Definition: dbdata.hxx:71
ScRange aAdvSource
source range
Definition: dbdata.hxx:87
bool bAutoFilter
AutoFilter? (not saved)
Definition: dbdata.hxx:92
void SetDoSize(bool bSet)
Definition: dbdata.hxx:137
void SetTotals(bool bTotals)
Definition: dbdata.hxx:133
bool bHasHeader
Definition: dbdata.hxx:79
SCTAB nTable
Definition: dbdata.hxx:73
SC_DLLPUBLIC const ::std::vector< OUString > & GetTableColumnNames() const
Definition: dbdata.hxx:149
void SetContainer(ScDBDataContainerBase *pContainer)
Definition: dbdata.hxx:143
SCROW nStartRow
Definition: dbdata.hxx:75
bool AreTableColumnNamesDirty() const
Definition: dbdata.hxx:150
void SetHeader(bool bHasH)
Definition: dbdata.hxx:131
void SetImportSelection(bool bSet)
Definition: dbdata.hxx:202
std::unique_ptr< ScSubTotalParam > mpSubTotal
Definition: dbdata.hxx:65
void SetModified(bool bMod)
Definition: dbdata.hxx:208
SCTAB GetTab() const
Definition: dbdata.hxx:123
bool IsStripData() const
Definition: dbdata.hxx:140
bool bIsAdvanced
QueryParam.
Definition: dbdata.hxx:86
std::unique_ptr< ScQueryParam > mpQueryParam
Definition: dbdata.hxx:64
bool mbTableColumnNamesDirty
Definition: dbdata.hxx:96
SCCOL nStartCol
Definition: dbdata.hxx:74
void SetStripData(bool bSet)
Definition: dbdata.hxx:141
void SetKeepFmt(bool bSet)
Definition: dbdata.hxx:139
bool HasImportSelection() const
Definition: dbdata.hxx:201
bool bKeepFmt
Definition: dbdata.hxx:82
bool bHasTotals
Definition: dbdata.hxx:80
sal_uInt16 nIndex
unique index formulas
Definition: dbdata.hxx:91
bool IsKeepFmt() const
Definition: dbdata.hxx:138
ScDBDataContainerBase * mpContainer
Definition: dbdata.hxx:68
SCSIZE nFilteredRowCount
Definition: dbdata.hxx:97
::std::vector< OUString > maTableColumnNames
names of table columns
Definition: dbdata.hxx:95
bool bStripData
Definition: dbdata.hxx:83
bool bDoSize
Definition: dbdata.hxx:81
sal_uInt16 GetIndex() const
Definition: dbdata.hxx:135
OUString aUpper
Definition: dbdata.hxx:72
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:299
sal_Int32 nIndex
OUString aName
size
enumrange< T >::Iterator begin(enumrange< T >)
end
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
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:519