Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsqltablemodel.h
Go to the documentation of this file.
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 QSQLTABLEMODEL_H
5#define QSQLTABLEMODEL_H
6
7#include <QtSql/qtsqlglobal.h>
8#include <QtSql/qsqldatabase.h>
9#include <QtSql/qsqlquerymodel.h>
10
12
14
15
17class QSqlRecord;
18class QSqlField;
19class QSqlIndex;
20
21class Q_SQL_EXPORT QSqlTableModel: public QSqlQueryModel
22{
24 Q_DECLARE_PRIVATE(QSqlTableModel)
25 Q_MOC_INCLUDE(<QtSql/qsqlrecord.h>)
26
27public:
28 enum EditStrategy {OnFieldChange, OnRowChange, OnManualSubmit};
29
30 explicit QSqlTableModel(QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase());
31 virtual ~QSqlTableModel();
32
33 virtual void setTable(const QString &tableName);
34 QString tableName() const;
35
36 Qt::ItemFlags flags(const QModelIndex &index) const override;
37
38 QSqlRecord record() const;
39 QSqlRecord record(int row) const;
40 QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
41 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
42 bool clearItemData(const QModelIndex &index) override;
43
44 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
45
46 bool isDirty() const;
47 bool isDirty(const QModelIndex &index) const;
48
49 void clear() override;
50
51 virtual void setEditStrategy(EditStrategy strategy);
52 EditStrategy editStrategy() const;
53
54 QSqlIndex primaryKey() const;
55 QSqlDatabase database() const;
56 int fieldIndex(const QString &fieldName) const;
57
58 void sort(int column, Qt::SortOrder order) override;
59 virtual void setSort(int column, Qt::SortOrder order);
60
61 QString filter() const;
62 virtual void setFilter(const QString &filter);
63
64 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
65
66 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
67 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
68 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
69
70 bool insertRecord(int row, const QSqlRecord &record);
71 bool setRecord(int row, const QSqlRecord &record);
72
73 virtual void revertRow(int row);
74
75public Q_SLOTS:
76 virtual bool select();
77 virtual bool selectRow(int row);
78
79 bool submit() override;
80 void revert() override;
81
82 bool submitAll();
83 void revertAll();
84
87
90 void beforeDelete(int row);
91
92protected:
93 QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent = nullptr, const QSqlDatabase &db = QSqlDatabase());
94
95 virtual bool updateRowInTable(int row, const QSqlRecord &values);
96 virtual bool insertRowIntoTable(const QSqlRecord &values);
97 virtual bool deleteRowFromTable(int row);
98 virtual QString orderByClause() const;
99 virtual QString selectStatement() const;
100
101 void setPrimaryKey(const QSqlIndex &key);
102#if QT_SQL_REMOVED_SINCE(6, 5)
103 void setQuery(const QSqlQuery &query);
104#endif
105 QModelIndex indexInQuery(const QModelIndex &item) const override;
106 QSqlRecord primaryValues(int row) const;
107};
108
110
111#endif // QSQLTABLEMODEL_H
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QSqlDatabase class handles a connection to a database.
The QSqlField class manipulates the fields in SQL database tables and views.
Definition qsqlfield.h:19
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition qsqlindex.h:18
The QSqlQueryModel class provides a read-only data model for SQL result sets.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition qsqlquery.h:24
The QSqlRecord class encapsulates a database record.
Definition qsqlrecord.h:20
The QSqlTableModel class provides an editable data model for a single database table.
EditStrategy
This enum type describes which strategy to choose when editing values in the database.
void primeInsert(int row, QSqlRecord &record)
This signal is emitted by insertRows(), when an insertion is initiated in the given row of the curren...
void beforeInsert(QSqlRecord &record)
This signal is emitted by insertRowIntoTable() before a new row is inserted into the currently active...
void beforeDelete(int row)
This signal is emitted by deleteRowFromTable() before the row is deleted from the currently active da...
void beforeUpdate(int row, QSqlRecord &record)
This signal is emitted by updateRowInTable() before the row is updated in the currently active databa...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
b clear()
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ EditRole
@ DisplayRole
SortOrder
Definition qnamespace.h:121
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLsizei GLsizei GLint * values
[15]
GLuint64 key
GLuint index
[2]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield flags
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLenum GLenum GLsizei void GLsizei void * column
GLenum query
GLenum GLenum GLsizei void * row
GLfixed GLfixed GLint GLint order
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define Q_SLOTS
#define Q_MOC_INCLUDE(...)
#define Q_SIGNALS
qDebug()<< QUrl("file copy setQuery(copy.query(QUrl::FullyDecoded), QUrl::DecodedMode)
mimeData setData("text/csv", csvData)
QMimeDatabase db
[0]
MyRecord record(int row) const
[0]
QGraphicsItem * item
selection select(topLeft, bottomRight)