DbModel Pile   version 0.0.1
DbModel pile.
DbModel Class Reference

A Qt model capable of representing sql tables. More...

#include <dbmodel.h>

+ Inheritance diagram for DbModel:

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 DbModelColcolumnData (int index) const
 Get the model data regarding a column; index is a virtual index.
 
const DbModelTbltableData (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.
 

Detailed Description

A Qt model capable of representing sql tables.

Constructor & Destructor Documentation

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.

Parameters
dbthe database to use (NULL can be used to allow later initialization
metatable to be loaded (NULL can be used to allow later initialization
parentthe 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().

Parameters
dbthe database to use (NULL can be used to allow later initialization
componenttable to be loaded (-1 can be used to allow later initialization
parentthe parent QObject
DbModel::~DbModel ( )
virtual

Destructor.

Detailed description for destructor.

Member Function Documentation

int DbModel::columnCount ( ) const

Number of columns.

This method exists because, for table-only models, we will never have a parent.

Returns
number of columns
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.

Parameters
tablename of the table to search for
Returns
-1 if it was not found, 0 based index otherwise
int DbModel::rowCount ( ) const

Number of rows.

This method exists because, for table-only models, we will never have a parent.

Returns
number of rows
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.

Parameters
columnthe column of the cell to highlite
rowthe row of the cell to highlite
Returns
true if the checks passed
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.

Parameters
valuethe 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.

Parameters
filterThe filter to apply
table_indexthe index of the table
Returns
false if the index is out of bounds or the model does not exist
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.

Parameters
filterThe filter to apply
table
Returns
false if the name was not found or the model is invalid
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.

Parameters
metathe 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:

model->setDatabase (database);
model->setMeta (meta);
Parameters
metathe 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.

Parameters
columnthe column to use for sorting;
orderthe order to apply to sid column
table_indexthe index of the table
Returns
false if the index is out of bounds or the model does not exist
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.

Parameters
filterThe filter to apply
table
Returns
false if the name was not found or the model is invalid

The documentation for this class was generated from the following files: