mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Ref T190, text message formatting
This commit is contained in:
@@ -28,27 +28,27 @@ namespace BlackMisc
|
||||
|
||||
QString CTextMessage::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s(this->m_message);
|
||||
QString s(m_message);
|
||||
if (this->isPrivateMessage())
|
||||
{
|
||||
s.append(" ").append(this->m_senderCallsign.toQString(i18n));
|
||||
s.append(" ").append(this->m_recipientCallsign.toQString(i18n));
|
||||
s.append(" ").append(m_senderCallsign.toQString(i18n));
|
||||
s.append(" ").append(m_recipientCallsign.toQString(i18n));
|
||||
}
|
||||
else
|
||||
{
|
||||
s.append(" ").append(this->m_frequency.toQString(i18n));
|
||||
s.append(" ").append(m_frequency.toQString(i18n));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
bool CTextMessage::isPrivateMessage() const
|
||||
{
|
||||
return !this->m_senderCallsign.isEmpty() && !this->m_recipientCallsign.isEmpty();
|
||||
return !m_senderCallsign.isEmpty() && !m_recipientCallsign.isEmpty();
|
||||
}
|
||||
|
||||
bool CTextMessage::isSupervisorMessage() const
|
||||
{
|
||||
return this->m_senderCallsign.isSupervisorCallsign();
|
||||
return m_senderCallsign.isSupervisorCallsign();
|
||||
}
|
||||
|
||||
bool CTextMessage::wasSent() const
|
||||
@@ -67,15 +67,15 @@ namespace BlackMisc
|
||||
|
||||
QString CTextMessage::getRecipientCallsignOrFrequency() const
|
||||
{
|
||||
if (!this->m_recipientCallsign.isEmpty()) { return m_recipientCallsign.asString(); }
|
||||
if (this->m_frequency.isNull()) { return ""; }
|
||||
return this->m_frequency.valueRoundedWithUnit(CFrequencyUnit::MHz(), 3);
|
||||
if (!m_recipientCallsign.isEmpty()) { return m_recipientCallsign.asString(); }
|
||||
if (m_frequency.isNull()) { return ""; }
|
||||
return m_frequency.valueRoundedWithUnit(CFrequencyUnit::MHz(), 3);
|
||||
}
|
||||
|
||||
bool CTextMessage::isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const
|
||||
{
|
||||
if (!this->isRadioMessage()) { return false; }
|
||||
return this->m_frequency == frequency;
|
||||
return m_frequency == frequency;
|
||||
}
|
||||
|
||||
bool CTextMessage::isSendToUnicom() const
|
||||
@@ -85,19 +85,19 @@ namespace BlackMisc
|
||||
|
||||
bool CTextMessage::hasValidRecipient() const
|
||||
{
|
||||
if (!this->m_recipientCallsign.isEmpty()) return true;
|
||||
return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency);
|
||||
if (!m_recipientCallsign.isEmpty()) return true;
|
||||
return CComSystem::isValidCivilAviationFrequency(m_frequency);
|
||||
}
|
||||
|
||||
bool CTextMessage::isRadioMessage() const
|
||||
{
|
||||
return (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency));
|
||||
return (CComSystem::isValidCivilAviationFrequency(m_frequency));
|
||||
}
|
||||
|
||||
bool CTextMessage::isServerMessage() const
|
||||
{
|
||||
if (!this->isPrivateMessage()) return false;
|
||||
CCallsign cs = this->getSenderCallsign();
|
||||
const CCallsign cs = this->getSenderCallsign();
|
||||
return (cs.asString().startsWith("SERVER", Qt::CaseInsensitive));
|
||||
}
|
||||
|
||||
@@ -106,34 +106,34 @@ namespace BlackMisc
|
||||
QString s(this->getFormattedUtcTimestampHms());
|
||||
if (withSender)
|
||||
{
|
||||
if (!this->m_senderCallsign.isEmpty())
|
||||
if (!m_senderCallsign.isEmpty())
|
||||
{
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_senderCallsign.getStringAsSet());
|
||||
s.append(m_senderCallsign.getStringAsSet());
|
||||
}
|
||||
}
|
||||
|
||||
if (withRecipient)
|
||||
{
|
||||
if (!this->m_recipientCallsign.isEmpty())
|
||||
if (!m_recipientCallsign.isEmpty())
|
||||
{
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_recipientCallsign.getStringAsSet());
|
||||
s.append(m_recipientCallsign.getStringAsSet());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency))
|
||||
if (CComSystem::isValidCivilAviationFrequency(m_frequency))
|
||||
{
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_frequency.valueRoundedWithUnit(3, true));
|
||||
s.append(m_frequency.valueRoundedWithUnit(3, true));
|
||||
}
|
||||
|
||||
}
|
||||
} // to
|
||||
|
||||
if (this->m_message.isEmpty()) return s;
|
||||
if (m_message.isEmpty()) return s;
|
||||
if (!s.isEmpty()) s.append(separator);
|
||||
s.append(this->m_message);
|
||||
s.append(m_message);
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace BlackMisc
|
||||
|
||||
void CTextMessage::toggleSenderRecipient()
|
||||
{
|
||||
qSwap(this->m_senderCallsign, this->m_recipientCallsign);
|
||||
qSwap(m_senderCallsign, m_recipientCallsign);
|
||||
}
|
||||
|
||||
bool CTextMessage::isSelcalMessage() const
|
||||
@@ -153,7 +153,7 @@ namespace BlackMisc
|
||||
// some first level checks, before really parsing the message
|
||||
if (this->isEmpty()) return false;
|
||||
if (this->isPrivateMessage()) return false;
|
||||
if (this->m_message.length() > 15 || this->m_message.length() < 10) return false; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
|
||||
if (m_message.length() > 15 || m_message.length() < 10) return false; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
|
||||
return this->getSelcalCode().length() == 4;
|
||||
}
|
||||
|
||||
@@ -172,9 +172,9 @@ namespace BlackMisc
|
||||
|
||||
if (this->isEmpty()) return {};
|
||||
if (this->isPrivateMessage()) return {};
|
||||
if (!this->m_message.startsWith(QLatin1String("SELCAL"), Qt::CaseInsensitive)) return {};
|
||||
if (this->m_message.length() > 15 || this->m_message.length() < 10) return {}; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
|
||||
QString candidate = removeChars(this->m_message, [](QChar c) { return !c.isLetter(); }); // SELCALABCD
|
||||
if (!m_message.startsWith(QLatin1String("SELCAL"), Qt::CaseInsensitive)) return {};
|
||||
if (m_message.length() > 15 || m_message.length() < 10) return {}; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
|
||||
QString candidate = removeChars(m_message, [](QChar c) { return !c.isLetter(); }); // SELCALABCD
|
||||
if (candidate.length() != 10) return {};
|
||||
return std::move(candidate).right(4).toUpper();
|
||||
}
|
||||
@@ -194,19 +194,14 @@ namespace BlackMisc
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSenderCallsign:
|
||||
return this->m_senderCallsign.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexRecipientCallsign:
|
||||
return this->m_recipientCallsign.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexRecipientCallsignOrFrequency:
|
||||
return CVariant::fromValue(this->getRecipientCallsignOrFrequency());
|
||||
case IndexMessage:
|
||||
return CVariant::fromValue(this->m_message);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
case IndexSenderCallsign: return m_senderCallsign.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexRecipientCallsign: return m_recipientCallsign.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexRecipientCallsignOrFrequency: return CVariant::fromValue(this->getRecipientCallsignOrFrequency());
|
||||
case IndexMessage: return CVariant::fromValue(m_message);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,23 +210,14 @@ namespace BlackMisc
|
||||
if (index.isMyself()) { (*this) = variant.to<CTextMessage>(); return; }
|
||||
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSenderCallsign:
|
||||
this->m_senderCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexRecipientCallsign:
|
||||
this->m_recipientCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexMessage:
|
||||
this->m_message = variant.value<QString>();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
case IndexSenderCallsign: m_senderCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexRecipientCallsign: m_recipientCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexMessage: m_message = variant.value<QString>(); break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -37,13 +37,13 @@ namespace BlackMisc
|
||||
*/
|
||||
class BLACKMISC_EXPORT CTextMessage :
|
||||
public CValueObject<CTextMessage>,
|
||||
public BlackMisc::ITimestampBased
|
||||
public ITimestampBased
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexSenderCallsign = BlackMisc::CPropertyIndex::GlobalIndexCTextMessage,
|
||||
IndexSenderCallsign = CPropertyIndex::GlobalIndexCTextMessage,
|
||||
IndexRecipientCallsign,
|
||||
IndexRecipientCallsignOrFrequency,
|
||||
IndexMessage
|
||||
@@ -53,33 +53,33 @@ namespace BlackMisc
|
||||
CTextMessage() {}
|
||||
|
||||
//! Constructor, radio message
|
||||
CTextMessage(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &senderCallsign = BlackMisc::Aviation::CCallsign())
|
||||
CTextMessage(const QString &message, const PhysicalQuantities::CFrequency &frequency, const Aviation::CCallsign &senderCallsign = {})
|
||||
: m_message(message), m_senderCallsign(senderCallsign), m_frequency(frequency)
|
||||
{
|
||||
this->m_frequency.switchUnit(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz());
|
||||
m_frequency.switchUnit(PhysicalQuantities::CFrequencyUnit::MHz());
|
||||
}
|
||||
|
||||
//! Constructor, private message
|
||||
CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign = BlackMisc::Aviation::CCallsign())
|
||||
CTextMessage(const QString &message, const Aviation::CCallsign &senderCallsign, const Aviation::CCallsign &recipientCallsign = {})
|
||||
: m_message(message), m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(0, nullptr) {}
|
||||
|
||||
//! Get callsign (from)
|
||||
const BlackMisc::Aviation::CCallsign &getSenderCallsign() const { return m_senderCallsign; }
|
||||
const Aviation::CCallsign &getSenderCallsign() const { return m_senderCallsign; }
|
||||
|
||||
//! Set callsign (from)
|
||||
void setSenderCallsign(const BlackMisc::Aviation::CCallsign &callsign) { m_senderCallsign = callsign;}
|
||||
void setSenderCallsign(const Aviation::CCallsign &callsign) { m_senderCallsign = callsign;}
|
||||
|
||||
//! Get callsign (to)
|
||||
const BlackMisc::Aviation::CCallsign &getRecipientCallsign() const { return m_recipientCallsign; }
|
||||
const Aviation::CCallsign &getRecipientCallsign() const { return m_recipientCallsign; }
|
||||
|
||||
//! Set callsign (recipient)
|
||||
void setRecipientCallsign(const BlackMisc::Aviation::CCallsign &callsign) { m_recipientCallsign = callsign; }
|
||||
void setRecipientCallsign(const Aviation::CCallsign &callsign) { m_recipientCallsign = callsign; }
|
||||
|
||||
//! Get recipient or frequency
|
||||
QString getRecipientCallsignOrFrequency() const;
|
||||
|
||||
//! Send to particular frequency?
|
||||
bool isSendToFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) const;
|
||||
bool isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const;
|
||||
|
||||
//! Send to UNICOM?
|
||||
bool isSendToUnicom() const;
|
||||
@@ -97,10 +97,10 @@ namespace BlackMisc
|
||||
void setMessage(const QString &message) { m_message = message.trimmed(); }
|
||||
|
||||
//! Get frequency
|
||||
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }
|
||||
const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }
|
||||
|
||||
//! Set frequency
|
||||
void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { m_frequency = frequency; }
|
||||
void setFrequency(const PhysicalQuantities::CFrequency &frequency) { m_frequency = frequency; }
|
||||
|
||||
//! Is private message?
|
||||
bool isPrivateMessage() const;
|
||||
@@ -129,7 +129,7 @@ namespace BlackMisc
|
||||
* \param separator values separated by given value
|
||||
* \return
|
||||
*/
|
||||
BlackMisc::CStatusMessage asStatusMessage(bool withSender, bool withRecipient, const QString &separator = ", ") const;
|
||||
CStatusMessage asStatusMessage(bool withSender, bool withRecipient, const QString &separator = ", ") const;
|
||||
|
||||
//! Toggle sender receiver, can be used to ping my own message
|
||||
void toggleSenderRecipient();
|
||||
@@ -173,9 +173,9 @@ namespace BlackMisc
|
||||
|
||||
private:
|
||||
QString m_message;
|
||||
BlackMisc::Aviation::CCallsign m_senderCallsign;
|
||||
BlackMisc::Aviation::CCallsign m_recipientCallsign;
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequency { 0, nullptr };
|
||||
Aviation::CCallsign m_senderCallsign;
|
||||
Aviation::CCallsign m_recipientCallsign;
|
||||
PhysicalQuantities::CFrequency m_frequency { 0, nullptr };
|
||||
bool m_wasSent = false;
|
||||
|
||||
BLACK_METACLASS(
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace BlackMisc
|
||||
//! Value object encapsulating a list of text messages
|
||||
class BLACKMISC_EXPORT CTextMessageList :
|
||||
public CSequence<CTextMessage>,
|
||||
public BlackMisc::ITimestampObjectList<CTextMessage, CTextMessageList>,
|
||||
public BlackMisc::Mixin::MetaType<CTextMessageList>
|
||||
public ITimestampObjectList<CTextMessage, CTextMessageList>,
|
||||
public Mixin::MetaType<CTextMessageList>
|
||||
{
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CTextMessageList)
|
||||
@@ -44,19 +44,19 @@ namespace BlackMisc
|
||||
CTextMessageList();
|
||||
|
||||
//! Constructor, single private message
|
||||
CTextMessageList(const QString &message, const BlackMisc::Aviation::CCallsign &recipientCallsign);
|
||||
CTextMessageList(const QString &message, const Aviation::CCallsign &recipientCallsign);
|
||||
|
||||
//! Constructor, single private message
|
||||
CTextMessageList(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign);
|
||||
CTextMessageList(const QString &message, const Aviation::CCallsign &senderCallsign, const Aviation::CCallsign &recipientCallsign);
|
||||
|
||||
//! Constructor, single radio message
|
||||
CTextMessageList(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &senderCallsign = BlackMisc::Aviation::CCallsign());
|
||||
CTextMessageList(const QString &message, const PhysicalQuantities::CFrequency &frequency, const Aviation::CCallsign &senderCallsign = Aviation::CCallsign());
|
||||
|
||||
//! Constructor, single message
|
||||
CTextMessageList(const CTextMessage &message);
|
||||
|
||||
//! Constructor, multi-frequency radio messages
|
||||
CTextMessageList(const QString &message, const QList<BlackMisc::PhysicalQuantities::CFrequency> &frequencies, const BlackMisc::Aviation::CCallsign &sender = BlackMisc::Aviation::CCallsign());
|
||||
CTextMessageList(const QString &message, const QList<PhysicalQuantities::CFrequency> &frequencies, const Aviation::CCallsign &sender = Aviation::CCallsign());
|
||||
|
||||
//! Construct from a base class object.
|
||||
CTextMessageList(const CSequence<CTextMessage> &other);
|
||||
@@ -80,7 +80,7 @@ namespace BlackMisc
|
||||
CTextMessageList containsSupervisorMessages() const;
|
||||
|
||||
//! Find by frequency
|
||||
CTextMessageList findByFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) const;
|
||||
CTextMessageList findByFrequency(const PhysicalQuantities::CFrequency &frequency) const;
|
||||
|
||||
//! Toggle all sender receivers
|
||||
void toggleSenderRecipients();
|
||||
|
||||
Reference in New Issue
Block a user