QXmppDataFormBase Class

Header: #include <QXmppDataFormBase>
Since: QXmpp 1.5
Inherited By:

QXmppExtensibleDataFormBase

Public Functions

virtual QXmppDataForm toDataForm() const

Protected Functions

virtual QString formType() const = 0
std::optional<bool> parseBool(const QVariant &variant)
virtual void parseForm(const QXmppDataForm &form) = 0
std::optional<quint32> parseUInt(const QVariant &variant)
std::optional<quint64> parseULongLong(const QVariant &variant)
virtual void serializeForm(QXmppDataForm &form) const = 0

Static Protected Members

bool fromDataForm(const QXmppDataForm &form, QXmppDataFormBase &output)
void serializeDatetime(QXmppDataForm &form, const QString &name, const QDateTime &datetime, QXmppDataForm::Field::Type type = QXmppDataForm::Field::TextSingleField)
void serializeEmptyable(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const T &value)
void serializeNullable(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const T &value)
void serializeOptional(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const std::optional<T> &optional, ValueConverter convert = [](T a) { return a; })
void serializeOptionalNumber(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, std::optional<T> optional)
void serializeValue(QXmppDataForm &form, QXmppDataForm::Field::Type type, const QString &name, const T &value)

Detailed Description

QXmppDataFormBase is an abstract class types that can be serialized to data forms.

QXmppDataFormBase based types can easily be converted to QXmppDataForms, it is as simple as this:

 MyDataFormBase foo;
 QXmppDataForm dataForm(foo);

To make this work, you will need to at least implement the toDataForm() method. For parsing your type you should also create a static creator method, like this:

 static std::optional<MyType> fromDataForm(const QXmppDataForm &);

Member Function Documentation

[pure virtual protected] QString QXmppDataFormBase::formType() const

Returns the 'FORM_TYPE' value of the parsed form.

[static protected] bool QXmppDataFormBase::fromDataForm(const QXmppDataForm &form, QXmppDataFormBase &output)

Parses the QXmppDataForm. Returns true on success.

output and form.

[protected] std::optional<bool> QXmppDataFormBase::parseBool(const QVariant &variant)

Returns the contained boolean value if the QVariant variant contains a bool.

[pure virtual protected] void QXmppDataFormBase::parseForm(const QXmppDataForm &form)

This is called when a QXmppDataForm is parsed. You can parse all values from the given form and its fields.

[protected] std::optional<quint32> QXmppDataFormBase::parseUInt(const QVariant &variant)

Parses an unsigned int from a QVariant (QString) variant. Returns std::nullopt if no number could be parsed.

[protected] std::optional<quint64> QXmppDataFormBase::parseULongLong(const QVariant &variant)

Parses an unsigned long long from a QVariant (QString) variant. Returns std::nullopt if no number could be parsed.

[static protected] void QXmppDataFormBase::serializeDatetime(QXmppDataForm &form, const QString &name, const QDateTime &datetime, QXmppDataForm::Field::Type type = QXmppDataForm::Field::TextSingleField)

Adds a new field to the form if the passed QDateTime is valid and formats it as ISO timestamp and always uses UTC.

name, type, datetime, and form.

[static protected] template <typename T> void QXmppDataFormBase::serializeEmptyable(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const T &value)

Adds a new field of type and name to form if !value.isEmpty() for value.

[pure virtual protected] void QXmppDataFormBase::serializeForm(QXmppDataForm &form) const

This is called when the object is serialized to a QXmppDataForm. You need to serialize all fields and values into form.

[static protected] template <typename T> void QXmppDataFormBase::serializeNullable(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const T &value)

Adds a new field of type and name to form if !value.isNull() for value.

[static protected] template <typename T, typename ValueConverter = T (*)(T)> void QXmppDataFormBase::serializeOptional(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const std::optional<T> &optional, ValueConverter convert = [](T a) { return a; })

Adds a new field of type and name to form if optional.has_value() for optional, applying convert to the contained value first.

[static protected] template <typename T> void QXmppDataFormBase::serializeOptionalNumber(QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, std::optional<T> optional)

Adds a new field of type and name to form if optional.has_value() for optional, converting the contained value to QString using QString::number().

[static protected] template <typename T> void QXmppDataFormBase::serializeValue(QXmppDataForm &form, QXmppDataForm::Field::Type type, const QString &name, const T &value)

Adds a new field to form with the given field type, field name and value.

[virtual] QXmppDataForm QXmppDataFormBase::toDataForm() const

Serializes all fields to a QXmppDataForm.