![]() |
QxOrm
1.2.7
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifndef _IX_MODEL_H_ 00033 #define _IX_MODEL_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <QtCore/qabstractitemmodel.h> 00047 00048 #ifndef Q_MOC_RUN 00049 #include <QxRegister/IxClass.h> 00050 #include <QxDataMember/IxDataMemberX.h> 00051 #include <QxCollection/IxCollection.h> 00052 #include <QxDao/IxSqlRelation.h> 00053 #include <QxDao/QxSqlQuery.h> 00054 #include <QxDao/QxDao.h> 00055 #include <QxValidator/QxInvalidValueX.h> 00056 #include <QxValidator/QxValidatorFct.h> 00057 #endif // Q_MOC_RUN 00058 00059 namespace qx { 00060 00144 class QX_DLL_EXPORT IxModel : public QAbstractItemModel 00145 { 00146 00147 Q_OBJECT 00148 00149 protected: 00150 00151 IxClass * m_pClass; 00152 IxDataMemberX * m_pDataMemberX; 00153 IxDataMember * m_pDataMemberId; 00154 IxCollection * m_pCollection; 00155 QHash<int, QByteArray> m_lstRoleNames; 00156 QList<IxDataMember *> m_lstDataMember; 00157 QHash<QString, int> m_lstDataMemberByKey; 00158 QHash<QString, QString> m_lstHeaders; 00159 QStringList m_lstColumns; 00160 QSqlDatabase m_database; 00161 QSqlError m_lastError; 00162 00163 public: 00164 00165 IxModel(QObject * parent = 0); 00166 virtual ~IxModel(); 00167 00168 IxClass * getClass() const; 00169 IxCollection * getCollection() const; 00170 QSqlDatabase getDatabase() const; 00171 QSqlError getLastError() const; 00172 Q_INVOKABLE QString getLastErrorAsString() const; 00173 Q_INVOKABLE QStringList getListOfColumns() const; 00174 QHash<QString, QString> getListOfHeaders() const; 00175 IxDataMember * getDataMember(int column) const; 00176 Q_INVOKABLE QString getDataMemberKey(int column) const; 00177 Q_INVOKABLE QVariant getModelValue(int row, const QString & column) const; 00178 00179 void setDatabase(const QSqlDatabase & db); 00180 Q_INVOKABLE void setListOfColumns(const QStringList & lst); 00181 void setListOfHeaders(const QHash<QString, QString> & lst); 00182 Q_INVOKABLE bool setModelValue(int row, const QString & column, const QVariant & value); 00183 00184 virtual long qxCount(const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL) = 0; 00185 virtual QSqlError qxCount(long & lCount, const qx::QxSqlQuery & query = qx::QxSqlQuery(), QSqlDatabase * pDatabase = NULL) = 0; 00186 virtual QSqlError qxFetchById(const QVariant & id, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00187 virtual QSqlError qxFetchAll(const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00188 virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery & query, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00189 virtual QSqlError qxInsert(const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00190 virtual QSqlError qxUpdate(const qx::QxSqlQuery & query = qx::QxSqlQuery(), const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00191 virtual QSqlError qxSave(const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00192 virtual QSqlError qxSaveRow(int row, const QStringList & relation = QStringList(), QSqlDatabase * pDatabase = NULL) = 0; 00193 virtual QSqlError qxDeleteById(const QVariant & id, QSqlDatabase * pDatabase = NULL) = 0; 00194 virtual QSqlError qxDeleteAll(QSqlDatabase * pDatabase = NULL) = 0; 00195 virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) = 0; 00196 virtual QSqlError qxDestroyById(const QVariant & id, QSqlDatabase * pDatabase = NULL) = 0; 00197 virtual QSqlError qxDestroyAll(QSqlDatabase * pDatabase = NULL) = 0; 00198 virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) = 0; 00199 virtual QSqlError qxExecuteQuery(qx::QxSqlQuery & query, QSqlDatabase * pDatabase = NULL) = 0; 00200 virtual qx_bool qxExist(const QVariant & id, QSqlDatabase * pDatabase = NULL) = 0; 00201 virtual qx::QxInvalidValueX qxValidate(const QStringList & groups = QStringList()) = 0; 00202 00203 Q_INVOKABLE int qxCount_(const QString & sQuery); 00204 Q_INVOKABLE bool qxFetchById_(const QVariant & id, const QStringList & relation = QStringList()); 00205 Q_INVOKABLE bool qxFetchAll_(const QStringList & relation = QStringList()); 00206 Q_INVOKABLE bool qxFetchByQuery_(const QString & sQuery, const QStringList & relation = QStringList()); 00207 Q_INVOKABLE bool qxInsert_(const QStringList & relation = QStringList()); 00208 Q_INVOKABLE bool qxUpdate_(const QString & sQuery, const QStringList & relation = QStringList()); 00209 Q_INVOKABLE bool qxSave_(const QStringList & relation = QStringList()); 00210 Q_INVOKABLE bool qxSaveRow_(int row, const QStringList & relation = QStringList()); 00211 Q_INVOKABLE bool qxDeleteById_(const QVariant & id); 00212 Q_INVOKABLE bool qxDeleteAll_(); 00213 Q_INVOKABLE bool qxDeleteByQuery_(const QString & sQuery); 00214 Q_INVOKABLE bool qxDestroyById_(const QVariant & id); 00215 Q_INVOKABLE bool qxDestroyAll_(); 00216 Q_INVOKABLE bool qxDestroyByQuery_(const QString & sQuery); 00217 Q_INVOKABLE bool qxExecuteQuery_(const QString & sQuery); 00218 Q_INVOKABLE bool qxExist_(const QVariant & id); 00219 Q_INVOKABLE QString qxValidate_(const QStringList & groups = QStringList()); 00220 00221 protected: 00222 00223 void raiseEvent_headerDataChanged(Qt::Orientation orientation, int first, int last); 00224 #if (QT_VERSION >= 0x050000) 00225 void raiseEvent_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles = QVector<int>()); 00226 void raiseEvent_layoutAboutToBeChanged(const QList<QPersistentModelIndex> & parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint); 00227 void raiseEvent_layoutChanged(const QList<QPersistentModelIndex> & parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint); 00228 #else // (QT_VERSION >= 0x050000) 00229 void raiseEvent_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight); 00230 void raiseEvent_layoutAboutToBeChanged(); 00231 void raiseEvent_layoutChanged(); 00232 #endif // (QT_VERSION >= 0x050000) 00233 00234 public: 00235 00236 Q_INVOKABLE void clear(bool bUpdateColumns = false); 00237 00238 virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; 00239 virtual int columnCount(const QModelIndex & parent = QModelIndex()) const; 00240 virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; 00241 virtual QModelIndex parent(const QModelIndex & index) const; 00242 virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const; 00243 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 00244 virtual Qt::ItemFlags flags(const QModelIndex & index) const; 00245 virtual Qt::DropActions supportedDropActions() const; 00246 virtual bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); 00247 virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole); 00248 00249 #if (QT_VERSION >= 0x050000) 00250 virtual QHash<int, QByteArray> roleNames() const; 00251 virtual Qt::DropActions supportedDragActions() const; 00252 #endif // (QT_VERSION >= 0x050000) 00253 00254 protected: 00255 00256 void generateRoleNames(); 00257 QSqlDatabase * database(QSqlDatabase * other); 00258 00259 }; 00260 00261 } // namespace qx 00262 00263 #endif // _IX_MODEL_H_