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

Description

The ParameterTuningModel class represents parameters which can be tuned in real time in ParameterTuningWidget. In the fitting activity context handles dragging of ParameterItem's to the FitParametersWidget.

Definition at line 29 of file ParameterTuningModel.h.

Inheritance diagram for ParameterTuningModel:
[legend]
Collaboration diagram for ParameterTuningModel:
[legend]

Public Member Functions

 ParameterTuningModel (QObject *rootObject, QObject *parent=nullptr)
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 
QVariant data (const QModelIndex &index, int role) const override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
ParameterItemgetParameterItem (const QModelIndex &index) const
 Returns ParameterItem from given index. More...
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
 
QModelIndex indexForItem (ParameterItem *item) const
 
QMimeData * mimeData (const QModelIndexList &indexes) const override
 
QModelIndex parent (const QModelIndex &index) const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
Qt::DropActions supportedDragActions () const override
 
Qt::DropActions supportedDropActions () const override
 

Static Public Member Functions

static ParameterItemtoParameterItem (const QModelIndex &index)
 
static ParameterLabelItemtoParameterLabelItem (const QModelIndex &index)
 

Private Attributes

QObject * m_rootObject
 

Constructor & Destructor Documentation

◆ ParameterTuningModel()

ParameterTuningModel::ParameterTuningModel ( QObject *  rootObject,
QObject *  parent = nullptr 
)

Definition at line 21 of file ParameterTuningModel.cpp.

22  : QAbstractItemModel(parent)
23  , m_rootObject(rootObject)
24 {
25 }
QModelIndex parent(const QModelIndex &index) const override

Member Function Documentation

◆ columnCount()

int ParameterTuningModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 107 of file ParameterTuningModel.cpp.

108 {
109  return 2;
110 }

◆ data()

QVariant ParameterTuningModel::data ( const QModelIndex &  index,
int  role 
) const
override

Definition at line 34 of file ParameterTuningModel.cpp.

35 {
36  if (!index.isValid())
37  return {};
38 
39  if (const auto* label = toParameterLabelItem(index)) {
40  if (role == Qt::DisplayRole && index.column() == 0)
41  return label->title();
42  return {};
43  }
44 
45  if (auto var = toParameterItem(index)) {
46  if (role == Qt::DisplayRole || role == Qt::EditRole) {
47  if (index.column() == 0)
48  return var->title();
49  return var->valueOfLink();
50  }
51  return {};
52  }
53 
54  return {};
55 }
static ParameterLabelItem * toParameterLabelItem(const QModelIndex &index)
static ParameterItem * toParameterItem(const QModelIndex &index)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override

References index(), toParameterItem(), and toParameterLabelItem().

Referenced by mimeData().

Here is the call graph for this function:

◆ flags()

Qt::ItemFlags ParameterTuningModel::flags ( const QModelIndex &  index) const
override

Definition at line 57 of file ParameterTuningModel.cpp.

58 {
59  Qt::ItemFlags result = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
60  if (toParameterItem(index)) {
61  result |= Qt::ItemIsDragEnabled;
62  if (index.column() == 1)
63  result |= Qt::ItemIsEditable;
64  }
65  return result;
66 }

References index(), and toParameterItem().

Here is the call graph for this function:

◆ getParameterItem()

ParameterItem * ParameterTuningModel::getParameterItem ( const QModelIndex &  index) const

Returns ParameterItem from given index.

Definition at line 137 of file ParameterTuningModel.cpp.

138 {
139  return toParameterItem(index);
140 }

References index(), and toParameterItem().

Referenced by ParameterTuningWidget::getSelectedParameters().

Here is the call graph for this function:

◆ headerData()

QVariant ParameterTuningModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
override

Definition at line 27 of file ParameterTuningModel.cpp.

28 {
29  if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
30  return {};
31  return (section == 0) ? "Name" : "Value";
32 }

◆ index()

QModelIndex ParameterTuningModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
override

Definition at line 68 of file ParameterTuningModel.cpp.

69 {
70  if (!hasIndex(row, column, parent))
71  return {};
72 
73  if (!parent.isValid())
74  return createIndex(row, column, m_rootObject->children()[row]);
75 
76  if (auto label = toParameterLabelItem(parent))
77  return createIndex(row, column, label->children()[row]);
78 
79  return {};
80 }

