BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SessionItemUtils Namespace Reference

Functions

QVariant CheckStateRole (const SessionItem &item)
 Returns check state for given item. More...
 
bool CompatibleVariantTypes (const QVariant &oldValue, const QVariant &newValue)
 Returns true if variants has compatible types. More...
 
QVariant DecorationRole (const SessionItem &item)
 Returns tooltip for given item. More...
 
QVariant ForegroundRole (const SessionItem &item)
 Returns text color for given item. More...
 
GroupInfo GetGroupInfo (const QString &group_type)
 Returns GroupInfo for group property construction. More...
 
bool HasOwnAbundance (const SessionItem *item)
 
bool IsPositionRelated (const SessionItem &item)
 Returns true if current item is related to the position on sample editor canvas. More...
 
bool IsTheSame (const QVariant &var1, const QVariant &var2)
 Returns true if given variants have same type and value. More...
 
bool IsValidGroup (const QString &group_type)
 Returns true if there is registered group. More...
 
int ParentRow (const SessionItem &item)
 Returns the index of the given item within its parent. Returns -1 when no parent is set. More...
 
int ParentVisibleRow (const SessionItem &item)
 Returns the row of the given item within its parent not accounting for all hidden items above. More...
 
QVariant ToolTipRole (const SessionItem &item, int ncol=0)
 Returns tooltip for given item. More...
 
int VariantType (const QVariant &variant)
 Returns type of variant (additionally checks for user type). More...
 

Function Documentation

◆ CheckStateRole()

QVariant SessionItemUtils::CheckStateRole ( const SessionItem item)

Returns check state for given item.

Definition at line 93 of file SessionItemUtils.cpp.

94 {
95  if (item.value().type() == QVariant::Bool)
96  return item.value().toBool() ? Qt::Checked : Qt::Unchecked;
97  return QVariant();
98 }
QVariant value() const
Get value.

References SessionItem::value().

Referenced by ModelView::ViewDataItem::data(), MultiComboPropertyEditor::initEditor(), ModelView::SelectableComboBoxEditor::onModelDataChanged(), and ModelView::SelectableComboBoxEditor::update_components().

Here is the call graph for this function:

◆ CompatibleVariantTypes()

bool SessionItemUtils::CompatibleVariantTypes ( const QVariant &  oldValue,
const QVariant &  newValue 
)

Returns true if variants has compatible types.

Definition at line 118 of file SessionItemUtils.cpp.

119 {
120  // if olfValue is undefined than it is compatible with any value, otherwise newValue
121  // should have same variant type as oldValue
122 
123  if (oldValue.isValid())
124  return SessionItemUtils::VariantType(oldValue) == SessionItemUtils::VariantType(newValue);
125  else
126  return true;
127 }
int VariantType(const QVariant &variant)
Returns type of variant (additionally checks for user type).

References VariantType().

Referenced by SessionItem::setValue().

Here is the call graph for this function:

◆ DecorationRole()

QVariant SessionItemUtils::DecorationRole ( const SessionItem item)

Returns tooltip for given item.

Definition at line 85 of file SessionItemUtils.cpp.

86 {
87  if (item.value().canConvert<ExternalProperty>())
88  return QIcon(item.value().value<ExternalProperty>().pixmap());
89 
90  return QVariant();
91 }
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
QPixmap pixmap() const

References ExternalProperty::pixmap(), and SessionItem::value().

Referenced by SessionDecorationModel::data(), qdesigner_internal::WidgetBoxCategoryModel::data(), AbstractDataLoaderResultModel::data(), RealDataTreeModel::data(), ModelView::ViewDataItem::data(), TEST_F(), and ModelView::ExternalPropertyComboEditor::update_components().

Here is the call graph for this function:

◆ ForegroundRole()

QVariant SessionItemUtils::ForegroundRole ( const SessionItem item)

Returns text color for given item.

Definition at line 68 of file SessionItemUtils.cpp.

69 {
70  return item.isEnabled() ? QVariant() : QColor(Qt::gray);
71 }
bool isEnabled() const

References SessionItem::isEnabled().

Referenced by ModelView::PropertyFlatView::PropertyFlatViewImpl::connect_model(), SessionDecorationModel::data(), AbstractDataLoaderResultModel::data(), RealDataTreeModel::data(), FitParameterProxyModel::data(), ModelView::ViewItem::data(), ModelView::Utils::ItemRoleToQtRole(), and TEST_F().

Here is the call graph for this function:

◆ GetGroupInfo()

GroupInfo SessionItemUtils::GetGroupInfo ( const QString &  group_type)

Returns GroupInfo for group property construction.

Definition at line 105 of file SessionItemUtils.cpp.

106 {
107  return groupInfoCatalog().groupInfo(group_type);
108 }

Referenced by SessionItem::addGroupProperty().

◆ HasOwnAbundance()

bool SessionItemUtils::HasOwnAbundance ( const SessionItem item)

Definition at line 156 of file SessionItemUtils.cpp.

157 {
158  static QStringList special_parent = parents_with_abundance();
159  return item ? special_parent.contains(item->modelType()) : false;
160 }
QString modelType() const
Get model type.

