refs #335, SELCAL tweaks discovered during refactoring

* better case handling in SELCAL
* SELCAL in aircraft
* SELCAL selector, improved getter / setters
* changed cockpit SELCAL elements to promoted GUI element
* synchronized flightplan and cockpit SELCAL codes, used new signal/slot syntacs in flightplan
* added SELCAL in own aircraft context
This commit is contained in:
Klaus Basan
2014-11-25 23:46:55 +01:00
committed by Roland Winklmeier
parent dd587207fe
commit 0c6f5f1777
16 changed files with 169 additions and 77 deletions

View File

@@ -58,26 +58,24 @@ namespace BlackGui
{
// SELCAL pairs in cockpit
this->ui->cb_ComPanelSelcalSelector1->clear();
this->ui->cb_ComPanelSelcalSelector2->clear();
this->ui->cb_ComPanelSelcalSelector1->addItems(BlackMisc::Aviation::CSelcal::codePairs());
this->ui->cb_ComPanelSelcalSelector2->addItems(BlackMisc::Aviation::CSelcal::codePairs());
this->ui->frp_ComPanelSelcalBottom->clear();
connect(this->ui->pb_ComPanelSelcalTest, &QPushButton::clicked, this, &CCockpitComComponent::ps_testSelcal);
// COM GUI events
connect(this->ui->pb_ComPanelCom1Toggle, &QPushButton::clicked, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->pb_ComPanelCom2Toggle, &QPushButton::clicked, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->ds_ComPanelCom1Active, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->ds_ComPanelCom2Active, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->ds_ComPanelCom1Standby, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->ds_ComPanelCom2Standby, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->sbp_ComPanelTransponder, &QDoubleSpinBox::editingFinished, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderModeChanged, this, &CCockpitComComponent::ps_guiChangedCockpitValues);
connect(this->ui->frp_ComPanelSelcalBottom, &CSelcalCodeSelector::valueChanged, this, &CCockpitComComponent::ps_guiChangedSelcal);
// hook up with changes from own aircraft context
Q_ASSERT(this->getIContextOwnAircraft());
this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitComComponent::ps_updateCockpitFromContext);
this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedSelcal, this, &CCockpitComComponent::ps_onChangedSelcal);
// hook up with audio context
Q_ASSERT(this->getIContextAudio());
@@ -114,6 +112,11 @@ namespace BlackGui
this->updateOwnCockpitInContext(ownAircraft);
}
void CCockpitComComponent::ps_guiChangedSelcal()
{
this->getIContextOwnAircraft()->updateSelcal(this->getSelcal(), cockpitOriginator());
}
void CCockpitComComponent::ps_updateCockpitFromContext(const CAircraft &ownAircraft, const QString &originator)
{
if (originator == CCockpitComComponent::cockpitOriginator()) return; // comes from myself
@@ -165,14 +168,14 @@ namespace BlackGui
void CCockpitComComponent::ps_testSelcal()
{
QString selcalCode = this->getSelcalCode();
if (!CSelcal::isValidCode(selcalCode))
CSelcal selcal = this->getSelcal();
if (!selcal.isValid())
{
CLogMessage().validationWarning("Invalid SELCAL codde");
}
else if (this->getIContextAudio())
{
CSelcal selcal(selcalCode);
CSelcal selcal(selcal);
this->getIContextAudio()->playSelcalTone(selcal);
}
else
@@ -181,10 +184,15 @@ namespace BlackGui
}
}
QString CCockpitComComponent::getSelcalCode() const
void CCockpitComComponent::ps_onChangedSelcal(const CSelcal &selcal, const QString &originator)
{
QString selcal = this->ui->cb_ComPanelSelcalSelector1->currentText().append(this->ui->cb_ComPanelSelcalSelector2->currentText());
return selcal;
if (originator == CCockpitComComponent::cockpitOriginator()) return; // comes from myself
this->ui->frp_ComPanelSelcalBottom->setSelcalCode(selcal);
}
CSelcal CCockpitComComponent::getSelcal() const
{
return ui->frp_ComPanelSelcalBottom->getSelcal();
}
void CCockpitComComponent::initLeds()

