Ref T345, improved handling of info message in CAtcStation

This commit is contained in:
Klaus Basan
2018-09-09 23:28:55 +02:00
parent 62601bde9d
commit ad37e67a6b
4 changed files with 95 additions and 41 deletions

View File

@@ -236,6 +236,13 @@ namespace BlackMisc
return (this->getRelativeDistance() <= m_range); 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 bool CAtcStation::hasValidBookingTimes() const
{ {
return !m_bookedFromUtc.isNull() && m_bookedFromUtc.isValid() && 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 CLatitude CAtcStation::latitude() const
{ {
return this->getPosition().latitude(); return this->getPosition().latitude();
@@ -311,7 +340,7 @@ namespace BlackMisc
return m_position.normalVectorDouble(); 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); } if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
@@ -344,39 +373,17 @@ namespace BlackMisc
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexBookedFrom: case IndexBookedFrom: this->setBookedFromUtc(variant.value<QDateTime>()); break;
this->setBookedFromUtc(variant.value<QDateTime>()); case IndexBookedUntil: this->setBookedUntilUtc(variant.value<QDateTime>()); break;
break; case IndexCallsign: m_callsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
case IndexBookedUntil: case IndexController: m_controller.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
this->setBookedUntilUtc(variant.value<QDateTime>()); case IndexFrequency: m_frequency.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
break; case IndexIsOnline: this->setOnline(variant.value<bool>()); break;
case IndexCallsign: case IndexPosition: m_position.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
m_callsign.setPropertyByIndex(index.copyFrontRemoved(), variant); case IndexRange: m_range.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
break; case IndexAtis: m_atis.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
case IndexController: case IndexMetar: m_metar.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
m_controller.setPropertyByIndex(index.copyFrontRemoved(), variant); case IndexVoiceRoom: m_voiceRoom.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
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: default:
if (ICoordinateWithRelativePosition::canHandleIndex(index)) if (ICoordinateWithRelativePosition::canHandleIndex(index))
{ {
@@ -392,7 +399,7 @@ namespace BlackMisc
int CAtcStation::comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const 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>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
@@ -407,8 +414,8 @@ namespace BlackMisc
case IndexPosition: return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition()); case IndexPosition: return m_position.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getPosition());
case IndexRange: return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange()); case IndexRange: return m_range.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getRange());
case IndexIsInRange: return Compare::compare(this->isInRange(), compareValue.isInRange()); case IndexIsInRange: return Compare::compare(this->isInRange(), compareValue.isInRange());
case IndexAtis: return m_atis.getMessage().compare(compareValue.getAtis().getMessage()); case IndexAtis: return m_atis.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getAtis());
case IndexMetar: return m_metar.getMessage().compare(compareValue.getMetar().getMessage()); case IndexMetar: return m_metar.comparePropertyByIndex(index.copyFrontRemoved(), compareValue.getMetar());
case IndexVoiceRoom: return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl()); case IndexVoiceRoom: return this->getVoiceRoom().getVoiceRoomUrl().compare(compareValue.getVoiceRoom().getVoiceRoomUrl());
default: default:
if (ICoordinateWithRelativePosition::canHandleIndex(index)) if (ICoordinateWithRelativePosition::canHandleIndex(index))

View File

@@ -48,7 +48,7 @@ namespace BlackMisc
//! Properties by index //! Properties by index
enum ColumnIndex enum ColumnIndex
{ {
IndexCallsign = BlackMisc::CPropertyIndex::GlobalIndexCAtcStation, IndexCallsign = CPropertyIndex::GlobalIndexCAtcStation,
IndexController, IndexController,
IndexFrequency, IndexFrequency,
IndexPosition, IndexPosition,
@@ -159,7 +159,7 @@ namespace BlackMisc
bool isOnline() const { return m_isOnline; } bool isOnline() const { return m_isOnline; }
//! Set online //! Set online
void setOnline(bool online) { m_isOnline = online; } bool setOnline(bool online);
//! Get voice room //! Get voice room
const Audio::CVoiceRoom &getVoiceRoom() const { return m_voiceRoom; } const Audio::CVoiceRoom &getVoiceRoom() const { return m_voiceRoom; }
@@ -214,12 +214,18 @@ namespace BlackMisc
//! Get METAR //! Get METAR
const CInformationMessage &getMetar() const { return m_metar; } const CInformationMessage &getMetar() const { return m_metar; }
//! Message per type
const CInformationMessage &getInformationMessage(CInformationMessage::InformationType type) const;
//! Set METAR //! Set METAR
void setMetar(const CInformationMessage &metar) { m_metar = metar;} void setMetar(const CInformationMessage &metar) { m_metar = metar;}
//! Set METAR Message //! Set METAR Message
void setMetarMessage(const QString &metar) { m_metar.setMessage(metar); } void setMetarMessage(const QString &metar) { m_metar.setMessage(metar); }
//! Set given message
bool setMessage(const CInformationMessage &message);
//! Set booked until //! Set booked until
void setBookedUntilUtc(const QDateTime &until) { m_bookedUntilUtc = until; } void setBookedUntilUtc(const QDateTime &until) { m_bookedUntilUtc = until; }
@@ -244,7 +250,7 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant); 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; int comparePropertyByIndex(const CPropertyIndex &index, const CAtcStation &compareValue) const;
//! \copydoc BlackMisc::Mixin::String::toQString //! \copydoc BlackMisc::Mixin::String::toQString

View File

@@ -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 CAtcStationList CAtcStationList::stationsWithValidVoiceRoom() const
{ {
return this->findBy(&CAtcStation::hasValidVoiceRoom, true); return this->findBy(&CAtcStation::hasValidVoiceRoom, true);

View File

@@ -46,7 +46,13 @@ namespace BlackMisc
CAtcStationList(const CSequence<CAtcStation> &other); CAtcStationList(const CSequence<CAtcStation> &other);
//! Find 0..n stations tune in frequency of COM unit (with 25kHt channel spacing //! 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 //! Find 0..n stations with valid voice room
//! \sa CAtcStation::hasValidVoiceRoom //! \sa CAtcStation::hasValidVoiceRoom