32#ifndef _QX_MODEL_SERVICE_H_
33#define _QX_MODEL_SERVICE_H_
57template <
class T,
class S,
class B = qx::IxModel>
78 this->
qxCount(lCount, query, pDatabase);
90 virtual QSqlError
qxFetchById(
const QVariant &
id,
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL)
95 if (! this->
m_pDataMemberId) { qDebug(
"[QxOrm] problem with 'qxFetchById()' method : '%s'",
"data member id not registered");
qAssert(
false); }
96 if (! this->
m_pDataMemberId) { this->
m_lastError = QSqlError(
"[QxOrm] problem with 'qxFetchById()' method : 'data member id not registered'",
"", QSqlError::UnknownError);
return this->
m_lastError; }
101 this->beginInsertRows(QModelIndex(), 0, 0);
107 this->endInsertRows();
111 virtual QSqlError
qxFetchAll(
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL)
120 if (tmp->count() <= 0) {
return this->
m_lastError; }
121 this->beginResetModel();
124 this->endResetModel();
137 if (tmp->count() <= 0) {
return this->
m_lastError; }
138 this->beginResetModel();
141 this->endResetModel();
145 virtual QSqlError
qxFetchRow(
int row,
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL)
148 if ((row < 0) || (row >= this->
m_model.
count())) {
return QSqlError(); }
155 QModelIndex idxTopLeft = this->
index(row, 0);
162 virtual QSqlError
qxInsert(
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL,
bool bUseExecBatch =
false)
164 Q_UNUSED(pDatabase); Q_UNUSED(bUseExecBatch);
177 virtual QSqlError
qxInsertRow(
int row,
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL)
180 if ((row < 0) || (row >= this->
m_model.
count())) {
return QSqlError(); }
185 this->
m_lastError = services.insert(pItem, relation);
193 Q_UNUSED(pDatabase); Q_UNUSED(bUseExecBatch);
209 if ((row < 0) || (row >= this->
m_model.
count())) {
return QSqlError(); }
220 virtual QSqlError
qxSave(
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL)
235 virtual QSqlError
qxSaveRow(
int row,
const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL)
238 if ((row < 0) || (row >= this->
m_model.
count())) {
return QSqlError(); }
243 this->
m_lastError = services.save(pItem, relation);
249 virtual QSqlError
qxDeleteById(
const QVariant &
id, QSqlDatabase * pDatabase = NULL)
253 if (! this->
m_pDataMemberId) { qDebug(
"[QxOrm] problem with 'qxDeleteById()' method : '%s'",
"data member id not registered");
qAssert(
false); }
254 if (! this->
m_pDataMemberId) { this->
m_lastError = QSqlError(
"[QxOrm] problem with 'qxDeleteById()' method : 'data member id not registered'",
"", QSqlError::UnknownError);
return this->
m_lastError; }
278 virtual QSqlError
qxDeleteRow(
int row, QSqlDatabase * pDatabase = NULL)
281 if ((row < 0) || (row >= this->
m_model.
count())) {
return QSqlError(); }
289 virtual QSqlError
qxDestroyById(
const QVariant &
id, QSqlDatabase * pDatabase = NULL)
293 if (! this->
m_pDataMemberId) { qDebug(
"[QxOrm] problem with 'qxDeleteById()' method : '%s'",
"data member id not registered");
qAssert(
false); }
294 if (! this->
m_pDataMemberId) { this->
m_lastError = QSqlError(
"[QxOrm] problem with 'qxDeleteById()' method : 'data member id not registered'",
"", QSqlError::UnknownError);
return this->
m_lastError; }
314 this->
m_lastError = services.destroyByQuery(query);
318 virtual QSqlError
qxDestroyRow(
int row, QSqlDatabase * pDatabase = NULL)
321 if ((row < 0) || (row >= this->
m_model.
count())) {
return QSqlError(); }
336 this->
m_lastError = services.executeQuery(query, tmp);
338 if (tmp->count() <= 0) {
return this->
m_lastError; }
339 this->beginResetModel();
342 this->endResetModel();
350 if (! this->
m_pDataMemberId) { qDebug(
"[QxOrm] problem with 'qxExist()' method : '%s'",
"data member id not registered");
qAssert(
false); }
355 return services.exist(pItem);
364 return services.isValid(tmp);
374 return services.isValid(pItem);
383 if ((row < 0) || (row >= this->
m_model.
count())) {
return QVariant(); }
390 if (bLoadFromDatabase)
392 QString sRelation = relation;
393 if (! sAppendRelations.isEmpty() && ! sAppendRelations.startsWith(
"->") && ! sAppendRelations.startsWith(
">>")) { sRelation +=
"->" + sAppendRelations; }
394 else if (! sAppendRelations.isEmpty()) { sRelation += sAppendRelations; }
399 S services; QStringList columns;
400 QSqlError daoError = services.fetchById(pItemTemp, columns, QStringList() << sRelation);
401 if (daoError.isValid()) {
return QVariant(); }
404 QJsonValue json = pDataMember->
toJson(pItemTemp.get());
if (json.isNull()) {
return QVariant(); }
405 if (json.isArray()) {
return json.toArray().toVariantList(); }
406 return json.toObject().toVariantMap();
All classes registered into QxOrm context can be used with Qt model/view architecture (Qt widgets and...
qx::IxDataMember : common interface for all class properties registered into QxOrm context
bool hasSqlRelation() const
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const =0
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)=0
IxSqlRelation * getSqlRelation() const
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context) const =0
bool exist(const QString &sKey) const
virtual IxDataMember * get_WithDaoStrategy(long lIndex) const =0
qx::IxModel : interface to manage Qt model/view architecture with classes registered into QxOrm conte...
void raiseEvent_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
QList< IxDataMember * > m_lstDataMember
List of data member exposed by the model.
QSqlError m_lastError
Last SQL error.
IxDataMemberX * m_pDataMemberX
List of properties defined into QxOrm context.
virtual void syncAllNestedModel(const QStringList &relation)
Q_INVOKABLE void clear(bool bUpdateColumns=false)
QStringList m_lstColumns
List of columns exposed by the model (if empty, all columns)
virtual QModelIndex parent(const QModelIndex &index) const
IxDataMember * m_pDataMemberId
Primary key (property id) defined into QxOrm context.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
virtual void syncNestedModel(int row, const QStringList &relation)
qx::IxSqlRelation : common interface for all relationships defined between 2 classes (or between 2 ta...
qx_bool : boolean type with code and description message when an error occured
bool insert(const Key &key, const Value &value)
Add element 'value' at the end of the list indexed by 'key'.
long count() const
Return the number of items in the list (same as 'size()')
const_reference_value getByIndex(long index) const
Return the item at index position 'index'.
qx::QxInvalidValueX : list of invalid values
qx::QxModel<T, B> : all classes registered into QxOrm context can be used with Qt model/view architec...
virtual void updateShowEmptyLine()
qx::trait::get_primary_key< T >::type type_primary_key
std::shared_ptr< T > type_ptr
qx::QxModelService<T, S> : provides an easy way to connect your model to the QxService module (all qu...
std::shared_ptr< type_collection > type_collection_ptr
virtual QVariant getRelationshipValues_Helper(int row, const QString &relation, bool bLoadFromDatabase, const QString &sAppendRelations)
virtual ~QxModelService()
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...
QxModelService(qx::IxModel *other, QObject *parent)
virtual QSqlError qxUpdate(const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Update all items in the model into database.
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,...
qx::QxModel< T, B >::type_primary_key type_primary_key
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 fi...
QxModelService(QObject *parent=0)
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...
qx::QxModel< T, B >::type_ptr type_ptr
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 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 co...
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,...
virtual qx_bool qxExist(const QVariant &id, QSqlDatabase *pDatabase=NULL)
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...
virtual qx::QxInvalidValueX qxValidate(const QStringList &groups=QStringList())
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),...
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...
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 c...
virtual QSqlError qxSave(const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
Save all items (insert or update) in the model into database.
virtual qx::QxInvalidValueX qxValidateRow(int row, const QStringList &groups=QStringList())
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
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 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 (regi...
qx::QxModel< T, B >::type_collection type_collection
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...
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 c...
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 qxInsert(const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
Insert all items in the model into database.
virtual QSqlError qxDeleteAll(QSqlDatabase *pDatabase=NULL)
Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context),...
qx::QxSqlQuery : define a user SQL query added to default SQL query builded by QxOrm library,...
qx_bool from_variant(const QVariant &v, T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
Root namespace for all QxOrm library features.