diff --git a/example/sACN Explorer/universemodel.cpp b/example/sACN Explorer/universemodel.cpp index 7697ba3..78a59f4 100644 --- a/example/sACN Explorer/universemodel.cpp +++ b/example/sACN Explorer/universemodel.cpp @@ -138,42 +138,23 @@ bool UniverseModel::setData(const QModelIndex &index, const QVariant &value, return false; uint16_t slot = (index.row() * 10) + (index.column() + 1); - uint8_t data; + uint data; + bool ok; switch (data_mode_) { case Decimal: - { - if (!value.canConvert()) - return false; - unsigned int d = value.toUInt(); - if (d > 255) - return false; - data = d; - } + data = value.toUInt(&ok); break; case Hex: - { - if (!value.canConvert()) - return false; - bool ok; - unsigned int d = value.toString().toInt(&ok, 16); - if (!ok || d > 255) - return false; - data = d; - } + data = value.toString().toUInt(&ok, 16); break; case Percent: - { - if (!value.canConvert()) - return false; - int d = 255 * (value.toDouble() / 100); - if (d < 0 || d > 255) - return false; - data = d; - } + data = 255 * (value.toDouble(&ok) / 100); break; } + if (!ok || data > 255) + return false; universe_->setValue(slot, data); emit dataChanged(index, index, QVector() << role);