mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
refs #195, refs #212, SELCAL code selector as own component, as now used with flight plan and cockpit
This commit is contained in:
61
src/blackgui/selcalcodeselector.cpp
Normal file
61
src/blackgui/selcalcodeselector.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "selcalcodeselector.h"
|
||||
#include "ui_selcalcodeselector.h"
|
||||
#include "blackmisc/avselcal.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
CSelcalCodeSelector::CSelcalCodeSelector(QWidget *parent) :
|
||||
QFrame(parent), ui(new Ui::CSelcalCodeSelector)
|
||||
{
|
||||
this->ui->setupUi(this);
|
||||
this->resetSelcalCodes(false);
|
||||
|
||||
bool c;
|
||||
c = connect(this->ui->cb_SelcalPairs1, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valueChanged()));
|
||||
Q_ASSERT(c);
|
||||
c = connect(this->ui->cb_SelcalPairs2, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valueChanged()));
|
||||
Q_ASSERT(c);
|
||||
}
|
||||
|
||||
CSelcalCodeSelector::~CSelcalCodeSelector()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString CSelcalCodeSelector::getSelcalCode() const
|
||||
{
|
||||
QString selcal = this->ui->cb_SelcalPairs1->currentText();
|
||||
selcal.append(this->ui->cb_SelcalPairs2->currentText());
|
||||
return selcal;
|
||||
}
|
||||
|
||||
void CSelcalCodeSelector::resetSelcalCodes(bool allowEmptyValue)
|
||||
{
|
||||
this->ui->cb_SelcalPairs1->clear();
|
||||
if (allowEmptyValue) this->ui->cb_SelcalPairs1->addItem(" ");
|
||||
this->ui->cb_SelcalPairs1->addItems(BlackMisc::Aviation::CSelcal::codePairs());
|
||||
this->ui->cb_SelcalPairs2->clear();
|
||||
if (allowEmptyValue) this->ui->cb_SelcalPairs2->addItem(" ");
|
||||
this->ui->cb_SelcalPairs2->addItems(BlackMisc::Aviation::CSelcal::codePairs());
|
||||
}
|
||||
|
||||
void CSelcalCodeSelector::setSelcalCode(const QString &selcal)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
bool CSelcalCodeSelector::hasValidCode() const
|
||||
{
|
||||
QString s = this->getSelcalCode();
|
||||
if (s.length() != 4) return false;
|
||||
return BlackMisc::Aviation::CSelcal::isValidCode(s);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user