diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-02-28 11:04:36 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-02-28 15:28:23 +0100 |
commit | d4748c7c936cdf603e0b72bfdb4e39f822ab2e9d (patch) | |
tree | a22d2290f4929fd0c8e14d6eb314ff7dd514bf84 /src | |
parent | 83fdcbf3be0ddbbee1fd2c8c9ff1a4e3c707e3f0 (diff) |
TableModel: Allow a double to be added to a field seen as int previously
Since the type for a TableModelColumn can be seen as an int when it is
in the first row, it is still possible that it is representing a double
value in other rows. Therefore it should be allowed to add/change a row
that would display a double for that column.
Change-Id: I994a8ead595f836a20a4e82fbf94953b1aa4b7da
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlmodels/qqmltablemodel.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/qmlmodels/qqmltablemodel.cpp b/src/qmlmodels/qqmltablemodel.cpp index f190ad86b1..fab20f7410 100644 --- a/src/qmlmodels/qqmltablemodel.cpp +++ b/src/qmlmodels/qqmltablemodel.cpp @@ -1028,11 +1028,24 @@ bool QQmlTableModel::validateNewRow(const char *functionName, const QVariant &ro } const QVariant rolePropertyValue = rowAsMap.value(roleData.name); + if (rolePropertyValue.type() != roleData.type) { - qmlWarning(this).quote() << functionName << ": expected the property named " - << roleData.name << " to be of type " << roleData.typeName - << ", but got " << QString::fromLatin1(rolePropertyValue.typeName()) << " instead"; - return false; + if (!rolePropertyValue.canConvert(int(roleData.type))) { + qmlWarning(this).quote() << functionName << ": expected the property named " + << roleData.name << " to be of type " << roleData.typeName + << ", but got " << QString::fromLatin1(rolePropertyValue.typeName()) + << " instead"; + return false; + } + + QVariant effectiveValue = rolePropertyValue; + if (!effectiveValue.convert(int(roleData.type))) { + qmlWarning(this).nospace() << functionName << ": failed converting value " + << rolePropertyValue << " set at column " << columnIndex << " with role " + << QString::fromLatin1(rolePropertyValue.typeName()) << " to " + << roleData.typeName; + return false; + } } } } |