1
0
Fork 0

#2177 - launcher - added flightplan info to summary window:

- Summary.qml - new row with Flight Plan info
- LauncherController.hxx, Launcher.qml - signals to show flightPlan & 
  exposing flight plan object
- FlightPlan.qml - add red color to information about airport mismatch
- FlightPlanController.cxx, FlightPlanController.hxx - description
  handling, support to loading flight-plan from command line argument 
  'flight-plan', saving last used dir when loading/saving flightplans
This commit is contained in:
Slawek Mikula 2021-01-06 01:05:26 +01:00 committed by James Turner
parent b738058945
commit 354d7d02d2
5 changed files with 74 additions and 10 deletions

View file

@ -1,9 +1,11 @@
#include "FlightPlanController.hxx"
#include <QDebug>
#include <Main/options.hxx>
#include <QAbstractListModel>
#include <QQmlComponent>
#include <QDebug>
#include <QFileDialog>
#include <QQmlComponent>
#include <QSettings>
#include <QTimer>
#include <simgear/misc/sg_path.hxx>
@ -290,11 +292,19 @@ void FlightPlanController::onRestore()
_enabled = _config->getValueForKey("", "fp-enabled", false).toBool();
emit enabledChanged(_enabled);
std::string planXML = _config->getValueForKey("", "fp", QString()).toString().toStdString();
if (!planXML.empty()) {
std::istringstream ss(planXML);
_fp->load(ss);
emit infoChanged();
// if the user specified --flight-plan, load that one
auto options = flightgear::Options::sharedInstance();
std::string fpArgPath = options->valueForOption("flight-plan");
SGPath fp = SGPath::fromUtf8(fpArgPath);
if (fp.exists()) {
loadFromPath(QString::fromStdString(fpArgPath));
} else {
std::string planXML = _config->getValueForKey("", "fp", QString()).toString().toStdString();
if (!planXML.empty()) {
std::istringstream ss(planXML);
_fp->load(ss);
emit infoChanged();
}
}
}
@ -326,6 +336,19 @@ void FlightPlanController::setCruiseAltitude(QuantityValue alt)
emit infoChanged();
}
QString FlightPlanController::description() const
{
if (_fp->numLegs() == 0) {
return tr("No flight-plan");
}
return tr("From %1 (%2) to %3 (%4)")
.arg(departure()->ident())
.arg(departure()->name())
.arg(destination()->ident())
.arg(destination()->name());
}
QmlPositioned *FlightPlanController::departure() const
{
if (!_fp->departureAirport())
@ -507,24 +530,36 @@ void FlightPlanController::computeDuration()
bool FlightPlanController::loadPlan()
{
QSettings settings;
QString lastUsedDir = settings.value("flightplan-lastdir", "").toString();
QString file = QFileDialog::getOpenFileName(nullptr, tr("Load a flight-plan"),
{}, "*.fgfp *.gpx");
lastUsedDir, "*.fgfp *.gpx");
if (file.isEmpty())
return false;
QFileInfo fi(file);
settings.setValue("flightplan-lastdir", fi.absolutePath());
return loadFromPath(file);
}
void FlightPlanController::savePlan()
{
QSettings settings;
QString lastUsedDir = settings.value("flightplan-lastdir", "").toString();
QString file = QFileDialog::getSaveFileName(nullptr, tr("Save flight-plan"),
{}, "*.fgfp");
lastUsedDir, "*.fgfp");
if (file.isEmpty())
return;
if (!file.endsWith(".fgfp")) {
file += ".fgfp";
}
QFileInfo fi(file);
settings.setValue("flightplan-lastdir", fi.absolutePath());
saveToPath(file);
}

View file

@ -19,6 +19,7 @@ class FlightPlanController : public QObject
Q_OBJECT
Q_PROPERTY(bool enabled MEMBER _enabled NOTIFY enabledChanged)
Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
Q_PROPERTY(QString callsign READ callsign WRITE setCallsign NOTIFY infoChanged)
Q_PROPERTY(QString remarks READ remarks WRITE setRemarks NOTIFY infoChanged)
@ -78,6 +79,8 @@ public:
QuantityValue cruiseAltitude() const;
void setCruiseAltitude(QuantityValue alt);
QString description() const;
QmlPositioned* departure() const;
QmlPositioned* destination() const;
QmlPositioned* alternate() const;
@ -113,6 +116,7 @@ signals:
void waypointsChanged();
void enabledChanged(bool enabled);
void descriptionChanged(QString description);
public slots:

View file

@ -237,6 +237,7 @@ Item {
ClickableText {
width: parent.width
color: Style.destructiveActionColor
text: qsTr("The flight-plan departure airport (%1) is different to the " +
"initial location (%2). Click here to set the initial location to " +
"the flight-plan's airport.").

View file

@ -175,6 +175,7 @@ Item {
ignoreUnknownSignals: true
onShowSelectedAircraft: root.selectPage(1)
onShowSelectedLocation: root.selectPage(2)
onShowFlightPlan: root.enterFlightPlan()
}
Menu {

View file

@ -8,6 +8,7 @@ Item {
signal showSelectedAircraft();
signal showSelectedLocation();
signal showFlightPlan();
Rectangle {
anchors.fill: parent
@ -261,7 +262,7 @@ Item {
} // of connections
}
Item {
Item {
width: 1; height: 1
visible: stateSelectionGroup.visible
}
@ -292,6 +293,28 @@ Item {
}
}
// flight plan summary row
StyledText {
id: flightPlanLabel
text: qsTr("Flight Plan:")
horizontalAlignment: Text.AlignRight
font.pixelSize: Style.headingFontPixelSize
visible: _launcher.flightPlan.enabled
}
ClickableText {
text: _launcher.flightPlan.description
font.pixelSize: Style.headingFontPixelSize
width: summaryGrid.middleColumnWidth
onClicked: root.showFlightPlan()
visible: _launcher.flightPlan.enabled
}
Item { // padding item for flight plan row
width: 1; height: 1
visible: _launcher.flightPlan.enabled
}
// settings summary row
StyledText {
text: qsTr("Settings:")