DbModel Pile
version 0.0.1
DbModel pile.
|
Internal model. More...
#include <dbmodelprivate.h>
Public Member Functions | |
DbModelPrivate (DbStruct *db, DbTaew *meta, DbModel *parent) | |
Create a new model from a table or view definition and a database. More... | |
DbModelPrivate (DbStruct *db, int component, DbModel *parent) | |
Create a new model from a database and an index. More... | |
virtual | ~DbModelPrivate () |
destructor More... | |
DbModel * | parentDbModel () const |
Get the front-end model. | |
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... | |
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 real 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... | |
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) |
DbColumn::Callback | columnCallback (int table_index, int column_index) |
void * | columnCallbackData () |
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 cell. More... | |
int | getMarkerRow () const |
Retreive highlite row. | |
int | getMarkerCol () const |
Retreive highlite column. | |
bool | hasMarkerCell () const |
Tell if we have a highlite cell set. | |
QSqlTableModel | |
Qt::ItemFlags | flags (const QModelIndex &index) const |
QVariant | data (const QModelIndex &idx, int role=Qt::DisplayRole) const |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
bool | setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) |
bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) |
bool | validateIndex (const QModelIndex &idx) const |
Tell if an index is valid for this model. | |
void | sort (int column, Qt::SortOrder order=Qt::AscendingOrder) |
Set sorting order. | |
bool | removeRows (int row, int count, const QModelIndex &parent) |
Remove a number of rows. | |
static QVariant | formattedData (const DbColumn &colorig, const QVariant &original_value) |
Convert the data for the user. | |
int | rowCount (const QModelIndex &parent) const |
int | columnCount (const QModelIndex &parent) const |
Internal model.
DbModelPrivate::DbModelPrivate | ( | DbStruct * | db, |
DbTaew * | meta, | ||
DbModel * | parent | ||
) |
Create a new model from a table or view definition and a database.
file dbmodelprivate.cc date November 2015 author Nicu Tofan
brief Contains the implementation for DbModelPrivate class. 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 |
DbModelPrivate::DbModelPrivate | ( | DbStruct * | db, |
int | component, | ||
DbModel * | parent | ||
) |
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 DbModelPrivate::columnCount | ( | ) | const |
Number of columns.
This method exists because, for table-only models, we will never have a parent.
QVariant DbModelPrivate::data | ( | const QModelIndex & | idx, |
int | role = Qt::DisplayRole |
||
) | const |
|
inline |
Retreive the database. Ownership of returned pointer stays with this instance.
int DbModelPrivate::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 DbModelPrivate::rowCount | ( | ) | const |
Number of rows.
This method exists because, for table-only models, we will never have a parent.
bool DbModelPrivate::setColumnCallback | ( | int | table_index, |
int | column_index, | ||
DbColumn::Callback | value, | ||
void * | user_data | ||
) |
bool DbModelPrivate::setCurrentMarker | ( | int | row, |
int | column | ||
) |
Set the indicated cell.
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 DbModelPrivate::setDatabase | ( | DbStruct * | value | ) |
Set the database; also invalidates the table.
This method exists because, for table-only models, we will never have a parent.
bool DbModelPrivate::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 DbModelPrivate::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 |
bool DbModelPrivate::setHeaderData | ( | int | section, |
Qt::Orientation | orientation, | ||
const QVariant & | value, | ||
int | role = Qt::EditRole |
||
) |
Sets the caption for a horizontal header for the specified role to value. This is useful if the model is used to display data in a view (e.g., QTableView).
Returns true
if orientation is Qt::Horizontal and the section refers to a valid section; otherwise returns false.
Note that this function cannot be used to modify values in the database since the model is read-only.
void DbModelPrivate::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 DbModelPrivate::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 DbModelPrivate::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 DbModelPrivate::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 |