mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 07:35:41 +08:00
As of workshop RW/KB, improved / fixed text messages
Also refs #351 * messages can be formatted with style sheet * fixed: removed command from message * added originator to command line * msg parsing now in core * using ITimestampBased for text messages and status messages * allow to resize rows to content (view base) * model / views for text messages * removed old qt stylesheets
This commit is contained in:
@@ -45,10 +45,10 @@ namespace BlackMisc
|
||||
|
||||
protected:
|
||||
//! Myself
|
||||
virtual const CAircraftSituationList &container() const { return *this; }
|
||||
virtual const CAircraftSituationList &container() const override { return *this; }
|
||||
|
||||
//! Myself
|
||||
virtual CAircraftSituationList &container() { return *this; }
|
||||
virtual CAircraftSituationList &container() override { return *this; }
|
||||
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -76,6 +76,14 @@ namespace BlackMisc
|
||||
return atcCallsignSuffixes().contains(this->getSuffix(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
/*
|
||||
* Supervisor callsign?
|
||||
*/
|
||||
bool CCallsign::isSupervisorCallsign() const
|
||||
{
|
||||
return this->m_callsign.endsWith("SUP");
|
||||
}
|
||||
|
||||
/*
|
||||
* ATC callsign?
|
||||
*/
|
||||
|
||||
@@ -60,6 +60,9 @@ namespace BlackMisc
|
||||
//! Observer callsign?
|
||||
bool isObserverCallsign() const;
|
||||
|
||||
//! Supervisor?
|
||||
bool isSupervisorCallsign() const;
|
||||
|
||||
//! Get callsign.
|
||||
const QString &asString() const { return this->m_callsign; }
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "blackmisc/avselcal.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -38,51 +39,55 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* Private message?
|
||||
*/
|
||||
bool CTextMessage::isPrivateMessage() const
|
||||
{
|
||||
return !this->m_senderCallsign.isEmpty() && !this->m_recipientCallsign.isEmpty();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sent to frequency?
|
||||
*/
|
||||
bool CTextMessage::isSupervisorMessage() const
|
||||
{
|
||||
return this->m_senderCallsign.isSupervisorCallsign();
|
||||
}
|
||||
|
||||
bool CTextMessage::wasSent() const
|
||||
{
|
||||
return m_wasSent;
|
||||
}
|
||||
|
||||
void CTextMessage::markAsSent()
|
||||
{
|
||||
m_wasSent = true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool CTextMessage::isSendToFrequency(const PhysicalQuantities::CFrequency &frequency) const
|
||||
{
|
||||
if (!this->isRadioMessage()) return false;
|
||||
if (!this->isRadioMessage()) { return false; }
|
||||
return this->m_frequency == frequency;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sent to UNICOM?
|
||||
*/
|
||||
bool CTextMessage::isSendToUnicom() const
|
||||
{
|
||||
return this->isSendToFrequency(BlackMisc::PhysicalQuantities::CPhysicalQuantitiesConstants::FrequencyUnicom());
|
||||
}
|
||||
|
||||
/*
|
||||
* Valid receiver?
|
||||
*/
|
||||
bool CTextMessage::hasValidRecipient() const
|
||||
{
|
||||
if (!this->m_recipientCallsign.isEmpty()) return true;
|
||||
return BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency);
|
||||
}
|
||||
|
||||
/*
|
||||
* Radio message?
|
||||
*/
|
||||
bool CTextMessage::isRadioMessage() const
|
||||
{
|
||||
return (BlackMisc::Aviation::CComSystem::isValidCivilAviationFrequency(this->m_frequency));
|
||||
}
|
||||
|
||||
/*
|
||||
* Initial server message?
|
||||
*/
|
||||
bool CTextMessage::isServerMessage() const
|
||||
{
|
||||
if (!this->isPrivateMessage()) return false;
|
||||
@@ -90,12 +95,9 @@ namespace BlackMisc
|
||||
return (cs.asString().startsWith("SERVER", Qt::CaseInsensitive));
|
||||
}
|
||||
|
||||
/*
|
||||
* Formatted string
|
||||
*/
|
||||
QString CTextMessage::asString(bool withSender, bool withRecipient, const QString &separator) const
|
||||
{
|
||||
QString s = this->receivedTime();
|
||||
QString s(this->getFormattedUtcTimestampHms());
|
||||
if (withSender)
|
||||
{
|
||||
if (!this->m_senderCallsign.isEmpty())
|
||||
@@ -129,26 +131,17 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* As status message
|
||||
*/
|
||||
CStatusMessage CTextMessage::asStatusMessage(bool withSender, bool withRecipient, const QString &separator) const
|
||||
{
|
||||
QString m = this->asString(withSender, withRecipient, separator);
|
||||
return { this, CStatusMessage::SeverityInfo, m };
|
||||
}
|
||||
|
||||
/*
|
||||
* Toggle sender / receiver
|
||||
*/
|
||||
void CTextMessage::toggleSenderRecipient()
|
||||
{
|
||||
qSwap(this->m_senderCallsign, this->m_recipientCallsign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find out if this is a SELCAL message
|
||||
*/
|
||||
bool CTextMessage::isSelcalMessage() const
|
||||
{
|
||||
// some first level checks, before really parsing the message
|
||||
@@ -158,18 +151,12 @@ namespace BlackMisc
|
||||
return this->getSelcalCode().length() == 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Matching given SELCAL code
|
||||
*/
|
||||
bool CTextMessage::isSelcalMessageFor(const QString &selcal) const
|
||||
{
|
||||
if (!CSelcal::isValidCode(selcal)) return false;
|
||||
return selcal.toUpper() == this->getSelcalCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* SELCAL code, 4 letters
|
||||
*/
|
||||
QString CTextMessage::getSelcalCode() const
|
||||
{
|
||||
// http://forums.vatsim.net/viewtopic.php?f=8&t=63467#p458062
|
||||
@@ -189,5 +176,63 @@ namespace BlackMisc
|
||||
return candidate.right(4).toUpper();
|
||||
}
|
||||
|
||||
CIcon CTextMessage::toIcon() const
|
||||
{
|
||||
return m_senderCallsign.toIcon();
|
||||
}
|
||||
|
||||
QPixmap CTextMessage::toPixmap() const
|
||||
{
|
||||
return m_senderCallsign.toPixmap();
|
||||
}
|
||||
|
||||
CVariant CTextMessage::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toCVariant(); }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void CTextMessage::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself())
|
||||
{
|
||||
this->convertFromCVariant(variant);
|
||||
return;
|
||||
}
|
||||
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexSenderCallsign:
|
||||
this->m_senderCallsign.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
case IndexRecipientCallsign:
|
||||
this->m_recipientCallsign.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
case IndexMessage:
|
||||
this->m_message = variant.value<QString>();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef BLACKMISC_TEXTMESSAGE_H
|
||||
#define BLACKMISC_TEXTMESSAGE_H
|
||||
|
||||
#include "blackmisc/timestampbased.h"
|
||||
#include "pqfrequency.h"
|
||||
#include "avcallsign.h"
|
||||
#include "statusmessage.h"
|
||||
@@ -25,102 +26,82 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Value object encapsulating information of a text message
|
||||
*/
|
||||
class CTextMessage : public CValueObjectStdTuple<CTextMessage>
|
||||
class CTextMessage :
|
||||
public CValueObjectStdTuple<CTextMessage>,
|
||||
public BlackMisc::ITimestampBased
|
||||
{
|
||||
public:
|
||||
//! \brief Default constructor.
|
||||
CTextMessage() : m_received(QDateTime::currentDateTimeUtc()), m_frequency(0, BlackMisc::PhysicalQuantities::CFrequencyUnit::nullUnit()) {}
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexSenderCallsign = BlackMisc::CPropertyIndex::GlobalIndexCTextMessage,
|
||||
IndexRecipientCallsign,
|
||||
IndexRecipientCallsignOrFrequency,
|
||||
IndexMessage
|
||||
};
|
||||
|
||||
//! \brief Constructor, radio message
|
||||
//! Default constructor.
|
||||
CTextMessage() {}
|
||||
|
||||
//! Constructor, radio message
|
||||
CTextMessage(const QString &message, const BlackMisc::PhysicalQuantities::CFrequency &frequency, const BlackMisc::Aviation::CCallsign &senderCallsign = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_received(QDateTime::currentDateTimeUtc()), m_senderCallsign(senderCallsign), m_frequency(frequency)
|
||||
: m_message(message), m_senderCallsign(senderCallsign), m_frequency(frequency)
|
||||
{
|
||||
this->m_frequency.switchUnit(BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz());
|
||||
}
|
||||
|
||||
//! \brief Constructor, private message
|
||||
//! Constructor, private message
|
||||
CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_received(QDateTime::currentDateTimeUtc()), m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(0, BlackMisc::PhysicalQuantities::CFrequencyUnit::nullUnit()) {}
|
||||
: m_message(message), m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(0, BlackMisc::PhysicalQuantities::CFrequencyUnit::nullUnit()) {}
|
||||
|
||||
//! \brief Get callsign (from)
|
||||
const BlackMisc::Aviation::CCallsign &getSenderCallsign() const
|
||||
{
|
||||
return m_senderCallsign;
|
||||
}
|
||||
//! Get callsign (from)
|
||||
const BlackMisc::Aviation::CCallsign &getSenderCallsign() const { return m_senderCallsign; }
|
||||
|
||||
//! \brief Set callsign (from)
|
||||
void setSenderCallsign(const BlackMisc::Aviation::CCallsign &callsign)
|
||||
{
|
||||
m_senderCallsign = callsign;
|
||||
}
|
||||
//! Set callsign (from)
|
||||
void setSenderCallsign(const BlackMisc::Aviation::CCallsign &callsign) { m_senderCallsign = callsign;}
|
||||
|
||||
//! \brief Get callsign (to)
|
||||
const BlackMisc::Aviation::CCallsign &getRecipientCallsign() const
|
||||
{
|
||||
return m_recipientCallsign;
|
||||
}
|
||||
//! Get callsign (to)
|
||||
const BlackMisc::Aviation::CCallsign &getRecipientCallsign() const { return m_recipientCallsign; }
|
||||
|
||||
//! \brief Set callsign (recipient)
|
||||
void setRecipientCallsign(const BlackMisc::Aviation::CCallsign &callsign)
|
||||
{
|
||||
m_recipientCallsign = callsign;
|
||||
}
|
||||
//! Set callsign (recipient)
|
||||
void setRecipientCallsign(const BlackMisc::Aviation::CCallsign &callsign) { m_recipientCallsign = callsign; }
|
||||
|
||||
//! \brief Send to particular frequency?
|
||||
//! Get recipient or frequency
|
||||
QString getRecipientCallsignOrFrequency() const;
|
||||
|
||||
//! Send to particular frequency?
|
||||
bool isSendToFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) const;
|
||||
|
||||
//! \brief Send to UNICOM?
|
||||
//! Send to UNICOM?
|
||||
bool isSendToUnicom() const;
|
||||
|
||||
//! \brief Valid receviver?
|
||||
//! Valid receviver?
|
||||
bool hasValidRecipient() const;
|
||||
|
||||
//! \brief Get message
|
||||
const QString &getMessage() const
|
||||
{
|
||||
return m_message;
|
||||
}
|
||||
//! Get message
|
||||
const QString &getMessage() const { return m_message; }
|
||||
|
||||
//! \brief Empty message
|
||||
bool isEmpty() const
|
||||
{
|
||||
return m_message.isEmpty();
|
||||
}
|
||||
//! Empty message
|
||||
bool isEmpty() const { return m_message.isEmpty(); }
|
||||
|
||||
//! \brief Set message
|
||||
void setMessage(const QString &message)
|
||||
{
|
||||
m_message = message.trimmed();
|
||||
}
|
||||
//! Set message
|
||||
void setMessage(const QString &message) { m_message = message.trimmed(); }
|
||||
|
||||
//! \brief Get frequency
|
||||
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
//! Get frequency
|
||||
const BlackMisc::PhysicalQuantities::CFrequency &getFrequency() const { return m_frequency; }
|
||||
|
||||
//! \brief Set frequency
|
||||
void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
}
|
||||
//! Set frequency
|
||||
void setFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) { m_frequency = frequency; }
|
||||
|
||||
//! \brief Is private message?
|
||||
//! Is private message?
|
||||
bool isPrivateMessage() const;
|
||||
|
||||
//! \brief Is radio message?
|
||||
//! Is radio message?
|
||||
bool isRadioMessage() const;
|
||||
|
||||
//! \brief Initial message of server?
|
||||
//! Initial message of server?
|
||||
bool isServerMessage() const;
|
||||
|
||||
//! \brief Received (hh mm ss)
|
||||
QString receivedTime() const
|
||||
{
|
||||
QString rt = this->m_received.toString("hh::mm::ss");
|
||||
return rt;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Whole message as formatted string.
|
||||
* Used to display message in a console window.
|
||||
@@ -141,23 +122,42 @@ namespace BlackMisc
|
||||
*/
|
||||
BlackMisc::CStatusMessage asStatusMessage(bool withSender, bool withRecipient, const QString &separator = ", ") const;
|
||||
|
||||
//! \brief Toggle sender receiver, can be used to ping my own message
|
||||
//! Toggle sender receiver, can be used to ping my own message
|
||||
void toggleSenderRecipient();
|
||||
|
||||
/*!
|
||||
* \brief Is this a text message encapsulating a SELCAL
|
||||
* Is this a text message encapsulating a SELCAL
|
||||
* \see http://forums.vatsim.net/viewtopic.php?f=8&t=63467
|
||||
*/
|
||||
bool isSelcalMessage() const;
|
||||
|
||||
/*!
|
||||
* \brief Is this a text message encapsulating a SELCAL for given code
|
||||
*/
|
||||
//! Is this a text message encapsulating a SELCAL for given code?
|
||||
bool isSelcalMessageFor(const QString &selcal) const;
|
||||
|
||||
//! \brief Get SELCAL code (if applicable, e.g. ABCD), otherwise ""
|
||||
//! Supervisor message?
|
||||
bool isSupervisorMessage() const;
|
||||
|
||||
//! Was sent?
|
||||
bool wasSent() const;
|
||||
|
||||
//! Mark as sent
|
||||
void markAsSent();
|
||||
|
||||
//! Get SELCAL code (if applicable, e.g. ABCD), otherwise ""
|
||||
QString getSelcalCode() const;
|
||||
|
||||
//! As icon, not implement by all classes
|
||||
virtual CIcon toIcon() const override;
|
||||
|
||||
//! As pixmap, required for most GUI views
|
||||
virtual QPixmap toPixmap() const override;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
virtual void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
@@ -165,15 +165,15 @@ namespace BlackMisc
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CTextMessage)
|
||||
QString m_message;
|
||||
QDateTime m_received;
|
||||
BlackMisc::Aviation::CCallsign m_senderCallsign;
|
||||
BlackMisc::Aviation::CCallsign m_recipientCallsign;
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequency;
|
||||
BlackMisc::PhysicalQuantities::CFrequency m_frequency {0, BlackMisc::PhysicalQuantities::CFrequencyUnit::nullUnit()};
|
||||
bool m_wasSent = false;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CTextMessage, (o.m_message, o.m_received, o.m_senderCallsign, o.m_recipientCallsign, o.m_frequency))
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Network::CTextMessage, (o.m_message, o.m_timestampMSecsSinceEpoch, o.m_senderCallsign, o.m_recipientCallsign, o.m_frequency))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Network::CTextMessage)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -93,6 +93,14 @@ namespace BlackMisc
|
||||
return this->contains(&CTextMessage::isPrivateMessage, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Supervisor messages?
|
||||
*/
|
||||
CTextMessageList CTextMessageList::containsSupervisorMessages() const
|
||||
{
|
||||
return this->findBy(&CTextMessage::isSupervisorMessage, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Radio messages
|
||||
*/
|
||||
@@ -101,6 +109,14 @@ namespace BlackMisc
|
||||
return this->findBy(&CTextMessage::isRadioMessage, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Supervisor messages
|
||||
*/
|
||||
CTextMessageList CTextMessageList::getSupervisorMessages() const
|
||||
{
|
||||
return this->findBy(&CTextMessage::isSupervisorMessage, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Radio messages?
|
||||
*/
|
||||
@@ -136,8 +152,16 @@ namespace BlackMisc
|
||||
*/
|
||||
void CTextMessageList::toggleSenderRecipients()
|
||||
{
|
||||
if (this->isEmpty()) return;
|
||||
std::for_each(this->begin(), this->end(), [](CTextMessage &tm) { tm.toggleSenderRecipient(); });
|
||||
if (this->isEmpty()) { return; }
|
||||
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.toggleSenderRecipient(); });
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark all messages as sent
|
||||
*/
|
||||
void CTextMessageList::markAsSent()
|
||||
{
|
||||
std::for_each(this->begin(), this->end(), [](CTextMessage & tm) { tm.markAsSent(); });
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKMISC_TEXTMESSAGELIST_H
|
||||
|
||||
#include "nwtextmessage.h"
|
||||
#include "timestampobjectlist.h"
|
||||
#include "collection.h"
|
||||
#include "sequence.h"
|
||||
#include <QObject>
|
||||
@@ -26,7 +27,9 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Value object encapsulating a list of text messages
|
||||
*/
|
||||
class CTextMessageList : public CSequence<CTextMessage>
|
||||
class CTextMessageList :
|
||||
public CSequence<CTextMessage>,
|
||||
public BlackMisc::ITimestampObjectList<CTextMessage, CTextMessageList>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
@@ -59,15 +62,24 @@ namespace BlackMisc
|
||||
//! Public messages
|
||||
CTextMessageList getRadioMessages() const;
|
||||
|
||||
//! Supervisor messages
|
||||
CTextMessageList getSupervisorMessages() const;
|
||||
|
||||
//! Contains radio messages?
|
||||
bool containsRadioMessages() const;
|
||||
|
||||
//! Contains supervisor message
|
||||
CTextMessageList containsSupervisorMessages() const;
|
||||
|
||||
//! Find by frequency
|
||||
CTextMessageList findByFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency) const;
|
||||
|
||||
//! Toggle all sender receivers
|
||||
void toggleSenderRecipients();
|
||||
|
||||
//! Mark all messages as sent
|
||||
void markAsSent();
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||
|
||||
@@ -76,6 +88,14 @@ namespace BlackMisc
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
protected:
|
||||
//! Myself
|
||||
virtual const CTextMessageList &container() const override { return *this; }
|
||||
|
||||
//! Myself
|
||||
virtual CTextMessageList &container() override { return *this; }
|
||||
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
@@ -41,4 +41,4 @@ namespace BlackMisc
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::PhysicalQuantities::CFrequency)
|
||||
|
||||
#endif // BLACKMISC_PQFREQUENCY_H
|
||||
#endif // guard
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace BlackMisc
|
||||
break;
|
||||
case SeparatorsBestGuess:
|
||||
numberD = number.toDouble(&success);
|
||||
if (!success) numberD = QLocale::system().toDouble(number, &success);
|
||||
if (!success) { numberD = QLocale::system().toDouble(number, &success); }
|
||||
break;
|
||||
default:
|
||||
qFatal("Wrong mode");
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace BlackMisc
|
||||
GlobalIndexCAircraftModel = 4300,
|
||||
GlobalIndexCSimulatedAircraft = 4400,
|
||||
GlobalIndexCAircraftMapping = 4500,
|
||||
GlobalIndexCTextMessage = 4600,
|
||||
GlobalIndexCVoiceRoom = 5000,
|
||||
GlobalIndexCSettingKeyboardHotkey = 6000,
|
||||
GlobalIndexCAircraftCfgEntries = 7000,
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace BlackMisc
|
||||
|
||||
void CSimpleCommandParser::parse(const QString &commandLine)
|
||||
{
|
||||
this->m_knownCommand = false;
|
||||
this->m_originalLine = commandLine;
|
||||
this->m_cleanedLine = commandLine.trimmed().simplified();
|
||||
if (!this->m_cleanedLine.isEmpty())
|
||||
@@ -52,8 +53,8 @@ namespace BlackMisc
|
||||
if (index < 0) { return this->m_originalLine.trimmed(); }
|
||||
QString p = this->part(index);
|
||||
int fi = this->m_originalLine.indexOf(p, 0, Qt::CaseInsensitive);
|
||||
if (fi < 0) return "";
|
||||
return this->m_originalLine.right(fi + p.length()).trimmed();
|
||||
if (fi < 0) { return ""; }
|
||||
return this->m_originalLine.mid(fi).trimmed();
|
||||
}
|
||||
|
||||
int CSimpleCommandParser::countParts() const
|
||||
@@ -97,7 +98,7 @@ namespace BlackMisc
|
||||
double CSimpleCommandParser::toDouble(int index, double def) const
|
||||
{
|
||||
const QString p = this->part(index);
|
||||
if (p.isEmpty()) return def;
|
||||
if (p.isEmpty()) { return def; }
|
||||
bool ok;
|
||||
double d = CPqString::parseNumber(p, ok, CPqString::SeparatorsBestGuess);
|
||||
return ok ? d : def;
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace BlackMisc
|
||||
s.append(QString::number(this->m_severity));
|
||||
|
||||
s.append(" when: ");
|
||||
s.append(this->m_timestamp.toString("yyyy-MM-dd HH:mm::ss"));
|
||||
s.append(this->getFormattedUtcTimestampYmdhms());
|
||||
|
||||
s.append(" ").append(this->m_message);
|
||||
return s;
|
||||
@@ -247,6 +247,7 @@ namespace BlackMisc
|
||||
CVariant CStatusMessage::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toCVariant(); }
|
||||
if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -256,13 +257,6 @@ namespace BlackMisc
|
||||
return CVariant::from(static_cast<uint>(this->m_severity));
|
||||
case IndexSeverityAsString:
|
||||
return CVariant::from(this->getSeverityAsString());
|
||||
case IndexTimestamp:
|
||||
return CVariant::from(this->m_timestamp);
|
||||
case IndexTimestampFormatted:
|
||||
{
|
||||
if (this->m_timestamp.isNull() || !this->m_timestamp.isValid()) return "";
|
||||
return this->m_timestamp.toString("HH:mm::ss.zzz");
|
||||
}
|
||||
case IndexCategories:
|
||||
return CVariant::from(this->m_categories.toQString());
|
||||
case IndexCategoryHumanReadable:
|
||||
@@ -277,20 +271,14 @@ namespace BlackMisc
|
||||
*/
|
||||
void CStatusMessage::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself())
|
||||
{
|
||||
this->convertFromCVariant(variant);
|
||||
return;
|
||||
}
|
||||
if (index.isMyself()) { this->convertFromCVariant(variant); return; }
|
||||
if (ITimestampBased::canHandleIndex(index)) { ITimestampBased::setPropertyByIndex(variant, index); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMessage:
|
||||
this->m_message = variant.value<QString>();
|
||||
break;
|
||||
case IndexTimestamp:
|
||||
this->m_timestamp = variant.value<QDateTime>();
|
||||
break;
|
||||
case IndexSeverity:
|
||||
this->m_severity = static_cast<StatusSeverity>(variant.value<uint>());
|
||||
break;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "icon.h"
|
||||
#include "propertyindex.h"
|
||||
#include "logcategorylist.h"
|
||||
#include <QDateTime>
|
||||
#include "timestampbased.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -23,7 +23,9 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Streamable status message, e.g. from Core -> GUI
|
||||
*/
|
||||
class CStatusMessage : public CValueObjectStdTuple<CStatusMessage>
|
||||
class CStatusMessage :
|
||||
public CValueObjectStdTuple<CStatusMessage>,
|
||||
public ITimestampBased
|
||||
{
|
||||
public:
|
||||
//! Status severities
|
||||
@@ -42,9 +44,7 @@ namespace BlackMisc
|
||||
IndexCategoryHumanReadable,
|
||||
IndexSeverity,
|
||||
IndexSeverityAsString,
|
||||
IndexMessage,
|
||||
IndexTimestamp,
|
||||
IndexTimestampFormatted
|
||||
IndexMessage
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
@@ -147,7 +147,6 @@ namespace BlackMisc
|
||||
CLogCategoryList m_categories;
|
||||
StatusSeverity m_severity = SeverityDebug;
|
||||
QString m_message;
|
||||
QDateTime m_timestamp = QDateTime::currentDateTimeUtc();
|
||||
bool m_redundant = false;
|
||||
mutable QVector<quintptr> m_handledByObjects;
|
||||
mutable QString m_humanReadableCategory; //!< human readable category cache
|
||||
@@ -157,13 +156,13 @@ namespace BlackMisc
|
||||
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CStatusMessage, (
|
||||
o.m_categories,
|
||||
o.m_severity,
|
||||
o.m_message,
|
||||
o.m_timestamp,
|
||||
o.m_redundant,
|
||||
attr(o.m_handledByObjects, flags<DisabledForHashing | DisabledForJson | DisabledForComparison | DisabledForMarshalling>())
|
||||
))
|
||||
o.m_categories,
|
||||
o.m_severity,
|
||||
o.m_message,
|
||||
o.m_timestampMSecsSinceEpoch,
|
||||
o.m_redundant,
|
||||
attr(o.m_handledByObjects, flags < DisabledForHashing | DisabledForJson | DisabledForComparison | DisabledForMarshalling > ())
|
||||
))
|
||||
Q_DECLARE_METATYPE(BlackMisc::CStatusMessage)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#ifndef BLACKMISC_STATUSMESSAGELIST_H
|
||||
#define BLACKMISC_STATUSMESSAGELIST_H
|
||||
|
||||
#include "timestampobjectlist.h"
|
||||
#include "valueobject.h"
|
||||
#include "sequence.h"
|
||||
#include "collection.h"
|
||||
@@ -23,7 +24,9 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Status messages, e.g. from Core -> GUI
|
||||
*/
|
||||
class CStatusMessageList : public CSequence<CStatusMessage>
|
||||
class CStatusMessageList :
|
||||
public CSequence<CStatusMessage>,
|
||||
public ITimestampObjectList<CStatusMessage, CStatusMessageList>
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
@@ -52,6 +55,13 @@ namespace BlackMisc
|
||||
|
||||
//! Register metadata of unit and quantity
|
||||
static void registerMetadata();
|
||||
|
||||
protected:
|
||||
//! Myself
|
||||
virtual const CStatusMessageList &container() const override { return *this; }
|
||||
|
||||
//! Myself
|
||||
virtual CStatusMessageList &container() override { return *this; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,6 @@ namespace BlackMisc
|
||||
return QDateTime::fromMSecsSinceEpoch(this->m_timestampMSecsSinceEpoch, Qt::UTC);
|
||||
}
|
||||
|
||||
QString ITimestampBased::getFormattedUtcTimestamp() const
|
||||
{
|
||||
return this->getUtcTimestamp().toString("dd hh:mm:ss");
|
||||
}
|
||||
|
||||
void ITimestampBased::setUtcTimestamp(const QDateTime ×tamp)
|
||||
{
|
||||
this->m_timestampMSecsSinceEpoch = timestamp.toMSecsSinceEpoch();
|
||||
@@ -75,6 +70,37 @@ namespace BlackMisc
|
||||
this->m_timestampMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
|
||||
QString ITimestampBased::getFormattedUtcTimestamp() const
|
||||
{
|
||||
return this->getUtcTimestamp().toString("dd hh:mm:ss");
|
||||
}
|
||||
|
||||
QString ITimestampBased::getFormattedUtcTimestampHms() const
|
||||
{
|
||||
return this->getUtcTimestamp().toString("hh:mm:ss");
|
||||
}
|
||||
|
||||
QString ITimestampBased::getFormattedUtcTimestampHm() const
|
||||
{
|
||||
return this->getUtcTimestamp().toString("hh::mm");
|
||||
}
|
||||
|
||||
QString ITimestampBased::getFormattedUtcTimestampYmdhms() const
|
||||
{
|
||||
return this->getUtcTimestamp().toString("yyyy-MM-dd HH:mm::ss");
|
||||
}
|
||||
|
||||
QString ITimestampBased::getFormattedUtcTimestampYmdhmsz() const
|
||||
{
|
||||
return this->getUtcTimestamp().toString("yyyy-MM-dd HH:mm:ss.zzz");
|
||||
}
|
||||
|
||||
bool ITimestampBased::canHandleIndex(const CPropertyIndex &index)
|
||||
{
|
||||
int i = index.frontCasted<int>();
|
||||
return (i >= static_cast<int>(IndexUtcTimestamp)) && (i <= static_cast<int>(IndexMSecsSinceEpoch));
|
||||
}
|
||||
|
||||
CVariant ITimestampBased::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (!index.isEmpty())
|
||||
@@ -88,6 +114,10 @@ namespace BlackMisc
|
||||
return CVariant::fromValue(this->getMSecsSinceEpoch());
|
||||
case IndexUtcTimestampFormatted:
|
||||
return CVariant::fromValue(this->getFormattedUtcTimestamp());
|
||||
case IndexUtcTimestampFormattedHm:
|
||||
return CVariant::fromValue(this->getFormattedUtcTimestampHm());
|
||||
case IndexUtcTimestampFormattedHms:
|
||||
return CVariant::fromValue(this->getFormattedUtcTimestampHms());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@ namespace BlackMisc
|
||||
{
|
||||
IndexUtcTimestamp = BlackMisc::CPropertyIndex::GlobalIndexTimestampBased,
|
||||
IndexUtcTimestampFormatted,
|
||||
IndexMSecsSinceEpoch
|
||||
IndexUtcTimestampFormattedHms,
|
||||
IndexUtcTimestampFormattedHm,
|
||||
IndexMSecsSinceEpoch // keep this as last item
|
||||
};
|
||||
|
||||
//! Get timestamp
|
||||
@@ -39,9 +41,6 @@ namespace BlackMisc
|
||||
//! Timestamp as ms value
|
||||
void setMSecsSinceEpoch(qint64 mSecsSinceEpoch) { m_timestampMSecsSinceEpoch = mSecsSinceEpoch; }
|
||||
|
||||
//! Formatted timestamp
|
||||
QString getFormattedUtcTimestamp() const;
|
||||
|
||||
//! Set timestamp
|
||||
void setUtcTimestamp(const QDateTime ×tamp);
|
||||
|
||||
@@ -72,12 +71,23 @@ namespace BlackMisc
|
||||
//! Set the current time as timestamp
|
||||
void setCurrentUtcTime();
|
||||
|
||||
//! Formatted timestamp
|
||||
QString getFormattedUtcTimestamp() const;
|
||||
|
||||
//! As hh:mm:ss
|
||||
QString getFormattedUtcTimestampHms() const;
|
||||
|
||||
//! As hh:mm
|
||||
QString getFormattedUtcTimestampHm() const;
|
||||
|
||||
//! As YYYY mm dd hh ss
|
||||
QString getFormattedUtcTimestampYmdhms() const;
|
||||
|
||||
//! As YYYY mm dd hh ss.zzz
|
||||
QString getFormattedUtcTimestampYmdhmsz() const;
|
||||
|
||||
//! Can given index be handled
|
||||
static bool canHandleIndex(const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
int i = index.frontCasted<int>();
|
||||
return (i >= static_cast<int>(IndexUtcTimestamp)) && (i <= static_cast<int>(IndexMSecsSinceEpoch));
|
||||
}
|
||||
static bool canHandleIndex(const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "blackmisc/predicates.h"
|
||||
#include "blackmisc/avaircraftsituationlist.h"
|
||||
#include "blackmisc/aviation/aircraftpartslist.h"
|
||||
#include "blackmisc/nwtextmessagelist.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
@@ -156,5 +158,7 @@ namespace BlackMisc
|
||||
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
|
||||
template class ITimestampObjectList<BlackMisc::Aviation::CAircraftSituation, BlackMisc::Aviation::CAircraftSituationList>;
|
||||
template class ITimestampObjectList<BlackMisc::Aviation::CAircraftParts, BlackMisc::Aviation::CAircraftPartsList>;
|
||||
template class ITimestampObjectList<BlackMisc::Network::CTextMessage, BlackMisc::Network::CTextMessageList>;
|
||||
template class ITimestampObjectList<BlackMisc::CStatusMessage, BlackMisc::CStatusMessageList>;
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user