Add type check when converting QVariant in QAbstractItemModel::setData
parent
8ccb2e519b
commit
c87339ed6a
|
@ -816,6 +816,9 @@ QVariant TimeSeries::cos(int row) const
|
|||
bool TimeSeries::setCos(int row, const QVariant& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = time_series_set_data_cos(m_d, row, value.value<float>());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
|
@ -834,6 +837,9 @@ QVariant TimeSeries::sin(int row) const
|
|||
bool TimeSeries::setSin(int row, const QVariant& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = time_series_set_data_sin(m_d, row, value.value<float>());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
|
@ -852,6 +858,9 @@ QVariant TimeSeries::time(int row) const
|
|||
bool TimeSeries::setTime(int row, const QVariant& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<float>())) {
|
||||
return false;
|
||||
}
|
||||
set = time_series_set_data_time(m_d, row, value.value<float>());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
|
|
|
@ -173,6 +173,7 @@ void writeModelGetterSetter(QTextStream& cpp, const QString& index,
|
|||
.arg(lcname, snakeCase(ip.name), idx) << endl;
|
||||
cpp << " } else\n";
|
||||
}
|
||||
cpp << QString(" if (!value.canConvert(qMetaTypeId<%1>())) {\n return false;\n }\n").arg(ip.type.name);
|
||||
QString val = QString("value.value<%1>()").arg(ip.type.name);
|
||||
if (ip.type.isComplex()) {
|
||||
cpp << QString(" const %1 s = %2;").arg(ip.type.name, val);
|
||||
|
|
|
@ -111,6 +111,9 @@ QVariant Persons::userName(int row) const
|
|||
bool Persons::setUserName(int row, const QVariant& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<QString>())) {
|
||||
return false;
|
||||
}
|
||||
const QString s = value.value<QString>(); set = persons_set_data_user_name(m_d, row, s.utf16(), s.length());
|
||||
if (set) {
|
||||
QModelIndex index = createIndex(row, 0, row);
|
||||
|
|
|
@ -127,6 +127,9 @@ QVariant Persons::userName(const QModelIndex& index) const
|
|||
bool Persons::setUserName(const QModelIndex& index, const QVariant& value)
|
||||
{
|
||||
bool set = false;
|
||||
if (!value.canConvert(qMetaTypeId<QString>())) {
|
||||
return false;
|
||||
}
|
||||
const QString s = value.value<QString>(); set = persons_set_data_user_name(m_d, index.internalId(), s.utf16(), s.length());
|
||||
if (set) {
|
||||
emit dataChanged(index, index);
|
||||
|
|
Loading…
Reference in New Issue