While QVariant::Type can be directly static_cast to QMetaType::Type,
the reverse is not true and many QMetaType::Type values don't
have exact counterparts in QVariant::Type.
So we use the logic:
- If no conversion is possible, QVariant::UserType will be returned.
Note that we don't use QVariant::Invalid, as the value DOES have
a type, it's just one which needs special handling (just like user
types do)
- 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. Eg we map QMetaType::Type::Float to QVariant::Type::Double
QgsVariantUtils::variantTypeToMetaType is included for clarity/
completeness/future proof-ness, even though it currently can
be handled with just a simple static cast.
This method restores the Qt 5 logic for testing for null variants,
where for core Qt types the isNull check is forwarded to the actual
data type.
E.g. on Qt 5: QVariant( QDateTime()).isNull() is true, but
on Qt 6 it's false
This breaks a LOT of assumptions made throughout QGIS. The new
helper method avoids this breakage by ensuring we follow the Qt 5
logic also on Qt 6 builds, and also gives us the option to extend
this logic for user types (e.g QVariant( QgsGeometry() ).isNull() could
return true). (That's not included here)