Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QSQLTABLEMODEL_H
00043 #define QSQLTABLEMODEL_H
00044
00045 #include <QtSql/qsqldatabase.h>
00046 #include <QtSql/qsqlquerymodel.h>
00047
00048 QT_BEGIN_HEADER
00049
00050 QT_BEGIN_NAMESPACE
00051
00052 QT_MODULE(Sql)
00053
00054 class QSqlTableModelPrivate;
00055 class QSqlRecord;
00056 class QSqlField;
00057 class QSqlIndex;
00058
00059 class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel
00060 {
00061 Q_OBJECT
00062 Q_DECLARE_PRIVATE(QSqlTableModel)
00063
00064 public:
00065 enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit};
00066
00067 explicit QSqlTableModel(QObject *parent = 0, QSqlDatabase db = QSqlDatabase());
00068 virtual ~QSqlTableModel();
00069
00070 virtual bool select();
00071
00072 virtual void setTable(const QString &tableName);
00073 QString tableName() const;
00074
00075 Qt::ItemFlags flags(const QModelIndex &index) const;
00076
00077 QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const;
00078 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00079
00080 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00081
00082 bool isDirty(const QModelIndex &index) const;
00083 void clear();
00084
00085 virtual void setEditStrategy(EditStrategy strategy);
00086 EditStrategy editStrategy() const;
00087
00088 QSqlIndex primaryKey() const;
00089 QSqlDatabase database() const;
00090 int fieldIndex(const QString &fieldName) const;
00091
00092 void sort(int column, Qt::SortOrder order);
00093 virtual void setSort(int column, Qt::SortOrder order);
00094
00095 QString filter() const;
00096 virtual void setFilter(const QString &filter);
00097
00098 int rowCount(const QModelIndex &parent = QModelIndex()) const;
00099
00100 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
00101 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
00102 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
00103
00104 bool insertRecord(int row, const QSqlRecord &record);
00105 bool setRecord(int row, const QSqlRecord &record);
00106
00107 virtual void revertRow(int row);
00108
00109 public Q_SLOTS:
00110 bool submit();
00111 void revert();
00112
00113 bool submitAll();
00114 void revertAll();
00115
00116 Q_SIGNALS:
00117 void primeInsert(int row, QSqlRecord &record);
00118
00119 void beforeInsert(QSqlRecord &record);
00120 void beforeUpdate(int row, QSqlRecord &record);
00121 void beforeDelete(int row);
00122
00123 protected:
00124 QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = 0, QSqlDatabase db = QSqlDatabase());
00125
00126 virtual bool updateRowInTable(int row, const QSqlRecord &values);
00127 virtual bool insertRowIntoTable(const QSqlRecord &values);
00128 virtual bool deleteRowFromTable(int row);
00129 virtual QString orderByClause() const;
00130 virtual QString selectStatement() const;
00131
00132 void setPrimaryKey(const QSqlIndex &key);
00133 void setQuery(const QSqlQuery &query);
00134 QModelIndex indexInQuery(const QModelIndex &item) const;
00135 };
00136
00137 QT_END_NAMESPACE
00138
00139 QT_END_HEADER
00140
00141 #endif // QSQLTABLEMODEL_H