Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QSQLRELATIONALTABLEMODEL_H
6#define QSQLRELATIONALTABLEMODEL_H
7
8#include <QtSql/qtsqlglobal.h>
9#include <QtSql/qsqltablemodel.h>
10
11#include <QtCore/qtypeinfo.h>
12
14
16
17
19{
20public:
21 QSqlRelation() {}
22 QSqlRelation(const QString &aTableName, const QString &indexCol,
23 const QString &displayCol)
24 : tName(aTableName), iColumn(indexCol), dColumn(displayCol) {}
25
26 void swap(QSqlRelation &other) noexcept
27 {
28 tName.swap(other.tName);
29 iColumn.swap(other.iColumn);
30 dColumn.swap(other.dColumn);
31 }
32
33 inline QString tableName() const
34 { return tName; }
35 inline QString indexColumn() const
36 { return iColumn; }
37 inline QString displayColumn() const
38 { return dColumn; }
39 bool isValid() const noexcept
40 { return !(tName.isEmpty() || iColumn.isEmpty() || dColumn.isEmpty()); }
41private:
42 QString tName, iColumn, dColumn;
43};
45
47
48class Q_SQL_EXPORT QSqlRelationalTableModel: public QSqlTableModel
49{
50 Q_OBJECT
51
52public:
53 enum JoinMode {
54 InnerJoin,
55 LeftJoin
56 };
57
58 explicit QSqlRelationalTableModel(QObject *parent = nullptr,
59 const QSqlDatabase &db = QSqlDatabase());
60 virtual ~QSqlRelationalTableModel();
61
62 QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
63 bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole) override;
64 bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
65
66 void clear() override;
67 bool select() override;
68
69 void setTable(const QString &tableName) override;
70 virtual void setRelation(int column, const QSqlRelation &relation);
71 QSqlRelation relation(int column) const;
72 virtual QSqlTableModel *relationModel(int column) const;
73 void setJoinMode( QSqlRelationalTableModel::JoinMode joinMode );
74
75public Q_SLOTS:
76 void revertRow(int row) override;
77
78protected:
79 QString selectStatement() const override;
80 bool updateRowInTable(int row, const QSqlRecord &values) override;
81 bool insertRowIntoTable(const QSqlRecord &values) override;
82 QString orderByClause() const override;
83
84private:
85 Q_DECLARE_PRIVATE(QSqlRelationalTableModel)
86};
87
88QT_END_NAMESPACE
89
90#endif // QSQLRELATIONALTABLEMODEL_H
QRelatedTableModel(QRelation *rel, QObject *parent, const QSqlDatabase &db)
bool select() override
Populates the model with data from the table that was set via setTable(), using the specified filter ...
QList< QSharedPointer< QRelation > > relations
int nameToIndex(const QString &name) const override
void translateFieldNames(QSqlRecord &values) const
static const QString relTablePrefix(int i)
The QSqlRelationalTableModel class provides an editable data model for a single database table,...
QT_REQUIRE_CONFIG(sqlmodel)
QSqlRelationalTableModelSql SqlrTm
QRelatedTableModel * model
bool isDictionaryInitialized() const
QHash< QString, QVariant > dictionary
void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation, int column)