Commit 9b68c43f authored by Don Gagne's avatar Don Gagne

Parameter load errors shown to user

parent 29365f96
...@@ -163,9 +163,9 @@ void AutoPilotPlugin::writeParametersToStream(QTextStream &stream) ...@@ -163,9 +163,9 @@ void AutoPilotPlugin::writeParametersToStream(QTextStream &stream)
_getParameterLoader()->writeParametersToStream(stream, _uas->getUASName()); _getParameterLoader()->writeParametersToStream(stream, _uas->getUASName());
} }
void AutoPilotPlugin::readParametersFromStream(QTextStream &stream) QString AutoPilotPlugin::readParametersFromStream(QTextStream &stream)
{ {
_getParameterLoader()->readParametersFromStream(stream); return _getParameterLoader()->readParametersFromStream(stream);
} }
bool AutoPilotPlugin::armed(void) bool AutoPilotPlugin::armed(void)
......
...@@ -89,7 +89,8 @@ public: ...@@ -89,7 +89,8 @@ public:
void writeParametersToStream(QTextStream &stream); void writeParametersToStream(QTextStream &stream);
/// Reads the parameters from the stream and updates values /// Reads the parameters from the stream and updates values
void readParametersFromStream(QTextStream &stream); /// @return Errors during load. Empty string for no errors
QString readParametersFromStream(QTextStream &stream);
/// Returns true if the specifed fact exists /// Returns true if the specifed fact exists
Q_INVOKABLE bool factExists(FactSystem::Provider_t provider, ///< fact provider Q_INVOKABLE bool factExists(FactSystem::Provider_t provider, ///< fact provider
......
...@@ -579,8 +579,9 @@ void ParameterLoader::_saveToEEPROM(void) ...@@ -579,8 +579,9 @@ void ParameterLoader::_saveToEEPROM(void)
qCDebug(ParameterLoaderLog) << "_saveToEEPROM"; qCDebug(ParameterLoaderLog) << "_saveToEEPROM";
} }
void ParameterLoader::readParametersFromStream(QTextStream& stream) QString ParameterLoader::readParametersFromStream(QTextStream& stream)
{ {
QString errors;
bool userWarned = false; bool userWarned = false;
while (!stream.atEnd()) { while (!stream.atEnd()) {
...@@ -597,7 +598,7 @@ void ParameterLoader::readParametersFromStream(QTextStream& stream) ...@@ -597,7 +598,7 @@ void ParameterLoader::readParametersFromStream(QTextStream& stream)
QGCMessageBox::Ok | QGCMessageBox::Cancel, QGCMessageBox::Ok | QGCMessageBox::Cancel,
QGCMessageBox::Cancel); QGCMessageBox::Cancel);
if (button == QGCMessageBox::Cancel) { if (button == QGCMessageBox::Cancel) {
return; return QString();
} }
} }
...@@ -607,18 +608,29 @@ void ParameterLoader::readParametersFromStream(QTextStream& stream) ...@@ -607,18 +608,29 @@ void ParameterLoader::readParametersFromStream(QTextStream& stream)
uint mavType = wpParams.at(4).toUInt(); uint mavType = wpParams.at(4).toUInt();
if (!_autopilot->factExists(FactSystem::ParameterProvider, componentId, paramName)) { if (!_autopilot->factExists(FactSystem::ParameterProvider, componentId, paramName)) {
QString error;
error = QString("Skipped parameter %1:%2 - does not exist on this vehicle\n").arg(componentId).arg(paramName);
errors += error;
qCDebug(ParameterLoaderLog) << error;
continue; continue;
} }
Fact* fact = _autopilot->getFact(FactSystem::ParameterProvider, componentId, paramName); Fact* fact = _autopilot->getFact(FactSystem::ParameterProvider, componentId, paramName);
if (fact->type() != _mavTypeToFactType((MAV_PARAM_TYPE)mavType)) { if (fact->type() != _mavTypeToFactType((MAV_PARAM_TYPE)mavType)) {
QString error;
error = QString("Skipped parameter %1:%2 - type mismatch %3:%4\n").arg(componentId).arg(paramName).arg(fact->type()).arg(_mavTypeToFactType((MAV_PARAM_TYPE)mavType));
errors += error;
qCDebug(ParameterLoaderLog) << error;
continue; continue;
} }
qCDebug(ParameterLoaderLog) << "Updating parameter" << componentId << paramName << valStr;
fact->setValue(valStr); fact->setValue(valStr);
} }
} }
} }
return errors;
} }
void ParameterLoader::writeParametersToStream(QTextStream &stream, const QString& name) void ParameterLoader::writeParametersToStream(QTextStream &stream, const QString& name)
......
...@@ -80,7 +80,9 @@ public: ...@@ -80,7 +80,9 @@ public:
const QMap<int, QMap<QString, QStringList> >& getGroupMap(void); const QMap<int, QMap<QString, QStringList> >& getGroupMap(void);
void readParametersFromStream(QTextStream& stream); /// Returns error messages from loading
QString readParametersFromStream(QTextStream& stream);
void writeParametersToStream(QTextStream &stream, const QString& name); void writeParametersToStream(QTextStream &stream, const QString& name);
/// Return the parameter for which the default component id is derived from. Return an empty /// Return the parameter for which the default component id is derived from. Return an empty
......
...@@ -49,7 +49,14 @@ QGCView { ...@@ -49,7 +49,14 @@ QGCView {
readonly property real __rightMargin: 20 readonly property real __rightMargin: 20
readonly property int __maxParamChars: 16 readonly property int __maxParamChars: 16
ParameterEditorController { id: controller; factPanel: panel } ParameterEditorController {
id: controller;
factPanel: panel
onShowErrorMessage: {
showMessage("Parameter Load Errors", errorMsg, StandardButton.Ok)
}
}
Component { Component {
id: editorDialogComponent id: editorDialogComponent
......
...@@ -95,6 +95,8 @@ void ParameterEditorController::saveToFile(void) ...@@ -95,6 +95,8 @@ void ParameterEditorController::saveToFile(void)
void ParameterEditorController::loadFromFile(void) void ParameterEditorController::loadFromFile(void)
{ {
QString errors;
Q_ASSERT(_autopilot); Q_ASSERT(_autopilot);
QString msgTitle("Load Parameters"); QString msgTitle("Load Parameters");
...@@ -112,8 +114,12 @@ void ParameterEditorController::loadFromFile(void) ...@@ -112,8 +114,12 @@ void ParameterEditorController::loadFromFile(void)
} }
QTextStream stream(&file); QTextStream stream(&file);
_autopilot->readParametersFromStream(stream); errors = _autopilot->readParametersFromStream(stream);
file.close(); file.close();
if (!errors.isEmpty()) {
emit showErrorMessage(errors);
}
} }
} }
......
...@@ -54,6 +54,9 @@ public: ...@@ -54,6 +54,9 @@ public:
Q_INVOKABLE void setRCToParam(const QString& paramName); Q_INVOKABLE void setRCToParam(const QString& paramName);
QList<QObject*> model(void); QList<QObject*> model(void);
signals:
void showErrorMessage(const QString& errorMsg);
private: private:
QStringList _componentIds; QStringList _componentIds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment