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 QSQLRELATIONALTABLEMODEL_H
00043 #define QSQLRELATIONALTABLEMODEL_H
00044
00045 #include <QtSql/qsqltablemodel.h>
00046
00047 QT_BEGIN_HEADER
00048
00049 QT_BEGIN_NAMESPACE
00050
00051 QT_MODULE(Sql)
00052
00053 class Q_SQL_EXPORT QSqlRelation
00054 {
00055 public:
00056 QSqlRelation() {}
00057 QSqlRelation(const QString &aTableName, const QString &indexCol,
00058 const QString &displayCol)
00059 : tName(aTableName), iColumn(indexCol), dColumn(displayCol) {}
00060 inline QString tableName() const
00061 { return tName; }
00062 inline QString indexColumn() const
00063 { return iColumn; }
00064 inline QString displayColumn() const
00065 { return dColumn; }
00066 inline bool isValid() const
00067 { return !(tName.isEmpty() || iColumn.isEmpty() || dColumn.isEmpty()); }
00068 private:
00069 QString tName, iColumn, dColumn;
00070 };
00071
00072 class QSqlRelationalTableModelPrivate;
00073
00074 class Q_SQL_EXPORT QSqlRelationalTableModel: public QSqlTableModel
00075 {
00076 Q_OBJECT
00077
00078 public:
00079 explicit QSqlRelationalTableModel(QObject *parent = 0,
00080 QSqlDatabase db = QSqlDatabase());
00081 virtual ~QSqlRelationalTableModel();
00082
00083 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const;
00084 bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole);
00085 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex());
00086
00087 void clear();
00088 bool select();
00089
00090 void setTable(const QString &tableName);
00091 virtual void setRelation(int column, const QSqlRelation &relation);
00092 QSqlRelation relation(int column) const;
00093 virtual QSqlTableModel *relationModel(int column) const;
00094
00095 public Q_SLOTS:
00096 void revertRow(int row);
00097
00098 protected:
00099 QString selectStatement() const;
00100 bool updateRowInTable(int row, const QSqlRecord &values);
00101 bool insertRowIntoTable(const QSqlRecord &values);
00102 QString orderByClause() const;
00103
00104 private:
00105 Q_DECLARE_PRIVATE(QSqlRelationalTableModel)
00106 };
00107
00108 QT_END_NAMESPACE
00109
00110 QT_END_HEADER
00111
00112 #endif // QSQLRELATIONALTABLEMODEL_H