Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-06 09:27:50

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