Qx v0.5.8
Qt Extensions Library
|
The Table class is a template class that provides a dynamic two-dimensional array. More...
#include <qx/core/qx-table.h>
Public Types | |
typedef QList< QList< T > >::const_iterator | row_iterator |
Public Member Functions | |
Table () | |
Table (QSize size) | |
Table (QSize size, const T &value) | |
Table (std::initializer_list< std::initializer_list< T > > table) | |
void | addColumns (qsizetype c) |
void | addRows (qsizetype r) |
void | appendColumn (const QList< T > &c) |
void | appendRow (const QList< T > &r) |
T & | at (qsizetype r, qsizetype c) |
const T & | at (qsizetype r, qsizetype c) const |
QSize | capacity () const |
QList< T > | columnAt (qsizetype i) const |
qsizetype | columnCount () const |
void | fill (const T &value, QSize size) |
QList< T > | firstColumn () const |
const QList< T > & | firstRow () const |
qsizetype | height () const |
void | insertColumn (qsizetype i, const QList< T > &c) |
void | insertRow (qsizetype i, const QList< T > &r) |
bool | isEmpty () const |
QList< T > | lastColumn () const |
const QList< T > & | lastRow () const |
bool | operator!= (const Table &other) const |
bool | operator== (const Table &other) const |
void | removeColumnAt (qsizetype i) |
void | removeColumns (qsizetype i, qsizetype n=1) |
void | removeFirstColumn () |
void | removeFirstRow () |
void | removeLastColumn () |
void | removeLastRow () |
void | removeRowAt (qsizetype i) |
void | removeRows (qsizetype i, qsizetype n=1) |
void | replaceColumn (qsizetype i, const QList< T > &c) |
void | replaceRow (qsizetype i, const QList< T > &r) |
void | reserve (QSize size) |
void | resize (QSize size) |
void | resizeColumns (qsizetype size) |
void | resizeRows (qsizetype size) |
const QList< T > & | rowAt (qsizetype i) const |
row_iterator | rowBegin () const |
qsizetype | rowCount () const |
row_iterator | rowEnd () const |
Table | section (qsizetype r, qsizetype c, qsizetype height, qsizetype width) const |
QSize | size () const |
void | squeeze () |
QList< T > | takeColumnAt (qsizetype i) |
QList< T > | takeFirstColumn () |
QList< T > | takeFirstRow () |
QList< T > | takeLastColumn () |
QList< T > | takeLastRow () |
QList< T > | takeRowAt (qsizetype i) |
T | value (qsizetype r, qsizetype c) const |
T | value (qsizetype r, qsizetype c, const T &defaultValue) const |
qsizetype | width () const |
Protected Attributes | |
QList< QList< T > > | mTable |
Table<T> is a generic container class that features fast index-based access and a similar API to QList<T>.
Qx::Table< T >::row_iterator |
The Table::row_iterator typedef provides an STL_style const iterator for Table.
This iterator steps through each row of the table.
Constructs a Table of size size, with every element initialized with a default-constructed value.
Constructs a Table of size size, with every element initialized to value.
|
inline |
Constructs a Table with a copy of each row in the initializer list list.
If all rows in the list are not the same size, this constructor will produce an empty table.
|
inline |
Appends c columns, with their elements initialized to default-constructed values, to the 'right' end of the table.
Equivalent to:
|
inline |
Appends c columns, with their elements initialized to default-constructed values, to the 'bottom' end of the table.
Equivalent to:
Appends c as a column to the 'right' end of the table.
If c is smaller than the current height (rowCount()) of the table, it will be expanded with default-constructed values after insertion to match the current height. If c is larger than the current height, the rest of the table's columns will be expanded with default-constructed values to match the height of c.
Appends r as a row to the 'bottom' end of the table.
If r is smaller than the current width (columnCount()) of the table, it will be expanded with default-constructed values after insertion to match the current width. If r is larger than the current width, the rest of the table's rows will be expanded with default-constructed values to match the width of c.
|
inline |
Returns the element at row r and column c as a modifiable reference.
r and c must point to a valid position within the table (i.e. 0 <= r < rowCount() && 0 <= c < columnCount()).
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the element as a constant reference.
Returns the items in column i of the table as a list.
i must be a valid column index in the table (i.e. 0 <= i < columnCount())
|
inline |
Returns the number of columns in the table.
Assigns value to all items in the table. If size is not null (the default), the table is resized to size beforehand.
Returns the items in the first column of the table as a list. This function assumes that the table isn't empty.
Returns the items in the first row of the table as a list. This function assumes that the table isn't empty.
|
inline |
Same as rowCount().
|
inline |
Inserts c as a column to column index i in the table. If i is 0, the column is prepended to the table. If i is columnSize(), the column is appended to the table.
If c is smaller than the current height (rowCount()) of the table, it will be expanded with default-constructed values after insertion to match the current height. If c is larger than the current height, the rest of the table's columns will be expanded with default-constructed values to match the height of c.
Inserts r as a row to row index i in the table. If i is 0, the row is prepended to the table. If i is rowSize(), the row is appended to the table.
If r is smaller than the current width (columnCount()) of the table, it will be expanded with default-constructed values after insertion to match the current width. If r is larger than the current width, the rest of the table's rows will be expanded with default-constructed values to match the width of c.
|
inline |
Returns the items in the last column of the table as a list. This function assumes that the table isn't empty.
Returns the items in the last row of the table as a list. This function assumes that the table isn't empty.
Returns true
if the table does not contain the same elements as other; otherwise, returns false
.
Returns true
if the table contains the same elements as other; otherwise, returns false
.
|
inline |
Removes the column i from the table.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes n columns from the table, starting at column i.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes the first column from the table. Calling this function is equivalent to calling removeColumns(0)
. The table must have columns. To prevent failure, call columnCount() before calling this function.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes the first row from the table. Calling this function is equivalent to calling removeRows(0)
. The table must have rows. To prevent failure, call rowCount() before calling this function.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes the last column from the table. Calling this function is equivalent to calling removeColumns(columnCount() - 1)
. The table must have columns. To prevent failure, call columnCount() before calling this function.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes the last row from the table. Calling this function is equivalent to calling removeRows(rowCount() - 1)
. The table must have rows. To prevent failure, call rowCount() before calling this function.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes the row i from the table.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Removes n rows from the table, starting at row i.
Element removal will preserve the table's capacity and not reduce the amount of allocated memory. To shed extra capacity and free as much memory as possible, call squeeze().
|
inline |
Replaces column i with c in the table.
If c is smaller than the current height (rowCount()) of the table, it will be expanded with default-constructed values after insertion to match the current height. If c is larger than the current height, the rest of the table's columns will be expanded with default-constructed values to match the height of c.
Replaces row i with r in the table.
If r is smaller than the current width (columnCount()) of the table, it will be expanded with default-constructed values after insertion to match the current width. If r is larger than the current width, the rest of the table's rows will be expanded with default-constructed values to match the width of c.
Attempts to allocate memory for size elements.
If you know in advance how large the table will be, you should call this function to prevent reallocations and memory fragmentation. If you resize the table often, you are also likely to get better performance.
If in doubt about how much space shall be needed, it is usually better to use an upper bound as size, or a high estimate of the most likely size, if a strict upper bound would be much bigger than this. If size is an underestimate, the table will grow as needed once the reserved size is exceeded, which may lead to a larger allocation than your best overestimate would have and will slow the operation that triggers it.
Sets the size of the table to size. If size is greater than the current size, elements are added to each end of the table; the new elements are initialized with default-constructed values. If size is less than the current size, elements are removed from each end.
|
inline |
Sets the number of columns in the table to size. If size is greater than the current column count, columns are added to the 'right' end of the table; the new elements are initialized with default-constructed values. If size is less than the current column count, columns are removed from the 'right' end.
|
inline |
Sets the number of rows in the table to size. If size is greater than the current row count, rows are added to the 'bottom' end of the table; the new elements are initialized with default-constructed values. If size is less than the current row count, rows are removed from the 'bottom' end.
Returns the items in row i of the table as a list.
i must be a valid column index in the table (i.e. 0 <= i < rowCount())
|
inline |
|
inline |
Returns the number of rows in the table.
|
inline |
Returns a const STL-style iterator pointing just after the last row in the table.
|
inline |
Returns a new Table that contains a portion of the table's elements.
r and specify
the origin of the subsection, while height specifies the number of rows to include, and width specifies the number of columns to include.
Any portions of the specified section that fall outside the bounds of the table are simply ignored, which can result in the new table being empty if the section does not intersect with the table whatsoever.
Returns the column count (width), and row count (height) of the table as a QSize object.
|
inline |
Releases any memory not required to store the elements.
The sole purpose of this function is to provide a means of fine tuning Table's memory usage. In general, you will rarely ever need to call this function.
|
inline |
Removes column i and returns it.
Equivalent to:
|
inline |
Removes the first column from the table and returns it. This function assumes the table has columns. To avoid failure, call columnCount() before calling this function.
|
inline |
Removes the first row from the table and returns it. This function assumes the table has rows. To avoid failure, call rowCount() before calling this function.
|
inline |
Removes the last column from the table and returns it. This function assumes the table has columns. To avoid failure, call columnCount() before calling this function.
|
inline |
Removes the last row from the table and returns it. This function assumes the table has rows. To avoid failure, call rowCount() before calling this function.
|
inline |
Removes row i and returns it.
Equivalent to:
|
inline |
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
If the position is out of bounds, the function returns defaultValue.
|
inline |
Same as columnCount().
|
protected |
This is the internal structure of the table, available for direct modification in derived classes.