Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:09:19

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