swift
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
swift::misc::CVariant Class Reference

Wrapper around QVariant which provides transparent access to CValueObject methods of the contained object if it is registered with swift::misc::registerMetaValueType. More...

Inheritance diagram for swift::misc::CVariant:
[legend]

Public Member Functions

 CVariant ()
 Default constructor.
 
 CVariant (const CVariant &)=default
 Copy constructor.
 
 CVariant (CVariant &&other) noexcept=default
 Move constructor.
 
 CVariant (const QVariant &var)
 Construct from a QVariant.
 
 CVariant (QVariant &&var) noexcept
 Move-construct from a QVariant.
 
 CVariant (QVariant::Type type)
 Construct a null variant of the given type.
 
 CVariant (int)=delete
 Avoid unexpected implicit cast to QVariant::Type. (Use CVariant::from() instead.)
 
 CVariant (const QString &string)
 Implicit conversion from QString.
 
 CVariant (const char *string)
 Implicit conversion from C string.
 
 CVariant (int typeId, const void *copy)
 Construct a variant from the given type and opaque pointer.
 
void reset (const QVariant &var)
 Change the internal QVariant.
 
void reset (QVariant &&var)
 Change the internal QVariant.
 
CVariantoperator= (const CVariant &other)=default
 Copy assignment operator.
 
CVariantoperator= (CVariant &&other) noexcept=default
 Move assignment operatior.
 
CVariantoperator= (const QVariant &var)
 Change the internal QVariant.
 
CVariantoperator= (QVariant &&var) noexcept
 Change the internal QVariant.
 
void swap (CVariant &other) noexcept
 Swap this variant with another.
 
void swap (QVariant &other) noexcept
 Swap the internal QVariant with another.
 
template<typename T >
void setValue (T &&value)
 Change the value.
 
template<typename T >
void set (T &&value)
 Synonym for setValue().
 
template<typename T >
value () const
 Return the value converted to the type T.
 
template<typename T >
to () const
 Synonym for value().
 
template<typename T >
valueOrDefault (T def) const
 Returns the value converted to the type T, or a default if it can not be converted. More...
 
const QVariant & getQVariant () const
 Return the internal QVariant.
 
 operator const QVariant & () const
 Return the internal QVariant.
 
 operator QVariant () &&
 Return the internal QVariant.
 
bool canConvert (int typeId) const
 True if this variant can be converted to the type with the given metatype ID.
 
template<typename T >
bool canConvert () const
 True if this variant can be converted to the type T.
 
bool convert (int typeId)
 Convert this variant to the type with the given metatype ID and return true if successful.
 
QString convertToQString (bool i18n=false) const
 Cast as QString. More...
 
bool isIntegral () const
 True if this variant's type is an integral type.
 
bool isArithmetic () const
 True if this variant's type is an integral or floating-point type.
 
bool toBool () const
 Convert this variant to a bool.
 
int toInt (bool *ok=nullptr) const
 Convert this variant to an integer.
 
qlonglong toLongLong (bool *ok=nullptr) const
 Convert this variant to a longlong integer.
 
qulonglong toULongLong (bool *ok=nullptr) const
 Convert this variant to a unsigned longlong integer.
 
qint64 toQInt64 (bool *ok=nullptr) const
 COnvert to qint64, which is used for all timestamps.
 
double toDouble (bool *ok=nullptr) const
 Convert this variant to double.
 
QDateTime toDateTime () const
 Convert this variant to QDateTime.
 
QUrl toUrl () const
 Convert this variant to QUrl.
 
void clear ()
 Set the variant to null.
 
bool isNull () const
 True if this variant is null.
 
bool isValid () const
 True if this variant is valid.
 
QMetaType::Type type () const
 Return the metatype ID of the value in this variant, or QMetaType::User if it is a user type.
 
const char * typeName () const
 Return the typename of the value in this variant.
 
int userType () const
 Return the metatype ID of the value in this variant.
 
QMetaType metaType () const
 Return the QMetaType of the type in this variant.
 
QJsonObject toJson () const
 Cast to JSON object. More...
 
QString toJsonString (QJsonDocument::JsonFormat format=QJsonDocument::Indented) const
 Convenience function JSON as string.
 
void convertFromJson (const QJsonObject &json)
 Assign from JSON object. More...
 
CStatusMessage convertFromJsonNoThrow (const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix)
 Call convertFromJson, catch any CJsonException that is thrown and return it as CStatusMessage.
 
QJsonObject toMemoizedJson () const
 To compact JSON format.
 
void convertFromMemoizedJson (const QJsonObject &json, bool allowFallbackToJson)
 From compact JSON format.
 
CStatusMessage convertFromMemoizedJsonNoThrow (const QJsonObject &json, const CLogCategoryList &categories, const QString &prefix)
 Call convertFromMemoizedJson, catch any CJsonException that is thrown and return it as CStatusMessage.
 
void marshallToDbus (QDBusArgument &argument) const
 Marshall without begin/endStructure, for when composed within another object. More...
 
void unmarshallFromDbus (const QDBusArgument &argument)
 Unmarshall without begin/endStructure, for when composed within another object. More...
 
void marshalToDataStream (QDataStream &stream) const
 Marshal a value to a QDataStream. More...
 
