#include "avinformationmessage.h" #include "blackmiscfreefunctions.h" namespace BlackMisc { namespace Aviation { /* * Convert to string */ QString CInformationMessage::convertToQString(bool /** i18n **/) const { return this->m_message; } /* * metaTypeId */ int CInformationMessage::getMetaTypeId() const { return qMetaTypeId(); } /* * is a */ bool CInformationMessage::isA(int metaTypeId) const { if (metaTypeId == qMetaTypeId()) { return true; } return this->CValueObject::isA(metaTypeId); } /* * Compare */ int CInformationMessage::compareImpl(const CValueObject &otherBase) const { const auto &other = static_cast(otherBase); return compare(TupleConverter::toTuple(*this), TupleConverter::toTuple(other)); } /* * Marshall to DBus */ void CInformationMessage::marshallToDbus(QDBusArgument &argument) const { argument << TupleConverter::toTuple(*this); } /* * Unmarshall from DBus */ void CInformationMessage::unmarshallFromDbus(const QDBusArgument &argument) { argument >> TupleConverter::toTuple(*this); } /* * Equal? */ bool CInformationMessage::operator ==(const CInformationMessage &other) const { if (this == &other) return true; return TupleConverter::toTuple(*this) == TupleConverter::toTuple(other); } /* * Unequal? */ bool CInformationMessage::operator !=(const CInformationMessage &other) const { return !((*this) == other); } /* * Hash */ uint CInformationMessage::getValueHash() const { return qHash(TupleConverter::toTuple(*this)); } /* * Register metadata */ void CInformationMessage::registerMetadata() { qRegisterMetaType(); qDBusRegisterMetaType(); } /* * JSON members */ const QStringList &CInformationMessage::jsonMembers() { return TupleConverter::jsonMembers(); } /* * To JSON */ QJsonObject CInformationMessage::toJson() const { return BlackMisc::serializeJson(CInformationMessage::jsonMembers(), TupleConverter::toTuple(*this)); } /* * To JSON */ void CInformationMessage::fromJson(const QJsonObject &json) { this->m_message = json.value("m_message").toString(); this->m_type = static_cast(qRound(json.value("m_type").toDouble())); this->m_receivedTimestamp = QDateTime::fromString(json.value("m_receivedTimestamp").toString()); } /* * Type as string */ const QString &CInformationMessage::getTypeAsString() const { switch (this->m_type) { case ATIS: { static const QString atis("ATIS"); return atis; } case METAR: { static const QString metar("METAR"); return metar; } case TAF: { static const QString taf("TAF"); return taf; } default: { static const QString ds("unknown"); return ds; } } } } // namespace } // namespace