Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:19

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QSQLTABLEMODEL_H
0005 #define QSQLTABLEMODEL_H
0006 
0007 #include <QtSql/qtsqlglobal.h>
0008 #include <QtSql/qsqldatabase.h>
0009 #include <QtSql/qsqlquerymodel.h>
0010 
0011 QT_REQUIRE_CONFIG(sqlmodel);
0012 
0013 QT_BEGIN_NAMESPACE
0014 
0015 
0016 class QSqlTableModelPrivate;
0017 class QSqlRecord;
0018 class QSqlField;
0019 class QSqlIndex;
0020 
0021 class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel
0022 {
0023     Q_OBJECT
0024     Q_DECLARE_PRIVATE(QSqlTableModel)
0025     Q_MOC_INCLUDE(<QtSql/qsqlrecord.h>)
0026 
0027 public:
0028     enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit};
0029 
0030     explicit QSqlTableModel(QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase());
0031     virtual ~QSqlTableModel();
0032 
0033     virtual void setTable(const QString &tableName);
0034     QString tableName() const;
0035 
0036     Qt::ItemFlags flags(const QModelIndex &index) const override;
0037 
0038     QSqlRecord record() const;
0039     QSqlRecord record(int row) const;
0040     QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
0041     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0042     bool clearItemData(const QModelIndex &index) override;
0043 
0044     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0045 
0046     bool isDirty() const;
0047     bool isDirty(const QModelIndex &index) const;
0048 
0049     void clear() override;
0050 
0051     virtual void setEditStrategy(EditStrategy strategy);
0052     EditStrategy editStrategy() const;
0053 
0054     QSqlIndex primaryKey() const;
0055     QSqlDatabase database() const;
0056     int fieldIndex(const QString &fieldName) const;
0057 
0058     void sort(int column, Qt::SortOrder order) override;
0059     virtual void setSort(int column, Qt::SortOrder order);
0060 
0061     QString filter() const;
0062     virtual void setFilter(const QString &filter);
0063 
0064     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0065 
0066     bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
0067     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0068     bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0069 
0070     bool insertRecord(int row, const QSqlRecord &record);
0071     bool setRecord(int row, const QSqlRecord &record);
0072 
0073     virtual void revertRow(int row);
0074 
0075 public Q_SLOTS:
0076     virtual bool select();
0077     virtual bool selectRow(int row);
0078 
0079     bool submit() override;
0080     void revert() override;
0081 
0082     bool submitAll();
0083     void revertAll();
0084 
0085 Q_SIGNALS:
0086     void primeInsert(int row, QSqlRecord &record);
0087 
0088     void beforeInsert(QSqlRecord &record);
0089     void beforeUpdate(int row, QSqlRecord &record);
0090     void beforeDelete(int row);
0091 
0092 protected:
0093     QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase());
0094 
0095     virtual bool updateRowInTable(int row, const QSqlRecord &values);
0096     virtual bool insertRowIntoTable(const QSqlRecord &values);
0097     virtual bool deleteRowFromTable(int row);
0098     virtual QString orderByClause() const;
0099     virtual QString selectStatement() const;
0100 
0101     void setPrimaryKey(const QSqlIndex &key);
0102 #if QT_SQL_REMOVED_SINCE(6, 5)
0103     void setQuery(const QSqlQuery &query);
0104 #endif
0105     QModelIndex indexInQuery(const QModelIndex &item) const override;
0106     QSqlRecord primaryValues(int row) const;
0107 };
0108 
0109 QT_END_NAMESPACE
0110 
0111 #endif // QSQLTABLEMODEL_H