Commit 69cc3141 authored by Don Gagne's avatar Don Gagne

Move error handling to correct location

parent 644ac77f
......@@ -25,7 +25,6 @@
/// @author Don Gagne <don@thegagnes.com>
#include "QGCQmlWidgetHolder.h"
#include "QGCMessageBox.h"
QGCQmlWidgetHolder::QGCQmlWidgetHolder(QWidget *parent) :
QWidget(parent)
......@@ -46,17 +45,5 @@ void QGCQmlWidgetHolder::setAutoPilot(AutoPilotPlugin* autoPilot)
bool QGCQmlWidgetHolder::setSource(const QUrl& qmlUrl)
{
_ui.qmlWidget->setSource(qmlUrl);
if (_ui.qmlWidget->status() != QQuickWidget::Ready) {
QString errorList;
foreach (QQmlError error, _ui.qmlWidget->errors()) {
errorList += error.toString();
errorList += "\n";
}
QGCMessageBox::warning(tr("Qml Error"), tr("Source not ready: %1\nErrors:\n%2").arg(_ui.qmlWidget->status()).arg(errorList));
return false;
}
return true;
return _ui.qmlWidget->setSource(qmlUrl);
}
......@@ -49,7 +49,8 @@ public:
/// Sets the UAS into the widget which in turn will load facts into the context
void setAutoPilot(AutoPilotPlugin* autoPilot);
/// Sets the QML into the control
/// Sets the QML into the control. Will display errors message box if error occurs loading source.
/// @return true: source loaded, false: source not loaded, errors occured
bool setSource(const QUrl& qmlUrl);
private:
......
......@@ -23,6 +23,7 @@
#include "QGCQuickWidget.h"
#include "AutoPilotPluginManager.h"
#include "QGCMessageBox.h"
#include <QQmlContext>
#include <QQmlEngine>
......@@ -43,3 +44,20 @@ void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot)
{
rootContext()->setContextProperty("autopilot", autoPilot);
}
bool QGCQuickWidget::setSource(const QUrl& qmlUrl)
{
QQuickWidget::setSource(qmlUrl);
if (status() != Ready) {
QString errorList;
foreach (QQmlError error, errors()) {
errorList += error.toString();
errorList += "\n";
}
QGCMessageBox::warning(tr("Qml Error"), tr("Source not ready: Status(%1)\nErrors:\n%2").arg(status()).arg(errorList));
return false;
}
return true;
}
......@@ -42,6 +42,10 @@ public:
/// Sets the UAS into the widget which in turn will load facts into the context
void setAutoPilot(AutoPilotPlugin* autoPilot);
/// Sets the QML into the control. Will display errors message box if error occurs loading source.
/// @return true: source loaded, false: source not loaded, errors occured
bool setSource(const QUrl& qmlUrl);
};
#endif
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