mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
Status message list model (so they can displayed as table view in GUI),
and the corresponding property methods in CStatusMessage
This commit is contained in:
committed by
Mathew Sutcliffe
parent
5731bd3dd1
commit
f476388f8b
@@ -101,6 +101,89 @@ namespace BlackMisc
|
||||
return BlackMisc::calculateHash(hashs, "CStatusMessage");
|
||||
}
|
||||
|
||||
/*
|
||||
* Type
|
||||
*/
|
||||
const QString &CStatusMessage::getTypeAsString() const
|
||||
{
|
||||
switch (this->m_type)
|
||||
{
|
||||
case TypeAudio:
|
||||
{
|
||||
static QString t("audio");
|
||||
return t;
|
||||
}
|
||||
case TypeCore:
|
||||
{
|
||||
static QString t("core");
|
||||
return t;
|
||||
}
|
||||
case TypeGui:
|
||||
{
|
||||
static QString t("gui");
|
||||
return t;
|
||||
}
|
||||
case TypeSettings:
|
||||
{
|
||||
static QString t("settings");
|
||||
return t;
|
||||
}
|
||||
case TypeTrafficNetwork:
|
||||
{
|
||||
static QString t("traffic network");
|
||||
return t;
|
||||
}
|
||||
case TypeUnknown:
|
||||
{
|
||||
static QString t("unknown");
|
||||
return t;
|
||||
}
|
||||
case TypeUnspecific:
|
||||
{
|
||||
static QString t("unspecific");
|
||||
return t;
|
||||
}
|
||||
case TypeValidation:
|
||||
{
|
||||
static QString t("validation");
|
||||
return t;
|
||||
}
|
||||
default:
|
||||
static QString x("unknown type");
|
||||
qFatal("Unknown type");
|
||||
return x; // just for compiler warning
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Severity
|
||||
*/
|
||||
const QString &CStatusMessage::getSeverityAsString() const
|
||||
{
|
||||
switch (this->m_severity)
|
||||
{
|
||||
case SeverityInfo:
|
||||
{
|
||||
static QString i("info");
|
||||
return i;
|
||||
}
|
||||
case SeverityWarning:
|
||||
{
|
||||
static QString w("warning");
|
||||
return w;
|
||||
}
|
||||
case SeverityError:
|
||||
{
|
||||
static QString e("error");
|
||||
return e;
|
||||
}
|
||||
default:
|
||||
static QString x("unknown severity");
|
||||
qFatal("Unknown severity");
|
||||
return x; // just for compiler warning
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal
|
||||
*/
|
||||
@@ -145,4 +228,78 @@ namespace BlackMisc
|
||||
this->m_type = static_cast<StatusType>(type);
|
||||
this->m_severity = static_cast<StatusSeverity>(severity);
|
||||
}
|
||||
|
||||
/*
|
||||
* Property by index
|
||||
*/
|
||||
QVariant CStatusMessage::propertyByIndex(int index) const
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case IndexMessage:
|
||||
return QVariant(this->m_message);
|
||||
case IndexSeverity:
|
||||
return QVariant(static_cast<uint>(this->m_severity));
|
||||
case IndexSeverityAsString:
|
||||
return QVariant(this->getSeverityAsString());
|
||||
case IndexTimestamp:
|
||||
return QVariant(this->m_timestamp);
|
||||
case IndexType:
|
||||
return QVariant(static_cast<uint>(this->m_type));
|
||||
case IndexTypeAsString:
|
||||
return QVariant(this->getTypeAsString());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Q_ASSERT_X(false, "CStatusMessage", "index unknown");
|
||||
QString m = QString("no property, index ").append(QString::number(index));
|
||||
return QVariant::fromValue(m);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set property as index
|
||||
*/
|
||||
void CStatusMessage::propertyByIndex(const QVariant &variant, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
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;
|
||||
case IndexType:
|
||||
this->m_type = static_cast<StatusType>(variant.value<uint>());
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT_X(false, "CStatusMessage", "index unknown (setter)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Property as string by index
|
||||
*/
|
||||
QString CStatusMessage::propertyByIndexAsString(int index, bool i18n) const
|
||||
{
|
||||
QVariant qv = this->propertyByIndex(index);
|
||||
switch (index)
|
||||
{
|
||||
case IndexTimestamp:
|
||||
{
|
||||
QDateTime dt = qv.value<QDateTime>();
|
||||
if (dt.isNull() || !dt.isValid()) return "";
|
||||
return dt.toString("HH:mm::ss.zzz");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return BlackMisc::qVariantToString(qv, i18n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,19 @@ namespace BlackMisc
|
||||
SeverityError
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Properties by index
|
||||
*/
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexType,
|
||||
IndexTypeAsString,
|
||||
IndexSeverity,
|
||||
IndexSeverityAsString,
|
||||
IndexMessage,
|
||||
IndexTimestamp
|
||||
};
|
||||
|
||||
private:
|
||||
StatusType m_type;
|
||||
StatusSeverity m_severity;
|
||||
@@ -98,6 +111,21 @@ namespace BlackMisc
|
||||
return QVariant::fromValue(*this);
|
||||
}
|
||||
|
||||
//! \brief Type as string
|
||||
const QString &getTypeAsString() const;
|
||||
|
||||
//! \brief Type as string
|
||||
const QString &getSeverityAsString() const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex(int)
|
||||
QVariant propertyByIndex(int index) const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex(const QVariant, int)
|
||||
void propertyByIndex(const QVariant &variant, int index);
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndexAsString
|
||||
QString propertyByIndexAsString(int index, bool i18n) const;
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
* \param other
|
||||
|
||||
@@ -8,6 +8,13 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*
|
||||
* Construct from base class object
|
||||
*/
|
||||
CStatusMessageList::CStatusMessageList(const CSequence<CStatusMessage> &other) :
|
||||
CSequence<CStatusMessage>(other)
|
||||
{ }
|
||||
|
||||
/*
|
||||
* Messages by type
|
||||
*/
|
||||
@@ -45,6 +52,10 @@ namespace BlackMisc
|
||||
*/
|
||||
void CStatusMessageList::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<BlackMisc::CSequence<CStatusMessage>>();
|
||||
qDBusRegisterMetaType<BlackMisc::CSequence<CStatusMessage>>();
|
||||
qRegisterMetaType<BlackMisc::CCollection<CStatusMessage>>();
|
||||
qDBusRegisterMetaType<BlackMisc::CCollection<CStatusMessage>>();
|
||||
qRegisterMetaType<CStatusMessageList>();
|
||||
qDBusRegisterMetaType<CStatusMessageList>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user