DbModel Pile
version 0.0.1
DbModel pile.
|
A Qt model capable of representing sql tables. More...
#include <dbmodel.h>
Public Member Functions | |
DbModel (DbStruct *db, DbTaew *meta, QObject *parent=NULL) | |
Create a new model from a table or view definition and a database. More... | |
DbModel (DbStruct *db, int component, QObject *parent=NULL) | |
Create a new model from a database and an index. More... | |
virtual | ~DbModel () |
Destructor. More... | |
bool | isValid () const |
Is this a valid model (with a table set) or not? | |
void | setMeta (DbTaew *meta) |
void | setMeta (DbStruct *database, DbTaew *meta) |
DbTaew * | takeMeta () |
Give away the pointer and remove it from internal storage. | |
DbTaew * | metaTaew () const |
Get a pointer to meta object; ownership stays with this instance. | |
QSqlTableModel * | mainModel () const |
Get a pointer to internal main model object. | |
bool | selectMe () |
Select the model (retreive information using options). | |
int | rowCount () const |
Number of rows. More... | |
int | columnCount () const |
Number of columns. More... | |
bool | lessThan (const QModelIndex &left, const QModelIndex &right) const |
Custom sorting. | |
DbStruct * | database () const |
void | setDatabase (DbStruct *value) |
Set the database; also invalidates the table. More... | |
DbStruct * | takeDatabase () |
Give away the pointer and remove it from internal storage. | |
const DbModelCol & | columnData (int index) const |
Get the model data regarding a column; index is a virtual index. | |
const DbModelTbl & | tableData (int table_index) const |
Get the model data regarding a table. | |
bool | setFilter (const QString &filter, int table_index=0) |
Set a filter on one of the internal models identified by its index. More... | |
bool | setFilter (const QString &filter, const QString &table) |
Set a filter on one of the internal models identified by its name. More... | |
const QString & | filter () const |
Get the filter installed on main model. | |
bool | setOrder (int column, Qt::SortOrder order, int table_index=0) |
Set a filter on one of the internal models identified by its index. More... | |
bool | setOrder (int column, Qt::SortOrder order, const QString &table) |
Set a filter on one of the internal models identified by its name. More... | |
int | findTable (const QString &table) const |
Find the index of a model identified by its name. More... | |
QSqlRecord | record (int row) const |
Get a record for a row. | |
void | reloadHeaders () |
Read the labels again (possibly in a different language). | |
bool | setColumnCallback (int table_index, int column_index, DbColumn::Callback value, void *user_data=NULL) |
Set the callback for a column in a table. | |
bool | setColumnCallback (int column_index, DbColumn::Callback value, void *user_data=NULL) |
Set the callback for a column in main table. | |
DbColumn::Callback | columnCallback (int table_index, int column_index) |
Get the callback for a cell. | |
void * | columnCallbackData () |
Get the callback for a cell. | |
Marker | |
A cell may be highlited in a different color and with a special icon; the model only stores the coordinates of that cell. | |
bool | setCurrentMarker (int row, int column) |
Set the indicated . More... | |
int | getMarkerRow () const |
Retreive highlite row. | |
int | getMarkerCol () const |
Retreive highlite column. | |
bool | hasMarkerCell () const |
Tell if we have a highlite cell set. | |
A Qt model capable of representing sql tables.
DbModel::DbModel | ( | DbStruct * | db, |
DbTaew * | meta, | ||
QObject * | parent = NULL |
||
) |
Create a new model from a table or view definition and a database.
This constructor variant uses table metadata provided by the user and it takes it on faith that the table belongs to the db
database.
db | the database to use (NULL can be used to allow later initialization |
meta | table to be loaded (NULL can be used to allow later initialization |
parent | the parent QObject |
DbModel::DbModel | ( | DbStruct * | db, |
int | component, | ||
QObject * | parent = NULL |
||
) |
Create a new model from a database and an index.
This constructor variant uses the database to retreive the main table. The component
must be a valid index for DbStructMeta::taew()
.
db | the database to use (NULL can be used to allow later initialization |
component | table to be loaded (-1 can be used to allow later initialization |
parent | the parent QObject |
|
virtual |
Destructor.
Detailed description for destructor.
int DbModel::columnCount | ( | ) | const |
Number of columns.
This method exists because, for table-only models, we will never have a parent.
DbStruct * DbModel::database | ( | ) | const |
Retreive the database. Ownership of returned pointer stays with this instance.
int DbModel::findTable | ( | const QString & | table | ) | const |
Find the index of a model identified by its name.
The method iterates internal list in search for the name.
table | name of the table to search for |
int DbModel::rowCount | ( | ) | const |
Number of rows.
This method exists because, for table-only models, we will never have a parent.
bool DbModel::setCurrentMarker | ( | int | row, |
int | column | ||
) |
Set the indicated .
The method checks the input against current valid range and stores the coordinates of the cell to highlite with a different color and icon.
column | the column of the cell to highlite |
row | the row of the cell to highlite |
void DbModel::setDatabase | ( | DbStruct * | value | ) |
Set the database; also invalidates the table.
The model will NOT be valid after this call because the metadata for the table is not set.
value | the database to use; this instance takes ownership of the pointer and delete will be called in the destructor. |
bool DbModel::setFilter | ( | const QString & | filter, |
int | table_index = 0 |
||
) |
Set a filter on one of the internal models identified by its index.
To set the filter for this model's main table call the method without the table_index parameter.
filter | The filter to apply |
table_index | the index of the table |
bool DbModel::setFilter | ( | const QString & | filter, |
const QString & | table | ||
) |
Set a filter on one of the internal models identified by its name.
This overload searches for the name in internal list to identify the index, then calls the base method.
filter | The filter to apply |
table |
void DbModel::setMeta | ( | DbTaew * | meta | ) |
Set the table or view; old instance is deleted; ovnership of table is assumed.
A call to this functionammounts to a complete change in the data that is displayied. It is a shortcut for destroying the model and creating a new one for another table.
The database is assumed to stay the same. The function fails if there is no database present in this instance.
meta | the table to load; may be NULL to bring the model in invalid state. A future call with a non-NULL value will make it valid again. |
void DbModel::setMeta | ( | DbStruct * | database, |
DbTaew * | meta | ||
) |
Set the database and table or view; old instance is deleted; ovnership of table is assumed.
A call to this functionammounts to a complete change in the data that is displayied. It is a shortcut for destroying the model and creating a new one for another table.
The database if first changed. If the database is valid we proceed to changing the table.
Calling this function is a shortcut for:
meta | the table to load; may be NULL to bring the model in invalid state. A future call with a non-NULL value will make it valid again. |
bool DbModel::setOrder | ( | int | column, |
Qt::SortOrder | order, | ||
int | table_index = 0 |
||
) |
Set a filter on one of the internal models identified by its index.
To set the sorting order for this model's main table call the method without the table_index parameter.
column | the column to use for sorting; |
order | the order to apply to sid column |
table_index | the index of the table |
bool DbModel::setOrder | ( | int | column, |
Qt::SortOrder | order, | ||
const QString & | table | ||
) |
Set a filter on one of the internal models identified by its name.
This overload searches for the name in internal list to identify the index, then calls the base method.
filter | The filter to apply |
table |