1
0
Fork 0

Validation of METAR in the launcher

This commit is contained in:
James Turner 2017-05-18 09:17:27 +01:00
parent 0c4eaa8b29
commit 42508619ee
3 changed files with 43 additions and 1 deletions

View file

@ -14,6 +14,8 @@
// simgear headers
#include <simgear/package/Install.hxx>
#include <simgear/environment/metar.hxx>
#include <simgear/structure/exception.hxx>
// FlightGear headers
#include <Network/HTTPClient.hxx>
@ -348,6 +350,8 @@ void LauncherMainWindow::buildEnvironmentSections()
LauncherMainWindow::~LauncherMainWindow()
{
m_qmlEngine->collectGarbage();
delete m_qmlEngine;
}
bool LauncherMainWindow::execInApp()
@ -1097,3 +1101,19 @@ void LauncherMainWindow::onSettingsSearchChanged()
ss->setSearchTerm(m_ui->settingsSearchEdit->text());
}
}
bool LauncherMainWindow::validateMetarString(QString metar)
{
if (metar.isEmpty()) {
return true;
}
try {
std::string s = metar.toStdString();
SGMetar theMetar(s);
} catch (sg_io_exception&) {
return false;
}
return true;
}

View file

@ -57,6 +57,9 @@ public:
bool execInApp();
bool wasRejected();
Q_INVOKABLE bool validateMetarString(QString metar);
protected:
virtual void closeEvent(QCloseEvent *event) override;

View file

@ -1,4 +1,5 @@
import FlightGear.Launcher 1.0
import QtQml 2.2
Section {
id: weatherSettings
@ -23,11 +24,29 @@ Section {
LineEdit {
id: customMETAR
property bool __cachedValid: true
function revalidate() {
__cachedValid = _launcher.validateMetarString(value);
}
visible: weatherScenario.isCustomMETAR
enabled: !fetchMetar.checked
label: "METAR"
placeholder: "XXXX 012345Z 28035G50KT 250V300 9999 TSRA SCT022CB BKN030 13/09 Q1005"
description: "Enter a custom METAR string"
description: __cachedValid ? "Enter a custom METAR string"
: "The entered METAR string doesn't seem to be valid."
onValueChanged: {
validateTimeout.restart()
}
}
Timer {
id: validateTimeout
interval: 200
onTriggered: customMETAR.revalidate();
}
onApply: {