1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

Fixes for OP-595:

Changed the UAV import of saved settings to not pull in invalid enum
values. Will warn on the dialog that an element of the UAVObject was
invalid and turn off the "save" checkbox. Also will send a qDebug output
showing the UAVObject name and the invalid enum value.
This commit is contained in:
naiiawah 2011-11-25 16:12:38 -07:00
parent d3cc67f5c4
commit 3303313908
3 changed files with 21 additions and 9 deletions

View File

@ -492,13 +492,13 @@ QVariant UAVObjectField::getValue(quint32 index)
return QVariant();
}
void UAVObjectField::setValue(const QVariant& value, quint32 index)
bool UAVObjectField::setValue(const QVariant& value, quint32 index)
{
QMutexLocker locker(obj->getMutex());
// Check that index is not out of bounds
if ( index >= numElements )
{
return;
return false;
}
// Get metadata
UAVObject::Metadata mdata = obj->getMetadata();
@ -552,8 +552,11 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index)
case ENUM:
{
qint8 tmpenum = options.indexOf( value.toString() );
Q_ASSERT(tmpenum >= 0); // To catch any programming errors where we set invalid values
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
// Q_ASSERT(tmpenum >= 0); // To catch any programming errors where we set invalid values
if(tmpenum < 0)
return false;
else
memcpy(&data[offset + numBytesPerElement*index], &tmpenum, numBytesPerElement);
break;
}
case STRING:
@ -570,6 +573,7 @@ void UAVObjectField::setValue(const QVariant& value, quint32 index)
}
}
}
return true;
}
double UAVObjectField::getDouble(quint32 index)

View File

@ -56,7 +56,7 @@ public:
qint32 pack(quint8* dataOut);
qint32 unpack(const quint8* dataIn);
QVariant getValue(quint32 index = 0);
void setValue(const QVariant& data, quint32 index = 0);
bool setValue(const QVariant& data, quint32 index = 0);
double getDouble(quint32 index = 0);
void setDouble(double value, quint32 index = 0);
quint32 getDataOffset();

View File

@ -153,6 +153,7 @@ void UAVSettingsImportExportFactory::importUAVSettings()
// - Update each field
// - Issue and "updated" command
bool error=false;
bool setError=false;
QDomNode field = node.firstChild();
while(!field.isNull()) {
QDomElement f = field.toElement();
@ -161,16 +162,21 @@ void UAVSettingsImportExportFactory::importUAVSettings()
if (uavfield) {
QStringList list = f.attribute("values").split(",");
if (list.length() == 1) {
uavfield->setValue(f.attribute("values"));
if (false == uavfield->setValue(f.attribute("values"))) {
qDebug() << "setValue returned false on: " << uavObjectName << f.attribute("values");
setError = true;
}
} else {
// This is an enum:
int i=0;
QStringList list = f.attribute("values").split(",");
foreach (QString element, list) {
uavfield->setValue(element,i++);
if (false == uavfield->setValue(element,i++)) {
qDebug() << "setValue returned false on: " << uavObjectName << list;
setError = true;
}
}
}
error = false;
} else {
error = true;
}
@ -183,7 +189,9 @@ void UAVSettingsImportExportFactory::importUAVSettings()
} else if (uavObjectID != obj->getObjID()) {
qDebug() << "Mismatch for Object " << uavObjectName << uavObjectID << " - " << obj->getObjID();
swui.addLine(uavObjectName, "Warning (ObjectID mismatch)", true);
} else
} else if (setError) {
swui.addLine(uavObjectName, "Warning (Objects field value(s) invalid)", false);
} else
swui.addLine(uavObjectName, "OK", true);
}
}