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

@@ -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;
};

View File

@@ -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;

View File

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

View File

@@ -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