QXmpp: QXmppDataFormBase Class Reference

QXmpp Version: 1.14.2

Loading...
Searching...
No Matches
QXmppDataFormBase Class Referenceabstract
Inheritance diagram for QXmppDataFormBase:

## Public Member Functions
virtual QXmppDataForm | toDataForm () const

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

## Static Protected Member Functions
static bool | fromDataForm (const QXmppDataForm &form, QXmppDataFormBase &parent)
template<typename T>
static void | serializeValue (QXmppDataForm &form, QXmppDataForm::Field::Type type, const QString &name, const T &value)
template<typename T>
static void | serializeNullable (QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const T &value)
template<typename T>
static void | serializeEmptyable (QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const T &value)
template<typename T, typename ValueConverter = T (*)(T)>
static void | serializeOptional (QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, const std::optional< T > &optional, ValueConverter convert=[](T a) { return a;})
template<typename T>
static void | serializeOptionalNumber (QXmppDataForm &form, QXmppDataForm::Field::Type type, QStringView name, std::optional< T > optional)
static void | serializeDatetime (QXmppDataForm &form, const QString &name, const QDateTime &datetime, QXmppDataForm::Field::Type type=QXmppDataForm::Field::TextSingleField)

## 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);
QXmppDataForm
Definition QXmppDataForm.h:28

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 &);
QXmppDataFormBase::fromDataForm
static bool fromDataForm(const QXmppDataForm &form, QXmppDataFormBase &parent)
Definition QXmppDataFormBase.cpp:55

Since
  QXmpp 1.5

## Member Function Documentation

## ◆ formType()

virtual QString QXmppDataFormBase::formType | ( |  | ) | const
| protectedpure virtual

Returns the 'FORM_TYPE' value of the parsed form.

Implemented in QXmppContactAddresses, QXmppMucRoomInfo, and QXmppPubSubSubAuthorization.

## ◆ fromDataForm()

bool QXmppDataFormBase::fromDataForm | ( | const QXmppDataForm & | form,
|  | QXmppDataFormBase & | output )
| staticprotected

Parses the QXmppDataForm.

## ◆ parseBool()

std::optional< bool > QXmppDataFormBase::parseBool | ( | const QVariant & | variant | ) |
| inlineprotected

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

## ◆ parseForm()

virtual void QXmppDataFormBase::parseForm | ( | const QXmppDataForm & |  | ) |
| protectedpure virtual

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

Implemented in QXmppExtensibleDataFormBase.

## ◆ parseUInt()

std::optional< quint32 > QXmppDataFormBase::parseUInt | ( | const QVariant & | variant | ) |
| inlineprotected

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

## ◆ parseULongLong()

std::optional< quint64 > QXmppDataFormBase::parseULongLong | ( | const QVariant & | variant | ) |
| inlineprotected

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

## ◆ serializeDatetime()

void QXmppDataFormBase::serializeDatetime | ( | QXmppDataForm & | form,
|  | const QString & | name,
|  | const QDateTime & | datetime,
|  | QXmppDataForm::Field::Type | type = QXmppDataForm::Field::TextSingleField )
| staticprotected

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

## ◆ serializeEmptyable()

template<typename T>

void QXmppDataFormBase::serializeEmptyable | ( | QXmppDataForm & | form,
|  | QXmppDataForm::Field::Type | type,
|  | QStringView | name,
|  | const T & | value )
| inlinestaticprotected

Adds a new field to the form if

!value.isEmpty()

.

## ◆ serializeForm()

virtual void QXmppDataFormBase::serializeForm | ( | QXmppDataForm & |  | ) | const
| protectedpure virtual

This is called the object is serialized to a QXmppDataForm. You need to create a new QXmppDataForm and serialize all fields and values.

Implemented in QXmppContactAddresses, QXmppExtensibleDataFormBase, QXmppMucRoomInfo, and QXmppPubSubSubAuthorization.

## ◆ serializeNullable()

template<typename T>

void QXmppDataFormBase::serializeNullable | ( | QXmppDataForm & | form,
|  | QXmppDataForm::Field::Type | type,
|  | QStringView | name,
|  | const T & | value )
| inlinestaticprotected

Adds a new field to the form if

!value.isNull()

.

## ◆ serializeOptional()

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; } )
| inlinestaticprotected

Adds a new field to the form if

optional.has_value()

.

## ◆ serializeOptionalNumber()

template<typename T>

void QXmppDataFormBase::serializeOptionalNumber | ( | QXmppDataForm & | form,
|  | QXmppDataForm::Field::Type | type,
|  | QStringView | name,
|  | std::optional< T > | optional )
| inlinestaticprotected

Adds a new field to the form if

optional.has_value()

. Converts the optional's value to QString using QString::number().

## ◆ serializeValue()

template<typename T>

void QXmppDataFormBase::serializeValue | ( | QXmppDataForm & | form,
|  | QXmppDataForm::Field::Type | type,
|  | const QString & | name,
|  | const T & | value )
| inlinestaticprotected

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

## ◆ toDataForm()

QXmppDataForm QXmppDataFormBase::toDataForm | ( |  | ) | const
| virtual

Serializes all fields to a QXmppDataForm.

The documentation for this class was generated from the following files:

- QXmppDataFormBase.h
- QXmppDataFormBase.cpp