mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 13:35:34 +08:00
committed by
Mathew Sutcliffe
parent
fe1a570c39
commit
4747b3b484
114
src/blackmisc/avcallsign.cpp
Normal file
114
src/blackmisc/avcallsign.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "avcallsign.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CCallsign::convertToQString(bool /** i18n **/) const
|
||||
{
|
||||
return this->m_callsign;
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
void CCallsign::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << this->m_callsignAsSet;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmarshall from DBus
|
||||
*/
|
||||
void CCallsign::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> this->m_callsignAsSet;
|
||||
this->m_callsign = CCallsign::unifyCallsign(this->m_callsignAsSet);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unify the callsign
|
||||
*/
|
||||
QString CCallsign::unifyCallsign(const QString &callsign)
|
||||
{
|
||||
QString unified = callsign.toUpper();
|
||||
unified = unified.remove(QRegExp("[^a-zA-Z\\d\\s]"));
|
||||
return unified;
|
||||
}
|
||||
|
||||
/*
|
||||
* Equals callsign?
|
||||
*/
|
||||
bool CCallsign::equalsString(const QString &callsignString) const
|
||||
{
|
||||
if (callsignString.isEmpty()) return false;
|
||||
if (this->isEmpty()) return false;
|
||||
if (callsignString == this->m_callsign || callsignString == this->m_callsignAsSet) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal?
|
||||
*/
|
||||
bool CCallsign::operator ==(const CCallsign &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return other.asString() == this->asString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Unequal?
|
||||
*/
|
||||
bool CCallsign::operator !=(const CCallsign &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Less than?
|
||||
*/
|
||||
bool CCallsign::operator <(const CCallsign &other) const
|
||||
{
|
||||
return this->m_callsign < other.m_callsign;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CCallsign::getValueHash() const
|
||||
{
|
||||
return qHash(this->m_callsign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CCallsign::compare(const QVariant &qv) const
|
||||
{
|
||||
Q_ASSERT(qv.canConvert<CCallsign>());
|
||||
Q_ASSERT(!qv.isNull() && qv.isValid());
|
||||
return this->compare(qv.value<CCallsign>());
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CCallsign::compare(const CCallsign &callsign) const
|
||||
{
|
||||
return this->m_callsign.compare(callsign.asString(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CCallsign::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CCallsign>();
|
||||
qDBusRegisterMetaType<CCallsign>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user