diff options
author | Tobias Koenig <[email protected]> | 2015-08-11 15:09:46 +0200 |
---|---|---|
committer | Christian Ehrlicher <[email protected]> | 2024-09-04 06:17:52 +0200 |
commit | 608da527743ff5845fb40a76e80dced31bff0cb0 (patch) | |
tree | 0d8dd51ec3050864cae41cdab0eae302155e95a0 /src/sql/models/qsqlrelationaltablemodel.cpp | |
parent | 8f8ce8d7a7e029e62a4f9b5b209dcc37f61410cb (diff) |
Allow resetting foreign key in QSqlRelationalTableModel
Change the QSqlRelationalTableModel::setData() method to remove the
associated foreign key, if called on a relational column.
Task-number: QTBUG-47713
Change-Id: Ib3cf03f1da506d63f1a59349d64d5da45bde4137
Reviewed-by: Axel Spoerl <[email protected]>
Diffstat (limited to 'src/sql/models/qsqlrelationaltablemodel.cpp')
-rw-r--r-- | src/sql/models/qsqlrelationaltablemodel.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp index d892be070e7..29beefb94db 100644 --- a/src/sql/models/qsqlrelationaltablemodel.cpp +++ b/src/sql/models/qsqlrelationaltablemodel.cpp @@ -428,8 +428,9 @@ QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) cons example, if \a index is out of bounds). For relational columns, \a value must be the index, not the - display value. The index must also exist in the referenced - table, otherwise the function returns \c false. + display value. If an index is given, it must also exist in the + referenced table, otherwise the function returns \c false. + If a QVariant() is passed instead of an index, the index is cleared. \sa editStrategy(), data(), submit(), revertRow() */ @@ -442,7 +443,7 @@ bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant auto relation = d->relations.at(index.column()); if (!relation->isDictionaryInitialized()) relation->populateDictionary(); - if (!relation->dictionary.contains(value.toString())) + if (value.isValid() && !relation->dictionary.contains(value.toString())) return false; } return QSqlTableModel::setData(index, value, role); |