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
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,9 @@ public:
|
|||
bool execInApp();
|
||||
|
||||
bool wasRejected();
|
||||
|
||||
Q_INVOKABLE bool validateMetarString(QString metar);
|
||||
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in a new issue