BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SessionItemData Class Reference

Description

Handles all data roles for SessionItem.

Definition at line 23 of file SessionItemData.h.

Classes

class  ItemData
 

Public Member Functions

QVariant data (int role) const
 
QVector< int > roles () const
 
bool setData (int role, const QVariant &value)
 Sets the data for given role. Returns true if data was changed. More...
 

Private Attributes

QVector< ItemDatam_values
 

Member Function Documentation

◆ data()

QVariant SessionItemData::data ( int  role) const

Definition at line 39 of file SessionItemData.cpp.

40 {
41  role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
42  for (const auto& value : m_values) {
43  if (value.role == role)
44  return value.data;
45  }
46  return QVariant();
47 }
QVector< ItemData > m_values

References m_values.

Referenced by SessionItemData::ItemData::operator==().

◆ roles()

QVector< int > SessionItemData::roles ( ) const

Definition at line 31 of file SessionItemData.cpp.

32 {
33  QVector<int> result;
34  for (const auto& value : m_values)
35  result.push_back(value.role);
36  return result;
37 }

References m_values.

◆ setData()

bool SessionItemData::setData ( int  role,
const QVariant &  value 
)

Sets the data for given role. Returns true if data was changed.

Definition at line 51 of file SessionItemData.cpp.

52 {
53  role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
54  for (auto* it = m_values.begin(); it != m_values.end(); ++it) {
55  if (it->role == role) {
56  if (value.isValid()) {
57  if (GUI::Util::Variant::IsTheSame(it->data, value))
58  return false;
59  it->data = value;
60  } else {
61  m_values.erase(it);
62  }
63  return true;
64  }
65  }
66  m_values.push_back(ItemData(role, value));
67  return true;
68 }
bool IsTheSame(const QVariant &var1, const QVariant &var2)
Returns true if given variants have same type and value. For custom variants (e.g....
Definition: VariantUtil.cpp:39

References GUI::Util::Variant::IsTheSame(), and m_values.

Here is the call graph for this function:

Member Data Documentation

◆ m_values

QVector<ItemData> SessionItemData::m_values
private

Definition at line 40 of file SessionItemData.h.

Referenced by data(), roles(), and setData().


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