| QxOrm 1.4.5 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
qx::QxModel< T, B > Class Template Reference
QxModelView : All classes registered into QxOrm context can be used with Qt model/view architecture (Qt widgets and/or QML views)

qx::QxModel<T, B> : all classes registered into QxOrm context can be used with Qt model/view architecture (Qt widgets and/or QML views) More...

`#include <QxModel.h>`

Inheritance diagram for qx::QxModel< T, B >:

List of all members.

## Public Types
enum | { qx_is_valid = (qx::trait::is_qx_registered<T>::value && std::is_base_of<qx::IxModel, B>::value) }
typedef std::shared_ptr< T > | type_ptr
typedef qx::trait::get_primary_key< T > ::type | type_primary_key
typedef qx::QxCollection < type_primary_key, type_ptr > | type_collection
typedef B | type_base_class
## Public Member Functions
| QxModel (QObject *parent=0)
| QxModel (qx::IxModel *other, QObject *parent)
virtual | ~QxModel ()
virtual bool | insertRows (int row, int count, const QModelIndex &parent=QModelIndex())
virtual void | sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
virtual bool | getShowEmptyLine () const
virtual void | setShowEmptyLine (bool b)
virtual long | qxCount (const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)
| Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query.
virtual QSqlError | qxCount (long &lCount, const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)
| Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query.
virtual QSqlError | qxFetchById (const QVariant &id, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Clear the model and fetch an object (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database.
virtual QSqlError | qxFetchAll (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Clear the model and fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database.
virtual QSqlError | qxFetchByQuery (const qx::QxSqlQuery &query, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Clear the model and fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query.
virtual QSqlError | qxFetchRow (int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Get an item in the model at line row and fetch all its properties mapped to a table in the database, then all views attached to this model are automatically updated.
virtual QSqlError | qxInsert (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Insert all items in the model into database.
virtual QSqlError | qxInsertRow (int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Insert an item of the model at line row into database.
virtual QSqlError | qxUpdate (const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Update all items in the model into database.
virtual QSqlError | qxUpdateRow (int row, const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Update an item of the model at line row into database.
virtual QSqlError | qxSave (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Save all items (insert or update) in the model into database.
virtual QSqlError | qxSaveRow (int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
| Save an item of the model at line row into database.
virtual QSqlError | qxSaveRowData (int row, const QStringList &column=QStringList(), QSqlDatabase *pDatabase=NULL)
| Used internally by qx::IxModel::setData() method with e_auto_update_on_field_change option, save an item (even if it is the dirty row item) of the model at line row into database.
virtual QSqlError | qxDeleteById (const QVariant &id, QSqlDatabase *pDatabase=NULL)
| Delete a line of a table (database) mapped to a C++ object of type T (registered into QxOrm context), if no error occurred then you should remove row from the model.
virtual QSqlError | qxDeleteAll (QSqlDatabase *pDatabase=NULL)
| Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context), if no error occurred then you should clear the model.
virtual QSqlError | qxDeleteByQuery (const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
| Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query, if no error occurred then you should refresh the model.
virtual QSqlError | qxDeleteRow (int row, QSqlDatabase *pDatabase=NULL)
| Delete in database the item at line row in the model, if no error occurred then you should remove row from the model.
virtual QSqlError | qxDestroyById (const QVariant &id, QSqlDatabase *pDatabase=NULL)
| Delete a line of a table (even if a logical delete is defined) mapped to a C++ object of type T (registered into QxOrm context), if no error occurred then you should remove row from the model.
virtual QSqlError | qxDestroyAll (QSqlDatabase *pDatabase=NULL)
| Delete all lines of a table (even if a logical delete is defined) mapped to a C++ class T (registered into QxOrm context), if no error occurred then you should clear the model.
virtual QSqlError | qxDestroyByQuery (const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
| Delete all lines of a table (even if a logical delete is defined) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query, if no error occurred then you should refresh the model.
virtual QSqlError | qxDestroyRow (int row, QSqlDatabase *pDatabase=NULL)
| Delete in database (even if a logical delete is defined) the item at line row in the model, if no error occurred then you should remove row from the model.
virtual QSqlError | qxExecuteQuery (qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
virtual qx_bool | qxExist (const QVariant &id, QSqlDatabase *pDatabase=NULL)
virtual qx::QxInvalidValueX | qxValidate (const QStringList &groups=QStringList())
virtual qx::QxInvalidValueX | qxValidateRow (int row, const QStringList &groups=QStringList())
## Protected Member Functions
void | init ()
void | initFrom (qx::IxModel *pOther)
type_ptr | getRowItemAt (int row) const
virtual void * | getRowItemAsVoidPtr (int row) const
virtual void | dumpModelImpl (bool bJsonFormat) const
virtual QObject * | cloneModelImpl ()
virtual void | updateShowEmptyLine ()
virtual bool | isDirtyRow (int row) const
virtual void | insertDirtyRowToModel ()
void | addDirtyRow ()
void | insertItem (int row, const type_ptr &pItem)
void | updateKey (int row)
void | updateAllKeys ()
virtual QString | toJson_Helper (int row) const
virtual bool | fromJson_Helper (const QString &json, int row)
virtual QVariant | getRelationshipValues_Helper (int row, const QString &relation, bool bLoadFromDatabase, const QString &sAppendRelations)
virtual bool | setRelationshipValues_Helper (int row, const QString &relation, const QVariant &values)
## Protected Attributes
type_collection | m_model
| Model associated to a class registered into QxOrm context.
std::shared_ptr< QPair< int, type_ptr > > | m_pDirtyRow
| When displayed in a QTableView, this will cause an empty line awaiting user input to be displayed at the bottom (enabled with setShowEmptyLine() method)
## Friends
struct | qx::model_view::detail::QxNestedModel
struct | qx::model_view::detail::QxNestedModel_Generic
struct | qx::model_view::detail::QxNestedModel_Container

## Detailed Description

### template<class T, class B = qx::IxModel>
class qx::QxModel< T, B >

qx::QxModel<T, B> : all classes registered into QxOrm context can be used with Qt model/view architecture (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 :

- Qt widgets : QTableView or QListView for example to display/modify a database table content ;
- QML : each property defined in QxOrm context is exposed to QML engine : QxModelView module makes easier integration between QML and databases.

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.

Definition at line 163 of file QxModel.h.

## Member Typedef Documentation

template<class T, class B = qx::IxModel>

typedef B qx::QxModel< T, B >::type_base_class

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 175 of file QxModel.h.

template<class T, class B = qx::IxModel>

typedef qx::QxCollection<type_primary_key, type_ptr> qx::QxModel< T, B >::type_collection

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 174 of file QxModel.h.

template<class T, class B = qx::IxModel>

typedef qx::trait::get_primary_key<T>::type qx::QxModel< T, B >::type_primary_key

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 173 of file QxModel.h.

template<class T, class B = qx::IxModel>

typedef std::shared_ptr<T> qx::QxModel< T, B >::type_ptr

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 172 of file QxModel.h.

## Member Enumeration Documentation

template<class T, class B = qx::IxModel>

anonymous enum

Enumerator:

  qx_is_valid |

Definition at line 177 of file QxModel.h.

## Constructor & Destructor Documentation

template<class T, class B = qx::IxModel>

qx::QxModel< T, B >::QxModel | ( | QObject * | parent = `0` | ) | `[inline]`

Definition at line 186 of file QxModel.h.

template<class T, class B = qx::IxModel>

qx::QxModel< T, B >::QxModel | ( | qx::IxModel * | other,
|  | QObject * | parent
| ) |  | `[inline]`

Definition at line 187 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual qx::QxModel< T, B >::~QxModel | ( |  | ) | `[inline, virtual]`

Definition at line 188 of file QxModel.h.

## Member Function Documentation

template<class T, class B = qx::IxModel>

void qx::QxModel< T, B >::addDirtyRow | ( |  | ) | `[inline, protected]`

Definition at line 656 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QObject* qx::QxModel< T, B >::cloneModelImpl | ( |  | ) | `[inline, protected, virtual]`

Definition at line 634 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual void qx::QxModel< T, B >::dumpModelImpl | ( | bool | bJsonFormat | ) | const`[inline, protected, virtual]`

Definition at line 632 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual bool qx::QxModel< T, B >::fromJson_Helper | ( | const QString & | json,
|  | int | row
| ) |  | `[inline, protected, virtual]`

Definition at line 711 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QVariant qx::QxModel< T, B >::getRelationshipValues_Helper | ( | int | row,
|  | const QString & | relation,
|  | bool | bLoadFromDatabase,
|  | const QString & | sAppendRelations
| ) |  | `[inline, protected, virtual]`

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 735 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual void* qx::QxModel< T, B >::getRowItemAsVoidPtr | ( | int | row | ) | const`[inline, protected, virtual]`

Definition at line 630 of file QxModel.h.

template<class T, class B = qx::IxModel>

type_ptr qx::QxModel< T, B >::getRowItemAt | ( | int | row | ) | const`[inline, protected]`

Definition at line 623 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual bool qx::QxModel< T, B >::getShowEmptyLine | ( |  | ) | const`[inline, virtual]`

Definition at line 236 of file QxModel.h.

template<class T, class B = qx::IxModel>

void qx::QxModel< T, B >::init | ( |  | ) | `[inline, protected]`

Definition at line 192 of file QxModel.h.

template<class T, class B = qx::IxModel>

void qx::QxModel< T, B >::initFrom | ( | qx::IxModel * | pOther | ) | `[inline, protected]`

Definition at line 202 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual void qx::QxModel< T, B >::insertDirtyRowToModel | ( |  | ) | `[inline, protected, virtual]`

Definition at line 646 of file QxModel.h.

template<class T, class B = qx::IxModel>

void qx::QxModel< T, B >::insertItem | ( | int | row,
|  | const type_ptr & | pItem
| ) |  | `[inline, protected]`

Definition at line 667 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual bool qx::QxModel< T, B >::insertRows | ( | int | row,
|  | int | count,
|  | const QModelIndex & | parent = `QModelIndex()`
| ) |  | `[inline, virtual]`

Definition at line 215 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual bool qx::QxModel< T, B >::isDirtyRow | ( | int | row | ) | const`[inline, protected, virtual]`

Definition at line 644 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual long qx::QxModel< T, B >::qxCount | ( | const qx::QxSqlQuery & | query = `qx::QxSqlQuery()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query.

Parameters:

  query | Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 254 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxCount | ( | long & | lCount,
|  | const qx::QxSqlQuery & | query = `qx::QxSqlQuery()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query.

Parameters:

  lCount | Output parameter with the number of lines in the table associated to the SQL query
  query | Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 265 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDeleteAll | ( | QSqlDatabase * | pDatabase = `NULL` | ) | `[inline, virtual]`

Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context), if no error occurred then you should clear the model.

Parameters:

  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 502 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDeleteById | ( | const QVariant & | id,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Delete a line of a table (database) mapped to a C++ object of type T (registered into QxOrm context), if no error occurred then you should remove row from the model.

Parameters:

  id | Row id to be deleted from database
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 487 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDeleteByQuery | ( | const qx::QxSqlQuery & | query,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query, if no error occurred then you should refresh the model.

Parameters:

  query | Define a user SQL query added to default SQL query builded by QxOrm library
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 514 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDeleteRow | ( | int | row,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Delete in database the item at line row in the model, if no error occurred then you should remove row from the model.

Parameters:

  row | Delete in database the item in the model at line row
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 526 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDestroyAll | ( | QSqlDatabase * | pDatabase = `NULL` | ) | `[inline, virtual]`

Delete all lines of a table (even if a logical delete is defined) mapped to a C++ class T (registered into QxOrm context), if no error occurred then you should clear the model.

Parameters:

  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 555 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDestroyById | ( | const QVariant & | id,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Delete a line of a table (even if a logical delete is defined) mapped to a C++ object of type T (registered into QxOrm context), if no error occurred then you should remove row from the model.

Parameters:

  id | Row id to be deleted from database
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 540 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDestroyByQuery | ( | const qx::QxSqlQuery & | query,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Delete all lines of a table (even if a logical delete is defined) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query, if no error occurred then you should refresh the model.

Parameters:

  query | Define a user SQL query added to default SQL query builded by QxOrm library
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 567 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxDestroyRow | ( | int | row,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Delete in database (even if a logical delete is defined) the item at line row in the model, if no error occurred then you should remove row from the model.

Parameters:

  row | Delete in database the item in the model at line row
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 579 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxExecuteQuery | ( | qx::QxSqlQuery & | query,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 587 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual qx_bool qx::QxModel< T, B >::qxExist | ( | const QVariant & | id,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 601 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxFetchAll | ( | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Clear the model and fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database.

Parameters:

  relation | List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 304 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxFetchById | ( | const QVariant & | id,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Clear the model and fetch an object (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database.

Parameters:

  id | Row id to be fetched (retrieve all properties from database)
  relation | List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 278 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxFetchByQuery | ( | const qx::QxSqlQuery & | query,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Clear the model and fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query.

Parameters:

  query | Define a user SQL query added to default SQL query builded by QxOrm library
  relation | List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 326 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxFetchRow | ( | int | row,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Get an item in the model at line row and fetch all its properties mapped to a table in the database, then all views attached to this model are automatically updated.

Parameters:

  row | Get an item in the model at line row
  relation | List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 348 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxInsert | ( | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Insert all items in the model into database.

Parameters:

  relation | List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 368 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxInsertRow | ( | int | row,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Insert an item of the model at line row into database.

Parameters:

  row | Insert an item in the model at line row
  relation | List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 384 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxSave | ( | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Save all items (insert or update) in the model into database.

Parameters:

  relation | List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 435 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxSaveRow | ( | int | row,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Save an item of the model at line row into database.

Parameters:

  row | Save an item (insert or update) in the model at line row
  relation | List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 451 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxSaveRowData | ( | int | row,
|  | const QStringList & | column = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Used internally by qx::IxModel::setData() method with e_auto_update_on_field_change option, save an item (even if it is the dirty row item) of the model at line row into database.

Parameters:

  row | Save an item (insert or update) in the model at line row
  column | List of columns of model to save in database
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Definition at line 469 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxUpdate | ( | const qx::QxSqlQuery & | query = `qx::QxSqlQuery()`,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Update all items in the model into database.

Parameters:

  query | Define a user SQL query added to default SQL query builded by QxOrm library
  relation | List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 401 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QSqlError qx::QxModel< T, B >::qxUpdateRow | ( | int | row,
|  | const qx::QxSqlQuery & | query = `qx::QxSqlQuery()`,
|  | const QStringList & | relation = `QStringList()`,
|  | QSqlDatabase * | pDatabase = `NULL`
| ) |  | `[inline, virtual]`

Update an item of the model at line row into database.

Parameters:

  row | Update an item in the model at line row
  query | Define a user SQL query added to default SQL query builded by QxOrm library
  relation | List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
  pDatabase | Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)

Returns:
  Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 418 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual qx::QxInvalidValueX qx::QxModel< T, B >::qxValidate | ( | const QStringList & | groups = `QStringList()` | ) | `[inline, virtual]`

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 610 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual qx::QxInvalidValueX qx::QxModel< T, B >::qxValidateRow | ( | int | row,
|  | const QStringList & | groups = `QStringList()`
| ) |  | `[inline, virtual]`

Reimplemented in qx::QxModelService< T, S, B >.

Definition at line 615 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual bool qx::QxModel< T, B >::setRelationshipValues_Helper | ( | int | row,
|  | const QString & | relation,
|  | const QVariant & | values
| ) |  | `[inline, protected, virtual]`

Definition at line 761 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual void qx::QxModel< T, B >::setShowEmptyLine | ( | bool | b | ) | `[inline, virtual]`

Definition at line 238 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual void qx::QxModel< T, B >::sort | ( | int | column,
|  | Qt::SortOrder | order = `Qt::AscendingOrder`
| ) |  | `[inline, virtual]`

Definition at line 229 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual QString qx::QxModel< T, B >::toJson_Helper | ( | int | row | ) | const`[inline, protected, virtual]`

Definition at line 704 of file QxModel.h.

template<class T, class B = qx::IxModel>

void qx::QxModel< T, B >::updateAllKeys | ( |  | ) | `[inline, protected]`

Definition at line 694 of file QxModel.h.

template<class T, class B = qx::IxModel>

void qx::QxModel< T, B >::updateKey | ( | int | row | ) | `[inline, protected]`

Definition at line 678 of file QxModel.h.

template<class T, class B = qx::IxModel>

virtual void qx::QxModel< T, B >::updateShowEmptyLine | ( |  | ) | `[inline, protected, virtual]`

Definition at line 642 of file QxModel.h.

## Friends And Related Function Documentation

template<class T, class B = qx::IxModel>

friend struct qx::model_view::detail::QxNestedModel`[friend]`

Definition at line 166 of file QxModel.h.

template<class T, class B = qx::IxModel>

friend struct qx::model_view::detail::QxNestedModel_Container`[friend]`

Definition at line 168 of file QxModel.h.

template<class T, class B = qx::IxModel>

friend struct qx::model_view::detail::QxNestedModel_Generic`[friend]`

Definition at line 167 of file QxModel.h.

## Member Data Documentation

template<class T, class B = qx::IxModel>

type_collection qx::QxModel< T, B >::m_model`[protected]`

Model associated to a class registered into QxOrm context.

Definition at line 181 of file QxModel.h.

template<class T, class B = qx::IxModel>

std::shared_ptr<QPair<int, type_ptr> > qx::QxModel< T, B >::m_pDirtyRow`[protected]`

When displayed in a QTableView, this will cause an empty line awaiting user input to be displayed at the bottom (enabled with setShowEmptyLine() method)

Definition at line 182 of file QxModel.h.

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

- C:/Dvlp/_Perso/QxOrm/include/QxModelView/QxModel.h