References m_rootObject, parent(), and toParameterLabelItem().

Referenced by data(), flags(), getParameterItem(), mimeData(), parent(), rowCount(), toParameterItem(), and toParameterLabelItem().

Here is the call graph for this function:

◆ indexForItem()

QModelIndex ParameterTuningModel::indexForItem ( ParameterItem item) const

Definition at line 142 of file ParameterTuningModel.cpp.

143 {
144  if (item == nullptr)
145  return {};
146 
147  if (item->parent()) {
148  const int row = item->parent()->children().indexOf(item);
149  return createIndex(row, 0, item);
150  }
151 
152  return {};
153 }

Referenced by ParameterTuningWidget::makeSelected().

◆ mimeData()

QMimeData * ParameterTuningModel::mimeData ( const QModelIndexList &  indexes) const
override

Definition at line 112 of file ParameterTuningModel.cpp.

113 {
114  auto* mimeData = new QMimeData();
115 
116  for (auto index : indexes) {
117  if (ParameterItem* parameterItem = toParameterItem(index)) {
118  QByteArray data;
119  data.setNum(reinterpret_cast<qlonglong>(parameterItem));
121  break;
122  }
123  }
124  return mimeData;
125 }
The ParameterItem class represent a tuning value in a parameter tuning tree.
QMimeData * mimeData(const QModelIndexList &indexes) const override
QVariant data(const QModelIndex &index, int role) const override
constexpr auto LinkMimeType
Definition: SessionXML.h:31

References data(), index(), GUI::Session::XML::LinkMimeType, and toParameterItem().

Here is the call graph for this function:

◆ parent()

QModelIndex ParameterTuningModel::parent ( const QModelIndex &  index) const
override

Definition at line 82 of file ParameterTuningModel.cpp.

83 {
84  if (!index.isValid())
85  return {};
86 
87  QObject* item = static_cast<QObject*>(index.internalPointer());
88  if (item->parent() == m_rootObject)
89  return {};
90 
91  const int row = item->parent()->parent()->children().indexOf(item->parent());
92  return createIndex(row, 0, item->parent());
93 }

References index(), and m_rootObject.

Referenced by index().

Here is the call graph for this function:

◆ rowCount()

int ParameterTuningModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Definition at line 95 of file ParameterTuningModel.cpp.

96 {
97  if (index.column() > 0)
98  return 0;
99 
100  if (!index.isValid())
101  return m_rootObject->children().size();
102 
103  QObject* item = static_cast<QObject*>(index.internalPointer());
104  return item->children().size();
105 }

References index(), and m_rootObject.

Here is the call graph for this function:

◆ supportedDragActions()

Qt::DropActions ParameterTuningModel::supportedDragActions ( ) const
override

Definition at line 127 of file ParameterTuningModel.cpp.

128 {
129  return Qt::CopyAction;
130 }

◆ supportedDropActions()

Qt::DropActions ParameterTuningModel::supportedDropActions ( ) const
override

Definition at line 132 of file ParameterTuningModel.cpp.

133 {
134  return Qt::IgnoreAction;
135 }

◆ toParameterItem()

ParameterItem * ParameterTuningModel::toParameterItem ( const QModelIndex &  index)
static

Definition at line 155 of file ParameterTuningModel.cpp.

156 {
157  QObject* item = static_cast<QObject*>(index.internalPointer());
158  return dynamic_cast<ParameterItem*>(item);
159 }

References index().

Referenced by ParameterTuningDelegate::createEditor(), data(), flags(), getParameterItem(), and mimeData().

Here is the call graph for this function:

◆ toParameterLabelItem()

ParameterLabelItem * ParameterTuningModel::toParameterLabelItem ( const QModelIndex &  index)
static

Definition at line 161 of file ParameterTuningModel.cpp.

162 {
163  QObject* item = static_cast<QObject*>(index.internalPointer());
164  return dynamic_cast<ParameterLabelItem*>(item);
165 }
ParameterTreeItems is a collection of items necessary to form a tuning tree for real time widget.

References index().

Referenced by data(), and index().

Here is the call graph for this function:

Member Data Documentation

◆ m_rootObject

QObject* ParameterTuningModel::m_rootObject
private

Definition at line 57 of file ParameterTuningModel.h.

Referenced by index(), parent(), and rowCount().


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