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
qsqlrelationaltablemodel.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 QSQLRELATIONALTABLEMODEL_H
5#define QSQLRELATIONALTABLEMODEL_H
6
7#include <QtSql/qtsqlglobal.h>
8#include <QtSql/qsqltablemodel.h>
9
10#include <QtCore/qtypeinfo.h>
11
13
15
16
17class Q_SQL_EXPORT QSqlRelation
18{
19public:
21 QSqlRelation(const QString &aTableName, const QString &indexCol,
22 const QString &displayCol)
23 : tName(aTableName), iColumn(indexCol), dColumn(displayCol) {}
24
25 void swap(QSqlRelation &other) noexcept
26 {
27 tName.swap(other.tName);
28 iColumn.swap(other.iColumn);
29 dColumn.swap(other.dColumn);
30 }
31
32 inline QString tableName() const
33 { return tName; }
34 inline QString indexColumn() const
35 { return iColumn; }
36 inline QString displayColumn() const
37 { return dColumn; }
38 bool isValid() const noexcept
39 { return !(tName.isEmpty() || iColumn.isEmpty() || dColumn.isEmpty()); }
40private:
41 QString tName, iColumn, dColumn;
42};
43Q_DECLARE_SHARED(QSqlRelation)
44
46
47class Q_SQL_EXPORT QSqlRelationalTableModel: public QSqlTableModel
48{
50
51public:
52 enum JoinMode {
54 LeftJoin
55 };
56
57 explicit QSqlRelationalTableModel(QObject *parent = nullptr,
58 const QSqlDatabase &db = QSqlDatabase());
60
61 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
62 bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole) override;
63 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
64
65 void clear() override;
66 bool select() override;
67
68 void setTable(const QString &tableName) override;
69 virtual void setRelation(int column, const QSqlRelation &relation);
70 QSqlRelation relation(int column) const;
71 virtual QSqlTableModel *relationModel(int column) const;
72 void setJoinMode( QSqlRelationalTableModel::JoinMode joinMode );
73
74public Q_SLOTS:
75 void revertRow(int row) override;
76
77protected:
78 QString selectStatement() const override;
79 bool updateRowInTable(int row, const QSqlRecord &values) override;
80 bool insertRowIntoTable(const QSqlRecord &values) override;
81 QString orderByClause() const override;
82
83private:
84 Q_DECLARE_PRIVATE(QSqlRelationalTableModel)
85};
86
88
89#endif // QSQLRELATIONALTABLEMODEL_H
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QSqlDatabase class handles a connection to a database.
The QSqlRecord class encapsulates a database record.
Definition qsqlrecord.h:20
void swap(QSqlRelation &other) noexcept
Swaps this with other.
QString tableName() const
Returns the name of the table to which a foreign key refers.
bool isValid() const noexcept
Returns true if the QSqlRelation object is valid; otherwise returns false.
QString indexColumn() const
Returns the index column from table tableName() to which a foreign key refers.
QSqlRelation()
Constructs an invalid QSqlRelation object.
QString displayColumn() const
Returns the column from table tableName() that should be presented to the user instead of a foreign k...
QSqlRelation(const QString &aTableName, const QString &indexCol, const QString &displayCol)
Constructs a QSqlRelation object, where tableName is the SQL table name to which a foreign key refers...
The QSqlRelationalTableModel class provides an editable data model for a single database table,...
JoinMode
\value InnerJoin - Inner join mode, return rows when there is at least one match in both tables.
The QSqlTableModel class provides an editable data model for a single database table.
\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.
@ EditRole
@ DisplayRole
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLsizei GLsizei GLint * values
[15]
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
#define QT_REQUIRE_CONFIG(feature)
#define Q_OBJECT
#define Q_SLOTS
mimeData setData("text/csv", csvData)
QMimeDatabase db
[0]
QSharedPointer< T > other(t)
[5]
QGraphicsItem * item
selection select(topLeft, bottomRight)