From 69cc314142205f92865bf9d3b000143894ce329c Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 22 Feb 2015 09:41:36 -0800 Subject: [PATCH] Move error handling to correct location --- src/QGCQmlWidgetHolder.cpp | 15 +-------------- src/QGCQmlWidgetHolder.h | 3 ++- src/QGCQuickWidget.cc | 18 ++++++++++++++++++ src/QGCQuickWidget.h | 4 ++++ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/QGCQmlWidgetHolder.cpp b/src/QGCQmlWidgetHolder.cpp index 5da881ce4..844ac5132 100644 --- a/src/QGCQmlWidgetHolder.cpp +++ b/src/QGCQmlWidgetHolder.cpp @@ -25,7 +25,6 @@ /// @author Don Gagne #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); } diff --git a/src/QGCQmlWidgetHolder.h b/src/QGCQmlWidgetHolder.h index 0cfb8a999..378e50199 100644 --- a/src/QGCQmlWidgetHolder.h +++ b/src/QGCQmlWidgetHolder.h @@ -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: diff --git a/src/QGCQuickWidget.cc b/src/QGCQuickWidget.cc index f15b78530..14899edca 100644 --- a/src/QGCQuickWidget.cc +++ b/src/QGCQuickWidget.cc @@ -23,6 +23,7 @@ #include "QGCQuickWidget.h" #include "AutoPilotPluginManager.h" +#include "QGCMessageBox.h" #include #include @@ -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; +} diff --git a/src/QGCQuickWidget.h b/src/QGCQuickWidget.h index 22a166ba5..af0d7d90f 100644 --- a/src/QGCQuickWidget.h +++ b/src/QGCQuickWidget.h @@ -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 -- 2.22.0