kspread
KSpread::Cluster Class Reference
This class defines a pointer map to all cells, which makes access to them more performant and additionally limits memory consumption. More...
#include <Cluster.h>
Public Member Functions | |
| Cluster () | |
| ~Cluster () | |
| bool | autoDelete () const |
| void | clear () |
| void | clearColumn (int col) |
| void | clearRow (int row) |
| Cell * | firstCell () const |
| Cell * | getFirstCellColumn (int col) const |
| Cell * | getFirstCellRow (int row) const |
| Cell * | getLastCellColumn (int col) const |
| Cell * | getLastCellRow (int row) const |
| Cell * | getNextCellDown (int col, int row) const |
| Cell * | getNextCellLeft (int col, int row) const |
| Cell * | getNextCellRight (int col, int row) const |
| Cell * | getNextCellUp (int col, int row) const |
| void | insert (Cell *cell, int x, int y) |
| bool | insertColumn (int col) |
| bool | insertRow (int row) |
| bool | insertShiftDown (const QPoint &marker) |
| bool | insertShiftRight (const QPoint &marker) |
| Cell * | lookup (int x, int y) const |
| void | remove (int x, int y) |
| void | removeColumn (int col) |
| void | removeRow (int row) |
| void | removeShiftLeft (const QPoint &marker) |
| void | removeShiftUp (const QPoint &marker) |
| void | setAutoDelete (bool) |
| Value | valueRange (int col1, int row1, int col2, int row2) const |
Detailed Description
This class defines a pointer map to all cells, which makes access to them more performant and additionally limits memory consumption.
In detail: The class defines 2 cluster, where the second cluster (LEVEL2) is a matrix for single cells, while the first cluster (LEVEL1) is a matrix to handle the matrices of LEVEL2. On initialization, one LEVEL1 matrix is generated only. Each time, a cell stores something, this class checks if for the given column and row a matrix of LEVEL2 is already initialized and in case not generates it on the fly. This helps to reduce the memory usage to only consum one pointer matrix for LEVEL1 and all matrices of LEVEL2 that are necessary.
LEVEL1 is defined as 128x128 matrix. LEVEL2 is defined as 256x256 matrices. Each direction then can have LEVEL1 * LEVEL2 = 128*256 = 2^15 different cells, which is in total (2^15)^2 cells.
It can be changed easily to different sizes, but it should be more senseful to have a small LEVEL1, as in most cases only one/two entries in LEVEL1 will be used.
There are 2 additional special classes to store pointers for column and row formats.
Future enhancements: To reduce memory consumption, it should be possible to enhance the functionality by another LEVEL0, which then keeps the LEVEL1 size smaller.
Maybe the LEVEL1 should only be generated when there is a need for more than 1 LEVEL2.
LEVEL1 maybe reallocated.
Another interesting possibility would be to differentiate between x size and y size. Currently both are equal in both matrizes, but normally it will be the regular case, that you have more need for a lot of rows than columns. Maybe something like LEVEL1=128/256 and LEVEL2=256/128 (x/y), still keeping 2^15 values/cells in each direction (benefit: you won't loose memory in empty columns).
Definition at line 72 of file Cluster.h.
Constructor & Destructor Documentation
| KSpread::Cluster::Cluster | ( | ) |
| KSpread::Cluster::~Cluster | ( | ) |
Member Function Documentation
| bool KSpread::Cluster::autoDelete | ( | ) | const |
| void KSpread::Cluster::clear | ( | ) |
Removes all cells from the sheet and frees memory that was used for the clusters.
| void KSpread::Cluster::clearColumn | ( | int | col | ) |
Removes all elements from the column.
| void KSpread::Cluster::clearRow | ( | int | row | ) |
| Cell* KSpread::Cluster::firstCell | ( | ) | const |
| Cell* KSpread::Cluster::getFirstCellColumn | ( | int | col | ) | const |
Retrieve the first used cell in a given column.
Can be used in conjunction with getNextCellDown to loop through a column.
- Parameters:
-
col The column to get the first cell from
- Returns:
- Returns a pointer to the cell, or 0 if there are no used cells in this column
| Cell* KSpread::Cluster::getFirstCellRow | ( | int | row | ) | const |
Retrieve the first used cell in a given row.
Can be used in conjunction with getNextCellRight to loop through a row.
- Parameters:
-
row The row to get the first cell from
- Returns:
- Returns a pointer to the cell, or 0 if there are no used cells in this row
| Cell* KSpread::Cluster::getLastCellColumn | ( | int | col | ) | const |
Retrieve the last used cell in a given column.
Can be used in conjunction with getNextCellUp to loop through a column.
- Parameters:
-
col The column to get the cell from
- Returns:
- Returns a pointer to the cell, or 0 if there are no used cells in this column
| Cell* KSpread::Cluster::getLastCellRow | ( | int | row | ) | const |
Retrieve the last used cell in a given row.
Can be used in conjunction with getNextCellLeft to loop through a row.
- Parameters:
-
row The row to get the last cell from
- Returns:
- Returns a pointer to the cell, or 0 if there are no used cells in this row
| Cell* KSpread::Cluster::getNextCellDown | ( | int | col, | |
| int | row | |||
| ) | const |
Retrieves the next used cell below the given col/row pair.
The given col/row pair does not need to reference a used cell.
- Parameters:
-
col column to start looking through row the row below which to start looking.
- Returns:
- Returns the next used cell below this one, or 0 if there are none
| Cell* KSpread::Cluster::getNextCellLeft | ( | int | col, | |
| int | row | |||
| ) | const |
Retrieves the next used cell to the left of the given col/row pair.
The given col/row pair does not need to reference a used cell.
- Parameters:
-
col the column before which should be searched row the row to search through
- Returns:
- Returns the next used cell to the left of this one, or 0 if there are none
| Cell* KSpread::Cluster::getNextCellRight | ( | int | col, | |
| int | row | |||
| ) | const |
Retrieves the next used cell to the right of the given col/row pair.
The given col/row pair does not need to reference a used cell.
- Parameters:
-
col the column after which should be searched row the row to search through
- Returns:
- Returns the next used cell to the right of this one, or 0 if there are none
| Cell* KSpread::Cluster::getNextCellUp | ( | int | col, | |
| int | row | |||
| ) | const |
Retrieves the next used cell above the given col/row pair.
The given col/row pair does not need to reference a used cell.
- Parameters:
-
col column to start looking through row the row above which to start looking.
- Returns:
- Returns the next used cell above this one, or 0 if there are none
| void KSpread::Cluster::insert | ( | Cell * | cell, | |
| int | x, | |||
| int | y | |||
| ) |
Inserts a cell at the requested position.
If there is already a cell, then remove is called on it.
| bool KSpread::Cluster::insertColumn | ( | int | col | ) |
Moves all columns beginning with col one position to the right.
If that does not work because a cell would drop out of the sheet, then false is returned.
- See also:
- removeColumn
| bool KSpread::Cluster::insertRow | ( | int | row | ) |
| bool KSpread::Cluster::insertShiftDown | ( | const QPoint & | marker | ) |
Moves all cells in the column marker.x() beginning with the one at marker.y() one position downwards.
- Returns:
- false if a cell would drop out of the sheet because of that. In this case the shift is not performed.
| bool KSpread::Cluster::insertShiftRight | ( | const QPoint & | marker | ) |
| Cell* KSpread::Cluster::lookup | ( | int | x, | |
| int | y | |||
| ) | const |
| void KSpread::Cluster::remove | ( | int | x, | |
| int | y | |||
| ) |
Removes the cell at the given position, if there is any.
| void KSpread::Cluster::removeColumn | ( | int | col | ) |
Removes all elements from the column and move all columns right of col one position to the left.
- See also:
- clearColumn
| void KSpread::Cluster::removeRow | ( | int | row | ) |
| void KSpread::Cluster::removeShiftLeft | ( | const QPoint & | marker | ) |
| void KSpread::Cluster::removeShiftUp | ( | const QPoint & | marker | ) |
Moves all cells in the column marker.x() beginning with the one at marker.y() + 1 one position upwards.
| void KSpread::Cluster::setAutoDelete | ( | bool | ) |
| Value KSpread::Cluster::valueRange | ( | int | col1, | |
| int | row1, | |||
| int | col2, | |||
| int | row2 | |||
| ) | const |
Retrieve a range of values stored in a Value.
The range is two-leveled with similar structure and reasoning as the storage of cells themselves.
The documentation for this class was generated from the following file:
