Skip to content

Commit

Permalink
More accuracy for flight plan calculation preference slider.
Browse files Browse the repository at this point in the history
  • Loading branch information
albar965 committed Apr 6, 2023
1 parent 786d865 commit c3c84f7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ See also [MSFS Common Problems](https://albar965.github.io/littlenavmap-faq.html
context menu use for departure or destination airport.
* Now copying flight plan cruise altitude over to the flight plan calculation window when opening
or changing it in flight plan window.
* More accuracy for flight plan calculation preference slider.
* Added blue question mark help buttons to information and aircraft progress windows linking to the
related user manual chapters.
* Fixed userpoints category not being enabled after assigning a new type to a userpoint.
Expand Down
41 changes: 30 additions & 11 deletions src/route/routecalcdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
#include "util/htmlbuilder.h"

// Factor to put on costs for direct connections. Airways <-> Waypoints
static const float DIRECT_COST_FACTORS[11] = {10.f, 8.f, 6.f, 4.f, 3.f, 2.f, 1.5f, 1.3f, 1.2f, 1.1f, 1.f};
// Sync withAIRWAY_WAYPOINT_PREF_MIN and AIRWAY_WAYPOINT_PREF_MAX
static const QVector<float> DIRECT_COST_FACTORS({10.00f, 09.00f, 08.00f, 07.00f, 06.00f, 04.00f, 03.00f,
02.00f, // Center/both
01.50f, 01.30f, 01.20f, 01.15f, 01.10f, 01.05f, 01.00f});

using atools::util::HtmlBuilder;

Expand All @@ -49,18 +52,25 @@ RouteCalcDialog::RouteCalcDialog(QWidget *parent)
preferenceTexts = QStringList({
tr("Airways and tracks only.\nFastest calculation."),
tr("More airways and few direct."),
tr("More airways and few direct."),
tr("More airways and less direct."),
tr("More airways and less direct."),
tr("Airways and less direct."),
tr("Airways and direct."),
tr("Airways and direct."),
tr("Airways and direct."), // Center / both
tr("Airways and direct."),
tr("Airways and more direct."),
tr("Less airways and more direct."),
tr("Less airways and more direct."),
tr("Few airways and more direct."),
tr("Few airways and more direct."),
tr("Direct using waypoints only.")
});

widgets = {ui->horizontalSliderRouteCalcAirwayPreference, ui->labelRouteCalcAirwayPreferWaypoint,
Q_ASSERT(preferenceTexts.size() == DIRECT_COST_FACTORS.size());
Q_ASSERT(DIRECT_COST_FACTORS.size() == AIRWAY_WAYPOINT_PREF_MAX - AIRWAY_WAYPOINT_PREF_MIN + 1);

widgets = {ui->horizontalSliderRouteCalcAirwayPref, ui->labelRouteCalcAirwayPreferWaypoint,
ui->radioButtonRouteCalcAirwayJet, ui->spinBoxRouteCalcCruiseAltitude, ui->radioButtonRouteCalcAirwayAll,
ui->checkBoxRouteCalcAirwayNoRnav, ui->checkBoxRouteCalcAirwayTrack, ui->radioButtonRouteCalcRadio,
ui->radioButtonRouteCalcAirwayVictor, ui->radioButtonRouteCalcAirway, ui->checkBoxRouteCalcRadioNdb};
Expand All @@ -75,17 +85,14 @@ RouteCalcDialog::RouteCalcDialog(QWidget *parent)
connect(ui->radioButtonRouteCalcRadio, &QRadioButton::clicked, this, &RouteCalcDialog::updateWidgets);
connect(ui->radioButtonRouteCalcFull, &QRadioButton::toggled, this, &RouteCalcDialog::updateWidgets);
connect(ui->radioButtonRouteCalcSelection, &QRadioButton::toggled, this, &RouteCalcDialog::updateWidgets);
connect(ui->horizontalSliderRouteCalcAirwayPreference, &QSlider::valueChanged, this, &RouteCalcDialog::updatePreferenceLabel);
connect(ui->horizontalSliderRouteCalcAirwayPref, &QSlider::valueChanged, this, &RouteCalcDialog::updatePreferenceLabel);

units = new UnitStringTool();
units->init({ui->spinBoxRouteCalcCruiseAltitude});

// Show error messages in tooltip on click ========================================
ui->labelRouteCalcHeader->installEventFilter(new atools::gui::ClickToolTipHandler(ui->labelRouteCalcHeader));

Q_ASSERT(ui->horizontalSliderRouteCalcAirwayPreference->minimum() == AIRWAY_WAYPOINT_PREF_MIN);
Q_ASSERT(ui->horizontalSliderRouteCalcAirwayPreference->maximum() == AIRWAY_WAYPOINT_PREF_MAX);

connect(ui->buttonBox, &QDialogButtonBox::clicked, this, &RouteCalcDialog::buttonBoxClicked);
}

Expand Down Expand Up @@ -172,7 +179,7 @@ void RouteCalcDialog::updateWidgets()
ui->radioButtonRouteCalcAirwayVictor->setEnabled(airway);
ui->checkBoxRouteCalcAirwayNoRnav->setEnabled(airway && NavApp::hasRouteTypeInDatabase());
ui->checkBoxRouteCalcAirwayTrack->setEnabled(airway && NavApp::hasTracks());
ui->horizontalSliderRouteCalcAirwayPreference->setEnabled(airway);
ui->horizontalSliderRouteCalcAirwayPref->setEnabled(airway);
ui->groupBoxRouteCalcAirwayPrefer->setEnabled(airway);
ui->labelRouteCalcAirwayPreferAirway->setEnabled(airway);
ui->labelRouteCalcAirwayPreferWaypoint->setEnabled(airway);
Expand Down Expand Up @@ -205,7 +212,11 @@ void RouteCalcDialog::updateWidgets()

void RouteCalcDialog::updatePreferenceLabel()
{
ui->labelRouteCalcPreference->setText(preferenceTexts.at(ui->horizontalSliderRouteCalcAirwayPreference->value()));
#ifdef DEBUG_INFORMATION
qDebug() << Q_FUNC_INFO << "horizontalSliderRouteCalcAirwayPreference->value()" << ui->horizontalSliderRouteCalcAirwayPref->value();
#endif

ui->labelRouteCalcPreference->setText(preferenceTexts.at(ui->horizontalSliderRouteCalcAirwayPref->value()));
}

void RouteCalcDialog::updateHeader()
Expand Down Expand Up @@ -274,6 +285,14 @@ void RouteCalcDialog::restoreState()
atools::gui::WidgetState state(lnm::ROUTE_CALC_DIALOG);
state.restore(this);
state.restore(widgets);

if(!state.contains(ui->horizontalSliderRouteCalcAirwayPref))
// Correct value to center if settings file is new
ui->horizontalSliderRouteCalcAirwayPref->setValue(AIRWAY_WAYPOINT_PREF_CENTER);

// Adjust slider to new values since they might be restored from settings
ui->horizontalSliderRouteCalcAirwayPref->setMinimum(AIRWAY_WAYPOINT_PREF_MIN);
ui->horizontalSliderRouteCalcAirwayPref->setMaximum(AIRWAY_WAYPOINT_PREF_MAX);
}

