refs #195, refs #212, SELCAL code selector as own component, as now used with flight plan and cockpit

This commit is contained in:
Klaus Basan
2014-04-26 16:07:03 +02:00
parent 4149b0a19d
commit c7ae163002
3 changed files with 154 additions and 0 deletions

View 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);
}
}

View File

@@ -0,0 +1,45 @@
#ifndef BLACKGUI_SELCALCODESELECTOR_H
#define BLACKGUI_SELCALCODESELECTOR_H
#include <QFrame>
namespace Ui { class CSelcalCodeSelector; }
namespace BlackGui
{
/*!
* \brief SELCAL mode selector
*/
class CSelcalCodeSelector : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CSelcalCodeSelector(QWidget *parent = nullptr);
//! Destructor
~CSelcalCodeSelector();
//! SELCAL code
QString getSelcalCode() const;
//! Reset the SELCAL code
void resetSelcalCodes(bool allowEmptyValue = false);
//! Set the SELCAL code
void setSelcalCode(const QString &selcal);
//! Valid code?
bool hasValidCode() const;
signals:
//! Value has been changed
void valueChanged();
private:
Ui::CSelcalCodeSelector *ui;
};
}
#endif // guard

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSelcalCodeSelector</class>
<widget class="QFrame" name="CSelcalCodeSelector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>143</width>
<height>22</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="hl_SelcalCodeSelector">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="cb_SelcalPairs1"/>
</item>
<item>
<widget class="QComboBox" name="cb_SelcalPairs2"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>