QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
QgsVariantUtils Class Reference

Contains utility functions for working with QVariants and QVariant types. More...

#include <qgsvariantutils.h>

Static Public Member Functions

static QVariant createNullVariant (QMetaType::Type metaType)
 Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
static QString displayString (const QVariant &variant, int precision=-1)
 Returns a localized representation of value with the given precision, if precision is -1 then precision is guessed from the default QVariant::toString output.
static bool isNull (const QVariant &variant, bool silenceNullWarnings=false)
 Returns true if the specified variant should be considered a NULL value.
static bool isNumericType (QMetaType::Type metaType)
 Returns true if the specified metaType is a numeric type.
static bool isUnsetAttributeValue (const QVariant &variant)
 Check if the variant is a QgsUnsetAttributeValue.
static QVariant::Type metaTypeToVariantType (QMetaType::Type metaType)
 Converts a QMetaType::Type to a QVariant::Type.
static QString typeToDisplayString (QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType)
 Returns a user-friendly translated string representing a QVariant type.
static Q_DECL_DEPRECATED QString typeToDisplayString (QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
 Returns a user-friendly translated string representing a QVariant type.
static QMetaType::Type variantTypeToMetaType (QVariant::Type variantType)
 Converts a QVariant::Type to a QMetaType::Type.

Detailed Description

Contains utility functions for working with QVariants and QVariant types.

Since
QGIS 3.24

Definition at line 31 of file qgsvariantutils.h.

Member Function Documentation

◆ createNullVariant()

QVariant QgsVariantUtils::createNullVariant ( QMetaType::Type metaType)
static

Helper method to properly create a null QVariant from a metaType Returns the created QVariant.

Definition at line 628 of file qgsvariantutils.cpp.

◆ displayString()

QString QgsVariantUtils::displayString ( const QVariant & variant,
int precision = -1 )
static

Returns a localized representation of value with the given precision, if precision is -1 then precision is guessed from the default QVariant::toString output.

The current localization settings are applied.

For strings, the input text is returned unchanged. For lists, a single string is generated with elements separated by ‘;’.

Note
Precision is ignored for integers.
Since
QGIS 4.0

Definition at line 638 of file qgsvariantutils.cpp.

◆ isNull()

bool QgsVariantUtils::isNull ( const QVariant & variant,
bool silenceNullWarnings = false )
static

Returns true if the specified variant should be considered a NULL value.

This method is more rigorous vs QVariant::isNull(), which will return false on newer Qt versions for tests like QVariant( QDateTime() ).isNull().

Since
QGIS 3.28

Definition at line 172 of file qgsvariantutils.cpp.

◆ isNumericType()

bool QgsVariantUtils::isNumericType ( QMetaType::Type metaType)
static

Returns true if the specified metaType is a numeric type.

Since
QGIS 3.40

Definition at line 476 of file qgsvariantutils.cpp.

◆ isUnsetAttributeValue()

bool QgsVariantUtils::isUnsetAttributeValue ( const QVariant & variant)
static

Check if the variant is a QgsUnsetAttributeValue.

Note
Not available in Python bindings
Since
QGIS 3.44

Definition at line 623 of file qgsvariantutils.cpp.

◆ metaTypeToVariantType()

QVariant::Type QgsVariantUtils::metaTypeToVariantType ( QMetaType::Type metaType)
static

Converts a QMetaType::Type to a QVariant::Type.

Warning
Not all QMetaType::Type values can be represented as a QVariant::Type. If no conversion is possible, QVariant::UserType will be returned. Some conversions are lossy, in that the QVariant::Type cannot represent the full range of values possible in QMetaType::Type. In these cases the returned type will be an "expanded" type capable of storing the full range of values possible in the original type.
See also
variantTypeToMetaType()
Since
QGIS 3.36

Definition at line 503 of file qgsvariantutils.cpp.

◆ typeToDisplayString() [1/2]

QString QgsVariantUtils::typeToDisplayString ( QMetaType::Type type,
QMetaType::Type subType = QMetaType::Type::UnknownType )
static

Returns a user-friendly translated string representing a QVariant type.

The optional subType can be used to specify the type of variant list or map values.

Definition at line 40 of file qgsvariantutils.cpp.

◆ typeToDisplayString() [2/2]

QString QgsVariantUtils::typeToDisplayString ( QVariant::Type type,
QVariant::Type subType = QVariant::Type::Invalid )
static

Returns a user-friendly translated string representing a QVariant type.

The optional subType can be used to specify the type of variant list or map values.

Deprecated
QGIS 3.38. Use the method with a QMetaType::Type argument instead.

Definition at line 167 of file qgsvariantutils.cpp.

◆ variantTypeToMetaType()

QMetaType::Type QgsVariantUtils::variantTypeToMetaType ( QVariant::Type variantType)
static

Converts a QVariant::Type to a QMetaType::Type.

See also
metaTypeToVariantType()
Since
QGIS 3.36

Definition at line 497 of file qgsvariantutils.cpp.


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