void RouteCalcDialog::saveState()
Expand Down Expand Up @@ -331,7 +350,7 @@ bool RouteCalcDialog::isUseTracks() const

int RouteCalcDialog::getAirwayWaypointPreference() const
{
return ui->horizontalSliderRouteCalcAirwayPreference->value();
return ui->horizontalSliderRouteCalcAirwayPref->value();
}

bool RouteCalcDialog::isRadionavNdb() const
Expand All @@ -346,7 +365,7 @@ bool RouteCalcDialog::isCalculateSelection() const

float RouteCalcDialog::getAirwayPreferenceCostFactor() const
{
return DIRECT_COST_FACTORS[ui->horizontalSliderRouteCalcAirwayPreference->value()];
return DIRECT_COST_FACTORS.at(ui->horizontalSliderRouteCalcAirwayPref->value());
}

void RouteCalcDialog::adjustAltitudePressed()
Expand Down
7 changes: 5 additions & 2 deletions src/route/routecalcdialog.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************
* Copyright 2015-2020 Alexander Barthel alex@littlenavmap.org
* Copyright 2015-2023 Alexander Barthel alex@littlenavmap.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -126,8 +126,11 @@ class RouteCalcDialog :

float getAirwayPreferenceCostFactor() const;

/* Min and max values including for ui->horizontalSliderRouteCalcAirwayPreference.
* Sync with DIRECT_COST_FACTORS */
static constexpr int AIRWAY_WAYPOINT_PREF_MIN = 0;
static constexpr int AIRWAY_WAYPOINT_PREF_MAX = 10;
static constexpr int AIRWAY_WAYPOINT_PREF_MAX = 14;
static constexpr int AIRWAY_WAYPOINT_PREF_CENTER = (AIRWAY_WAYPOINT_PREF_MAX - AIRWAY_WAYPOINT_PREF_MIN) / 2;

signals:
/* Use clicked calculate flight plan button */
Expand Down
10 changes: 5 additions & 5 deletions src/route/routecalcdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ Keeps procedures.</string>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QSlider" name="horizontalSliderRouteCalcAirwayPreference">
<widget class="QSlider" name="horizontalSliderRouteCalcAirwayPref">
<property name="toolTip">
<string>Move the slider left to use airways only. This is the fastest calculation method.
Move the slider to the right to use direct waypoint connections only.
Expand All @@ -254,13 +254,13 @@ allows to find a flight plan that can cross areas without an airway network or
unusable airways (e.g. due to altitude restrictions).</string>
</property>
<property name="maximum">
<number>10</number>
<number>14</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>5</number>
<number>7</number>
</property>
<property name="tracking">
<bool>true</bool>
Expand Down Expand Up @@ -601,7 +601,7 @@ Erases procedures.</string>
<tabstop>checkBoxRouteCalcAirwayNoRnav</tabstop>
<tabstop>checkBoxRouteCalcAirwayTrack</tabstop>
<tabstop>pushButtonRouteCalcTrackDownload</tabstop>
<tabstop>horizontalSliderRouteCalcAirwayPreference</tabstop>
<tabstop>horizontalSliderRouteCalcAirwayPref</tabstop>
<tabstop>radioButtonRouteCalcRadio</tabstop>
<tabstop>checkBoxRouteCalcRadioNdb</tabstop>
<tabstop>pushButtonRouteCalcDirect</tabstop>
Expand All @@ -612,7 +612,7 @@ Erases procedures.</string>
</resources>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup_2"/>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_2"/>
</buttongroups>
</ui>

0 comments on commit c3c84f7

Please sign in to comment.