![]() |
QxOrm
1.2.8
C++ Object Relational Mapping library
|
qx::IxModel : interface to manage Qt model/view architecture with classes registered into QxOrm context (Qt widgets and/or QML views) More...
#include <IxModel.h>
Public Types | |
typedef QHash< QString, IxModel * > | type_relation_by_name |
typedef QList < type_relation_by_name > | type_lst_relation_by_name |
Public Member Functions | |
IxModel (QObject *parent=0) | |
virtual | ~IxModel () |
IxClass * | getClass () const |
IxCollection * | getCollection () const |
QSqlDatabase | getDatabase () const |
QSqlError | getLastError () const |
Q_INVOKABLE QString | getLastErrorAsString () const |
Q_INVOKABLE QStringList | getListOfColumns () const |
QHash< QString, QString > | getListOfHeaders () const |
IxDataMember * | getDataMember (int column) const |
Q_INVOKABLE QString | getDataMemberKey (int column) const |
Q_INVOKABLE QVariant | getModelValue (int row, const QString &column) const |
void | setDatabase (const QSqlDatabase &db) |
Q_INVOKABLE void | setListOfColumns (const QStringList &lst) |
void | setListOfHeaders (const QHash< QString, QString > &lst) |
Q_INVOKABLE bool | setModelValue (int row, const QString &column, const QVariant &value) |
void | setParentModel (IxModel *pParent) |
virtual long | qxCount (const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxCount (long &lCount, const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxFetchById (const QVariant &id, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxFetchAll (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxFetchByQuery (const qx::QxSqlQuery &query, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxInsert (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxUpdate (const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxSave (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxSaveRow (int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxDeleteById (const QVariant &id, QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxDeleteAll (QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxDeleteByQuery (const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxDestroyById (const QVariant &id, QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxDestroyAll (QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxDestroyByQuery (const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)=0 |
virtual QSqlError | qxExecuteQuery (qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)=0 |
virtual qx_bool | qxExist (const QVariant &id, QSqlDatabase *pDatabase=NULL)=0 |
virtual qx::QxInvalidValueX | qxValidate (const QStringList &groups=QStringList())=0 |
Q_INVOKABLE int | qxCount_ (const QString &sQuery) |
Q_INVOKABLE bool | qxFetchById_ (const QVariant &id, const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxFetchAll_ (const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxFetchByQuery_ (const QString &sQuery, const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxInsert_ (const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxUpdate_ (const QString &sQuery, const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxSave_ (const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxSaveRow_ (int row, const QStringList &relation=QStringList()) |
Q_INVOKABLE bool | qxDeleteById_ (const QVariant &id) |
Q_INVOKABLE bool | qxDeleteAll_ () |
Q_INVOKABLE bool | qxDeleteByQuery_ (const QString &sQuery) |
Q_INVOKABLE bool | qxDestroyById_ (const QVariant &id) |
Q_INVOKABLE bool | qxDestroyAll_ () |
Q_INVOKABLE bool | qxDestroyByQuery_ (const QString &sQuery) |
Q_INVOKABLE bool | qxExecuteQuery_ (const QString &sQuery) |
Q_INVOKABLE bool | qxExist_ (const QVariant &id) |
Q_INVOKABLE QString | qxValidate_ (const QStringList &groups=QStringList()) |
Q_INVOKABLE void | clear (bool bUpdateColumns=false) |
virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const |
virtual int | columnCount (const QModelIndex &parent=QModelIndex()) const |
virtual QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
virtual QModelIndex | parent (const QModelIndex &index) const |
virtual bool | hasChildren (const QModelIndex &parent=QModelIndex()) const |
virtual QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
virtual Qt::ItemFlags | flags (const QModelIndex &index) const |
virtual Qt::DropActions | supportedDropActions () const |
virtual bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
virtual bool | setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) |
Protected Member Functions | |
void | raiseEvent_headerDataChanged (Qt::Orientation orientation, int first, int last) |
void | raiseEvent_dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight) |
void | raiseEvent_layoutAboutToBeChanged () |
void | raiseEvent_layoutChanged () |
void | generateRoleNames () |
QSqlDatabase * | database (QSqlDatabase *other) |
IxModel * | getChild (long row, const QString &relation) |
void | insertChild (long row, const QString &relation, IxModel *pChild) |
void | removeListOfChild (long row) |
Protected Attributes | |
IxClass * | m_pClass |
Class introspection registered into QxOrm context associated to the model. | |
IxDataMemberX * | m_pDataMemberX |
List of properties defined into QxOrm context. | |
IxDataMember * | m_pDataMemberId |
Primary key (property id) defined into QxOrm context. | |
IxCollection * | m_pCollection |
Interface to store a list of items. | |
QHash< int, QByteArray > | m_lstRoleNames |
List of model's role names to expose data to QML. | |
QList< IxDataMember * > | m_lstDataMember |
List of data member exposed by the model. | |
QHash< QString, int > | m_lstDataMemberByKey |
List of data member key to get column index in model. | |
QHash< QString, QString > | m_lstHeaders |
List of headers titles to override default data member key value. | |
QStringList | m_lstColumns |
List of columns exposed by the model (if empty, all columns) | |
QSqlDatabase | m_database |
Database connexion to execute SQL queries (if empty, default database connexion) | |
QSqlError | m_lastError |
Last SQL error. | |
IxModel * | m_pParent |
Parent model, NULL if current model is the root model. | |
type_lst_relation_by_name | m_lstChild |
List of child model : QxEntityEditor uses this property to manage relationships and create complex data structure. |
qx::IxModel : interface to manage Qt model/view architecture with classes registered into QxOrm context (Qt widgets and/or QML views)
QxModelView module provides an easy way to work with Qt model/view engine with all classes registered into QxOrm context :
qx::IxModel interface provides a generic way for all models linked to persistents classes registered into QxOrm context. All methods of this class prefixed by qx call functions from qx::dao namespace and then communicate with database.
The qxBlogModelView sample project in ./test/ directory of QxOrm package shows how to create quickly a model and associate it to the Qt model/view engine (first with a Qt widget, then with a QML view).
1- Here is an example to display/modify data from 'author' table (go to qxBlog tutorial for 'author' class definition) in a QTableView :
// Create a model and fetch all data from database qx::IxModel * pModel = new qx::QxModel<author>(); pModel->qxFetchAll(); // Associate the model to a QTableView and display it QTableView tableView; tableView.setModel(pModel); tableView.show();
2- Here is another example in QML (with Qt5, QxModelView module works fine with Qt4 too) :
// Create a model and fetch all data from database qx::IxModel * pModel = new qx::QxModel<author>(); pModel->qxFetchAll(); // Associate the model to a QML view and display it QQuickView qmlView; qmlView.rootContext()->setContextProperty("myModel", pModel); qmlView.setSource(QUrl("qrc:/documents/main.qml")); qmlView.show();
And here is the 'main.qml' file content :
import QtQuick 2.1 import QtQuick.Controls 1.0 Item { width: 400 height: 300 Row { height: 20 spacing: 20 Button { text: "Clear" onClicked: myModel.clear() } Button { text: "Fetch All" onClicked: myModel.qxFetchAll_() } Button { text: "Save" onClicked: myModel.qxSave_() } } ListView { y: 30 height: 270 model: myModel delegate: Row { height: 20 spacing: 10 Text { text: "id: " + author_id } TextField { text: name onTextChanged: name = text } } } }
As you can see in the 'main.qml' file, 'author_id' and 'name' properties of 'author' model ('myModel' variable) can be automatically read and write (because they are registered into QxOrm context). Moreover, qx::IxModel interface provides a list of methods for QML side (Q_INVOKABLE) to communicate with database : for example, the 'Save' button will save the model in database without having to write a C++ function.
Note : a QxEntityEditor plugin generates automatically the code to manage models with relationships. Then it is possible to work with nested C++ models.
typedef QList<type_relation_by_name> qx::IxModel::type_lst_relation_by_name |
typedef QHash<QString, IxModel *> qx::IxModel::type_relation_by_name |
qx::IxModel::IxModel | ( | QObject * | parent = 0 | ) |
virtual qx::IxModel::~IxModel | ( | ) | [virtual] |
Q_INVOKABLE void qx::IxModel::clear | ( | bool | bUpdateColumns = false | ) |
virtual int qx::IxModel::columnCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
QSqlDatabase* qx::IxModel::database | ( | QSqlDatabase * | other | ) | [protected] |
virtual Qt::ItemFlags qx::IxModel::flags | ( | const QModelIndex & | index | ) | const [virtual] |
void qx::IxModel::generateRoleNames | ( | ) | [protected] |
IxModel* qx::IxModel::getChild | ( | long | row, |
const QString & | relation | ||
) | [protected] |
IxClass* qx::IxModel::getClass | ( | ) | const |
IxCollection* qx::IxModel::getCollection | ( | ) | const |
QSqlDatabase qx::IxModel::getDatabase | ( | ) | const |
IxDataMember* qx::IxModel::getDataMember | ( | int | column | ) | const |
Q_INVOKABLE QString qx::IxModel::getDataMemberKey | ( | int | column | ) | const |
QSqlError qx::IxModel::getLastError | ( | ) | const |
Q_INVOKABLE QString qx::IxModel::getLastErrorAsString | ( | ) | const |
Q_INVOKABLE QStringList qx::IxModel::getListOfColumns | ( | ) | const |
QHash<QString, QString> qx::IxModel::getListOfHeaders | ( | ) | const |
Q_INVOKABLE QVariant qx::IxModel::getModelValue | ( | int | row, |
const QString & | column | ||
) | const |
virtual bool qx::IxModel::hasChildren | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
virtual QVariant qx::IxModel::headerData | ( | int | section, |
Qt::Orientation | orientation, | ||
int | role = Qt::DisplayRole |
||
) | const [virtual] |
virtual QModelIndex qx::IxModel::index | ( | int | row, |
int | column, | ||
const QModelIndex & | parent = QModelIndex() |
||
) | const [virtual] |
void qx::IxModel::insertChild | ( | long | row, |
const QString & | relation, | ||
IxModel * | pChild | ||
) | [protected] |
virtual QModelIndex qx::IxModel::parent | ( | const QModelIndex & | index | ) | const [virtual] |
virtual long qx::IxModel::qxCount | ( | const qx::QxSqlQuery & | query = qx::QxSqlQuery() , |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
virtual QSqlError qx::IxModel::qxCount | ( | long & | lCount, |
const qx::QxSqlQuery & | query = qx::QxSqlQuery() , |
||
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE int qx::IxModel::qxCount_ | ( | const QString & | sQuery | ) |
virtual QSqlError qx::IxModel::qxDeleteAll | ( | QSqlDatabase * | pDatabase = NULL | ) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxDeleteAll_ | ( | ) |
virtual QSqlError qx::IxModel::qxDeleteById | ( | const QVariant & | id, |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxDeleteById_ | ( | const QVariant & | id | ) |
virtual QSqlError qx::IxModel::qxDeleteByQuery | ( | const qx::QxSqlQuery & | query, |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxDeleteByQuery_ | ( | const QString & | sQuery | ) |
virtual QSqlError qx::IxModel::qxDestroyAll | ( | QSqlDatabase * | pDatabase = NULL | ) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxDestroyAll_ | ( | ) |
virtual QSqlError qx::IxModel::qxDestroyById | ( | const QVariant & | id, |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxDestroyById_ | ( | const QVariant & | id | ) |
virtual QSqlError qx::IxModel::qxDestroyByQuery | ( | const qx::QxSqlQuery & | query, |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxDestroyByQuery_ | ( | const QString & | sQuery | ) |
virtual QSqlError qx::IxModel::qxExecuteQuery | ( | qx::QxSqlQuery & | query, |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxExecuteQuery_ | ( | const QString & | sQuery | ) |
virtual qx_bool qx::IxModel::qxExist | ( | const QVariant & | id, |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxExist_ | ( | const QVariant & | id | ) |
virtual QSqlError qx::IxModel::qxFetchAll | ( | const QStringList & | relation = QStringList() , |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxFetchAll_ | ( | const QStringList & | relation = QStringList() | ) |
virtual QSqlError qx::IxModel::qxFetchById | ( | const QVariant & | id, |
const QStringList & | relation = QStringList() , |
||
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxFetchById_ | ( | const QVariant & | id, |
const QStringList & | relation = QStringList() |
||
) |
virtual QSqlError qx::IxModel::qxFetchByQuery | ( | const qx::QxSqlQuery & | query, |
const QStringList & | relation = QStringList() , |
||
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxFetchByQuery_ | ( | const QString & | sQuery, |
const QStringList & | relation = QStringList() |
||
) |
virtual QSqlError qx::IxModel::qxInsert | ( | const QStringList & | relation = QStringList() , |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxInsert_ | ( | const QStringList & | relation = QStringList() | ) |
virtual QSqlError qx::IxModel::qxSave | ( | const QStringList & | relation = QStringList() , |
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxSave_ | ( | const QStringList & | relation = QStringList() | ) |
virtual QSqlError qx::IxModel::qxSaveRow | ( | int | row, |
const QStringList & | relation = QStringList() , |
||
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxSaveRow_ | ( | int | row, |
const QStringList & | relation = QStringList() |
||
) |
virtual QSqlError qx::IxModel::qxUpdate | ( | const qx::QxSqlQuery & | query = qx::QxSqlQuery() , |
const QStringList & | relation = QStringList() , |
||
QSqlDatabase * | pDatabase = NULL |
||
) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE bool qx::IxModel::qxUpdate_ | ( | const QString & | sQuery, |
const QStringList & | relation = QStringList() |
||
) |
virtual qx::QxInvalidValueX qx::IxModel::qxValidate | ( | const QStringList & | groups = QStringList() | ) | [pure virtual] |
Implemented in qx::QxModel< T >.
Q_INVOKABLE QString qx::IxModel::qxValidate_ | ( | const QStringList & | groups = QStringList() | ) |
void qx::IxModel::raiseEvent_dataChanged | ( | const QModelIndex & | topLeft, |
const QModelIndex & | bottomRight | ||
) | [protected] |
void qx::IxModel::raiseEvent_headerDataChanged | ( | Qt::Orientation | orientation, |
int | first, | ||
int | last | ||
) | [protected] |
void qx::IxModel::raiseEvent_layoutAboutToBeChanged | ( | ) | [protected] |
void qx::IxModel::raiseEvent_layoutChanged | ( | ) | [protected] |
void qx::IxModel::removeListOfChild | ( | long | row | ) | [protected] |
virtual bool qx::IxModel::removeRows | ( | int | row, |
int | count, | ||
const QModelIndex & | parent = QModelIndex() |
||
) | [virtual] |
virtual int qx::IxModel::rowCount | ( | const QModelIndex & | parent = QModelIndex() | ) | const [virtual] |
void qx::IxModel::setDatabase | ( | const QSqlDatabase & | db | ) |
virtual bool qx::IxModel::setHeaderData | ( | int | section, |
Qt::Orientation | orientation, | ||
const QVariant & | value, | ||
int | role = Qt::EditRole |
||
) | [virtual] |
Q_INVOKABLE void qx::IxModel::setListOfColumns | ( | const QStringList & | lst | ) |
void qx::IxModel::setListOfHeaders | ( | const QHash< QString, QString > & | lst | ) |
Q_INVOKABLE bool qx::IxModel::setModelValue | ( | int | row, |
const QString & | column, | ||
const QVariant & | value | ||
) |
void qx::IxModel::setParentModel | ( | IxModel * | pParent | ) |
virtual Qt::DropActions qx::IxModel::supportedDropActions | ( | ) | const [virtual] |
QSqlDatabase qx::IxModel::m_database [protected] |
QSqlError qx::IxModel::m_lastError [protected] |
type_lst_relation_by_name qx::IxModel::m_lstChild [protected] |
QStringList qx::IxModel::m_lstColumns [protected] |
QList<IxDataMember *> qx::IxModel::m_lstDataMember [protected] |
QHash<QString, int> qx::IxModel::m_lstDataMemberByKey [protected] |
QHash<QString, QString> qx::IxModel::m_lstHeaders [protected] |
QHash<int, QByteArray> qx::IxModel::m_lstRoleNames [protected] |
IxClass* qx::IxModel::m_pClass [protected] |
IxCollection* qx::IxModel::m_pCollection [protected] |
IxDataMember* qx::IxModel::m_pDataMemberId [protected] |
IxDataMemberX* qx::IxModel::m_pDataMemberX [protected] |
IxModel* qx::IxModel::m_pParent [protected] |