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

Functions

const SessionItemancestor (const SessionItem *item, const QString &requiredModelType)
 Returns ancestor of given modelType for given item. More...
 
QModelIndex getIndexFromPath (const SessionModel *model, const QString &path)
 
SessionItemgetItemFromPath (const QString &relPath, const SessionItem *parent)
 returns an item from relative path wrt to given parent More...
 
QString getPathFromIndex (const QModelIndex &index)
 
bool isValidItem (SessionModel *model, SessionItem *item, const QModelIndex &parent)
 Iterates through all the model and returns true if item is found. This is to. More...
 
QString itemPathTranslation (const SessionItem &item, const SessionItem *topItem=0)
 Returns translation of item path to domain name. More...
 

Function Documentation

◆ ancestor()

const SessionItem * ModelPath::ancestor ( const SessionItem item,
const QString &  requiredModelType 
)

Returns ancestor of given modelType for given item.

For example, returns corresponding jobItem owning ParameterItem via ParameterContainer.

Definition at line 87 of file ModelPath.cpp.

88 {
89  const SessionItem* cur = item;
90  while (cur && cur->modelType() != requiredModelType)
91  cur = cur->parent();
92 
93  return cur;
94 }
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73
QString modelType() const
Get model type.

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

Referenced by DetectorMaskDelegate::createIntensityDataItem(), ComponentProxyStrategy::isGroupChildren(), qdesigner_internal::Utils::isObjectAncestorOf(), ComponentProxyStrategy::isSubGroup(), ParameterItem::linkedItem(), MaterialPropertyController::onMaterialDataChanged(), ComponentProxyStrategy::processGroupItem(), and ComponentProxyStrategy::processSubGroupItem().

Here is the call graph for this function:

◆ getIndexFromPath()

QModelIndex ModelPath::getIndexFromPath ( const SessionModel model,
const QString &  path 
)

Definition at line 36 of file ModelPath.cpp.

37 {
38  if (model) {
39  QStringList parts = path.split("/");
40  SessionItem* t = model->rootItem();
41  for (int i = 0; i < parts.length(); i++) {
42  if (t->modelType() == "JobItem" && parts[i] == "GISASInstrument") {
44  continue;
45  }
46  for (int j = 0; j < t->numberOfChildren(); j++) {
47  if (t->childAt(j)->itemName() == parts[i]) {
48  t = t->childAt(j);
49  break;
50  }
51  }
52  }
53  return t->index();
54  }
55  return QModelIndex();
56 }
static const QString T_INSTRUMENT
Definition: JobItem.h:49
QString itemName() const
Get item name, return display name if no name is set.
int numberOfChildren() const
Returns total number of children.
Definition: SessionItem.cpp:94
SessionItem * childAt(int row) const
Returns the child at the given row.
QModelIndex index() const
Returns model index of this item.
Definition: SessionItem.cpp:80
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SessionItem * rootItem() const

References SessionItem::childAt(), SessionItem::getItem(), SessionItem::index(), SessionItem::itemName(), SessionItem::modelType(), SessionItem::numberOfChildren(), SessionModel::rootItem(), and JobItem::T_INSTRUMENT.

Referenced by DataProperties::dataItem(), getItemFromPath(), and ParameterItem::linkedItem().

Here is the call graph for this function:

◆ getItemFromPath()

SessionItem * ModelPath::getItemFromPath ( const QString &  relPath,
const SessionItem parent 
)

returns an item from relative path wrt to given parent

Definition at line 60 of file ModelPath.cpp.

61 {
62  ASSERT(parent);
63  QString fullPath = getPathFromIndex(parent->index()) + "/" + relPath;
64  return parent->model()->itemForIndex(ModelPath::getIndexFromPath(parent->model(), fullPath));
65 }
#define ASSERT(condition)
Definition: Assert.h:31
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:66
SessionItem * itemForIndex(const QModelIndex &index) const
QModelIndex getIndexFromPath(const SessionModel *model, const QString &path)
Definition: ModelPath.cpp:36
QString getPathFromIndex(const QModelIndex &index)
Definition: ModelPath.cpp:19

References ASSERT, getIndexFromPath(), getPathFromIndex(), SessionItem::index(), SessionModel::itemForIndex(), and SessionItem::model().

Referenced by FitParameterHelper::getParameterItem(), ParameterTreeUtils::parameterDictionary(), ParameterTreeUtils::parameterNameToLinkedItem(), and FitParameterContainerItem::setValuesInParameterContainer().

Here is the call graph for this function:

◆ getPathFromIndex()

QString ModelPath::getPathFromIndex ( const QModelIndex &  index)

Definition at line 19 of file ModelPath.cpp.

20 {
21  if (index.isValid()) {
22  QStringList namePath;
23  QModelIndex cur = index;
24  while (cur.isValid()) {
25  namePath << cur.data().toString();
26  cur = cur.parent();
27  }
28  std::reverse(namePath.begin(), namePath.end());
29  return namePath.join("/");
30  }
31  return "";
32 }

Referenced by getItemFromPath(), FitParameterHelper::getParameterItemPath(), and DataProperties::setDataItem().

◆ isValidItem()

bool ModelPath::isValidItem ( SessionModel model,
SessionItem item,
const QModelIndex &  parent 
)

Iterates through all the model and returns true if item is found. This is to.

Definition at line 69 of file ModelPath.cpp.

70 {
71  for (int i_row = 0; i_row < model->rowCount(parent); ++i_row) {
72  QModelIndex index = model->index(i_row, 0, parent);
73  SessionItem* curr = model->itemForIndex(index);
74  if (curr == item)
75  return true;
76 
77  bool isvalid = isValidItem(model, item, index);
78  if (isvalid)
79  return isvalid;
80  }
81  return false;
82 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual int rowCount(const QModelIndex &parent) const
bool isValidItem(SessionModel *model, SessionItem *item, const QModelIndex &parent)
Iterates through all the model and returns true if item is found. This is to.
Definition: ModelPath.cpp:69

References SessionModel::index(), SessionModel::itemForIndex(), and SessionModel::rowCount().

Referenced by FitParameterProxyModel::isValidSourceItem().

Here is the call graph for this function:

◆ itemPathTranslation()

QString ModelPath::itemPathTranslation ( const SessionItem item,
const SessionItem topItem = 0 
)

Returns translation of item path to domain name.

Definition at line 98 of file ModelPath.cpp.

99 {
100  QStringList pathList;
101  const SessionItem* current(&item);
102  while (current && current != topItem) {
103  pathList = current->translateList(pathList);
104  current = current->parent();
105  }
106  std::reverse(pathList.begin(), pathList.end());
107  return pathList.join("/");
108 }

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

Referenced by ParameterTreeUtils::parameterDictionary().

Here is the call graph for this function: