BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUI::Util::Variant Namespace Reference

Functions

bool CompatibleVariantTypes (const QVariant &oldValue, const QVariant &newValue)
 Returns true if variants has compatible types. More...
 
bool IsTheSame (const QVariant &var1, const QVariant &var2)
 Returns true if given variants have same type and value. For custom variants (e.g. ComboProperty) will always return false (see explanations in cpp file). More...
 
int VariantType (const QVariant &variant)
 Returns type of variant (additionally checks for user type). More...
 

Function Documentation

◆ CompatibleVariantTypes()

bool GUI::Util::Variant::CompatibleVariantTypes ( const QVariant &  oldValue,
const QVariant &  newValue 
)

Returns true if variants has compatible types.

Definition at line 25 of file VariantUtil.cpp.

26 {
27  // if olfValue is undefined than it is compatible with any value, otherwise newValue
28  // should have same variant type as oldValue
29 
30  if (oldValue.isValid())
31  return GUI::Util::Variant::VariantType(oldValue)
33  return true;
34 }
int VariantType(const QVariant &variant)
Returns type of variant (additionally checks for user type).
Definition: VariantUtil.cpp:17

References VariantType().

Referenced by SessionItem::setValue().

Here is the call graph for this function:

◆ IsTheSame()

bool GUI::Util::Variant::IsTheSame ( const QVariant &  var1,
const QVariant &  var2 
)

Returns true if given variants have same type and value. For custom variants (e.g. ComboProperty) will always return false (see explanations in cpp file).

Definition at line 39 of file VariantUtil.cpp.

40 {
41  // variants of different type are always reported as not the same
42  if (VariantType(var1) != VariantType(var2))
43  return false;
44 
45  // custom type variants are always reported as not the same
46  if (var1.type() == QVariant::UserType)
47  return false;
48 
49  // standard variants (based on double, int, etc) are compared by value they are holding
50  return var1 == var2;
51 }

References VariantType().

Referenced by SessionItemData::ItemData::operator==(), and SessionItemData::setData().

Here is the call graph for this function:

◆ VariantType()

int GUI::Util::Variant::VariantType ( const QVariant &  variant)

Returns type of variant (additionally checks for user type).

Definition at line 17 of file VariantUtil.cpp.

18 {
19  int result = static_cast<int>(variant.type());
20  if (result == QVariant::UserType)
21  result = variant.userType();
22  return result;
23 }

Referenced by CompatibleVariantTypes(), and IsTheSame().