DbModel Pile   version 0.0.1
DbModel pile.
DbModelPrivate Class Reference

Internal model. More...

#include <dbmodelprivate.h>

+ Inheritance diagram for DbModelPrivate:

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

Reimplemented methods from 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
 

Detailed Description

Internal model.

Constructor & Destructor Documentation

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.

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
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().

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
DbModelPrivate::~DbModelPrivate ( )
virtual

destructor

Detailed description for destructor.

Member Function Documentation

int DbModelPrivate::columnCount ( ) const

Number of columns.

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

Returns
number of columns
QVariant DbModelPrivate::data ( const QModelIndex &  idx,
int  role = Qt::DisplayRole 
) const
Todo:
column.t_display_;
DbStruct* DbModelPrivate::database ( ) 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.

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

Number of rows.

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

Returns
number of rows
bool DbModelPrivate::setColumnCallback ( int  table_index,
int  column_index,
DbColumn::Callback  value,
void *  user_data 
)
Todo:
the cells in main table are also stored locally; this is a design flaw as we should only store a reference in DbModelCol.
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.

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

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

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

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

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

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

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
Todo:
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.

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: