Ref T190, text message formatting

This commit is contained in:
Klaus Basan
2017-11-11 23:22:01 +01:00
parent 069bfb921f
commit f55332b1ec
3 changed files with 61 additions and 75 deletions

View File

@@ -28,27 +28,27 @@ namespace BlackMisc
QString CTextMessage::convertToQString(bool i18n) const QString CTextMessage::convertToQString(bool i18n) const
{ {
QString s(this->m_message); QString s(m_message);
if (this->isPrivateMessage()) if (this->isPrivateMessage())
{ {
s.append(" ").append(this->m_senderCallsign.toQString(i18n)); s.append(" ").append(m_senderCallsign.toQString(i18n));
s.append(" ").append(this->m_recipientCallsign.toQString(i18n)); s.append(" ").append(m_recipientCallsign.toQString(i18n));
} }
else else
{ {
s.append(" ").append(this->m_frequency.toQString(i18n)); s.append(" ").append(m_frequency.toQString(i18n));
} }
return s; return s;
} }
bool CTextMessage::isPrivateMessage() const bool CTextMessage::isPrivateMessage() const
{ {
return !this->m_senderCallsign.isEmpty() && !this->m_recipientCallsign.isEmpty(); return !m_senderCallsign.isEmpty() && !m_recipientCallsign.isEmpty();
} }
bool CTextMessage::isSupervisorMessage() const bool CTextMessage::isSupervisorMessage() const
{ {
return this->m_senderCallsign.isSupervisorCallsign(); return m_senderCallsign.isSupervisorCallsign();
} }
bool CTextMessage::wasSent() const bool CTextMessage::wasSent() const
@@ -67,15 +67,15 @@ namespace BlackMisc
QString CTextMessage::getRecipientCallsignOrFrequency() const QString CTextMessage::getRecipientCallsignOrFrequency() const
{ {
if (!this->m_recipientCallsign.isEmpty()) { return m_recipientCallsign.asString(); } if (!m_recipientCallsign.isEmpty()) { return m_recipientCallsign.asString(); }
if (this->m_frequency.isNull()) { return ""; } if (m_frequency.isNull()) { return ""; }
return this->m_frequency.valueRoundedWithUnit(CFrequencyUnit::MHz(), 3); return m_frequency.valueRoundedWithUnit(CFrequencyUnit::MHz(), 3);
} }
bool CTextMessage::isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const bool CTextMessage::isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const
{ {
if (!this->isRadioMessage()) { return false; } if (!this->isRadioMessage()) { return false; }
return this->m_frequency == frequency; return m_frequency == frequency;
} }
bool CTextMessage::isSendToUnicom() const bool CTextMessage::isSendToUnicom() const
@@ -85,19 +85,19 @@ namespace BlackMisc
bool CTextMessage::hasValidRecipient() const bool CTextMessage::hasValidRecipient() const
{ {
if (!this->m_recipientCallsign.isEmpty()) return true; if (!m_recipientCallsign.isEmpty()) return true;
return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency); return CComSystem::isValidCivilAviationFrequency(m_frequency);
} }
bool CTextMessage::isRadioMessage() const bool CTextMessage::isRadioMessage() const
{ {
return (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency)); return (CComSystem::isValidCivilAviationFrequency(m_frequency));
} }
bool CTextMessage::isServerMessage() const bool CTextMessage::isServerMessage() const
{ {
if (!this->isPrivateMessage()) return false; if (!this->isPrivateMessage()) return false;
CCallsign cs = this->getSenderCallsign(); const CCallsign cs = this->getSenderCallsign();
return (cs.asString().startsWith("SERVER", Qt::CaseInsensitive)); return (cs.asString().startsWith("SERVER", Qt::CaseInsensitive));
} }
@@ -106,34 +106,34 @@ namespace BlackMisc
QString s(this->getFormattedUtcTimestampHms()); QString s(this->getFormattedUtcTimestampHms());
if (withSender) if (withSender)
{ {
if (!this->m_senderCallsign.isEmpty()) if (!m_senderCallsign.isEmpty())
{ {
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
s.append(this->m_senderCallsign.getStringAsSet()); s.append(m_senderCallsign.getStringAsSet());
} }
} }
if (withRecipient) if (withRecipient)
{ {
if (!this->m_recipientCallsign.isEmpty()) if (!m_recipientCallsign.isEmpty())
{ {
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
s.append(this->m_recipientCallsign.getStringAsSet()); s.append(m_recipientCallsign.getStringAsSet());
} }
else else
{ {
if (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency)) if (CComSystem::isValidCivilAviationFrequency(m_frequency))
{ {
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
s.append(this->m_frequency.valueRoundedWithUnit(3, true)); s.append(m_frequency.valueRoundedWithUnit(3, true));
} }
} }
} // to } // to
if (this->m_message.isEmpty()) return s; if (m_message.isEmpty()) return s;
if (!s.isEmpty()) s.append(separator); if (!s.isEmpty()) s.append(separator);
s.append(this->m_message); s.append(m_message);
return s; return s;
} }
@@ -145,7 +145,7 @@ namespace BlackMisc
void CTextMessage::toggleSenderRecipient() void CTextMessage::toggleSenderRecipient()
{ {
qSwap(this->m_senderCallsign, this->m_recipientCallsign); qSwap(m_senderCallsign, m_recipientCallsign);
} }
bool CTextMessage::isSelcalMessage() const bool CTextMessage::isSelcalMessage() const
@@ -153,7 +153,7 @@ namespace BlackMisc
// some first level checks, before really parsing the message // some first level checks, before really parsing the message
if (this->isEmpty()) return false; if (this->isEmpty()) return false;
if (this->isPrivateMessage()) 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; return this->getSelcalCode().length() == 4;
} }
@@ -172,9 +172,9 @@ namespace BlackMisc
if (this->isEmpty()) return {}; if (this->isEmpty()) return {};
if (this->isPrivateMessage()) return {}; if (this->isPrivateMessage()) return {};
if (!this->m_message.startsWith(QLatin1String("SELCAL"), Qt::CaseInsensitive)) return {}; if (!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 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(this->m_message, [](QChar c) { return !c.isLetter(); }); // SELCALABCD QString candidate = removeChars(m_message, [](QChar c) { return !c.isLetter(); }); // SELCALABCD
if (candidate.length() != 10) return {}; if (candidate.length() != 10) return {};
return std::move(candidate).right(4).toUpper(); return std::move(candidate).right(4).toUpper();
} }
@@ -194,19 +194,14 @@ namespace BlackMisc
if (index.isMyself()) { return CVariant::from(*this); } if (index.isMyself()) { return CVariant::from(*this); }
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexSenderCallsign: case IndexSenderCallsign: return m_senderCallsign.propertyByIndex(index.copyFrontRemoved());
return this->m_senderCallsign.propertyByIndex(index.copyFrontRemoved()); case IndexRecipientCallsign: return m_recipientCallsign.propertyByIndex(index.copyFrontRemoved());
case IndexRecipientCallsign: case IndexRecipientCallsignOrFrequency: return CVariant::fromValue(this->getRecipientCallsignOrFrequency());
return this->m_recipientCallsign.propertyByIndex(index.copyFrontRemoved()); case IndexMessage: return CVariant::fromValue(m_message);
case IndexRecipientCallsignOrFrequency: default: return CValueObject::propertyByIndex(index);
return CVariant::fromValue(this->getRecipientCallsignOrFrequency());
case IndexMessage:
return CVariant::fromValue(this->m_message);
default:
return CValueObject::propertyByIndex(index);
} }
} }
@@ -215,23 +210,14 @@ namespace BlackMisc
if (index.isMyself()) { (*this) = variant.to<CTextMessage>(); return; } if (index.isMyself()) { (*this) = variant.to<CTextMessage>(); return; }
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; } if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(index, variant); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexSenderCallsign: case IndexSenderCallsign: m_senderCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
this->m_senderCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); case IndexRecipientCallsign: m_recipientCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
break; case IndexMessage: m_message = variant.value<QString>(); break;
case IndexRecipientCallsign: default: CValueObject::setPropertyByIndex(index, variant); break;
this->m_recipientCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant);
break;
case IndexMessage:
this->m_message = variant.value<QString>();
break;
default:
CValueObject::setPropertyByIndex(index, variant);
break;
} }
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -37,13 +37,13 @@ namespace BlackMisc
*/ */
class BLACKMISC_EXPORT CTextMessage : class BLACKMISC_EXPORT CTextMessage :
public CValueObject<CTextMessage>, public CValueObject<CTextMessage>,
public BlackMisc::ITimestampBased public ITimestampBased
{ {
public: public:
//! Properties by index //! Properties by index
enum ColumnIndex enum ColumnIndex
{ {
IndexSenderCallsign = BlackMisc::CPropertyIndex::GlobalIndexCTextMessage, IndexSenderCallsign = CPropertyIndex::GlobalIndexCTextMessage,
IndexRecipientCallsign, IndexRecipientCallsign,
IndexRecipientCallsignOrFrequency, IndexRecipientCallsignOrFrequency,
IndexMessage IndexMessage
@@ -53,33 +53,33 @@ namespace BlackMisc
CTextMessage() {} CTextMessage() {}
//! Constructor, radio message //! 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) : 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 //! 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) {} : m_message(message), m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(0, nullptr) {}
//! Get callsign (from) //! Get callsign (from)
const BlackMisc::Aviation::CCallsign &getSenderCallsign() const { return m_senderCallsign; } const Aviation::CCallsign &getSenderCallsign() const { return m_senderCallsign; }
//! Set callsign (from) //! 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) //! Get callsign (to)
const BlackMisc::Aviation::CCallsign &getRecipientCallsign() const { return m_recipientCallsign; } const Aviation::CCallsign &getRecipientCallsign() const { return m_recipientCallsign; }
//! Set callsign (recipient) //! 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 //! Get recipient or frequency
QString getRecipientCallsignOrFrequency() const; QString getRecipientCallsignOrFrequency() const;
//! Send to particular frequency? //! Send to particular frequency?
bool isSendToFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) const; bool isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const;
//! Send to UNICOM? //! Send to UNICOM?
bool isSendToUnicom() const; bool isSendToUnicom() const;
@@ -97,10 +97,10 @@ namespace BlackMisc
void setMessage(const QString &message) { m_message = message.trimmed(); } void setMessage(const QString &message) { m_message = message.trimmed(); }
//! Get frequency //! Get frequency
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; } const PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }
//! Set 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? //! Is private message?
bool isPrivateMessage() const; bool isPrivateMessage() const;
@@ -129,7 +129,7 @@ namespace BlackMisc
* \param separator values separated by given value * \param separator values separated by given value
* \return * \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 //! Toggle sender receiver, can be used to ping my own message
void toggleSenderRecipient(); void toggleSenderRecipient();
@@ -173,9 +173,9 @@ namespace BlackMisc
private: private:
QString m_message; QString m_message;
BlackMisc::Aviation::CCallsign m_senderCallsign; Aviation::CCallsign m_senderCallsign;
BlackMisc::Aviation::CCallsign m_recipientCallsign; Aviation::CCallsign m_recipientCallsign;
BlackMisc::PhysicalQuantities::CFrequency m_frequency { 0, nullptr }; PhysicalQuantities::CFrequency m_frequency { 0, nullptr };
bool m_wasSent = false; bool m_wasSent = false;
BLACK_METACLASS( BLACK_METACLASS(

View File

@@ -34,8 +34,8 @@ namespace BlackMisc
//! Value object encapsulating a list of text messages //! Value object encapsulating a list of text messages
class BLACKMISC_EXPORT CTextMessageList : class BLACKMISC_EXPORT CTextMessageList :
public CSequence<CTextMessage>, public CSequence<CTextMessage>,
public BlackMisc::ITimestampObjectList<CTextMessage, CTextMessageList>, public ITimestampObjectList<CTextMessage, CTextMessageList>,
public BlackMisc::Mixin::MetaType<CTextMessageList> public Mixin::MetaType<CTextMessageList>
{ {
public: public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CTextMessageList) BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CTextMessageList)
@@ -44,19 +44,19 @@ namespace BlackMisc
CTextMessageList(); CTextMessageList();
//! Constructor, single private message //! 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 //! 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 //! 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 //! Constructor, single message
CTextMessageList(const CTextMessage &message); CTextMessageList(const CTextMessage &message);
//! Constructor, multi-frequency radio messages //! 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. //! Construct from a base class object.
CTextMessageList(const CSequence<CTextMessage> &other); CTextMessageList(const CSequence<CTextMessage> &other);
@@ -80,7 +80,7 @@ namespace BlackMisc
CTextMessageList containsSupervisorMessages() const; CTextMessageList containsSupervisorMessages() const;
//! Find by frequency //! Find by frequency
CTextMessageList findByFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) const; CTextMessageList findByFrequency(const PhysicalQuantities::CFrequency &frequency) const;
//! Toggle all sender receivers //! Toggle all sender receivers
void toggleSenderRecipients(); void toggleSenderRecipients();