1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SC_INC_DBDATA_HXX
21 #define INCLUDED_SC_INC_DBDATA_HXX
24 #include "refreshtimer.hxx"
25 #include "address.hxx"
28 #include <boost/ptr_container/ptr_vector.hpp>
29 #include <boost/ptr_container/ptr_set.hpp>
30 #include <boost/scoped_ptr.hpp>
35 struct ScSubTotalParam
;
38 class ScDBData
: public ScRefreshTimer
41 boost::scoped_ptr
<ScSortParam
> mpSortParam
;
42 boost::scoped_ptr
<ScQueryParam
> mpQueryParam
;
43 boost::scoped_ptr
<ScSubTotalParam
> mpSubTotal
;
44 boost::scoped_ptr
<ScImportParam
> mpImportParam
;
61 bool bIsAdvanced
; ///< true if created by advanced filter
62 ScRange aAdvSource
; ///< source range
64 bool bDBSelection
; ///< not in Param: if selection, block update
66 sal_uInt16 nIndex
; ///< unique index formulas
67 bool bAutoFilter
; ///< AutoFilter? (not saved)
68 bool bModified
; ///< is set/cleared for/by(?) UpdateReference
70 using ScRefreshTimer::operator==;
73 struct less
: public ::std::binary_function
<ScDBData
, ScDBData
, bool>
75 bool operator() (const ScDBData
& left
, const ScDBData
& right
) const;
78 SC_DLLPUBLIC
ScDBData(const OUString
& rName
,
80 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
,
81 bool bByR
= true, bool bHasH
= true);
82 ScDBData(const ScDBData
& rData
);
83 ScDBData(const OUString
& rName
, const ScDBData
& rData
);
86 ScDBData
& operator= (const ScDBData
& rData
);
88 bool operator== (const ScDBData
& rData
) const;
90 const OUString
& GetName() const { return aName
; }
91 const OUString
& GetUpperName() const { return aUpper
; }
92 void GetArea(SCTAB
& rTab
, SCCOL
& rCol1
, SCROW
& rRow1
, SCCOL
& rCol2
, SCROW
& rRow2
) const;
93 SC_DLLPUBLIC
void GetArea(ScRange
& rRange
) const;
94 void SetArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
95 void MoveTo(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
96 bool IsByRow() const { return bByRow
; }
97 void SetByRow(bool bByR
) { bByRow
= bByR
; }
98 bool HasHeader() const { return bHasHeader
; }
99 void SetHeader(bool bHasH
) { bHasHeader
= bHasH
; }
100 void SetIndex(sal_uInt16 nInd
) { nIndex
= nInd
; }
101 sal_uInt16
GetIndex() const { return nIndex
; }
102 bool IsDoSize() const { return bDoSize
; }
103 void SetDoSize(bool bSet
) { bDoSize
= bSet
; }
104 bool IsKeepFmt() const { return bKeepFmt
; }
105 void SetKeepFmt(bool bSet
) { bKeepFmt
= bSet
; }
106 bool IsStripData() const { return bStripData
; }
107 void SetStripData(bool bSet
) { bStripData
= bSet
; }
109 OUString
GetSourceString() const;
110 OUString
GetOperations() const;
112 void GetSortParam(ScSortParam
& rSortParam
) const;
113 void SetSortParam(const ScSortParam
& rSortParam
);
115 SC_DLLPUBLIC
void GetQueryParam(ScQueryParam
& rQueryParam
) const;
116 SC_DLLPUBLIC
void SetQueryParam(const ScQueryParam
& rQueryParam
);
117 SC_DLLPUBLIC
bool GetAdvancedQuerySource(ScRange
& rSource
) const;
118 SC_DLLPUBLIC
void SetAdvancedQuerySource(const ScRange
* pSource
);
120 void GetSubTotalParam(ScSubTotalParam
& rSubTotalParam
) const;
121 void SetSubTotalParam(const ScSubTotalParam
& rSubTotalParam
);
123 void GetImportParam(ScImportParam
& rImportParam
) const;
124 void SetImportParam(const ScImportParam
& rImportParam
);
126 bool IsDBAtCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
, bool bStartOnly
) const;
127 bool IsDBAtArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
) const;
129 bool HasImportParam() const;
130 SC_DLLPUBLIC
bool HasQueryParam() const;
131 bool HasSortParam() const;
132 bool HasSubTotalParam() const;
134 bool HasImportSelection() const { return bDBSelection
; }
135 void SetImportSelection(bool bSet
) { bDBSelection
= bSet
; }
137 bool HasAutoFilter() const { return bAutoFilter
; }
138 void SetAutoFilter(bool bSet
) { bAutoFilter
= bSet
; }
140 bool IsModified() const { return bModified
; }
141 void SetModified(bool bMod
) { bModified
= bMod
; }
143 void UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
);
144 void UpdateReference(ScDocument
* pDoc
, UpdateRefMode eUpdateRefMode
,
145 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
146 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
,
147 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
149 void ExtendDataArea(ScDocument
* pDoc
);
152 class SC_DLLPUBLIC ScDBCollection
155 enum RangeType
{ GlobalNamed
, GlobalAnonymous
, SheetAnonymous
};
158 * Stores global named database ranges.
160 class SC_DLLPUBLIC NamedDBs
162 friend class ScDBCollection
;
164 typedef ::boost::ptr_set
<ScDBData
, ScDBData::less
> DBsType
;
166 ScDBCollection
& mrParent
;
168 NamedDBs(ScDBCollection
& rParent
, ScDocument
& rDoc
);
169 NamedDBs(const NamedDBs
& r
);
171 typedef DBsType::iterator iterator
;
172 typedef DBsType::const_iterator const_iterator
;
176 const_iterator
begin() const;
177 const_iterator
end() const;
178 ScDBData
* findByIndex(sal_uInt16 nIndex
);
179 ScDBData
* findByUpperName(const OUString
& rName
);
180 // Takes ownership of p iff it returns true:
181 SAL_WARN_UNUSED_RESULT
bool insert(ScDBData
* p
);
182 void erase(iterator itr
);
183 void erase(const ScDBData
& r
);
186 bool operator== (const NamedDBs
& r
) const;
190 * Stores global anonymous database ranges.
194 typedef ::boost::ptr_vector
<ScDBData
> DBsType
;
197 typedef DBsType::iterator iterator
;
198 typedef DBsType::const_iterator const_iterator
;
202 const_iterator
begin() const;
203 const_iterator
end() const;
204 const ScDBData
* findAtCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
, bool bStartOnly
) const;
205 const ScDBData
* findByRange(const ScRange
& rRange
) const;
206 ScDBData
* getByRange(const ScRange
& rRange
);
207 void insert(ScDBData
* p
);
209 bool operator== (const AnonDBs
& r
) const;
213 Link aRefreshHandler
;
215 sal_uInt16 nEntryIndex
; ///< counter for unique indices
220 ScDBCollection(ScDocument
* pDocument
);
221 ScDBCollection(const ScDBCollection
& r
);
223 NamedDBs
& getNamedDBs();
224 const NamedDBs
& getNamedDBs() const;
226 AnonDBs
& getAnonDBs();
227 const AnonDBs
& getAnonDBs() const;
229 const ScDBData
* GetDBAtCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
, bool bStartOnly
) const;
230 ScDBData
* GetDBAtCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
, bool bStartOnly
);
231 const ScDBData
* GetDBAtArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
) const;
232 ScDBData
* GetDBAtArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
233 ScDBData
* GetDBNearCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
);
235 void DeleteOnTab( SCTAB nTab
);
236 void UpdateReference(UpdateRefMode eUpdateRefMode
,
237 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
238 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
,
239 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
);
240 void UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
);
242 sal_uInt16
GetEntryIndex() { return nEntryIndex
; }
243 void SetEntryIndex(sal_uInt16 nInd
) { nEntryIndex
= nInd
; }
245 void SetRefreshHandler( const Link
& rLink
)
246 { aRefreshHandler
= rLink
; }
247 const Link
& GetRefreshHandler() const { return aRefreshHandler
; }
250 bool operator== (const ScDBCollection
& r
) const;
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */