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

Functions

void iterate (const QModelIndex &index, const QAbstractItemModel *model, const std::function< void(const QModelIndex &)> &fun)
 Iterates through all model indices and calls user function. More...
 
void iterate_if (const QModelIndex &index, const QAbstractItemModel *model, const std::function< bool(const QModelIndex &)> &fun)
 Iterates through all model indices and calls user function. More...
 
QStringList topItemNames (SessionModel *model, const QString &modelType="")
 Returns list of top iten manes. More...
 

Function Documentation

◆ iterate()

void ModelUtils::iterate ( const QModelIndex &  index,
const QAbstractItemModel *  model,
const std::function< void(const QModelIndex &)> &  fun 
)

Iterates through all model indices and calls user function.

Definition at line 33 of file ModelUtils.cpp.

35 {
36  if (index.isValid())
37  fun(index);
38 
39  if (!model->hasChildren(index))
40  return;
41 
42  for (int i = 0; i < model->rowCount(index); ++i)
43  for (int j = 0; j < model->columnCount(index); ++j)
44  iterate(model->index(i, j, index), model, fun);
45 }
void iterate(const QModelIndex &index, const QAbstractItemModel *model, const std::function< void(const QModelIndex &)> &fun)
Iterates through all model indices and calls user function.
Definition: ModelUtils.cpp:33

Referenced by ModelView::Utils::iterate(), and MaterialPropertyController::relatedSampleItems().

◆ iterate_if()

void ModelUtils::iterate_if ( const QModelIndex &  index,
const QAbstractItemModel *  model,
const std::function< bool(const QModelIndex &)> &  fun 
)

Iterates through all model indices and calls user function.

If function returns false for given index, iteration will not go down to children.

Definition at line 47 of file ModelUtils.cpp.

49 {
50  bool proceed_with_children(true);
51  if (index.isValid())
52  proceed_with_children = fun(index);
53 
54  if (!model->hasChildren(index) || !proceed_with_children)
55  return;
56 
57  for (int i = 0; i < model->rowCount(index); ++i)
58  for (int j = 0; j < model->columnCount(index); ++j)
59  iterate_if(model->index(i, j, index), model, fun);
60 }
void iterate_if(const QModelIndex &index, const QAbstractItemModel *model, const std::function< bool(const QModelIndex &)> &fun)
Iterates through all model indices and calls user function.
Definition: ModelUtils.cpp:47

Referenced by ProxyModelStrategy::buildModelMap(), and ModelView::Utils::iterate_if().

◆ topItemNames()

QStringList ModelUtils::topItemNames ( SessionModel model,
const QString &  modelType = "" 
)

Returns list of top iten manes.

Definition at line 20 of file ModelUtils.cpp.

21 {
22  QStringList result;
23 
24  for (auto item : model->topItems())
25  if (modelType.isEmpty())
26  result.append(item->itemName());
27  else if (modelType == item->modelType())
28  result.append(item->itemName());
29 
30  return result;
31 }
QVector< T * > topItems() const
Definition: SessionModel.h:147

References SessionModel::topItems().

Referenced by InstrumentViewActions::mapOfNames(), and SimulationDataSelectorWidget::updateViewElements().

Here is the call graph for this function: