kspread Library API Documentation

kspread_cluster.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2000 Torben Weis <weis@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 /* Philipp
00021 This class defines a pointer map to all cells, which makes access to them more performant
00022 and additionally limits memory consumption.
00023 
00024 In detail: The class defines 2 cluster, where the second cluster (LEVEL2) is a matrix for
00025 single cells, while the first cluster (LEVEL1) is a matrix to handle the matrices of LEVEL2.
00026 On initialization, one LEVEL1 matrix is generated only.
00027 Each time, a cell stores something, this class checks if for the given column and row a
00028 matrix of LEVEL2 is already initialized and in case not generates it on the fly.
00029 This helps to reduce the memory usage to only consum one pointer matrix for LEVEL1 and all
00030 matrices of LEVEL2 that are necessary.
00031 
00032 LEVEL1 is defined as 128x128 matrix.
00033 LEVEL2 is defined as 256x256 matrices.
00034 Each direction then can have LEVEL1 * LEVEL2 = 128*256 = 2^15 different cells, which
00035 is in total (2^15)^2 cells.
00036 
00037 It can be changed easily to different sizes, but it should be more senseful to have a small LEVEL1,
00038 as in most cases only one/two entries in LEVEL1 will be used.
00039 
00040 There are 2 additional special classes to store pointers for column and row formats.
00041 
00042 Future enhancements:
00043 To reduce memory consumption, it should be possible to enhance the functionality by
00044 another LEVEL0, which then keeps the LEVEL1 size smaller.
00045 
00046 Maybe the LEVEL1 should only be generated when there is a need for more than 1 LEVEL2.
00047 
00048 LEVEL1 maybe reallocated.
00049 
00050 Another interesting possibility would be to differentiate between x size and y size. Currently both
00051 are equal in both matrizes, but normally it will be the regular case, that you have more need for
00052 a lot of rows than columns. Maybe something like LEVEL1=128/256 and LEVEL2=256/128 (x/y), still keeping
00053 2^15 values/cells in each direction (benefit: you won't loose memory in empty columns).
00054 */
00055 
00056 #ifndef kspread_cluster_h
00057 #define kspread_cluster_h
00058 
00059 class KSpreadCell;
00060 class ColumnFormat;
00061 class RowFormat;
00062 
00063 #include "kspread_value.h"
00064 
00065 class QPoint;
00066 
00067 #define KSPREAD_CLUSTER_LEVEL1 128
00068 #define KSPREAD_CLUSTER_LEVEL2 256
00069 #define KSPREAD_CLUSTER_MAX (128*256)
00070 
00071 class KSpreadCluster
00072 {
00073 public:
00074     KSpreadCluster();
00075     ~KSpreadCluster();
00076 
00077     KSpreadCell* lookup( int x, int y ) const;
00078 
00083     void clear();
00084 
00089     void insert( KSpreadCell* cell, int x, int y );
00093     void remove( int x, int y );
00094 
00095     void setAutoDelete( bool );
00096     bool autoDelete() const;
00097 
00098     KSpreadCell* firstCell() const;
00099 
00100     bool shiftRow( const QPoint& marker );
00108     bool shiftColumn( const QPoint& marker );
00109 
00114     void unshiftColumn( const QPoint& marker );
00115     void unshiftRow( const QPoint& marker );
00116 
00124     bool insertColumn( int col );
00125     bool insertRow( int row );
00126 
00134     void removeColumn( int col );
00135     void removeRow( int row );
00136 
00141     void clearColumn( int col );
00142     void clearRow( int row );
00143 
00148   KSpreadValue valueRange (int col1, int row1, int col2, int row2) const;
00149 
00159   KSpreadCell* getFirstCellColumn(int col) const;
00160 
00170   KSpreadCell* getLastCellColumn(int col) const;
00171 
00181   KSpreadCell* getFirstCellRow(int row) const;
00182 
00192   KSpreadCell* getLastCellRow(int row) const;
00193 
00203   KSpreadCell* getNextCellUp(int col, int row) const;
00204 
00214   KSpreadCell* getNextCellDown(int col, int row) const;
00215 
00226   KSpreadCell* getNextCellRight(int col, int row) const;
00227 
00238   KSpreadCell* getNextCellLeft(int col, int row) const;
00239 
00240 private:
00245     bool shiftRow( const QPoint& marker, bool& work );
00246     bool shiftColumn( const QPoint& marker, bool& work );
00247 
00248     void unshiftColumn( const QPoint& marker, bool& work );
00249     void unshiftRow( const QPoint& marker, bool& work );
00250 
00252     KSpreadValue makeArray (int col1, int row1, int col2, int row2) const;
00253     
00254     KSpreadCell*** m_cluster;
00255     KSpreadCell* m_first;
00256     bool m_autoDelete;
00257     unsigned int m_biggestX, m_biggestY;
00258 };
00259 
00260 class KSpreadColumnCluster
00261 {
00262 public:
00263     KSpreadColumnCluster();
00264     ~KSpreadColumnCluster();
00265 
00266     const ColumnFormat* lookup( int col ) const;
00267     ColumnFormat* lookup( int col );
00268 
00269     void clear();
00270 
00271     void insertElement( ColumnFormat*, int col );
00272     void removeElement( int col );
00273 
00274     bool insertColumn( int col );
00275     bool removeColumn( int col );
00276 
00277     void setAutoDelete( bool );
00278     bool autoDelete() const;
00279 
00280     ColumnFormat* first()const { return m_first; }
00281 
00282 private:
00283     ColumnFormat*** m_cluster;
00284     ColumnFormat* m_first;
00285     bool m_autoDelete;
00286 };
00287 
00288 class KSpreadRowCluster
00289 {
00290 public:
00291     KSpreadRowCluster();
00292     ~KSpreadRowCluster();
00293 
00294     const RowFormat* lookup( int col ) const;
00295     RowFormat* lookup( int col );
00296 
00297     void clear();
00298 
00299     void insertElement( RowFormat*, int row );
00300     void removeElement( int row );
00301 
00302     bool insertRow( int row );
00303     bool removeRow( int row );
00304 
00305     void setAutoDelete( bool );
00306     bool autoDelete() const;
00307 
00308     RowFormat* first()const { return m_first; }
00309 
00310 private:
00311     RowFormat*** m_cluster;
00312     RowFormat* m_first;
00313     bool m_autoDelete;
00314 };
00315 
00316 #endif
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:42:53 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003