Line data Source code
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 SC_DBCOLECT_HXX
21 : #define SC_DBCOLECT_HXX
22 :
23 : #include "scdllapi.h"
24 : #include "refreshtimer.hxx"
25 : #include "address.hxx"
26 : #include "global.hxx"
27 :
28 : #include <boost/ptr_container/ptr_vector.hpp>
29 : #include <boost/ptr_container/ptr_set.hpp>
30 : #include <boost/scoped_ptr.hpp>
31 :
32 : class ScDocument;
33 : struct ScSortParam;
34 : struct ScQueryParam;
35 : struct ScSubTotalParam;
36 : struct ScImportParam;
37 :
38 : class ScDBData : public ScRefreshTimer
39 : {
40 : private:
41 : boost::scoped_ptr<ScSortParam> mpSortParam;
42 : boost::scoped_ptr<ScQueryParam> mpQueryParam;
43 : boost::scoped_ptr<ScSubTotalParam> mpSubTotal;
44 : boost::scoped_ptr<ScImportParam> mpImportParam;
45 :
46 : /// DBParam
47 : const OUString aName;
48 : OUString aUpper;
49 : SCTAB nTable;
50 : SCCOL nStartCol;
51 : SCROW nStartRow;
52 : SCCOL nEndCol;
53 : SCROW nEndRow;
54 : bool bByRow;
55 : bool bHasHeader;
56 : bool bDoSize;
57 : bool bKeepFmt;
58 : bool bStripData;
59 :
60 : /// QueryParam
61 : bool bIsAdvanced; ///< true if created by advanced filter
62 : ScRange aAdvSource; ///< source range
63 :
64 : bool bDBSelection; ///< not in Param: if selection, block update
65 :
66 : sal_uInt16 nIndex; ///< unique index formulas
67 : bool bAutoFilter; ///< AutoFilter? (not saved)
68 : bool bModified; ///< is set/cleared for/by(?) UpdateReference
69 :
70 : using ScRefreshTimer::operator==;
71 :
72 : public:
73 : struct less : public ::std::binary_function<ScDBData, ScDBData, bool>
74 : {
75 : bool operator() (const ScDBData& left, const ScDBData& right) const;
76 : };
77 :
78 : SC_DLLPUBLIC ScDBData(const OUString& rName,
79 : SCTAB nTab,
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);
84 : virtual ~ScDBData();
85 :
86 : ScDBData& operator= (const ScDBData& rData);
87 :
88 : bool operator== (const ScDBData& rData) const;
89 :
90 0 : const OUString& GetName() const { return aName; }
91 0 : 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 0 : void SetByRow(bool bByR) { bByRow = bByR; }
98 0 : bool HasHeader() const { return bHasHeader; }
99 0 : void SetHeader(bool bHasH) { bHasHeader = bHasH; }
100 0 : void SetIndex(sal_uInt16 nInd) { nIndex = nInd; }
101 0 : sal_uInt16 GetIndex() const { return nIndex; }
102 0 : bool IsDoSize() const { return bDoSize; }
103 0 : void SetDoSize(bool bSet) { bDoSize = bSet; }
104 0 : bool IsKeepFmt() const { return bKeepFmt; }
105 0 : void SetKeepFmt(bool bSet) { bKeepFmt = bSet; }
106 0 : bool IsStripData() const { return bStripData; }
107 0 : void SetStripData(bool bSet) { bStripData = bSet; }
108 :
109 : OUString GetSourceString() const;
110 : OUString GetOperations() const;
111 :
112 : void GetSortParam(ScSortParam& rSortParam) const;
113 : void SetSortParam(const ScSortParam& rSortParam);
114 :
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);
119 :
120 : void GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const;
121 : void SetSubTotalParam(const ScSubTotalParam& rSubTotalParam);
122 :
123 : void GetImportParam(ScImportParam& rImportParam) const;
124 : void SetImportParam(const ScImportParam& rImportParam);
125 :
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;
128 :
129 : bool HasImportParam() const;
130 : SC_DLLPUBLIC bool HasQueryParam() const;
131 : bool HasSortParam() const;
132 : bool HasSubTotalParam() const;
133 :
134 0 : bool HasImportSelection() const { return bDBSelection; }
135 0 : void SetImportSelection(bool bSet) { bDBSelection = bSet; }
136 :
137 0 : bool HasAutoFilter() const { return bAutoFilter; }
138 0 : void SetAutoFilter(bool bSet) { bAutoFilter = bSet; }
139 :
140 : bool IsModified() const { return bModified; }
141 0 : void SetModified(bool bMod) { bModified = bMod; }
142 :
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);
148 :
149 : void ExtendDataArea(ScDocument* pDoc);
150 : };
151 :
152 0 : class SC_DLLPUBLIC ScDBCollection
153 : {
154 : public:
155 : enum RangeType { GlobalNamed, GlobalAnonymous, SheetAnonymous };
156 :
157 : /**
158 : * Stores global named database ranges.
159 : */
160 0 : class SC_DLLPUBLIC NamedDBs
161 : {
162 : friend class ScDBCollection;
163 :
164 : typedef ::boost::ptr_set<ScDBData, ScDBData::less> DBsType;
165 : DBsType maDBs;
166 : ScDBCollection& mrParent;
167 : ScDocument& mrDoc;
168 : NamedDBs(ScDBCollection& rParent, ScDocument& rDoc);
169 : NamedDBs(const NamedDBs& r);
170 : public:
171 : typedef DBsType::iterator iterator;
172 : typedef DBsType::const_iterator const_iterator;
173 :
174 : iterator begin();
175 : iterator end();
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);
184 : bool empty() const;
185 : size_t size() const;
186 : bool operator== (const NamedDBs& r) const;
187 : };
188 :
189 : /**
190 : * Stores global anonymous database ranges.
191 : */
192 0 : class AnonDBs
193 : {
194 : typedef ::boost::ptr_vector<ScDBData> DBsType;
195 : DBsType maDBs;
196 : public:
197 : typedef DBsType::iterator iterator;
198 : typedef DBsType::const_iterator const_iterator;
199 :
200 : iterator begin();
201 : iterator end();
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);
208 : bool empty() const;
209 : bool operator== (const AnonDBs& r) const;
210 : };
211 :
212 : private:
213 : Link aRefreshHandler;
214 : ScDocument* pDoc;
215 : sal_uInt16 nEntryIndex; ///< counter for unique indices
216 : NamedDBs maNamedDBs;
217 : AnonDBs maAnonDBs;
218 :
219 : public:
220 : ScDBCollection(ScDocument* pDocument);
221 : ScDBCollection(const ScDBCollection& r);
222 :
223 : NamedDBs& getNamedDBs();
224 : const NamedDBs& getNamedDBs() const;
225 :
226 : AnonDBs& getAnonDBs();
227 : const AnonDBs& getAnonDBs() const;
228 :
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 );
234 :
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 );
241 :
242 : sal_uInt16 GetEntryIndex() { return nEntryIndex; }
243 : void SetEntryIndex(sal_uInt16 nInd) { nEntryIndex = nInd; }
244 :
245 0 : void SetRefreshHandler( const Link& rLink )
246 0 : { aRefreshHandler = rLink; }
247 0 : const Link& GetRefreshHandler() const { return aRefreshHandler; }
248 :
249 : bool empty() const;
250 : bool operator== (const ScDBCollection& r) const;
251 : };
252 :
253 : #endif
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|