~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to kspread/kspread_cluster.h

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2000 Torben Weis <weis@kde.org>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
   Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
/* Philipp
 
21
This class defines a pointer map to all cells, which makes access to them more performant
 
22
and additionally limits memory consumption.
 
23
 
 
24
In detail: The class defines 2 cluster, where the second cluster (LEVEL2) is a matrix for
 
25
single cells, while the first cluster (LEVEL1) is a matrix to handle the matrices of LEVEL2.
 
26
On initialization, one LEVEL1 matrix is generated only.
 
27
Each time, a cell stores something, this class checks if for the given column and row a
 
28
matrix of LEVEL2 is already initialized and in case not generates it on the fly.
 
29
This helps to reduce the memory usage to only consum one pointer matrix for LEVEL1 and all
 
30
matrices of LEVEL2 that are necessary.
 
31
 
 
32
LEVEL1 is defined as 128x128 matrix.
 
33
LEVEL2 is defined as 256x256 matrices.
 
34
Each direction then can have LEVEL1 * LEVEL2 = 128*256 = 2^15 different cells, which
 
35
is in total (2^15)^2 cells.
 
36
 
 
37
It can be changed easily to different sizes, but it should be more senseful to have a small LEVEL1,
 
38
as in most cases only one/two entries in LEVEL1 will be used.
 
39
 
 
40
There are 2 additional special classes to store pointers for column and row formats.
 
41
 
 
42
Future enhancements:
 
43
To reduce memory consumption, it should be possible to enhance the functionality by
 
44
another LEVEL0, which then keeps the LEVEL1 size smaller.
 
45
 
 
46
Maybe the LEVEL1 should only be generated when there is a need for more than 1 LEVEL2.
 
47
 
 
48
LEVEL1 maybe reallocated.
 
49
 
 
50
Another interesting possibility would be to differentiate between x size and y size. Currently both
 
51
are equal in both matrizes, but normally it will be the regular case, that you have more need for
 
52
a lot of rows than columns. Maybe something like LEVEL1=128/256 and LEVEL2=256/128 (x/y), still keeping
 
53
2^15 values/cells in each direction (benefit: you won't loose memory in empty columns).
 
54
*/
 
55
 
1
56
#ifndef kspread_cluster_h
2
57
#define kspread_cluster_h
3
58
 
4
59
class KSpreadCell;
5
 
class ColumnLayout;
6
 
class RowLayout;
 
60
class ColumnFormat;
 
61
class RowFormat;
7
62
 
8
63
class QPoint;
9
64
 
10
 
#define KSPREAD_CLUSTER_LEVEL1 100
11
 
#define KSPREAD_CLUSTER_LEVEL2 100
12
 
#define KSPREAD_CLUSTER_MAX (100*100)
 
65
#define KSPREAD_CLUSTER_LEVEL1 128
 
66
#define KSPREAD_CLUSTER_LEVEL2 256
 
67
#define KSPREAD_CLUSTER_MAX (128*256)
13
68
 
