mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T345, improved handling of info message in CAtcStation
This commit is contained in:
@@ -236,6 +236,13 @@ namespace BlackMisc
|
||||
return (this->getRelativeDistance() <= m_range);
|
||||
}
|
||||
|
||||
bool CAtcStation::setOnline(bool online)
|
||||
{
|
||||
if (online == m_isOnline) { return false; }
|
||||
m_isOnline = online;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAtcStation::hasValidBookingTimes() const
|
||||
{
|
||||
return !m_bookedFromUtc.isNull() && m_bookedFromUtc.isValid() &&
|
||||
@@ -286,6 +293,28 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
const CInformationMessage &CAtcStation::getInformationMessage(CInformationMessage::InformationType type) const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CInformationMessage::ATIS: return this->getAtis();
|
||||
case CInformationMessage::METAR: return this->getMetar();
|
||||
default: break;
|
||||
}
|
||||
return CInformationMessage::unspecified();
|
||||
}
|
||||
|
||||
bool CAtcStation::setMessage(const CInformationMessage &message)
|
||||
{
|
||||
switch (message.getType())
|
||||
{
|
||||
case CInformationMessage::ATIS: this->setAtis(message); return true;
|
||||
case CInformationMessage::METAR: this->setMetar(message); return true;
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
CLatitude CAtcStation::latitude() const
|
||||
{
|
||||
return this->getPosition().latitude();
|
||||
@@ -311,7 +340,7 @@ namespace BlackMisc
|
||||
return m_position.normalVectorDouble();
|
||||
}
|
||||
|
||||
CVariant CAtcStation::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
CVariant CAtcStation::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
@@ -344,39 +373,17 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexBookedFrom:
|
||||
this->setBookedFromUtc(variant.value<QDateTime>());
|
||||
break;
|
||||
case IndexBookedUntil:
|
||||
this->setBookedUntilUtc(variant.value<QDateTime>());
|
||||
break;
|
||||
case IndexCallsign:
|
||||
m_callsign.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexController:
|
||||
m_controller.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexFrequency:
|
||||
m_frequency.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexIsOnline:
|
||||
this->setOnline(variant.value<bool>());
|
||||
break;
|
||||
case IndexPosition:
|
||||
m_position.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexRange:
|
||||
m_range.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexAtis:
|
||||
m_atis.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexMetar:
|
||||
m_metar.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexVoiceRoom:
|
||||
m_voiceRoom.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexBookedFrom: this->setBookedFromUtc(variant.value<QDateTime>()); break;
|
||||
case IndexBookedUntil: this->setBookedUntilUtc(variant.value<QDateTime>()); break;
|
||||
case IndexCallsign: m_callsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexController: m_controller.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexFrequency: m_frequency.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexIsOnline: this->setOnline(variant.value<bool>()); break;
|
||||
case IndexPosition: m_position.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexRange: m_range.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexAtis: m_atis.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexMetar: m_metar.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexVoiceRoom: m_voiceRoom.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
default:
|
||||
if (ICoordinateWithRelativePosition::canHandleIndex(index))
|
||||
{
|
||||
@@ -392,7 +399,7 @@ namespace BlackMisc
|
||||
|
||||
int CAtcStation::comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const
|
||||
{
|
||||
if (index.isMyself()) { return this->getCallsign().comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getCallsign()); }
|
||||
if (index.isMyself()) { return this->getCallsign().comparePropertyByIndex(CPropertyIndex::empty(), compareValue.getCallsign()); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -407,8 +414,8 @@ namespace BlackMisc
|
||||
case IndexPosition: return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition());
|
||||
case IndexRange: return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange());
|
||||
case IndexIsInRange: return Compare::compare(this->isInRange(), compareValue.isInRange());
|
||||
case IndexAtis: return m_atis.getMessage().compare(compareValue.getAtis().getMessage());
|
||||
case IndexMetar: return m_metar.getMessage().compare(compareValue.getMetar().getMessage());
|
||||
case IndexAtis: return m_atis.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getAtis());
|
||||
case IndexMetar: return m_metar.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getMetar());
|
||||
case IndexVoiceRoom: return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl());
|
||||
default:
|
||||
if (ICoordinateWithRelativePosition::canHandleIndex(index))
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace BlackMisc
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexCallsign = BlackMisc::CPropertyIndex::GlobalIndexCAtcStation,
|
||||
IndexCallsign = CPropertyIndex::GlobalIndexCAtcStation,
|
||||
IndexController,
|
||||
IndexFrequency,
|
||||
IndexPosition,
|
||||
@@ -159,7 +159,7 @@ namespace BlackMisc
|
||||
bool isOnline() const { return m_isOnline; }
|
||||
|
||||
//! Set online
|
||||
void setOnline(bool online) { m_isOnline = online; }
|
||||
bool setOnline(bool online);
|
||||
|
||||
//! Get voice room
|
||||
const Audio::CVoiceRoom &getVoiceRoom() const { return m_voiceRoom; }
|
||||
@@ -214,12 +214,18 @@ namespace BlackMisc
|
||||
//! Get METAR
|
||||
const CInformationMessage &getMetar() const { return m_metar; }
|
||||
|
||||
//! Message per type
|
||||
const CInformationMessage &getInformationMessage(CInformationMessage::InformationType type) const;
|
||||
|
||||
//! Set METAR
|
||||
void setMetar(const CInformationMessage &metar) { m_metar = metar;}
|
||||
|
||||
//! Set METAR Message
|
||||
void setMetarMessage(const QString &metar) { m_metar.setMessage(metar); }
|
||||
|
||||
//! Set given message
|
||||
bool setMessage(const CInformationMessage &message);
|
||||
|
||||
//! Set booked until
|
||||
void setBookedUntilUtc(const QDateTime &until) { m_bookedUntilUtc = until; }
|
||||
|
||||
@@ -244,7 +250,7 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! Compare by index
|
||||
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
|
||||
int comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
|
||||
@@ -40,6 +40,41 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
int CAtcStationList::updateIfMessageChanged(const CInformationMessage &im, bool overrideWithNewer)
|
||||
{
|
||||
int c = 0;
|
||||
const CInformationMessage::InformationType t = im.getType();
|
||||
for (CAtcStation &station : *this)
|
||||
{
|
||||
bool unequal = false;
|
||||
const CInformationMessage m = station.getInformationMessage(t);
|
||||
if (m.getType() == CInformationMessage::Unspecified) { continue; }
|
||||
if (m.getMessage() == im.getMessage())
|
||||
{
|
||||
if (!overrideWithNewer) { continue; }
|
||||
if (!im.isNewerThan(m)) { continue; }
|
||||
}
|
||||
else
|
||||
{
|
||||
unequal = true;
|
||||
}
|
||||
station.setMessage(m);
|
||||
if (unequal) c++; // only count unequals
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CAtcStationList::setOnline(const CCallsign &callsign, bool online)
|
||||
{
|
||||
int c = 0;
|
||||
for (CAtcStation &station : *this)
|
||||
{
|
||||
if (station.getCallsign() != callsign) { continue; }
|
||||
if (station.setOnline(online)) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
CAtcStationList CAtcStationList::stationsWithValidVoiceRoom() const
|
||||
{
|
||||
return this->findBy(&CAtcStation::hasValidVoiceRoom, true);
|
||||
|
||||
@@ -46,7 +46,13 @@ namespace BlackMisc
|
||||
CAtcStationList(const CSequence<CAtcStation> &other);
|
||||
|
||||
//! Find 0..n stations tune in frequency of COM unit (with 25kHt channel spacing
|
||||
CAtcStationList findIfComUnitTunedIn25KHz(const BlackMisc::Aviation::CComSystem &comUnit) const;
|
||||
CAtcStationList findIfComUnitTunedIn25KHz(const CComSystem &comUnit) const;
|
||||
|
||||
//! Update if message changed
|
||||
int updateIfMessageChanged(const CInformationMessage &im, bool overrideWithNewer);
|
||||
|
||||
//! Set online status
|
||||
int setOnline(const CCallsign &callsign, bool online);
|
||||
|
||||
//! Find 0..n stations with valid voice room
|
||||
//! \sa CAtcStation::hasValidVoiceRoom
|
||||
|
||||
Reference in New Issue
Block a user