1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-558 accept case insensitive uav enum values

this is needed because TRUE/FALSE enum has been changed to True/False
but old TRUE/FALSE is used by templates
LP templates can be fixed but users' templates can't

logic is now to try case sensitive, if that fails try case insensitive
if case insensitive works, a warning is logged

a new warning is also logged if the enum can't be found at all
This commit is contained in:
Philippe Renon 2017-10-30 23:14:19 +01:00
parent 2f1e7cd72d
commit f920e837c4

View File

@ -1152,9 +1152,18 @@ void UAVObjectField::setValue(const QVariant & value, quint32 index)
case ENUM:
{
qint8 tmpenum = options.indexOf(value.toString());
// try case insensitive
if (tmpenum < 0) {
QRegExp regexp(value.toString(), Qt::CaseInsensitive);
tmpenum = options.indexOf(regexp);
if (tmpenum >= 0) {
qWarning() << "Enum value" << value.toString() << "should be" << options.at(tmpenum);
}
}
// Default to 0 on invalid values.
if (tmpenum < 0) {
tmpenum = 0;
qWarning() << "Enum value" << value.toString() << "not found";
}
memcpy(&data[offset + numBytesPerElement * index], &tmpenum, numBytesPerElement);
break;