Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:22:30

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QSQLRELATIONALTABLEMODEL_H
0006 #define QSQLRELATIONALTABLEMODEL_H
0007 
0008 #include <QtSql/qtsqlglobal.h>
0009 #include <QtSql/qsqltablemodel.h>
0010 
0011 #include <QtCore/qtypeinfo.h>
0012 
0013 QT_REQUIRE_CONFIG(sqlmodel);
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 
0018 class Q_SQL_EXPORT QSqlRelation
0019 {
0020 public:
0021     QSqlRelation() {}
0022     QSqlRelation(const QString &aTableName, const QString &indexCol,
0023                const QString &displayCol)
0024         : tName(aTableName), iColumn(indexCol), dColumn(displayCol) {}
0025 
0026     void swap(QSqlRelation &other) noexcept
0027     {
0028         tName.swap(other.tName);
0029         iColumn.swap(other.iColumn);
0030         dColumn.swap(other.dColumn);
0031     }
0032 
0033     inline QString tableName() const
0034     { return tName; }
0035     inline QString indexColumn() const
0036     { return iColumn; }
0037     inline QString displayColumn() const
0038     { return dColumn; }
0039     bool isValid() const noexcept
0040     { return !(tName.isEmpty() || iColumn.isEmpty() || dColumn.isEmpty()); }
0041 private:
0042     QString tName, iColumn, dColumn;
0043 };
0044 Q_DECLARE_SHARED(QSqlRelation)
0045 
0046 class QSqlRelationalTableModelPrivate;
0047 
0048 class Q_SQL_EXPORT QSqlRelationalTableModel: public QSqlTableModel
0049 {
0050     Q_OBJECT
0051 
0052 public:
0053     enum JoinMode {
0054         InnerJoin,
0055         LeftJoin
0056     };
0057 
0058     explicit QSqlRelationalTableModel(QObject *parent = nullptr,
0059                                       const QSqlDatabase &db = QSqlDatabase());
0060     virtual ~QSqlRelationalTableModel();
0061 
0062     QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const override;
0063     bool setData(const QModelIndex &item, const QVariant &value, int role = Qt::EditRole) override;
0064     bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
0065 
0066     void clear() override;
0067     bool select() override;
0068 
0069     void setTable(const QString &tableName) override;
0070     virtual void setRelation(int column, const QSqlRelation &relation);
0071     QSqlRelation relation(int column) const;
0072     virtual QSqlTableModel *relationModel(int column) const;
0073     void setJoinMode( QSqlRelationalTableModel::JoinMode joinMode );
0074 
0075 public Q_SLOTS:
0076     void revertRow(int row) override;
0077 
0078 protected:
0079     QString selectStatement() const override;
0080     bool updateRowInTable(int row, const QSqlRecord &values) override;
0081     bool insertRowIntoTable(const QSqlRecord &values) override;
0082     QString orderByClause() const override;
0083 
0084 private:
0085     Q_DECLARE_PRIVATE(QSqlRelationalTableModel)
0086 };
0087 
0088 QT_END_NAMESPACE
0089 
0090 #endif // QSQLRELATIONALTABLEMODEL_H