File indexing completed on 2025-09-15 09:09:15
0001
0002
0003
0004 #ifndef QSQLQUERYMODEL_H
0005 #define QSQLQUERYMODEL_H
0006
0007 #include <QtSql/qtsqlglobal.h>
0008 #include <QtCore/qabstractitemmodel.h>
0009 #include <QtSql/qsqldatabase.h>
0010
0011 QT_REQUIRE_CONFIG(sqlmodel);
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 class QSqlQueryModelPrivate;
0016 class QSqlError;
0017 class QSqlRecord;
0018 class QSqlQuery;
0019
0020 class Q_SQL_EXPORT QSqlQueryModel: public QAbstractTableModel
0021 {
0022 Q_OBJECT
0023 Q_DECLARE_PRIVATE(QSqlQueryModel)
0024
0025 public:
0026 explicit QSqlQueryModel(QObject *parent = nullptr);
0027 virtual ~QSqlQueryModel();
0028
0029 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0030 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0031 QSqlRecord record(int row) const;
0032 QSqlRecord record() const;
0033
0034 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
0035 QVariant headerData(int section, Qt::Orientation orientation,
0036 int role = Qt::DisplayRole) const override;
0037 bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value,
0038 int role = Qt::EditRole) override;
0039
0040 bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
0041 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
0042
0043 #if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 2)
0044 QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Pass it by move instead.")
0045 void setQuery(const QSqlQuery &query);
0046 #endif
0047 void setQuery(QSqlQuery &&query);
0048 void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase());
0049 void refresh();
0050 #if QT_SQL_REMOVED_SINCE(6, 5)
0051 QSqlQuery query() const;
0052 #endif
0053 const QSqlQuery &query(QT6_DECL_NEW_OVERLOAD) const;
0054
0055 virtual void clear();
0056
0057 QSqlError lastError() const;
0058
0059 void fetchMore(const QModelIndex &parent = QModelIndex()) override;
0060 bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override;
0061
0062 QHash<int, QByteArray> roleNames() const override;
0063
0064 protected:
0065 void beginInsertRows(const QModelIndex &parent, int first, int last);
0066 void endInsertRows();
0067
0068 void beginRemoveRows(const QModelIndex &parent, int first, int last);
0069 void endRemoveRows();
0070
0071 void beginInsertColumns(const QModelIndex &parent, int first, int last);
0072 void endInsertColumns();
0073
0074 void beginRemoveColumns(const QModelIndex &parent, int first, int last);
0075 void endRemoveColumns();
0076
0077 void beginResetModel();
0078 void endResetModel();
0079 virtual void queryChange();
0080
0081 virtual QModelIndex indexInQuery(const QModelIndex &item) const;
0082 void setLastError(const QSqlError &error);
0083 QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent = nullptr);
0084 };
0085
0086 QT_END_NAMESPACE
0087
0088 #endif