View File

@@ -87,7 +87,7 @@ namespace BlackGui
BlackMisc::Aviation::CAircraft getOwnAircraft() const;
//! Current SELCAL code
QString getSelcalCode() const;
BlackMisc::Aviation::CSelcal getSelcal() const;
//! Cockpit updates
bool updateOwnCockpitInContext(const BlackMisc::Aviation::CAircraft &ownAircraft);

View File

@@ -71,7 +71,7 @@
<number>0</number>
</property>
<item row="1" column="0" colspan="2">
<widget class="QFrame" name="fr_ComPanelSelcalBottom">
<widget class="BlackGui::CSelcalCodeSelector" name="frp_ComPanelSelcalBottom">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -100,26 +100,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="cb_ComPanelSelcalSelector1">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cb_ComPanelSelcalSelector2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -648,6 +628,12 @@
<extends>QSpinBox</extends>
<header>blackgui/transpondercodespinbox.h</header>
</customwidget>
<customwidget>
<class>BlackGui::CSelcalCodeSelector</class>
<extends>QFrame</extends>
<header>blackgui/selcalcodeselector.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../blackmisc/blackmisc.qrc"/>

View File

@@ -34,38 +34,33 @@ namespace BlackGui
this->tabBar()->setExpanding(false);
// connect
connect(this->ui->pb_Send, &QPushButton::pressed, this, &CFlightPlanComponent::sendFlightPlan);
connect(this->ui->pb_Load, &QPushButton::pressed, this, &CFlightPlanComponent::loadFlightPlanFromNetwork);
connect(this->ui->pb_Reset, &QPushButton::pressed, this, &CFlightPlanComponent::resetFlightPlan);
connect(this->ui->pb_ValidateFlightPlan, &QPushButton::pressed, this, &CFlightPlanComponent::validateFlightPlan);
connect(this->ui->pb_Send, &QPushButton::pressed, this, &CFlightPlanComponent::ps_sendFlightPlan);
connect(this->ui->pb_Load, &QPushButton::pressed, this, &CFlightPlanComponent::ps_loadFlightPlanFromNetwork);
connect(this->ui->pb_Reset, &QPushButton::pressed, this, &CFlightPlanComponent::ps_resetFlightPlan);
connect(this->ui->pb_ValidateFlightPlan, &QPushButton::pressed, this, &CFlightPlanComponent::ps_validateFlightPlan);
bool c;
c = connect(this->ui->cb_VoiceCapabilities, SIGNAL(currentIndexChanged(int)), this, SLOT(buildRemarkString()));
connect(this->ui->cb_VoiceCapabilities, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::ps_currentTextChangedToBuildRemarks);
connect(this->ui->cb_NavigationEquipment, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::ps_currentTextChangedToBuildRemarks);
connect(this->ui->cb_PerformanceCategory, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::ps_currentTextChangedToBuildRemarks);
connect(this->ui->cb_PilotRating, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::ps_currentTextChangedToBuildRemarks);
connect(this->ui->cb_RequiredNavigationPerformance, &QComboBox::currentTextChanged, this, &CFlightPlanComponent::ps_currentTextChangedToBuildRemarks);
bool c = connect(this->ui->le_AircraftRegistration, SIGNAL(textChanged(QString)), this, SLOT(ps_buildRemarksString()));
Q_ASSERT(c);
c = connect(this->ui->cb_NavigationEquipment, SIGNAL(currentIndexChanged(int)), this, SLOT(buildRemarkString()));
c = connect(this->ui->cb_NoSidsStarts, SIGNAL(toggled(bool)), this, SLOT(ps_buildRemarksString()));
Q_ASSERT(c);
c = connect(this->ui->cb_PerformanceCategory, SIGNAL(currentIndexChanged(int)), this, SLOT(buildRemarkString()));
Q_ASSERT(c);
c = connect(this->ui->cb_PilotRating, SIGNAL(currentIndexChanged(int)), this, SLOT(buildRemarkString()));
Q_ASSERT(c);
c = connect(this->ui->cb_RequiredNavigationPerformance, SIGNAL(currentIndexChanged(int)), this, SLOT(buildRemarkString()));
Q_ASSERT(c);
c = connect(this->ui->cb_NoSidsStarts, SIGNAL(toggled(bool)), this, SLOT(buildRemarkString()));
Q_ASSERT(c);
c = connect(this->ui->le_AircraftRegistration, SIGNAL(textChanged(QString)), this, SLOT(buildRemarkString()));
Q_ASSERT(c);
c = connect(this->ui->le_AirlineOperator, SIGNAL(textChanged(QString)), this, SLOT(buildRemarkString()));
c = connect(this->ui->le_AirlineOperator, SIGNAL(textChanged(QString)), this, SLOT(ps_buildRemarksString()));
Q_ASSERT(c);
Q_UNUSED(c);
connect(this->ui->pte_AdditionalRemarks, &QPlainTextEdit::textChanged, this, &CFlightPlanComponent::buildRemarkString);
connect(this->ui->frp_SelcalCode, &CSelcalCodeSelector::valueChanged, this, &CFlightPlanComponent::buildRemarkString);
connect(this->ui->pb_CopyOver, &QPushButton::pressed, this, &CFlightPlanComponent::copyRemarks);
connect(this->ui->pb_RemarksGenerator, &QPushButton::clicked, this, &CFlightPlanComponent::currentTabGenerator);
connect(this->ui->pte_AdditionalRemarks, &QPlainTextEdit::textChanged, this, &CFlightPlanComponent::ps_buildRemarksString);
connect(this->ui->frp_SelcalCode, &CSelcalCodeSelector::valueChanged, this, &CFlightPlanComponent::ps_buildRemarksString);
connect(this->ui->frp_SelcalCode, &CSelcalCodeSelector::valueChanged, this, &CFlightPlanComponent::ps_setSelcalInOwnAircraft);
connect(this->ui->pb_CopyOver, &QPushButton::pressed, this, &CFlightPlanComponent::ps_copyRemarks);
connect(this->ui->pb_RemarksGenerator, &QPushButton::clicked, this, &CFlightPlanComponent::ps_currentTabGenerator);
this->ui->frp_SelcalCode->resetSelcalCodes(true);
this->resetFlightPlan();
this->buildRemarkString();
this->ps_resetFlightPlan();
this->ps_buildRemarksString();
}
CFlightPlanComponent::~CFlightPlanComponent()
@@ -92,9 +87,13 @@ namespace BlackGui
CAltitude cruiseAlt = flightPlan.getCruiseAltitude();
if (cruiseAlt.isFlightLevel())
{
this->ui->le_CrusingAltitude->setText(cruiseAlt.toQString());
}
else
{
this->ui->le_CrusingAltitude->setText(cruiseAlt.valueRoundedWithUnit(BlackMisc::PhysicalQuantities::CLengthUnit::ft(), 0));
}
}
CFlightPlan CFlightPlanComponent::getFlightPlan() const
@@ -277,6 +276,11 @@ namespace BlackGui
void CFlightPlanComponent::ps_setSelcalInOwnAircraft()
{
if (!this->getIContextOwnAircraft()) return;
if (!this->ui->frp_SelcalCode->hasValidCode()) return;
this->getIContextOwnAircraft()->updateSelcal(this->ui->frp_SelcalCode->getSelcal(), flightPlanOriginator());
}
void CFlightPlanComponent::ps_loadFlightPlanFromNetwork()
{
if (!this->getIContextNetwork())
@@ -386,5 +390,14 @@ namespace BlackGui
{
this->setCurrentWidget(this->ui->tb_RemarksGenerator);
}
}
}
const QString &CFlightPlanComponent::flightPlanOriginator()
{
// string is generated once, the timestamp allows to use multiple
// components (as long as they are not generated at the same ms)
static const QString o = QString("FLIGHTPLANCOMPONENT:").append(QString::number(QDateTime::currentMSecsSinceEpoch()));
return o;
}
} // namespace
} // namespace