14
69
class KSpreadCluster
15
70
{
17
72
    KSpreadCluster();
18
73
    ~KSpreadCluster();
19
74
 
20
 
    const KSpreadCell* lookup( int x, int y ) const;
21
 
    KSpreadCell* lookup( int x, int y );
 
75
    KSpreadCell* lookup( int x, int y ) const;
22
76
 
23
77
    /**
24
78
     * Removes all cells from the table and frees memory that
39
93
    void setAutoDelete( bool );
40
94
    bool autoDelete() const;
41
95
 
42
 
    KSpreadCell* firstCell();
 
96
    KSpreadCell* firstCell() const;
43
97
 
44
98
    bool shiftRow( const QPoint& marker );
45
99
    /**
80
134
 
81
135
    /**
82
136
     * Removes all elements from the column.
 
137
     *
 
138
     * @param presereDoM preserve the DependingOnMe lists of the cells if non-empty
83
139
     */
84
 
    void clearColumn( int col );
85
 
    void clearRow( int row );
 
140
    void clearColumn( int col, bool preserveDoM = false );
 
141
    void clearRow( int row, bool preserveDoM = false );
 
142
 
 
143
  /**
 
144
   * Retrieve the first used cell in a given column.  Can be used in conjunction
 
145
   * with getNextCellDown to loop through a column.
 
146
   *
 
147
   * @param col The column to get the first cell from
 
148
   *
 
149
   * @return Returns a pointer to the cell, or NULL if there are no used cells
 
150
   *         in this column
 
151
   */
 
152
  KSpreadCell* getFirstCellColumn(int col) const;
 
153
 
 
154
  /**
 
155
   * Retrieve the last used cell in a given column.  Can be used in conjunction
 
156
   * with getNextCellUp to loop through a column.
 
157
   *
 
158
   * @param col The column to get the cell from
 
159
   *
 
160
   * @return Returns a pointer to the cell, or NULL if there are no used cells
 
161
   *         in this column
 
162
   */
 
163
  KSpreadCell* getLastCellColumn(int col) const;
 
164
 
 
165
  /**
 
166
   * Retrieve the first used cell in a given row.  Can be used in conjunction
 
167
   * with getNextCellRight to loop through a row.
 
168
   *
 
169
   * @param row The row to get the first cell from
 
170
   *
 
171
   * @return Returns a pointer to the cell, or NULL if there are no used cells
 
172
   *         in this row
 
173
   */
 
174
  KSpreadCell* getFirstCellRow(int row) const;
 
175
 
 
176
  /**
 
177
   * Retrieve the last used cell in a given row.  Can be used in conjunction
 
178
   * with getNextCellLeft to loop through a row.
 
179
   *
 
180
   * @param row The row to get the last cell from
 
181
   *
 
182
   * @return Returns a pointer to the cell, or NULL if there are no used cells
 
183
   *         in this row
 
184
   */
 
185
  KSpreadCell* getLastCellRow(int row) const;
 
186
 
 
187
  /**
 
188
   * Retrieves the next used cell above the given col/row pair.  The given
 
189
   * col/row pair does not need to reference a used cell.
 
190
   *
 
191
   * @param col column to start looking through
 
192
   * @param row the row above which to start looking.
 
193
   *
 
194
   * @return Returns the next used cell above this one, or NULL if there are none
 
195
   */
 
196
  KSpreadCell* getNextCellUp(int col, int row) const;
 
197
 
 
198
  /**
 
199
   * Retrieves the next used cell below the given col/row pair.  The given
 
200
   * col/row pair does not need to reference a used cell.
 
201
   *
 
202
   * @param col column to start looking through
 
203
   * @param row the row below which to start looking.
 
204
   *
 
205
   * @return Returns the next used cell below this one, or NULL if there are none
 
206
   */
 
207
  KSpreadCell* getNextCellDown(int col, int row) const;
 
208
 
 
209
  /**
 
210
   * Retrieves the next used cell to the right of the given col/row pair.
 
211
   * The given col/row pair does not need to reference a used cell.
 
212
   *
 
213
   * @param col the column after which should be searched
 
214
   * @param row the row to search through
 
215
   *
 
216
   * @return Returns the next used cell to the right of this one, or NULL if
 
217
   * there are none
 
218
   */
 
219
  KSpreadCell* getNextCellRight(int col, int row) const;
 
220
 
 
221
  /**
 
222
   * Retrieves the next used cell to the left of the given col/row pair.
 
223
   * The given col/row pair does not need to reference a used cell.
 
224
   *
 
225
   * @param col the column before which should be searched
 
226
   * @param row the row to search through
 
227
   *
 
228
   * @return Returns the next used cell to the left of this one, or NULL if
 
229
   * there are none
 
230
   */
 
231
  KSpreadCell* getNextCellLeft(int col, int row) const;
86
232
 
87
233
private:
88
234
    /**
106
252
    KSpreadColumnCluster();
107
253
    ~KSpreadColumnCluster();
108
254
 
109
 
    const ColumnLayout* lookup( int col ) const;
110
 
    ColumnLayout* lookup( int col );
 
255
    const ColumnFormat* lookup( int col ) const;
 
256
    ColumnFormat* lookup( int col );
111
257
 
112
258
    void clear();
113
259
 
114
 
    void insertElement( ColumnLayout*, int col );
 
260
    void insertElement( ColumnFormat*, int col );
115
261
    void removeElement( int col );
116
262
 
117
263
    bool insertColumn( int col );
120
266
    void setAutoDelete( bool );
121
267
    bool autoDelete() const;
122
268
 
123
 
    ColumnLayout* first() { return m_first; }
 
269
    ColumnFormat* first()const { return m_first; }
124
270
 
125
271
private:
126
 
    ColumnLayout*** m_cluster;
127
 
    ColumnLayout* m_first;
 
272
    ColumnFormat*** m_cluster;
 
273
    ColumnFormat* m_first;
128
274
    bool m_autoDelete;
129
275
};
130
276
 
134
280
    KSpreadRowCluster();
135
281
    ~KSpreadRowCluster();
136
282
 
137
 
    const RowLayout* lookup( int col ) const;
138
 
    RowLayout* lookup( int col );
 
283
    const RowFormat* lookup( int col ) const;
 
284
    RowFormat* lookup( int col );
139
285
 
140
286
    void clear();
141
287
 
142
 
    void insertElement( RowLayout*, int row );
 
288
    void insertElement( RowFormat*, int row );
143
289
    void removeElement( int row );
144
290
 
145
291
    bool insertRow( int row );
148
294
    void setAutoDelete( bool );
149
295
    bool autoDelete() const;
150
296
 
151
 
    RowLayout* first() { return m_first; }
 
297
    RowFormat* first()const { return m_first; }
152
298
 
153
299
private:
154
 
    RowLayout*** m_cluster;
155
 
    RowLayout* m_first;
 
300
    RowFormat*** m_cluster;
 
301
    RowFormat* m_first;
156
302
    bool m_autoDelete;
157
303
};
158
304