QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
IxModel.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _IX_MODEL_H_
33#define _IX_MODEL_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#ifdef _QX_NO_PRECOMPILED_HEADER
47#ifndef Q_MOC_RUN
48#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
49#endif // Q_MOC_RUN
50#endif // _QX_NO_PRECOMPILED_HEADER
51
52#include <QtCore/qabstractitemmodel.h>
53
54#ifndef Q_MOC_RUN
55#include <QxRegister/IxClass.h>
58#include <QxDao/IxSqlRelation.h>
59#include <QxDao/QxSqlQuery.h>
60#include <QxDao/QxDao.h>
63#endif // Q_MOC_RUN
64
65namespace qx {
66namespace model_view {
67namespace detail {
68
69template <class T, class M> struct QxNestedModel;
70template <class T, class M> struct QxNestedModel_Generic;
71template <class T, class M> struct QxNestedModel_Container;
72
73} // namespace detail
74} // namespace model_view
75} // namespace qx
76
77namespace qx {
78
162class QX_DLL_EXPORT IxModel : public QAbstractItemModel
163{
164
165 Q_OBJECT
166
167 template <typename U, typename V> friend struct qx::model_view::detail::QxNestedModel;
168 template <typename U, typename V> friend struct qx::model_view::detail::QxNestedModel_Generic;
169 template <typename U, typename V> friend struct qx::model_view::detail::QxNestedModel_Container;
170
171public:
172
173 enum e_auto_update_database { e_no_auto_update, e_auto_update_on_field_change };
174
175 typedef QHash<QString, IxModel *> type_relation_by_name;
176 typedef QList<type_relation_by_name> type_lst_relation_by_name;
177 typedef QHash<IxModel *, QPair<int, QString> > type_child_to_its_relation;
178
179protected:
180
186 QHash<int, QByteArray> m_lstRoleNames;
187 QList<IxDataMember *> m_lstDataMember;
188 QHash<QString, int> m_lstDataMemberByKey;
189 QHash<QString, QVariant> m_lstHeadersData;
190 QStringList m_lstColumns;
191 QSqlDatabase m_database;
192 QSqlError m_lastError;
199 QHash<QString, QVariant> m_hCustomProperties;
200
201public:
202
203 IxModel(QObject * parent = 0);
204 virtual ~IxModel();
205
206 IxClass * getClass() const;
209 QSqlDatabase getDatabase() const;
210 QSqlError getLastError() const;
211 Q_INVOKABLE QString getLastErrorAsString() const;
212 Q_INVOKABLE QStringList getListOfColumns() const;
213 QHash<QString, QString> getListOfHeaders() const;
214 IxDataMember * getDataMember(int column) const;
215 Q_INVOKABLE QString getDataMemberKey(int column) const;
216 Q_INVOKABLE int getRowCount() const;
217 Q_INVOKABLE QVariant getModelValue(int row, const QString & column) const;
218 Q_INVOKABLE int getColumnIndex(const QString & sColumnName) const;
219 Q_INVOKABLE int getAutoUpdateDatabase_() const;
221 Q_INVOKABLE virtual bool getShowEmptyLine() const = 0;
222 Q_INVOKABLE QVariant getCustomProperty(const QString & key) const;
223 Q_INVOKABLE QObject * getParentModel() const;
224 Q_INVOKABLE void dumpModel(bool bJsonFormat = true) const;
225 Q_INVOKABLE QObject * cloneModel();
226
227 void setDatabase(const QSqlDatabase & db);
228 Q_INVOKABLE void setListOfColumns(const QStringList & lst);
229 void setListOfHeaders(const QHash<QString, QString> & lst);
230 Q_INVOKABLE bool setModelValue(int row, const QString & column, const QVariant & value);
231 void setParentModel(IxModel * pParent);
232 Q_INVOKABLE void setAutoUpdateDatabase_(int i);
234 Q_INVOKABLE virtual void setShowEmptyLine(bool b) = 0;
235 Q_INVOKABLE void setCustomProperty(const QString & key, const QVariant & val);
236
237 Q_INVOKABLE QString toJson(int row = -1) const;
238 Q_INVOKABLE bool fromJson(const QString & json, int row = -1);
239
240 Q_INVOKABLE QVariant getRelationshipValues(int row, const QString & relation, bool bLoadFromDatabase = false, const QString & sAppendRelations = QString());
241 Q_INVOKABLE bool setRelationshipValues(int row, const QString & relation, const QVariant & values);
242
243 virtual long qxCount(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL) = 0;
244 virtual QSqlError qxCount(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL) = 0;
245 virtual QSqlError qxFetchById(const QVariant & id, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
246 virtual QSqlError qxFetchAll(const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
247 virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery & query, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
248 virtual QSqlError qxFetchRow(int row, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
249 virtual QSqlError qxInsert(const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) = 0;
250 virtual QSqlError qxInsertRow(int row, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
251 virtual QSqlError qxUpdate(const qx::QxSqlQuery & query = qx::QxSqlQuery(), const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL, bool bUseExecBatch = false) = 0;
252 virtual QSqlError qxUpdateRow(int row, const qx::QxSqlQuery & query = qx::QxSqlQuery(), const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
253 virtual QSqlError qxSave(const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
254 virtual QSqlError qxSaveRow(int row, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
255 virtual QSqlError qxSaveRowData(int row, const QStringList & column = QStringList(), QSqlDatabase * pDatabase = NULL) = 0;
256 virtual QSqlError qxDeleteById(const QVariant & id, QSqlDatabase * pDatabase = NULL) = 0;
257 virtual QSqlError qxDeleteAll(QSqlDatabase * pDatabase = NULL) = 0;
258 virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) = 0;
259 virtual QSqlError qxDeleteRow(int row, QSqlDatabase * pDatabase = NULL) = 0;
260 virtual QSqlError qxDestroyById(const QVariant & id, QSqlDatabase * pDatabase = NULL) = 0;
261 virtual QSqlError qxDestroyAll(QSqlDatabase * pDatabase = NULL) = 0;
262 virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) = 0;
263 virtual QSqlError qxDestroyRow(int row, QSqlDatabase * pDatabase = NULL) = 0;
264 virtual QSqlError qxExecuteQuery(qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) = 0;
265 virtual qx_bool qxExist(const QVariant & id, QSqlDatabase * pDatabase = NULL) = 0;
266 virtual qx::QxInvalidValueX qxValidate(const QStringList & groups = QStringList()) = 0;
267 virtual qx::QxInvalidValueX qxValidateRow(int row, const QStringList & groups = QStringList()) = 0;
268
269 Q_INVOKABLE int qxCount_(const QString & sQuery);
270 Q_INVOKABLE bool qxFetchById_(const QVariant & id, const QStringList & relation = QStringList());
271 Q_INVOKABLE bool qxFetchAll_(const QStringList & relation = QStringList());
272 Q_INVOKABLE bool qxFetchByQuery_(const QString & sQuery, const QStringList & relation = QStringList());
273 Q_INVOKABLE bool qxFetchRow_(int row, const QStringList & relation = QStringList());
274 Q_INVOKABLE bool qxInsert_(const QStringList & relation = QStringList(), bool bUseExecBatch = false);
275 Q_INVOKABLE bool qxInsertRow_(int row, const QStringList & relation = QStringList());
276 Q_INVOKABLE bool qxUpdate_(const QString & sQuery, const QStringList & relation = QStringList(), bool bUseExecBatch = false);
277 Q_INVOKABLE bool qxUpdateRow_(int row, const QString & sQuery, const QStringList & relation = QStringList());
278 Q_INVOKABLE bool qxSave_(const QStringList & relation = QStringList());
279 Q_INVOKABLE bool qxSaveRow_(int row, const QStringList & relation = QStringList());
280 Q_INVOKABLE bool qxDeleteById_(const QVariant & id);
281 Q_INVOKABLE bool qxDeleteAll_();
282 Q_INVOKABLE bool qxDeleteByQuery_(const QString & sQuery);
283 Q_INVOKABLE bool qxDeleteRow_(int row);
284 Q_INVOKABLE bool qxDestroyById_(const QVariant & id);
285 Q_INVOKABLE bool qxDestroyAll_();
286 Q_INVOKABLE bool qxDestroyByQuery_(const QString & sQuery);
287 Q_INVOKABLE bool qxDestroyRow_(int row);
288 Q_INVOKABLE bool qxExecuteQuery_(const QString & sQuery);
289 Q_INVOKABLE bool qxExist_(const QVariant & id);
290 Q_INVOKABLE QString qxValidate_(const QStringList & groups = QStringList());
291 Q_INVOKABLE QString qxValidateRow_(int row, const QStringList & groups = QStringList());
292
293 QSqlError saveChildRelations(IxModel * pChild);
294 QVariant getIdFromChild(IxModel * pChild) const;
295 QPair<int, QString> getChildPosition(IxModel * pChild) const;
296
297protected:
298
299 void raiseEvent_headerDataChanged(Qt::Orientation orientation, int first, int last);
300#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
301 void raiseEvent_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int>());
302 void raiseEvent_layoutAboutToBeChanged(const QList<QPersistentModelIndex> & parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
303 void raiseEvent_layoutChanged(const QList<QPersistentModelIndex> & parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
304#else // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
305 void raiseEvent_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
306 void raiseEvent_layoutAboutToBeChanged();
307 void raiseEvent_layoutChanged();
308#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
309
310public:
311
312 Q_INVOKABLE void clear(bool bUpdateColumns = false);
313
314 virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
315 virtual bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
316 virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
317 virtual int columnCount(const QModelIndex & parent = QModelIndex()) const;
318 virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
319 virtual QModelIndex parent(const QModelIndex & index) const;
320 virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
321 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
322 virtual Qt::ItemFlags flags(const QModelIndex & index) const;
323 virtual Qt::DropActions supportedDropActions() const;
324 virtual bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
325 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole);
326 bool setHeaderData(const QString & sColumnName, const QVariant & value, int role = Qt::EditRole);
327
328#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
329 virtual QHash<int, QByteArray> roleNames() const;
330 virtual Qt::DropActions supportedDragActions() const;
331#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
332
333protected:
334
335 virtual QObject * cloneModelImpl() = 0;
336 virtual void dumpModelImpl(bool bJsonFormat) const = 0;
337 virtual void * getRowItemAsVoidPtr(int row) const = 0;
338 virtual bool isDirtyRow(int row) const = 0;
339 virtual void insertDirtyRowToModel() = 0;
340 virtual void updateShowEmptyLine() = 0;
341 virtual void syncNestedModel(int row, const QStringList & relation);
342 virtual void syncAllNestedModel(const QStringList & relation);
343 void syncNestedModelRecursive(IxModel * pNestedModel, const QStringList & relation);
344
346 QSqlDatabase * database(QSqlDatabase * other);
347 IxModel * getChild(long row, const QString & relation);
348 void insertChild(long row, const QString & relation, IxModel * pChild);
349 void removeListOfChild(long row);
350 bool removeRowsGeneric(int row, int count);
351 bool removeRowsAutoUpdateOnFieldChange(int row, int count);
352
353#ifndef _QX_NO_JSON
354
355 virtual QString toJson_Helper(int row) const = 0;
356 virtual bool fromJson_Helper(const QString & json, int row) = 0;
357
358 virtual QVariant getRelationshipValues_Helper(int row, const QString & relation, bool bLoadFromDatabase, const QString & sAppendRelations) = 0;
359 virtual bool setRelationshipValues_Helper(int row, const QString & relation, const QVariant & values) = 0;
360
361#endif // _QX_NO_JSON
362
363};
364
365} // namespace qx
366
367#endif // _IX_MODEL_H_
Common interface for all classes registered into QxOrm context.
Common interface for a list of IxDataMember class properties registered into QxOrm context (for examp...
Common interface for all relationships defined between 2 classes (or between 2 tables in database)
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
Provide template functions to map C++ class registered into QxOrm context with table database (ORM - ...
List of invalid values.
#define QX_DLL_EXPORT
Definition QxMacro.h:182
Define a user SQL query added to default SQL query builded by QxOrm library, and used by qx::dao::xxx...
Implementation of qx::validate<T>() function (validator engine)
qx::IxClass : common interface for all classes registered into QxOrm context
Definition IxClass.h:69
qx::IxCollection : common interface for all QxOrm containers qx::QxCollection<Key,...
qx::IxDataMember : common interface for all class properties registered into QxOrm context
qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOr...
qx::IxModel : interface to manage Qt model/view architecture with classes registered into QxOrm conte...
Definition IxModel.h:163
virtual QHash< int, QByteArray > roleNames() const
void raiseEvent_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
IxClass * getClass() const
Q_INVOKABLE bool qxDestroyById_(const QVariant &id)
Q_INVOKABLE bool setModelValue(int row, const QString &column, const QVariant &value)
virtual void * getRowItemAsVoidPtr(int row) const =0
void setAutoUpdateDatabase(e_auto_update_database e)
Q_INVOKABLE bool qxExist_(const QVariant &id)
virtual QSqlError qxDestroyAll(QSqlDatabase *pDatabase=NULL)=0
Q_INVOKABLE int getRowCount() const
virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)=0
Q_INVOKABLE bool qxInsert_(const QStringList &relation=QStringList(), bool bUseExecBatch=false)
virtual QSqlError qxDeleteRow(int row, QSqlDatabase *pDatabase=NULL)=0
virtual bool fromJson_Helper(const QString &json, int row)=0
type_child_to_its_relation m_hChild
Reverse link to m_lstChild, used in setData() to save relations.
Definition IxModel.h:195
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
void syncNestedModelRecursive(IxModel *pNestedModel, const QStringList &relation)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Q_INVOKABLE bool qxSaveRow_(int row, const QStringList &relation=QStringList())
virtual qx::QxInvalidValueX qxValidateRow(int row, const QStringList &groups=QStringList())=0
virtual QSqlError qxFetchAll(const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)=0
virtual QString toJson_Helper(int row) const =0
virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery &query, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
QHash< QString, int > m_lstDataMemberByKey
List of data member key to get column index in model.
Definition IxModel.h:188
bool removeRowsAutoUpdateOnFieldChange(int row, int count)
Q_INVOKABLE void setAutoUpdateDatabase_(int i)
Q_INVOKABLE bool qxDeleteByQuery_(const QString &sQuery)
QHash< IxModel *, QPair< int, QString > > type_child_to_its_relation
Definition IxModel.h:177
QList< IxDataMember * > m_lstDataMember
List of data member exposed by the model.
Definition IxModel.h:187
virtual QSqlError qxSaveRow(int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
virtual QSqlError qxDestroyRow(int row, QSqlDatabase *pDatabase=NULL)=0
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &val)
Q_INVOKABLE bool qxFetchAll_(const QStringList &relation=QStringList())
Q_INVOKABLE void dumpModel(bool bJsonFormat=true) const
virtual void insertDirtyRowToModel()=0
QSqlDatabase m_database
Database connexion to execute SQL queries (if empty, default database connexion)
Definition IxModel.h:191
virtual qx::QxInvalidValueX qxValidate(const QStringList &groups=QStringList())=0
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Q_INVOKABLE bool qxInsertRow_(int row, const QStringList &relation=QStringList())
void raiseEvent_layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
QHash< QString, QVariant > m_lstHeadersData
List of headers data by role and data member key.
Definition IxModel.h:189
IxModel * m_pParent
Parent model, NULL if current model is the root model.
Definition IxModel.h:193
QSqlError m_lastError
Last SQL error.
Definition IxModel.h:192
virtual QSqlError qxFetchById(const QVariant &id, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
Q_INVOKABLE bool qxFetchById_(const QVariant &id, const QStringList &relation=QStringList())
Q_INVOKABLE QObject * getParentModel() const
Can be used to figure out whether this model has a parent model (used only by nested models)
Q_INVOKABLE void setListOfColumns(const QStringList &lst)
Q_INVOKABLE QVariant getModelValue(int row, const QString &column) const
virtual Qt::DropActions supportedDragActions() const
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual QSqlError qxSaveRowData(int row, const QStringList &column=QStringList(), QSqlDatabase *pDatabase=NULL)=0
QVariant getIdFromChild(IxModel *pChild) const
Used to save foreign key in a nested model.
IxDataMemberX * m_pDataMemberX
List of properties defined into QxOrm context.
Definition IxModel.h:183
Q_INVOKABLE bool setRelationshipValues(int row, const QString &relation, const QVariant &values)
Depending on relationship type (1-1, 1-n, n-1, n-n) : values parameter can be a QVariantMap type or a...
IxModel(QObject *parent=0)
IxModel * getChild(long row, const QString &relation)
QList< type_relation_by_name > type_lst_relation_by_name
Definition IxModel.h:176
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
virtual bool setRelationshipValues_Helper(int row, const QString &relation, const QVariant &values)=0
IxCollection * m_pCollection
Interface to store a list of items.
Definition IxModel.h:185
Q_INVOKABLE bool qxDeleteAll_()
virtual bool hasChildren(const QModelIndex &parent=QModelIndex()) const
virtual Qt::DropActions supportedDropActions() const
virtual void dumpModelImpl(bool bJsonFormat) const =0
Q_INVOKABLE QStringList getListOfColumns() const
virtual void syncAllNestedModel(const QStringList &relation)
bool removeRowsGeneric(int row, int count)
IxClass * getModelClass() const
virtual long qxCount(const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)=0
bool setHeaderData(const QString &sColumnName, const QVariant &value, int role=Qt::EditRole)
virtual QSqlError qxInsertRow(int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
void raiseEvent_layoutChanged(const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
virtual QSqlError qxDeleteAll(QSqlDatabase *pDatabase=NULL)=0
IxClass * m_pClass
Class introspection registered into QxOrm context associated to the model.
Definition IxModel.h:181
IxDataMember * getDataMember(int column) const
Q_INVOKABLE int qxCount_(const QString &sQuery)
QSqlDatabase getDatabase() const
Q_INVOKABLE bool qxDeleteById_(const QVariant &id)
Q_INVOKABLE void clear(bool bUpdateColumns=false)
IxCollection * getCollection() const
QHash< int, QByteArray > m_lstRoleNames
List of model's role names to expose data to QML.
Definition IxModel.h:186
QStringList m_lstColumns
List of columns exposed by the model (if empty, all columns)
Definition IxModel.h:190
Q_INVOKABLE bool qxFetchByQuery_(const QString &sQuery, const QStringList &relation=QStringList())
QSqlDatabase * database(QSqlDatabase *other)
QHash< QString, QVariant > m_hCustomProperties
Use this generic hash-table to define extra-properties in your custom classes which inherit from qx::...
Definition IxModel.h:199
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
void setDatabase(const QSqlDatabase &db)
Q_INVOKABLE QString getDataMemberKey(int column) const
Q_INVOKABLE bool qxFetchRow_(int row, const QStringList &relation=QStringList())
void generateRoleNames()
virtual bool isDirtyRow(int row) const =0
virtual QVariant getRelationshipValues_Helper(int row, const QString &relation, bool bLoadFromDatabase, const QString &sAppendRelations)=0
IxClass * m_pModelClass
If model itself is registered into QxOrm context, then you can use this property to work with introsp...
Definition IxModel.h:182
Q_INVOKABLE QVariant getRelationshipValues(int row, const QString &relation, bool bLoadFromDatabase=false, const QString &sAppendRelations=QString())
Depending on relationship type (1-1, 1-n, n-1, n-n) : can return a QVariantMap type or a QVariantList...
void insertChild(long row, const QString &relation, IxModel *pChild)
virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole)
Q_INVOKABLE bool qxDeleteRow_(int row)
e_auto_update_database
Definition IxModel.h:173
void setListOfHeaders(const QHash< QString, QString > &lst)
Obsolete : use setHeaderData() instead.
Q_INVOKABLE QString getLastErrorAsString() const
virtual QObject * cloneModelImpl()=0
QPair< int, QString > getChildPosition(IxModel *pChild) const
virtual QModelIndex parent(const QModelIndex &index) const
Q_INVOKABLE bool qxUpdateRow_(int row, const QString &sQuery, const QStringList &relation=QStringList())
Q_INVOKABLE int getAutoUpdateDatabase_() const
Q_INVOKABLE bool qxExecuteQuery_(const QString &sQuery)
void removeListOfChild(long row)
long m_lManualInsertIndex
Index to insert manually items to the collection.
Definition IxModel.h:198
Q_INVOKABLE QString qxValidate_(const QStringList &groups=QStringList())
Q_INVOKABLE QString qxValidateRow_(int row, const QStringList &groups=QStringList())
QHash< QString, IxModel * > type_relation_by_name
Definition IxModel.h:175
QHash< QString, QString > getListOfHeaders() const
Obsolete : use headerData() instead.
Q_INVOKABLE int getColumnIndex(const QString &sColumnName) const
void setParentModel(IxModel *pParent)
Q_INVOKABLE QVariant getCustomProperty(const QString &key) const
virtual void updateShowEmptyLine()=0
Q_INVOKABLE bool qxDestroyRow_(int row)
virtual QSqlError qxUpdate(const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)=0
QSqlError saveChildRelations(IxModel *pChild)
virtual Q_INVOKABLE void setShowEmptyLine(bool b)=0
Q_INVOKABLE bool fromJson(const QString &json, int row=-1)
On QML side, use JSON.stringify() on a javascript object before calling this qx::IxModel::fromJson() ...
QSqlError getLastError() const
type_lst_relation_by_name m_lstChild
List of child model : QxEntityEditor uses this property to manage relationships and create complex da...
Definition IxModel.h:194
virtual QSqlError qxDeleteById(const QVariant &id, QSqlDatabase *pDatabase=NULL)=0
IxDataMember * m_pDataMemberId
Primary key (property id) defined into QxOrm context.
Definition IxModel.h:184
void raiseEvent_headerDataChanged(Qt::Orientation orientation, int first, int last)
Q_INVOKABLE bool qxUpdate_(const QString &sQuery, const QStringList &relation=QStringList(), bool bUseExecBatch=false)
Q_INVOKABLE QString toJson(int row=-1) const
On QML side, use JSON.parse() to create a javascript object after calling this qx::IxModel::toJson() ...
virtual qx_bool qxExist(const QVariant &id, QSqlDatabase *pDatabase=NULL)=0
virtual QSqlError qxSave(const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
e_auto_update_database getAutoUpdateDatabase() const
IxDataMember * m_pDataMemberRelationToParent
The data member holding relationship to its parent model (if one exists), used only by nested models.
Definition IxModel.h:197
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Q_INVOKABLE bool qxDestroyAll_()
virtual void syncNestedModel(int row, const QStringList &relation)
Q_INVOKABLE bool qxSave_(const QStringList &relation=QStringList())
virtual QSqlError qxUpdateRow(int row, const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
virtual Q_INVOKABLE bool getShowEmptyLine() const =0
Can be useful when a model is displayed in a table (QTableView for example) to add automatically an e...
virtual QSqlError qxInsert(const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)=0
e_auto_update_database m_eAutoUpdateDatabase
Auto-update database on field change (detected by the setData() method)
Definition IxModel.h:196
virtual ~IxModel()
Q_INVOKABLE bool qxDestroyByQuery_(const QString &sQuery)
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)=0
virtual QSqlError qxDestroyById(const QVariant &id, QSqlDatabase *pDatabase=NULL)=0
virtual QSqlError qxCount(long &lCount, const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)=0
virtual QSqlError qxFetchRow(int row, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)=0
Q_INVOKABLE QObject * cloneModel()
virtual Qt::ItemFlags flags(const QModelIndex &index) const
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
qx::QxInvalidValueX : list of invalid values
qx::QxSqlQuery : define a user SQL query added to default SQL query builded by QxOrm library,...
Definition QxSqlQuery.h:245
Root namespace for all QxOrm library features.