diff --git a/src/blackcore/context_ownaircraft.h b/src/blackcore/context_ownaircraft.h index 36d34db26..6a14fade0 100644 --- a/src/blackcore/context_ownaircraft.h +++ b/src/blackcore/context_ownaircraft.h @@ -16,6 +16,7 @@ #include "blackmisc/avaircraft.h" #include "blackmisc/avatcstation.h" #include "blackmisc/voiceroomlist.h" +#include "blackmisc/avselcal.h" //! \addtogroup dbus //! @{ @@ -79,6 +80,10 @@ namespace BlackCore //! \remarks DBus and local void changedAircraftCockpit(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator); + //! Changed SELCAL code + //! \remarks DBus and local + void changedSelcal(const BlackMisc::Aviation::CSelcal &selcal, const QString &originator); + public slots: //! Get own aircraft @@ -99,6 +104,9 @@ namespace BlackCore //! Set current pilot virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) = 0; + //! Own SELCAL code + virtual bool updateSelcal(const BlackMisc::Aviation::CSelcal &selcal, const QString &originator) = 0; + //! Output volumes, volumes 0..100 virtual void setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) = 0; diff --git a/src/blackcore/context_ownaircraft_impl.cpp b/src/blackcore/context_ownaircraft_impl.cpp index f12775935..e2dce5400 100644 --- a/src/blackcore/context_ownaircraft_impl.cpp +++ b/src/blackcore/context_ownaircraft_impl.cpp @@ -176,12 +176,20 @@ namespace BlackCore bool CContextOwnAircraft::updatePilot(const CUser &pilot, const QString &originator) { - if (this->m_ownAircraft.getPilot() == pilot) return false; + if (this->m_ownAircraft.getPilot() == pilot) { return false; } this->m_ownAircraft.setPilot(pilot); emit this->changedAircraft(this->m_ownAircraft, originator); return true; } + bool CContextOwnAircraft::updateSelcal(const CSelcal &selcal, const QString &originator) + { + if (this->m_ownAircraft.getSelcal() == selcal) { return false; } + this->m_ownAircraft.setSelcal(selcal); + emit this->changedSelcal(selcal, originator); + return true; + } + void CContextOwnAircraft::setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << outputVolumeCom1 << outputVolumeCom2; diff --git a/src/blackcore/context_ownaircraft_impl.h b/src/blackcore/context_ownaircraft_impl.h index 65fa3fd1b..505036c2b 100644 --- a/src/blackcore/context_ownaircraft_impl.h +++ b/src/blackcore/context_ownaircraft_impl.h @@ -58,6 +58,9 @@ namespace BlackCore //! \copydoc IContextOwnAircraft::updatePilot() virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override; + //! \copydoc IContextOwnAircraft::updateSelcal + virtual bool updateSelcal(const Aviation::CSelcal &selcal, const QString &originator) override; + //! \copydoc IContextOwnAircraft::setAudioOutputVolumes virtual void setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) override; diff --git a/src/blackcore/context_ownaircraft_proxy.cpp b/src/blackcore/context_ownaircraft_proxy.cpp index 241ae3754..12965108e 100644 --- a/src/blackcore/context_ownaircraft_proxy.cpp +++ b/src/blackcore/context_ownaircraft_proxy.cpp @@ -30,6 +30,9 @@ namespace BlackCore bool s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), "changedAircraftCockpit", this, SIGNAL(changedAircraftCockpit(BlackMisc::Aviation::CAircraft, QString))); Q_ASSERT(s); + s = connection.connect(serviceName, IContextOwnAircraft::ObjectPath(), IContextOwnAircraft::InterfaceName(), + "changedSelcal", this, SIGNAL(changedSelcal(BlackMisc::Aviation::CSelcal, QString))); + Q_ASSERT(s); Q_UNUSED(s); } @@ -63,6 +66,11 @@ namespace BlackCore return this->m_dBusInterface->callDBusRet(QLatin1Literal("updatePilot"), pilot, originator); } + bool CContextOwnAircraftProxy::updateSelcal(const Aviation::CSelcal &selcal, const QString &originator) + { + return this->m_dBusInterface->callDBusRet(QLatin1Literal("updateSelcal"), selcal, originator); + } + void CContextOwnAircraftProxy::setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) { this->m_dBusInterface->callDBus(QLatin1Literal("updateOwnCockpitOutputVolumes"), outputVolumeCom1, outputVolumeCom2); diff --git a/src/blackcore/context_ownaircraft_proxy.h b/src/blackcore/context_ownaircraft_proxy.h index e40c6e127..939563a42 100644 --- a/src/blackcore/context_ownaircraft_proxy.h +++ b/src/blackcore/context_ownaircraft_proxy.h @@ -64,6 +64,9 @@ namespace BlackCore //! \copydoc IContextOwnAircraft::updatePilot() virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override; + //! \copydoc IContextOwnAircraft::updateSelcal + virtual bool updateSelcal(const Aviation::CSelcal &selcal, const QString &originator) override; + //! \copydoc IContextOwnAircraft::setAudioOutputVolumes virtual void setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) override; diff --git a/src/blackgui/components/cockpitcomcomponent.cpp b/src/blackgui/components/cockpitcomcomponent.cpp index bfa3234a4..854ebb91d 100644 --- a/src/blackgui/components/cockpitcomcomponent.cpp +++ b/src/blackgui/components/cockpitcomcomponent.cpp @@ -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() diff --git a/src/blackgui/components/cockpitcomcomponent.h b/src/blackgui/components/cockpitcomcomponent.h index b6b5a2efe..fdd0f0c69 100644 --- a/src/blackgui/components/cockpitcomcomponent.h +++ b/src/blackgui/components/cockpitcomcomponent.h @@ -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); diff --git a/src/blackgui/components/cockpitcomcomponent.ui b/src/blackgui/components/cockpitcomcomponent.ui index fe3e8828b..b8135ff79 100644 --- a/src/blackgui/components/cockpitcomcomponent.ui +++ b/src/blackgui/components/cockpitcomcomponent.ui @@ -71,7 +71,7 @@ 0 - + 0 @@ -100,26 +100,6 @@ 0 - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - @@ -648,6 +628,12 @@ QSpinBox
blackgui/transpondercodespinbox.h
+ + BlackGui::CSelcalCodeSelector + QFrame +
blackgui/selcalcodeselector.h
+ 1 +
diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index b0e1c181f..9018c1af2 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -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 diff --git a/src/blackgui/components/flightplancomponent.h b/src/blackgui/components/flightplancomponent.h index 3ba4d2014..d56893e76 100644 --- a/src/blackgui/components/flightplancomponent.h +++ b/src/blackgui/components/flightplancomponent.h @@ -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(); diff --git a/src/blackgui/selcalcodeselector.cpp b/src/blackgui/selcalcodeselector.cpp index d454b4cfd..b90f87219 100644 --- a/src/blackgui/selcalcodeselector.cpp +++ b/src/blackgui/selcalcodeselector.cpp @@ -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); + } } diff --git a/src/blackgui/selcalcodeselector.h b/src/blackgui/selcalcodeselector.h index b8e106f6d..4dcecd25e 100644 --- a/src/blackgui/selcalcodeselector.h +++ b/src/blackgui/selcalcodeselector.h @@ -12,7 +12,9 @@ #ifndef BLACKGUI_SELCALCODESELECTOR_H #define BLACKGUI_SELCALCODESELECTOR_H +#include "blackmisc/avselcal.h" #include +#include 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; }; } diff --git a/src/blackmisc/avaircraft.h b/src/blackmisc/avaircraft.h index 6eb3037df..0f38c934e 100644 --- a/src/blackmisc/avaircraft.h +++ b/src/blackmisc/avaircraft.h @@ -16,6 +16,7 @@ #include "avaircraftsituation.h" #include "avaircrafticao.h" #include "avcallsign.h" +#include "avselcal.h" #include "aviotransponder.h" #include "aviocomsystem.h" #include "valueobject.h" @@ -149,10 +150,10 @@ namespace BlackMisc const BlackMisc::PhysicalQuantities::CAngle &getBank() const { return this->m_situation.getBank(); } //! Get COM1 system - const BlackMisc::Aviation::CComSystem &getCom1System() const { return this->m_com1system; } + const CComSystem &getCom1System() const { return this->m_com1system; } //! Get COM2 system - const BlackMisc::Aviation::CComSystem &getCom2System() const { return this->m_com2system; } + const CComSystem &getCom2System() const { return this->m_com2system; } //! Set COM1 system void setCom1System(const CComSystem &comSystem) { this->m_com1system = comSystem; } @@ -160,12 +161,24 @@ namespace BlackMisc //! Set COM2 system void setCom2System(const CComSystem &comSystem) { this->m_com2system = comSystem; } + //! Given SELCAL selected? + bool isSelcalSelected(const BlackMisc::Aviation::CSelcal &selcal) const { return this->m_selcal == selcal; } + + //! Valid SELCAL? + bool hasValidSelcal() const { return this->m_selcal.isValid(); } + + //! SELCAL + const CSelcal getSelcal() const { return m_selcal; } + //! Cockpit data void setCockpit(const CComSystem &com1, const CComSystem &com2, const CTransponder &transponder); //! Cockpit data void setCockpit(const CComSystem &com1, const CComSystem &com2, qint32 transponderCode); + //! Own SELCAL code + void setSelcal(const BlackMisc::Aviation::CSelcal &selcal) { this->m_selcal = selcal; } + //! Changed cockpit data? bool hasChangedCockpitData(const CComSystem &com1, const CComSystem &com2, const CTransponder &transponder) const; @@ -228,6 +241,7 @@ namespace BlackMisc BlackMisc::Aviation::CComSystem m_com1system; BlackMisc::Aviation::CComSystem m_com2system; BlackMisc::Aviation::CTransponder m_transponder; + BlackMisc::Aviation::CSelcal m_selcal; CAircraftIcao m_icao; BlackMisc::PhysicalQuantities::CLength m_distanceToPlane; }; diff --git a/src/blackmisc/avselcal.cpp b/src/blackmisc/avselcal.cpp index 2306cfca6..e2a48833e 100644 --- a/src/blackmisc/avselcal.cpp +++ b/src/blackmisc/avselcal.cpp @@ -63,7 +63,7 @@ namespace BlackMisc */ bool CSelcal::isValidCharacter(QChar c) { - return CSelcal::validCharacters().contains(c); + return CSelcal::validCharacters().contains(c.toUpper()); } /* @@ -73,10 +73,11 @@ namespace BlackMisc { if (code.length() != 4) return false; int p1, p2, p3, p4; - if ((p1 = CSelcal::validCharacters().indexOf(code.at(0))) < 0) return false; - if ((p2 = CSelcal::validCharacters().indexOf(code.at(1))) < 0) return false; - if ((p3 = CSelcal::validCharacters().indexOf(code.at(2))) < 0) return false; - if ((p4 = CSelcal::validCharacters().indexOf(code.at(3))) < 0) return false; + QString codeUpper = code.toUpper(); + if ((p1 = CSelcal::validCharacters().indexOf(codeUpper.at(0))) < 0) return false; + if ((p2 = CSelcal::validCharacters().indexOf(codeUpper.at(1))) < 0) return false; + if ((p3 = CSelcal::validCharacters().indexOf(codeUpper.at(2))) < 0) return false; + if ((p4 = CSelcal::validCharacters().indexOf(codeUpper.at(3))) < 0) return false; if (p1 >= p2 || p3 >= p4) return false; // pair in alphabetical order if (p1 == p3 || p2 == p3 || p2 == p4 || p3 == p4) return false; // given letter can be used only once in a SELCAL code return true; diff --git a/src/blackmisc/avselcal.h b/src/blackmisc/avselcal.h index 315481764..111f53589 100644 --- a/src/blackmisc/avselcal.h +++ b/src/blackmisc/avselcal.h @@ -31,13 +31,13 @@ namespace BlackMisc CSelcal() = default; //! Constructor. - CSelcal(const QString &code) : m_code(code.trimmed()) {} + CSelcal(const QString &code) : m_code(code.trimmed().toUpper()) {} /*! * Constructor. * Needed to disambiguate implicit conversion from string literal. */ - CSelcal(const char *code) : m_code(code) {} + CSelcal(const char *code) : m_code(QString(code).trimmed().toUpper()) {} //! Is valid? bool isValid() const { return isValidCode(this->m_code); } diff --git a/src/blackmisc/nwtextmessage.cpp b/src/blackmisc/nwtextmessage.cpp index 16ba1e724..0d271c66c 100644 --- a/src/blackmisc/nwtextmessage.cpp +++ b/src/blackmisc/nwtextmessage.cpp @@ -186,7 +186,7 @@ namespace BlackMisc QString candidate = this->m_message.toUpper().remove(QRegExp("[^A-Z]")); // SELCALABCD if (candidate.length() != 10) return invalid; if (!candidate.startsWith("SELCAL")) return invalid; - return candidate.right(4); + return candidate.right(4).toUpper(); } } // namespace