View File

@@ -63,7 +63,13 @@ namespace BlackGui
//! Default value for time
static const QString &defaultTime() { static QString t("00:00"); return t; }
//! Originator
static const QString &flightPlanOriginator();
private slots:
//! Call \sa ps_buildRemarksString from combo box signal
void ps_currentTextChangedToBuildRemarks(const QString &text) { this->ps_buildRemarksString(); Q_UNUSED(text); }
//! Send flightplan
void ps_sendFlightPlan();

View File

@@ -11,13 +11,15 @@
#include "ui_selcalcodeselector.h"
#include "blackmisc/avselcal.h"
using namespace BlackMisc::Aviation;
namespace BlackGui
{
CSelcalCodeSelector::CSelcalCodeSelector(QWidget *parent) :
QFrame(parent), ui(new Ui::CSelcalCodeSelector)
{
this->ui->setupUi(this);
this->resetSelcalCodes(false);
this->resetSelcalCodes(true);
bool c;
c = connect(this->ui->cb_SelcalPairs1, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valueChanged()));
@@ -27,9 +29,7 @@ namespace BlackGui
}
CSelcalCodeSelector::~CSelcalCodeSelector()
{
delete ui;
}
{ }
QString CSelcalCodeSelector::getSelcalCode() const
{
@@ -38,6 +38,12 @@ namespace BlackGui
return selcal;
}
BlackMisc::Aviation::CSelcal CSelcalCodeSelector::getSelcal() const
{
CSelcal selcal(getSelcalCode());
return selcal;
}
void CSelcalCodeSelector::resetSelcalCodes(bool allowEmptyValue)
{
this->ui->cb_SelcalPairs1->clear();
@@ -50,15 +56,25 @@ namespace BlackGui
void CSelcalCodeSelector::setSelcalCode(const QString &selcal)
{
if (selcal.length() == 4 && this->getSelcalCode() == selcal) return; // avoid unintended signals
QString s = selcal.isEmpty() ? " " : selcal.toUpper().trimmed();
Q_ASSERT(s.length() == 4);
if (s.length() != 4) return;
QString s1 = s.left(2);
QString s2 = s.right(2);
if (BlackMisc::Aviation::CSelcal::codePairs().contains(s1))
{
this->ui->cb_SelcalPairs1->setCurrentText(s1);
}
if (BlackMisc::Aviation::CSelcal::codePairs().contains(s2))
this->ui->cb_SelcalPairs1->setCurrentText(s2);
{
this->ui->cb_SelcalPairs2->setCurrentText(s2);
}
}
void CSelcalCodeSelector::setSelcalCode(const BlackMisc::Aviation::CSelcal &selcal)
{
this->setSelcalCode(selcal.getCode());
}
bool CSelcalCodeSelector::hasValidCode() const
@@ -67,4 +83,11 @@ namespace BlackGui
if (s.length() != 4) return false;
return BlackMisc::Aviation::CSelcal::isValidCode(s);
}
void CSelcalCodeSelector::clear()
{
if (this->ui->cb_SelcalPairs1->count() < 1) { this->resetSelcalCodes(true); }
this->ui->cb_SelcalPairs1->setCurrentIndex(0);
this->ui->cb_SelcalPairs2->setCurrentIndex(0);
}
}

View File

@@ -12,7 +12,9 @@
#ifndef BLACKGUI_SELCALCODESELECTOR_H
#define BLACKGUI_SELCALCODESELECTOR_H
#include "blackmisc/avselcal.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CSelcalCodeSelector; }
namespace BlackGui
@@ -33,21 +35,30 @@ namespace BlackGui
//! SELCAL code
QString getSelcalCode() const;
//! SELCAL
BlackMisc::Aviation::CSelcal getSelcal() const;
//! Reset the SELCAL code
void resetSelcalCodes(bool allowEmptyValue = false);
//! Set the SELCAL code
void setSelcalCode(const QString &selcal);
//! Set the SELCAL code
void setSelcalCode(const BlackMisc::Aviation::CSelcal &selcal);
//! Valid code?
bool hasValidCode() const;
//! Clear
void clear();
signals:
//! Value has been changed
void valueChanged();
private:
Ui::CSelcalCodeSelector *ui;
QScopedPointer<Ui::CSelcalCodeSelector> ui;
};
}