References SessionItem::modelType().

Referenced by MesoCrystalItem::MesoCrystalItem(), ParticleCompositionItem::ParticleCompositionItem(), ParticleCoreShellItem::ParticleCoreShellItem(), and ParticleItem::updatePropertiesAppearance().

Here is the call graph for this function:

◆ IsPositionRelated()

bool SessionItemUtils::IsPositionRelated ( const SessionItem item)

Returns true if current item is related to the position on sample editor canvas.

Definition at line 146 of file SessionItemUtils.cpp.

147 {
148  if (item.modelType() == "Property"
151  return true;
152 
153  return false;
154 }
static const QString P_XPOS
static const QString P_YPOS
QString displayName() const
Get display name of item, append index if ambigue.

References SessionItem::displayName(), SessionItem::modelType(), SessionGraphicsItem::P_XPOS, and SessionGraphicsItem::P_YPOS.

Referenced by PySampleWidget::onDataChanged(), and RealSpaceCanvas::onDataChanged().

Here is the call graph for this function:

◆ IsTheSame()

bool SessionItemUtils::IsTheSame ( const QVariant &  var1,
const QVariant &  var2 
)

Returns true if given variants have same type and value.

For custom variants (ComboProperty, ExternalProperty) will always return false (see explanations in cpp file).

Definition at line 132 of file SessionItemUtils.cpp.

133 {
134  // variants of different type are always reported as not the same
135  if (VariantType(var1) != VariantType(var2))
136  return false;
137 
138  // custom type variants are always reported as not the same
139  if (var1.type() == QVariant::UserType)
140  return false;
141 
142  // standard variants (based on double, int, etc) are compared by value they are holding
143  return var1 == var2;
144 }

References VariantType().

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

Here is the call graph for this function:

◆ IsValidGroup()

bool SessionItemUtils::IsValidGroup ( const QString &  group_type)

Returns true if there is registered group.

Definition at line 100 of file SessionItemUtils.cpp.

101 {
102  return groupInfoCatalog().containsGroup(group_type);
103 }

Referenced by SessionItem::addGroupProperty().

◆ ParentRow()

int SessionItemUtils::ParentRow ( const SessionItem item)

Returns the index of the given item within its parent. Returns -1 when no parent is set.

Definition at line 43 of file SessionItemUtils.cpp.

44 {
45  if (item.parent())
46  return item.parent()->rowOfChild(const_cast<SessionItem*>(&item));
47  return -1;
48 }
int rowOfChild(SessionItem *child) const
Returns row index of given child.
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73

References SessionItem::parent(), and SessionItem::rowOfChild().

Referenced by FitParameterProxyModel::indexOfItem(), SessionModel::parent(), and FitParameterProxyModel::parent().

Here is the call graph for this function:

◆ ParentVisibleRow()

int SessionItemUtils::ParentVisibleRow ( const SessionItem item)

Returns the row of the given item within its parent not accounting for all hidden items above.

Returns -1 when no parent set or item is hidden.

Definition at line 50 of file SessionItemUtils.cpp.

51 {
52  int result(-1);
53 
54  if (!item.parent() || !item.isVisible())
55  return result;
56 
57  for (auto child : item.parent()->children()) {
58  if (child->isVisible())
59  ++result;
60 
61  if (&item == child)
62  return result;
63  }
64 
65  return result;
66 }
bool isVisible() const
QVector< SessionItem * > children() const
Returns vector of all children.

References SessionItem::children(), SessionItem::isVisible(), and SessionItem::parent().

Here is the call graph for this function:

◆ ToolTipRole()

QVariant SessionItemUtils::ToolTipRole ( const SessionItem item,
int  ncol = 0 
)

Returns tooltip for given item.

Definition at line 73 of file SessionItemUtils.cpp.

74 {
75  QString result = item.toolTip();
76  if (result.isEmpty()) {
77  result = item.displayName();
78  if (ncol == 1 && item.value().canConvert<QString>())
79  result = item.value().toString();
80  }
81 
82  return QVariant(result);
83 }
QString toolTip() const

References SessionItem::displayName(), SessionItem::toolTip(), and SessionItem::value().

Referenced by SessionModel::data(), qdesigner_internal::WidgetBoxCategoryModel::data(), AbstractDataLoaderResultModel::data(), RealDataTreeModel::data(), FitParameterProxyModel::data(), ModelView::ViewItem::data(), FitParameterProxyModel::headerData(), ModelView::Utils::ItemRoleToQtRole(), SessionItem::setToolTip(), TEST_F(), SessionItem::toolTip(), and PropertyWidgetItem::updateItemRoles().

Here is the call graph for this function:

◆ VariantType()

int SessionItemUtils::VariantType ( const QVariant &  variant)

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

Definition at line 110 of file SessionItemUtils.cpp.

111 {
112  int result = static_cast<int>(variant.type());
113  if (result == QVariant::UserType)
114  result = variant.userType();
115  return result;
116 }

Referenced by CompatibleVariantTypes(), IsTheSame(), ModelView::Utils::IsTheSame(), and ParameterTuningDelegate::paint().