void unmarshalFromDataStream (QDataStream &stream)
 Unmarshal a value from a QDataStream. More...
 
void setPropertyByIndex (CPropertyIndexRef index, const QVariant &variant)
 Set property by index. More...
 
QVariant propertyByIndex (swift::misc::CPropertyIndexRef index) const
 Property by index. More...
 
bool equalsPropertyByIndex (const CVariant &compareValue, CPropertyIndexRef index) const
 Is given variant equal to value of property index? More...
 
QPixmap toPixmap () const
 Corresponding pixmap. More...
 
CIcons::IconIndex toIcon () const
 As icon, not implemented by all classes. More...
 
int getMetaTypeId () const
 Returns the Qt meta type ID of this object. More...
 
QString getClassName () const
 Class name. More...
 
bool isA (int metaTypeId) const
 Returns true if this object is an instance of the class with the given meta type ID, or one of its subclasses. More...
 
bool matches (const CVariant &event) const
 If this is an event subscription, return true if it matches the given event.
 
- Public Member Functions inherited from swift::misc::mixin::String< CVariant >
QString toQString (bool i18n=false) const
 Cast as QString.
 
std::string toStdString (bool i18n=false) const
 To std string.
 
QString stringForStreaming () const
 String for streaming operators.
 

Static Public Member Functions

template<typename T >
static CVariant fromValue (T &&value)
 Construct a variant from a value.
 
template<typename T >
static CVariant from (T &&value)
 Synonym for fromValue().
 
static void registerMetadata ()
 Register metadata. More...
 

Friends

size_t qHash (const CVariant &var)
 qHash overload, needed for storing value in a QSet. More...
 
int compare (const CVariant &a, const CVariant &b)
 Return negative, zero, or positive if a is less than, equal to, or greater than b. More...
 

Detailed Description

Wrapper around QVariant which provides transparent access to CValueObject methods of the contained object if it is registered with swift::misc::registerMetaValueType.

Definition at line 59 of file variant.h.

Member Function Documentation

◆ convertFromJson()

void swift::misc::CVariant::convertFromJson ( const QJsonObject &  json)

Assign from JSON object.

◆ convertToQString()

QString swift::misc::CVariant::convertToQString ( bool  i18n = false) const

Cast as QString.

◆ equalsPropertyByIndex()

bool swift::misc::CVariant::equalsPropertyByIndex ( const CVariant compareValue,
CPropertyIndexRef  index 
) const

Is given variant equal to value of property index?

◆ getClassName()

QString swift::misc::CVariant::getClassName ( ) const

Class name.

◆ getMetaTypeId()

int swift::misc::CVariant::getMetaTypeId ( ) const

Returns the Qt meta type ID of this object.

Remarks
for CVariant this returns the id of CVariant, not of the encapsulated object. valueVariant.userType()` returns metatype of the contained object

◆ isA()

bool swift::misc::CVariant::isA ( int  metaTypeId) const

Returns true if this object is an instance of the class with the given meta type ID, or one of its subclasses.

◆ marshallToDbus()

void swift::misc::CVariant::marshallToDbus ( QDBusArgument &  argument) const

Marshall without begin/endStructure, for when composed within another object.

◆ marshalToDataStream()

void swift::misc::CVariant::marshalToDataStream ( QDataStream &  stream) const

Marshal a value to a QDataStream.

◆ propertyByIndex()

QVariant swift::misc::CVariant::propertyByIndex ( swift::misc::CPropertyIndexRef  index) const

Property by index.

◆ registerMetadata()

static void swift::misc::CVariant::registerMetadata ( )
static

Register metadata.

◆ setPropertyByIndex()

void swift::misc::CVariant::setPropertyByIndex ( CPropertyIndexRef  index,
const QVariant &  variant 
)

Set property by index.

◆ toIcon()

CIcons::IconIndex swift::misc::CVariant::toIcon ( ) const

As icon, not implemented by all classes.

◆ toJson()

QJsonObject swift::misc::CVariant::toJson ( ) const

Cast to JSON object.

◆ toPixmap()

QPixmap swift::misc::CVariant::toPixmap ( ) const

Corresponding pixmap.

◆ unmarshalFromDataStream()

void swift::misc::CVariant::unmarshalFromDataStream ( QDataStream &  stream)

Unmarshal a value from a QDataStream.

◆ unmarshallFromDbus()

void swift::misc::CVariant::unmarshallFromDbus ( const QDBusArgument &  argument)

Unmarshall without begin/endStructure, for when composed within another object.

◆ valueOrDefault()

template<typename T >
T swift::misc::CVariant::valueOrDefault ( def) const
inline

Returns the value converted to the type T, or a default if it can not be converted.

Parameter is passed by value to avoid odr-using the argument in case it is an inline-initialized static const integral data member without a definition (ยง9.4.2/3).

Definition at line 185 of file variant.h.

Friends And Related Function Documentation

◆ compare

int compare ( const CVariant a,
const CVariant b 
)
friend

Return negative, zero, or positive if a is less than, equal to, or greater than b.

Definition at line 302 of file variant.h.

◆ qHash

size_t qHash ( const CVariant var)
friend

qHash overload, needed for storing value in a QSet.

Definition at line 103 of file variant.h.


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