QXmpp Version: 1.10.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
QXmppDataFormBase Class Referenceabstract
Inheritance diagram for QXmppDataFormBase:
Inheritance graph
[legend]

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

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

Member Function Documentation

◆ formType()

QXmppDataFormBase::formType ( ) const
protectedpure virtual

Returns the 'FORM_TYPE' value of the parsed form.

Implemented in QXmppPubSubSubAuthorization.

◆ fromDataForm()

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

Parses the QXmppDataForm.

◆ parseBool()

QXmppDataFormBase::parseBool ( const QVariant &  variant)
inlineprotected

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

◆ parseForm()

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()

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()

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 >
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()

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 QXmppExtensibleDataFormBase, and QXmppPubSubSubAuthorization.

◆ serializeNullable()

template<typename T >
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)>
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 >
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 >
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: