1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QSQLQUERYMODEL_H |
5 | #define QSQLQUERYMODEL_H |
6 | |
7 | #include <QtSql/qtsqlglobal.h> |
8 | #include <QtCore/qabstractitemmodel.h> |
9 | #include <QtSql/qsqldatabase.h> |
10 | |
11 | QT_REQUIRE_CONFIG(sqlmodel); |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QSqlQueryModelPrivate; |
16 | class QSqlError; |
17 | class QSqlRecord; |
18 | class QSqlQuery; |
19 | |
20 | class Q_SQL_EXPORT QSqlQueryModel: public QAbstractTableModel |
21 | { |
22 | Q_OBJECT |
23 | Q_DECLARE_PRIVATE(QSqlQueryModel) |
24 | |
25 | public: |
26 | explicit QSqlQueryModel(QObject *parent = nullptr); |
27 | virtual ~QSqlQueryModel(); |
28 | |
29 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
30 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
31 | QSqlRecord record(int row) const; |
32 | QSqlRecord record() const; |
33 | |
34 | QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override; |
35 | QVariant (int section, Qt::Orientation orientation, |
36 | int role = Qt::DisplayRole) const override; |
37 | bool (int section, Qt::Orientation orientation, const QVariant &value, |
38 | int role = Qt::EditRole) override; |
39 | |
40 | bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; |
41 | bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override; |
42 | |
43 | #if QT_DEPRECATED_SINCE(6, 2) |
44 | QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Pass it by move instead." ) |
45 | void setQuery(const QSqlQuery &query); |
46 | #endif |
47 | void setQuery(QSqlQuery &&query); |
48 | void setQuery(const QString &query, const QSqlDatabase &db = QSqlDatabase()); |
49 | #if QT_SQL_REMOVED_SINCE(6, 5) |
50 | QSqlQuery query() const; |
51 | #endif |
52 | const QSqlQuery &query(QT6_DECL_NEW_OVERLOAD) const; |
53 | |
54 | virtual void clear(); |
55 | |
56 | QSqlError lastError() const; |
57 | |
58 | void fetchMore(const QModelIndex &parent = QModelIndex()) override; |
59 | bool canFetchMore(const QModelIndex &parent = QModelIndex()) const override; |
60 | |
61 | QHash<int, QByteArray> roleNames() const override; |
62 | |
63 | protected: |
64 | void beginInsertRows(const QModelIndex &parent, int first, int last); |
65 | void endInsertRows(); |
66 | |
67 | void beginRemoveRows(const QModelIndex &parent, int first, int last); |
68 | void endRemoveRows(); |
69 | |
70 | void beginInsertColumns(const QModelIndex &parent, int first, int last); |
71 | void endInsertColumns(); |
72 | |
73 | void beginRemoveColumns(const QModelIndex &parent, int first, int last); |
74 | void endRemoveColumns(); |
75 | |
76 | void beginResetModel(); |
77 | void endResetModel(); |
78 | virtual void queryChange(); |
79 | |
80 | virtual QModelIndex indexInQuery(const QModelIndex &item) const; |
81 | void setLastError(const QSqlError &error); |
82 | QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent = nullptr); |
83 | }; |
84 | |
85 | QT_END_NAMESPACE |
86 | |
87 | #endif // QSQLQUERYMODEL_H |
88 | |