mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-29 12:45:40 +08:00
refs #327, CStatusMessage based on CRTP (proof of concept)
This commit is contained in:
@@ -23,6 +23,23 @@ namespace BlackMisc
|
|||||||
: m_type(type), m_severity(severity), m_message(message), m_timestamp(QDateTime::currentDateTimeUtc())
|
: m_type(type), m_severity(severity), m_message(message), m_timestamp(QDateTime::currentDateTimeUtc())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Equal?
|
||||||
|
*/
|
||||||
|
bool CStatusMessage::operator ==(const CStatusMessage &other) const
|
||||||
|
{
|
||||||
|
if (this == &other) return true;
|
||||||
|
return TupleConverter<CStatusMessage>::toTuple(*this) == TupleConverter<CStatusMessage>::toTuple(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unequal?
|
||||||
|
*/
|
||||||
|
bool CStatusMessage::operator !=(const CStatusMessage &other) const
|
||||||
|
{
|
||||||
|
return !((*this) == other);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
@@ -49,32 +66,6 @@ namespace BlackMisc
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* metaTypeId
|
|
||||||
*/
|
|
||||||
int CStatusMessage::getMetaTypeId() const
|
|
||||||
{
|
|
||||||
return qMetaTypeId<CStatusMessage>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* is a
|
|
||||||
*/
|
|
||||||
bool CStatusMessage::isA(int metaTypeId) const
|
|
||||||
{
|
|
||||||
if (metaTypeId == qMetaTypeId<CStatusMessage>()) { return true; }
|
|
||||||
return this->CValueObject::isA(metaTypeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Metadata
|
|
||||||
*/
|
|
||||||
void CStatusMessage::registerMetadata()
|
|
||||||
{
|
|
||||||
qRegisterMetaType<CStatusMessage>();
|
|
||||||
qDBusRegisterMetaType<CStatusMessage>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Validation Error
|
* Validation Error
|
||||||
*/
|
*/
|
||||||
@@ -121,30 +112,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* To JSON
|
|
||||||
*/
|
|
||||||
QJsonObject CStatusMessage::toJson() const
|
|
||||||
{
|
|
||||||
return BlackMisc::serializeJson(CStatusMessage::jsonMembers(), TupleConverter<CStatusMessage>::toTuple(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* From JSON
|
|
||||||
*/
|
|
||||||
void CStatusMessage::convertFromJson(const QJsonObject &json)
|
|
||||||
{
|
|
||||||
BlackMisc::deserializeJson(json, CStatusMessage::jsonMembers(), TupleConverter<CStatusMessage>::toTuple(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Members
|
|
||||||
*/
|
|
||||||
const QStringList &CStatusMessage::jsonMembers()
|
|
||||||
{
|
|
||||||
return TupleConverter<CStatusMessage>::jsonMembers();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Type
|
* Type
|
||||||
*/
|
*/
|
||||||
@@ -238,56 +205,6 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Compare
|
|
||||||
*/
|
|
||||||
int CStatusMessage::compareImpl(const CValueObject &otherBase) const
|
|
||||||
{
|
|
||||||
const auto &other = static_cast<const CStatusMessage &>(otherBase);
|
|
||||||
return compare(TupleConverter<CStatusMessage>::toTuple(*this), TupleConverter<CStatusMessage>::toTuple(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Marshall to DBus
|
|
||||||
*/
|
|
||||||
void CStatusMessage::marshallToDbus(QDBusArgument &argument) const
|
|
||||||
{
|
|
||||||
argument << TupleConverter<CStatusMessage>::toTuple(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Unmarshall from DBus
|
|
||||||
*/
|
|
||||||
void CStatusMessage::unmarshallFromDbus(const QDBusArgument &argument)
|
|
||||||
{
|
|
||||||
argument >> TupleConverter<CStatusMessage>::toTuple(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hash
|
|
||||||
*/
|
|
||||||
uint CStatusMessage::getValueHash() const
|
|
||||||
{
|
|
||||||
return qHash(TupleConverter<CStatusMessage>::toTuple(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Equal?
|
|
||||||
*/
|
|
||||||
bool CStatusMessage::operator ==(const CStatusMessage &other) const
|
|
||||||
{
|
|
||||||
if (this == &other) return true;
|
|
||||||
return TupleConverter<CStatusMessage>::toTuple(*this) == TupleConverter<CStatusMessage>::toTuple(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Unequal
|
|
||||||
*/
|
|
||||||
bool CStatusMessage::operator !=(const CStatusMessage &other) const
|
|
||||||
{
|
|
||||||
return !(other == (*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Property by index
|
* Property by index
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace BlackMisc
|
|||||||
/*!
|
/*!
|
||||||
* Streamable status message, e.g. from Core -> GUI
|
* Streamable status message, e.g. from Core -> GUI
|
||||||
*/
|
*/
|
||||||
class CStatusMessage : public CValueObject
|
class CStatusMessage : public CValueObjectStdTuple<CStatusMessage>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Status types
|
//! Status types
|
||||||
@@ -69,6 +69,12 @@ namespace BlackMisc
|
|||||||
//! Constructor
|
//! Constructor
|
||||||
CStatusMessage(StatusType type, StatusSeverity severity, const QString &message);
|
CStatusMessage(StatusType type, StatusSeverity severity, const QString &message);
|
||||||
|
|
||||||
|
//! Equal operator ==
|
||||||
|
bool operator ==(const CStatusMessage &other) const;
|
||||||
|
|
||||||
|
//! Unequal operator !=
|
||||||
|
bool operator !=(const CStatusMessage &other) const;
|
||||||
|
|
||||||
//! Status type
|
//! Status type
|
||||||
StatusType getType() const { return this->m_type; }
|
StatusType getType() const { return this->m_type; }
|
||||||
|
|
||||||
@@ -81,15 +87,6 @@ namespace BlackMisc
|
|||||||
//! Message empty
|
//! Message empty
|
||||||
bool isEmpty() const { return this->m_message.isEmpty(); }
|
bool isEmpty() const { return this->m_message.isEmpty(); }
|
||||||
|
|
||||||
//! \copydoc CValueObject::getValueHash()
|
|
||||||
virtual uint getValueHash() const override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::toQVariant()
|
|
||||||
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertFromQVariant
|
|
||||||
virtual void convertFromQVariant(const QVariant &variant) override { BlackMisc::setFromQVariant(this, variant); }
|
|
||||||
|
|
||||||
//! Type as string
|
//! Type as string
|
||||||
const QString &getTypeAsString() const;
|
const QString &getTypeAsString() const;
|
||||||
|
|
||||||
@@ -102,12 +99,6 @@ namespace BlackMisc
|
|||||||
//! Type as string
|
//! Type as string
|
||||||
const QString &getSeverityAsString() const;
|
const QString &getSeverityAsString() const;
|
||||||
|
|
||||||
//! \copydoc CValueObject::toJson
|
|
||||||
virtual QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertFromJson
|
|
||||||
virtual void convertFromJson(const QJsonObject &json) override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::propertyByIndex(int)
|
//! \copydoc CValueObject::propertyByIndex(int)
|
||||||
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||||
|
|
||||||
@@ -117,18 +108,6 @@ namespace BlackMisc
|
|||||||
//! To HTML
|
//! To HTML
|
||||||
QString toHtml() const;
|
QString toHtml() const;
|
||||||
|
|
||||||
//! Equal operator ==
|
|
||||||
bool operator ==(const CStatusMessage &other) const;
|
|
||||||
|
|
||||||
//! Unequal operator !=
|
|
||||||
bool operator !=(const CStatusMessage &other) const;
|
|
||||||
|
|
||||||
//! Register metadata
|
|
||||||
static void registerMetadata();
|
|
||||||
|
|
||||||
//! JSON member names
|
|
||||||
static const QStringList &jsonMembers();
|
|
||||||
|
|
||||||
//! Validation error
|
//! Validation error
|
||||||
static CStatusMessage getValidationError(const QString &message);
|
static CStatusMessage getValidationError(const QString &message);
|
||||||
|
|
||||||
@@ -145,24 +124,9 @@ namespace BlackMisc
|
|||||||
static const CIcon &convertToIcon(const CStatusMessage &statusMessage);
|
static const CIcon &convertToIcon(const CStatusMessage &statusMessage);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \copydoc CValueObject::marshallToDbus
|
|
||||||
virtual void marshallToDbus(QDBusArgument &arg) const override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::unmarshallFromDbus
|
|
||||||
virtual void unmarshallFromDbus(const QDBusArgument &arg) override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertToQString
|
//! \copydoc CValueObject::convertToQString
|
||||||
virtual QString convertToQString(bool i18n = false) const override;
|
virtual QString convertToQString(bool i18n = false) const override;
|
||||||
|
|
||||||
//! \copydoc CValueObject::getMetaTypeId
|
|
||||||
virtual int getMetaTypeId() const override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::isA
|
|
||||||
virtual bool isA(int metaTypeId) const override;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::compareImpl
|
|
||||||
virtual int compareImpl(const CValueObject &other) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage)
|
BLACK_ENABLE_TUPLE_CONVERSION(CStatusMessage)
|
||||||
StatusType m_type;
|
StatusType m_type;
|
||||||
@@ -171,7 +135,8 @@ namespace BlackMisc
|
|||||||
QDateTime m_timestamp;
|
QDateTime m_timestamp;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CStatusMessage, (o.m_type, o.m_severity, o.m_message, o.m_timestamp))
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CStatusMessage, (o.m_type, o.m_severity, o.m_message, o.m_timestamp))
|
||||||
Q_DECLARE_METATYPE(BlackMisc::CStatusMessage)
|
Q_DECLARE_METATYPE(BlackMisc::CStatusMessage)
|
||||||
|
|||||||
Reference in New Issue
Block a user