refs #192, enable value objects for JSON:

* from/toJson methods
* jsonMembers where applicable
This commit is contained in:
Klaus Basan
2014-03-26 18:44:17 +01:00
parent 586e1e4053
commit 88fb9e8832
47 changed files with 910 additions and 276 deletions

View File

@@ -36,13 +36,13 @@ namespace BlackMisc
TAF
};
/*!
* Default constructor.
*/
CInformationMessage(CInformationMessage::InformationType type = CInformationMessage::Unspecified)
: m_type(type), m_receivedTimestamp(QDateTime::currentDateTimeUtc())
//! \brief Default constructor.
CInformationMessage() : m_type(CInformationMessage::Unspecified), m_receivedTimestamp(QDateTime::currentDateTimeUtc())
{}
//! \brief Information message of type
explicit CInformationMessage(InformationType type) : m_type(type) {}
/*!
* \brief Information message of type
* \param type
@@ -52,138 +52,91 @@ namespace BlackMisc
: m_type(type), m_message(message)
{}
/*!
* \copydoc CValueObject::toQVariant
*/
//! \copydoc CValueObject::toQVariant
virtual QVariant toQVariant() const override
{
return QVariant::fromValue(*this);
}
/*!
* \brief Equal operator ==
* \param other
* @return
*/
//! \brief Equal operator ==
bool operator ==(const CInformationMessage &other) const;
/*!
* \brief operator !=
* \param other
* \return
*/
//! \brief operator !=
bool operator !=(const CInformationMessage &other) const;
/*!
* Get message.
* \return
*/
//! \brief Get message.
const QString &getMessage() const { return m_message; }
/*!
* \brief Is a message available
* \return
*/
//! \brief Is a message available
bool hasMessage() const { return !m_message.isEmpty(); }
/*!
* \brief Set message
* \param message
*/
//! \brief Set message
void setMessage(const QString &message)
{
this->m_receivedTimestamp = QDateTime::currentDateTimeUtc();
this->m_message = message;
}
/*!
* \brief Append message part
* \param messagePart
*/
//! \brief Append message part
void appendMessage(const QString &messagePart)
{
this->m_receivedTimestamp = QDateTime::currentDateTimeUtc();
this->m_message.append(messagePart);
}
/*!
* \brief Type as string
* \return
*/
//! \brief Type as string
const QString &getTypeAsString() const;
/*!
* \brief Type
* \return
*/
//! \brief Type
InformationType getType() const { return this->m_type; }
/*!
* \brief Set type
* \param type
*/
//! \brief Set type
void setType(InformationType type) { this->m_type = type; }
/*!
* \brief Timestamp
* \return
*/
//! \brief Timestamp
const QDateTime &getReceivedTimestamp() const { return this->m_receivedTimestamp; }
/*!
* \brief Received before n ms
* \return
*/
//! \brief Received before n ms
qint64 timeDiffReceivedMs() const
{
return this->m_receivedTimestamp.msecsTo(QDateTime::currentDateTimeUtc());
}
/*!
* \brief Is empty
* \return
*/
//! \brief Is empty?
bool isEmpty() const { return this->m_message.isEmpty(); }
/*!
* \copydoc CValueObject::getValueHash
*/
//! \copydoc CValueObject::getValueHash
virtual uint getValueHash() const override;
/*!
* \brief Register metadata
*/
//! \copydoc CValueObject::toJson
virtual QJsonObject toJson() const override;
//! \copydoc CValueObject::fromJson
void fromJson(const QJsonObject &json) override;
//! \brief Register metadata
static void registerMetadata();
//! \brief Members
static const QStringList &jsonMembers();
protected:
/*!
* \copydoc CValueObject::convertToQString
*/
//! \copydoc CValueObject::convertToQString
virtual QString convertToQString(bool i18n = false) const override;
/*!
* \copydoc CValueObject::getMetaTypeId
*/
//! \copydoc CValueObject::getMetaTypeId
virtual int getMetaTypeId() const override;
/*!
* \copydoc CValueObject::isA
*/
//! \copydoc CValueObject::isA
virtual bool isA(int metaTypeId) const override;
/*!
* \copydoc CValueObject::compareImpl
*/
//! \copydoc CValueObject::compareImpl
virtual int compareImpl(const CValueObject &other) const override;
/*!
* \copydoc CValueObject::marshallToDbus
*/
//! \copydoc CValueObject::marshallToDbus
virtual void marshallToDbus(QDBusArgument &argument) const override;
/*!
* \copydoc CValueObject::unmarshallFromDbus
*/
//! \copydoc CValueObject::unmarshallFromDbus
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
private: