File indexing completed on 2025-01-18 10:09:19
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_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 #if QT_SQL_REMOVED_SINCE(6, 5)
0050 QSqlQuery query() const;
0051 #endif
0052 const QSqlQuery &query(QT6_DECL_NEW_OVERLOAD) const;
0053
0054 virtual void clear();
0055
0056 QSqlError lastError() const;
0057
0058 void fetchMore(const QModelIndex &parent = QModelIndex()) override;
0059 bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override;
0060
0061 QHash<int, QByteArray> roleNames() const override;
0062
0063 protected:
0064 void beginInsertRows(const QModelIndex &parent, int first, int last);
0065 void endInsertRows();
0066
0067 void beginRemoveRows(const QModelIndex &parent, int first, int last);
0068 void endRemoveRows();
0069
0070 void beginInsertColumns(const QModelIndex &parent, int first, int last);
0071 void endInsertColumns();
0072
0073 void beginRemoveColumns(const QModelIndex &parent, int first, int last);
0074 void endRemoveColumns();
0075
0076 void beginResetModel();
0077 void endResetModel();
0078 virtual void queryChange();
0079
0080 virtual QModelIndex indexInQuery(const QModelIndex &item) const;
0081 void setLastError(const QSqlError &error);
0082 QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent = nullptr);
0083 };
0084
0085 QT_END_NAMESPACE
0086
0087 #endif