Validation of METAR in the launcher
This commit is contained in:
parent
0c4eaa8b29
commit
42508619ee
3 changed files with 43 additions and 1 deletions
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
// simgear headers
|
// simgear headers
|
||||||
#include <simgear/package/Install.hxx>
|
#include <simgear/package/Install.hxx>
|
||||||
|
#include <simgear/environment/metar.hxx>
|
||||||
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
// FlightGear headers
|
// FlightGear headers
|
||||||
#include <Network/HTTPClient.hxx>
|
#include <Network/HTTPClient.hxx>
|
||||||
|
@ -348,6 +350,8 @@ void LauncherMainWindow::buildEnvironmentSections()
|
||||||
|
|
||||||
LauncherMainWindow::~LauncherMainWindow()
|
LauncherMainWindow::~LauncherMainWindow()
|
||||||
{
|
{
|
||||||
|
m_qmlEngine->collectGarbage();
|
||||||
|
delete m_qmlEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LauncherMainWindow::execInApp()
|
bool LauncherMainWindow::execInApp()
|
||||||
|
@ -1097,3 +1101,19 @@ void LauncherMainWindow::onSettingsSearchChanged()
|
||||||
ss->setSearchTerm(m_ui->settingsSearchEdit->text());
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -57,6 +57,9 @@ public:
|
||||||
bool execInApp();
|
bool execInApp();
|
||||||
|
|
||||||
bool wasRejected();
|
bool wasRejected();
|
||||||
|
|
||||||
|
Q_INVOKABLE bool validateMetarString(QString metar);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent *event) override;
|
virtual void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import FlightGear.Launcher 1.0
|
import FlightGear.Launcher 1.0
|
||||||
|
import QtQml 2.2
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
id: weatherSettings
|
id: weatherSettings
|
||||||
|
@ -23,11 +24,29 @@ Section {
|
||||||
|
|
||||||
LineEdit {
|
LineEdit {
|
||||||
id: customMETAR
|
id: customMETAR
|
||||||
|
|
||||||
|
property bool __cachedValid: true
|
||||||
|
|
||||||
|
function revalidate() {
|
||||||
|
__cachedValid = _launcher.validateMetarString(value);
|
||||||
|
}
|
||||||
|
|
||||||
visible: weatherScenario.isCustomMETAR
|
visible: weatherScenario.isCustomMETAR
|
||||||
enabled: !fetchMetar.checked
|
enabled: !fetchMetar.checked
|
||||||
label: "METAR"
|
label: "METAR"
|
||||||
placeholder: "XXXX 012345Z 28035G50KT 250V300 9999 TSRA SCT022CB BKN030 13/09 Q1005"
|
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: {
|
onApply: {
|
||||||
|
|
Loading…
Reference in a new issue