BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
JobModel Class Reference
Inheritance diagram for JobModel:
[legend]
Collaboration diagram for JobModel:
[legend]

Public Slots

void cancelJob (const QModelIndex &index)
 
void onCancelAllJobs ()
 
void removeJob (const QModelIndex &index)
 
void runJob (const QModelIndex &index)
 

Signals

void aboutToDeleteJobItem (JobItem *item)
 
void focusRequest (JobItem *item)
 
void globalProgress (int)
 
void modelLoaded ()
 

Public Member Functions

 JobModel (QObject *parent=0)
 
virtual ~JobModel ()
 
QVector< QString > acceptableDefaultItemTypes (const QModelIndex &parent) const
 
JobItemaddJob (const MultiLayerItem *multiLayerItem, const InstrumentItem *instrumentItem, const RealDataItem *realDataItem, const SimulationOptionsItem *optionItem)
 Main method to add a job. More...
 
virtual bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
 
void clear () override
 
virtual int columnCount (const QModelIndex &parent) const
 
template<typename T >
T * copyItem (const T *item_to_copy, SessionItem *new_parent=0, const QString &tag="")
 
virtual SessionModelcreateCopy (SessionItem *parent=0)
 
void createRootItem ()
 
virtual QVariant data (const QModelIndex &index, int role) const
 
virtual bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
 
virtual Qt::ItemFlags flags (const QModelIndex &index) const
 
JobItemgetJobItemForIdentifier (const QString &identifier)
 
JobItemgetJobItemForIndex (const QModelIndex &index)
 
const JobItemgetJobItemForIndex (const QModelIndex &index) const
 
QString getModelName () const
 
QString getModelTag () const
 
bool hasUnfinishedJobs ()
 
virtual QVariant headerData (int section, Qt::Orientation orientation, int role) const
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent) const
 
QModelIndex indexOfItem (SessionItem *item) const
 
virtual void initFrom (SessionModel *model, SessionItem *parent)
 
template<typename T >
T * insertItem (const QModelIndex &parent, int row=-1, QString tag="")
 
template<typename T >
T * insertItem (SessionItem *parent=nullptr, int row=-1, QString tag="")
 
SessionIteminsertNewItem (QString model_type, const QModelIndex &parent_item, int row=-1, QString tag="")
 
SessionIteminsertNewItem (QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")
 
SessionItemitemForIndex (const QModelIndex &index) const
 
QVector< JobItem * > jobItems () const
 
void load (const QString &filename="")
 
virtual QMimeData * mimeData (const QModelIndexList &indexes) const
 
virtual QStringList mimeTypes () const
 
SessionItemmoveItem (SessionItem *item, SessionItem *new_parent=0, int row=-1, const QString &tag="")
 Move given parameterized item to the new_parent at given row. More...
 
QVector< SessionItem * > nonXMLItems () const override
 
virtual QModelIndex parent (const QModelIndex &child) const
 
virtual void readFrom (QXmlStreamReader *reader, MessageService *messageService=0) override
 
void removeItem (SessionItem *item)
 
virtual bool removeRows (int row, int count, const QModelIndex &parent)
 
void restore (JobItem *jobItem)
 restore instrument and sample model from backup for given JobItem More...
 
SessionItemrootItem () const
 
virtual int rowCount (const QModelIndex &parent) const
 
void save (const QString &filename="")
 
virtual bool setData (const QModelIndex &index, const QVariant &value, int role)
 
void setDraggedItemType (const QString &type)
 
virtual bool setHeaderData (int, Qt::Orientation, const QVariant &, int=Qt::EditRole)
 
virtual Qt::DropActions supportedDragActions () const
 
virtual Qt::DropActions supportedDropActions () const
 
template<typename T = SessionItem>
T * topItem () const
 Returns first item in list of topItems. More...
 
template<typename T = SessionItem>
QVector< T * > topItems () const
 
template<typename T = SessionItem>
QVector< T * > topItems (std::function< bool(const T &)> accept) const
 
virtual void writeTo (QXmlStreamWriter *writer, SessionItem *parent=0)
 

Protected Member Functions

void setRootItem (SessionItem *root)
 

Private Member Functions

SessionItemcopy (const SessionItem *item_to_copy, SessionItem *new_parent=0, const QString &tag="")
 Copy given item to the new_parent at given row. More...
 
QString generateJobName ()
 generates job name More...
 
void restoreItem (SessionItem *item)
 

Private Attributes

QString m_dragged_item_type
 
QString m_model_tag
 model tag (SampleModel, InstrumentModel) More...
 
QString m_name
 model name More...
 
JobQueueDatam_queue_data
 
SessionItemm_root_item
 

Detailed Description

Definition at line 25 of file JobModel.h.

Constructor & Destructor Documentation

◆ JobModel()

JobModel::JobModel ( QObject *  parent = 0)
explicit

Definition at line 32 of file JobModel.cpp.

34 {
35  m_queue_data = new JobQueueData(this);
38  setObjectName(SessionXML::JobModelTag);
39 }
void focusRequest(JobItem *item)
void globalProgress(int)
JobQueueData * m_queue_data
Definition: JobModel.h:64
The JobQueueData class holds all objects/logic to run simulation in a thread.
Definition: JobQueueData.h:28
void focusRequest(JobItem *jobItem)
void globalProgress(int)
virtual QModelIndex parent(const QModelIndex &child) const
SessionModel(QString model_tag, QObject *parent=0)
const QString JobModelTag("JobModel")

References focusRequest(), JobQueueData::focusRequest(), globalProgress(), JobQueueData::globalProgress(), SessionXML::JobModelTag(), and m_queue_data.

Here is the call graph for this function:

◆ ~JobModel()

JobModel::~JobModel ( )
virtual

Definition at line 41 of file JobModel.cpp.

42 {
43  delete m_queue_data;
44 }

References m_queue_data.

Member Function Documentation

◆ aboutToDeleteJobItem

void JobModel::aboutToDeleteJobItem ( JobItem item)
signal

Referenced by removeJob().

◆ acceptableDefaultItemTypes()

QVector< QString > SessionModel::acceptableDefaultItemTypes ( const QModelIndex &  parent) const
inherited

Definition at line 299 of file SessionModel.cpp.

300 {
301  QVector<QString> result;
302  if (SessionItem* parent_item = itemForIndex(parent))
303  result = parent_item->acceptableDefaultItemTypes();
304 
305  return result;
306 }
SessionItem * itemForIndex(const QModelIndex &index) const

References SessionModel::itemForIndex(), and SessionModel::parent().

Referenced by SessionModel::canDropMimeData(), SessionModel::flags(), and SampleTreeWidget::showContextMenu().

Here is the call graph for this function:

◆ addJob()

JobItem * JobModel::addJob ( const MultiLayerItem multiLayerItem,
const InstrumentItem instrumentItem,
const RealDataItem realDataItem,
const SimulationOptionsItem optionItem 
)

Main method to add a job.

Definition at line 73 of file JobModel.cpp.

76 {
77  ASSERT(multiLayerItem);
78  ASSERT(instrumentItem);
79  ASSERT(optionItem);
80 
81  auto jobItem = insertItem<JobItem>();
82  jobItem->setItemName(generateJobName());
83  jobItem->setIdentifier(GUIHelpers::createUuid());
84 
85  JobModelFunctions::setupJobItemSampleData(jobItem, multiLayerItem);
86  JobModelFunctions::setupJobItemInstrument(jobItem, instrumentItem);
87 
88  // TODO: remove when specular instrument is ready for magnetization
89  if (instrumentItem->is<SpecularInstrumentItem>())
91  copyItem(optionItem, jobItem, JobItem::T_SIMULATION_OPTIONS);
92 
93  jobItem->getItem(JobItem::P_SAMPLE_NAME)->setValue(multiLayerItem->itemName());
94 
96 
98 
99  if (realDataItem)
100  JobModelFunctions::setupJobItemForFit(jobItem, realDataItem);
101 
102  return jobItem;
103 }
#define ASSERT(condition)
Definition: Assert.h:31
static const QString T_SIMULATION_OPTIONS
Definition: JobItem.h:54
static const QString P_SAMPLE_NAME
Definition: JobItem.h:37
QString generateJobName()
generates job name
Definition: JobModel.cpp:200
QString itemName() const
Get item name, return display name if no name is set.
bool is() const
Definition: SessionItem.h:175
T * copyItem(const T *item_to_copy, SessionItem *new_parent=0, const QString &tag="")
Definition: SessionModel.h:136
QString createUuid()
Definition: GUIHelpers.cpp:242
void setupJobItemForFit(JobItem *jobItem, const RealDataItem *realDataItem)
Setups JobItem for fit.
void setupJobItemInstrument(JobItem *jobItem, const InstrumentItem *from)
Properly copies instrument into job item.
void setupJobItemSampleData(JobItem *jobItem, const MultiLayerItem *sampleItem)
Properly copies sample and materials into JobItem.
void muteMagnetizationData(JobItem *jobItem)
void setupJobItemOutput(JobItem *jobItem)
Setup items intended for storing results of the job.
void createParameterTree(JobItem *jobItem)

References ASSERT, SessionModel::copyItem(), ParameterTreeUtils::createParameterTree(), GUIHelpers::createUuid(), generateJobName(), SessionItem::is(), SessionItem::itemName(), JobModelFunctions::muteMagnetizationData(), JobItem::P_SAMPLE_NAME, JobModelFunctions::setupJobItemForFit(), JobModelFunctions::setupJobItemInstrument(), JobModelFunctions::setupJobItemOutput(), JobModelFunctions::setupJobItemSampleData(), and JobItem::T_SIMULATION_OPTIONS.

Referenced by SimulationSetupWidget::onRunSimulation().

Here is the call graph for this function:

◆ cancelJob

void JobModel::cancelJob ( const QModelIndex &  index)
slot

Definition at line 184 of file JobModel.cpp.

185 {
186  m_queue_data->cancelJob(getJobItemForIndex(index)->getIdentifier());
187 }
const JobItem * getJobItemForIndex(const QModelIndex &index) const
Definition: JobModel.cpp:46
void cancelJob(const QString &identifier)
Cancels running job.
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const

References JobQueueData::cancelJob(), getJobItemForIndex(), SessionModel::index(), and m_queue_data.

Referenced by JobListWidget::setModel().

Here is the call graph for this function:

◆ canDropMimeData()

bool SessionModel::canDropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
) const
virtualinherited

Definition at line 199 of file SessionModel.cpp.

201 {
202  Q_UNUSED(row);
203 
204  if (action == Qt::IgnoreAction)
205  return true;
206  if (action != Qt::MoveAction || column > 0 || !data
207  || !data->hasFormat(SessionXML::ItemMimeType))
208  return false;
209  if (!parent.isValid())
210  return true;
211  QVector<QString> acceptable_child_items = acceptableDefaultItemTypes(parent);
212  QByteArray xml_data = qUncompress(data->data(SessionXML::ItemMimeType));
213  QXmlStreamReader reader(xml_data);
214  while (!reader.atEnd()) {
215  reader.readNext();
216  if (reader.isStartElement()) {
217  if (reader.name() == SessionXML::ItemTag) {
218  const QString model_type =
219  reader.attributes().value(SessionXML::ModelTypeAttribute).toString();
220  return acceptable_child_items.contains(model_type);
221  }
222  }
223  }
224  return false;
225 }
virtual QVariant data(const QModelIndex &index, int role) const
QVector< QString > acceptableDefaultItemTypes(const QModelIndex &parent) const
std::string model_type
Definition: types.h:23
const QString ModelTypeAttribute("ModelType")
const QString ItemTag("Item")
const QString ItemMimeType
Definition: SessionXML.h:26

References SessionModel::acceptableDefaultItemTypes(), SessionModel::data(), SessionXML::ItemMimeType, SessionXML::ItemTag(), SessionXML::ModelTypeAttribute(), and SessionModel::parent().

Referenced by SessionModel::dropMimeData().

Here is the call graph for this function:

◆ clear()

void JobModel::clear ( )
overridevirtual

Reimplemented from SessionModel.

Definition at line 127 of file JobModel.cpp.

128 {
129  for (auto item : topItems())
130  removeJob(item->index());
131 
133 }
void removeJob(const QModelIndex &index)
Definition: JobModel.cpp:189
virtual void clear()
QVector< T * > topItems() const
Definition: SessionModel.h:147

References SessionModel::clear(), removeJob(), and SessionModel::topItems().

Referenced by ApplicationModels::resetModels().

Here is the call graph for this function:

◆ columnCount()

int SessionModel::columnCount ( const QModelIndex &  parent) const
virtualinherited

Definition at line 119 of file SessionModel.cpp.

120 {
121  if (parent.isValid() && parent.column() != 0)
122  return 0;
124 }

References SessionFlags::MAX_COLUMNS, and SessionModel::parent().

Referenced by SessionModel::data(), and SessionModel::index().

Here is the call graph for this function:

◆ copy()

SessionItem * SessionModel::copy ( const SessionItem item_to_copy,
SessionItem new_parent = 0,
const QString &  tag = "" 
)
privateinherited

Copy given item to the new_parent at given row.

Item intended for copying can belong to another model and it will remain intact. Returns pointer to the new child.

Definition at line 419 of file SessionModel.cpp.

421 {
422  if (!new_parent)
423  new_parent = m_root_item;
424 
425  const QString tagName = tag.isEmpty() ? new_parent->defaultTag() : tag;
426 
427  QByteArray xml_data;
428  QXmlStreamWriter writer(&xml_data);
429  SessionXML::writeItemAndChildItems(&writer, item_to_copy);
430 
431  QXmlStreamReader reader(xml_data);
432  SessionXML::readItems(&reader, new_parent, tagName);
433 
434  return new_parent->getItems(tagName).back();
435 }
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
QString defaultTag() const
Get default tag.
SessionItem * m_root_item
Definition: SessionModel.h:119
void writeItemAndChildItems(QXmlStreamWriter *writer, const SessionItem *item)
Definition: SessionXML.cpp:49
void readItems(QXmlStreamReader *reader, SessionItem *parent, QString topTag="", MessageService *messageService=nullptr)
Definition: SessionXML.cpp:122

References SessionItem::defaultTag(), SessionItem::getItems(), SessionModel::m_root_item, SessionXML::readItems(), and SessionXML::writeItemAndChildItems().

Referenced by SessionModel::copyItem().

Here is the call graph for this function:

◆ copyItem()

template<typename T >
T * SessionModel::copyItem ( const T *  item_to_copy,
SessionItem new_parent = 0,
const QString &  tag = "" 
)
inherited

Definition at line 136 of file SessionModel.h.

137 {
138  return static_cast<T*>(copy(item_to_copy, new_parent, tag));
139 }
SessionItem * copy(const SessionItem *item_to_copy, SessionItem *new_parent=0, const QString &tag="")
Copy given item to the new_parent at given row.

References SessionModel::copy().

Referenced by addJob(), MaterialModel::cloneMaterial(), JobModelFunctions::copyRealDataItem(), DetectorItem::importMasks(), MaterialItemContainer::insertCopy(), InstrumentViewActions::onCloneInstrument(), JobModelFunctions::setupJobItemInstrument(), and JobModelFunctions::setupJobItemSampleData().

Here is the call graph for this function:

◆ createCopy()

SessionModel * SessionModel::createCopy ( SessionItem parent = 0)
virtualinherited

Reimplemented in InstrumentModel, SampleModel, and MaterialModel.

Definition at line 437 of file SessionModel.cpp.

438 {
439  Q_UNUSED(parent);
440  throw GUIHelpers::Error("SessionModel::createCopy() -> Error. Not implemented.");
441 }

References SessionModel::parent().

Here is the call graph for this function:

◆ createRootItem()

void SessionModel::createRootItem ( )
inherited

Definition at line 36 of file SessionModel.cpp.

37 {
39  m_root_item->setModel(this);
40  m_root_item->registerTag("rootTag");
41  m_root_item->setDefaultTag("rootTag");
42 }
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
void setDefaultTag(const QString &tag)
Set default tag.
void setModel(SessionModel *model)
SessionItem * CreateEmptyItem()
create empty SessionItem that serves as a root item
Definition: ItemFactory.cpp:39

References ItemFactory::CreateEmptyItem(), SessionModel::m_root_item, SessionItem::registerTag(), SessionItem::setDefaultTag(), and SessionItem::setModel().

Referenced by SessionModel::SessionModel(), and SessionModel::clear().

Here is the call graph for this function:

◆ data()

QVariant SessionModel::data ( const QModelIndex &  index,
int  role 
) const
virtualinherited

Definition at line 70 of file SessionModel.cpp.

71 {
72  if (!m_root_item || !index.isValid() || index.column() < 0
73  || index.column() >= columnCount(QModelIndex())) {
74  return QVariant();
75  }
76  if (SessionItem* item = itemForIndex(index)) {
77  if (role == Qt::DisplayRole || role == Qt::EditRole) {
78  if (index.column() == SessionFlags::ITEM_VALUE)
79  return item->value();
80  if (index.column() == SessionFlags::ITEM_NAME)
81  return item->itemName();
82  } else if (role == Qt::ToolTipRole) {
83  return SessionItemUtils::ToolTipRole(*item, index.column());
84 
85  } else if (role == Qt::ForegroundRole) {
87  } else if (role == Qt::DecorationRole && index.column() == SessionFlags::ITEM_VALUE) {
89  } else if (role == Qt::CheckStateRole && index.column() == SessionFlags::ITEM_VALUE) {
91  } else {
92  return item->roleProperty(role);
93  }
94  }
95  return QVariant();
96 }
virtual int columnCount(const QModelIndex &parent) const
QVariant DecorationRole(const SessionItem &item)
Returns tooltip for given item.
QVariant CheckStateRole(const SessionItem &item)
Returns check state for given item.
QVariant ToolTipRole(const SessionItem &item, int ncol=0)
Returns tooltip for given item.
QVariant ForegroundRole(const SessionItem &item)
Returns text color for given item.

References SessionModel::columnCount(), SessionModel::index(), SessionFlags::ITEM_NAME, SessionFlags::ITEM_VALUE, SessionModel::itemForIndex(), SessionModel::m_root_item, and SessionItemUtils::ToolTipRole().

Referenced by SessionModel::canDropMimeData(), RealDataTreeModel::data(), SessionModel::dropMimeData(), gui2::JobModel::updateSLDProfile(), and gui2::JobModel::updateSpecularData().

Here is the call graph for this function:

◆ dropMimeData()

bool SessionModel::dropMimeData ( const QMimeData *  data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex &  parent 
)
virtualinherited

Definition at line 227 of file SessionModel.cpp.

229 {
230  if (action == Qt::IgnoreAction)
231  return true;
232  if (action != Qt::MoveAction || column > 0 || !data
233  || !data->hasFormat(SessionXML::ItemMimeType))
234  return false;
235  if (!canDropMimeData(data, action, row, column, parent))
236  return false;
237  if (SessionItem* item = itemForIndex(parent)) {
238  QByteArray xml_data = qUncompress(data->data(SessionXML::ItemMimeType));
239  QXmlStreamReader reader(xml_data);
240  if (row == -1)
241  row = item->numberOfChildren();
242  beginInsertRows(parent, row, row);
243  // this code block is currently not in use. The row parameter of the reader is removed
244  // SessionReader::readItems(&reader, item, row);
245  endInsertRows();
246  return true;
247  }
248  return false;
249 }
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const

References SessionModel::canDropMimeData(), SessionModel::data(), SessionModel::itemForIndex(), SessionXML::ItemMimeType, and SessionModel::parent().

Here is the call graph for this function:

◆ flags()

Qt::ItemFlags SessionModel::flags ( const QModelIndex &  index) const
virtualinherited

Definition at line 51 of file SessionModel.cpp.

52 {
53  Qt::ItemFlags result_flags = QAbstractItemModel::flags(index);
54  if (index.isValid()) {
55  result_flags |= Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
57  if (index.column() == SessionFlags::ITEM_VALUE && item->value().isValid()
58  && item->isEditable() && item->isEnabled())
59  result_flags |= Qt::ItemIsEditable;
60  QVector<QString> acceptable_child_items = acceptableDefaultItemTypes(index);
61  if (acceptable_child_items.contains(m_dragged_item_type)) {
62  result_flags |= Qt::ItemIsDropEnabled;
63  }
64  } else {
65  result_flags |= Qt::ItemIsDropEnabled;
66  }
67  return result_flags;
68 }
QVariant value() const
Get value.
bool isEnabled() const
bool isEditable() const
QString m_dragged_item_type
Definition: SessionModel.h:120

References SessionModel::acceptableDefaultItemTypes(), SessionModel::index(), SessionItem::isEditable(), SessionItem::isEnabled(), SessionFlags::ITEM_VALUE, SessionModel::itemForIndex(), SessionModel::m_dragged_item_type, and SessionItem::value().

Referenced by RealDataTreeModel::flags().

Here is the call graph for this function:

◆ focusRequest

void JobModel::focusRequest ( JobItem item)
signal

◆ generateJobName()

QString JobModel::generateJobName ( )
private

generates job name

Definition at line 200 of file JobModel.cpp.

201 {
202  int glob_index = 0;
203  QModelIndex parentIndex;
204  for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) {
205  QModelIndex itemIndex = index(i_row, 0, parentIndex);
206 
207  if (SessionItem* item = itemForIndex(itemIndex)) {
208  if (item->modelType() == "JobItem") {
209  QString jobName = item->itemName();
210  if (jobName.startsWith("job")) {
211  int job_index = jobName.remove(0, 3).toInt();
212  if (job_index > glob_index)
213  glob_index = job_index;
214  }
215  }
216  }
217  }
218  return QString("job") + QString::number(++glob_index);
219 }
virtual int rowCount(const QModelIndex &parent) const

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

Referenced by addJob().

Here is the call graph for this function:

◆ getJobItemForIdentifier()

JobItem * JobModel::getJobItemForIdentifier ( const QString &  identifier)

Definition at line 60 of file JobModel.cpp.

61 {
62  QModelIndex parentIndex;
63  for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) {
64  QModelIndex itemIndex = index(i_row, 0, parentIndex);
65  JobItem* jobItem = getJobItemForIndex(itemIndex);
66  if (jobItem->getIdentifier() == identifier)
67  return jobItem;
68  }
69  return nullptr;
70 }
QString getIdentifier() const
Definition: JobItem.cpp:103

References JobItem::getIdentifier(), getJobItemForIndex(), SessionModel::index(), and SessionModel::rowCount().

Referenced by JobQueueData::onFinishedJob(), JobQueueData::onProgressUpdate(), and JobQueueData::onStartedJob().

Here is the call graph for this function:

◆ getJobItemForIndex() [1/2]

JobItem * JobModel::getJobItemForIndex ( const QModelIndex &  index)

Definition at line 53 of file JobModel.cpp.

54 {
55  JobItem* result = dynamic_cast<JobItem*>(itemForIndex(index));
56  ASSERT(result);
57  return result;
58 }

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

Here is the call graph for this function:

◆ getJobItemForIndex() [2/2]

const JobItem * JobModel::getJobItemForIndex ( const QModelIndex &  index) const

Definition at line 46 of file JobModel.cpp.

47 {
48  const JobItem* result = dynamic_cast<const JobItem*>(itemForIndex(index));
49  ASSERT(result);
50  return result;
51 }

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

Referenced by cancelJob(), JobSelectorActions::canRemoveJob(), JobSelectorActions::canRunJob(), JobListWidget::currentJobItem(), JobListViewDelegate::editorEvent(), JobSelectorActions::equalizeSelectedToJob(), getJobItemForIdentifier(), JobListViewDelegate::paint(), removeJob(), runJob(), JobSelectorActions::setupEqualizeMenu(), and JobQueueData::updateGlobalProgress().

Here is the call graph for this function:

◆ getModelName()

QString SessionModel::getModelName ( ) const
inlineinherited

Definition at line 196 of file SessionModel.h.

197 {
198  return m_name;
199 }
QString m_name
model name
Definition: SessionModel.h:121

References SessionModel::m_name.

Referenced by SessionXML::writeTo().

◆ getModelTag()

QString SessionModel::getModelTag ( ) const
inlineinherited

Definition at line 191 of file SessionModel.h.

192 {
193  return m_model_tag;
194 }
QString m_model_tag
model tag (SampleModel, InstrumentModel)
Definition: SessionModel.h:122

References SessionModel::m_model_tag.

Referenced by ModelTreeView::ModelTreeView(), SessionXML::readItems(), and SessionXML::writeTo().

◆ globalProgress

void JobModel::globalProgress ( int  )
signal

◆ hasUnfinishedJobs()

bool JobModel::hasUnfinishedJobs ( )

Definition at line 116 of file JobModel.cpp.

117 {
118  bool result = m_queue_data->hasUnfinishedJobs();
119  for (auto jobItem : topItems<JobItem>()) {
120  if (jobItem->getStatus() == "Fitting")
121  result = true;
122  }
123 
124  return result;
125 }
bool hasUnfinishedJobs()

References JobQueueData::hasUnfinishedJobs(), and m_queue_data.

Here is the call graph for this function:

◆ headerData()

QVariant SessionModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
virtualinherited

Definition at line 98 of file SessionModel.cpp.

99 {
100  if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
101  switch (section) {
103  return "Name";
105  return "Value";
106  }
107  }
108  return QVariant();
109 }

References SessionFlags::ITEM_NAME, and SessionFlags::ITEM_VALUE.

◆ index()

QModelIndex SessionModel::index ( int  row,
int  column,
const QModelIndex &  parent 
) const
virtualinherited

Definition at line 126 of file SessionModel.cpp.

127 {
128  if (!m_root_item || row < 0 || column < 0 || column >= columnCount(QModelIndex())
129  || (parent.isValid() && parent.column() != 0))
130  return QModelIndex();
131 
132  SessionItem* parent_item = itemForIndex(parent);
133 
134  if (SessionItem* item = parent_item->childAt(row))
135  return createIndex(row, column, item);
136  return QModelIndex();
137 }
SessionItem * childAt(int row) const
Returns the child at the given row.

References SessionItem::childAt(), SessionModel::columnCount(), SessionModel::itemForIndex(), SessionModel::m_root_item, and SessionModel::parent().

Referenced by SampleViewAligner::alignSample(), cancelJob(), MaterialModel::cloneMaterial(), MaskResultsPresenter::createMaskPresentation(), SessionModel::data(), MaskGraphicsScene::deleteViews(), DesignerScene::deleteViews(), SessionModel::flags(), generateJobName(), SampleTreeWidget::getIndexAtColumnZero(), getJobItemForIdentifier(), getJobItemForIndex(), MaterialEditor::init_views(), ModelPath::isValidItem(), SessionModel::itemForIndex(), MaterialModel::materialFromIndex(), ModelMapper::onBeginRemoveRows(), MaterialPropertyController::onMaterialRowsAboutToBeRemoved(), ModelMapper::onRowRemoved(), MaskGraphicsScene::onRowsAboutToBeRemoved(), RealSpaceCanvas::onRowsAboutToBeRemoved(), DesignerScene::onRowsAboutToBeRemoved(), ItemStackWidget::onRowsAboutToBeRemoved(), ModelMapper::onRowsInserted(), SessionModel::removeItem(), removeJob(), runJob(), ItemSelectorWidget::selectLast(), SessionModel::setData(), MaskGraphicsScene::setItemName(), MaskGraphicsScene::setZValues(), ItemSelectorWidget::showEvent(), SessionModel::topItems(), JobQueueData::updateGlobalProgress(), InstrumentViewActions::updateSelection(), SampleViewAligner::updateViews(), MaskGraphicsScene::updateViews(), and DesignerScene::updateViews().

Here is the call graph for this function:

◆ indexOfItem()

QModelIndex SessionModel::indexOfItem ( SessionItem item) const
inherited

Definition at line 251 of file SessionModel.cpp.

252 {
253  if (!item || item == m_root_item || !item->parent())
254  return QModelIndex();
255  SessionItem* parent_item = item->parent();
256  int row = parent_item->rowOfChild(item);
257  return createIndex(row, 0, item);
258 }
int rowOfChild(SessionItem *child) const
Returns row index of given child.
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73

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

Referenced by SampleTreeWidget::addItem(), SampleViewAligner::alignSample(), MaskGraphicsScene::cancelCurrentDrawing(), MaskEditorActions::changeMaskStackingOrder(), RealDataTreeModel::data(), SessionItem::emitDataChanged(), RealDataTreeModel::flags(), SessionItem::index(), DetectorMaskDelegate::initMaskEditorContext(), MaskGraphicsScene::onSceneSelectionChanged(), DesignerScene::onSceneSelectionChanged(), MaskGraphicsScene::onSessionSelectionChanged(), DesignerScene::onSessionSelectionChanged(), MaskGraphicsScene::processLineItem(), MaskGraphicsScene::processPolygonItem(), SessionModel::removeItem(), and MaterialEditor::setInitialMaterialProperty().

Here is the call graph for this function:

◆ initFrom()

void SessionModel::initFrom ( SessionModel model,
SessionItem parent 
)
virtualinherited

Definition at line 443 of file SessionModel.cpp.

444 {
445  QByteArray byte_array;
446  QXmlStreamWriter writer(&byte_array);
447  writer.setAutoFormatting(true);
448 
449  model->writeTo(&writer);
450 
451  QXmlStreamReader reader(byte_array);
452 
453  while (!reader.atEnd()) {
454  reader.readNext();
455  if (reader.isStartElement())
456  readFrom(&reader);
457  }
458  modelLoaded();
459 }
void modelLoaded()
virtual void writeTo(QXmlStreamWriter *writer, SessionItem *parent=0)
virtual void readFrom(QXmlStreamReader *reader, MessageService *messageService=0)

References SessionModel::modelLoaded(), SessionModel::readFrom(), and SessionModel::writeTo().

Referenced by MaterialModel::createCopy(), SampleModel::createCopy(), InstrumentModel::createCopy(), and MaterialEditorDialog::onOKButton().

Here is the call graph for this function:

◆ insertItem() [1/2]

template<typename T >
T * SessionModel::insertItem ( const QModelIndex &  parent,
int  row = -1,
QString  tag = "" 
)
inherited

Definition at line 130 of file SessionModel.h.

131 {
132  return insertItem<T>(itemForIndex(parent), row, tag);
133 }

References SessionModel::itemForIndex(), and SessionModel::parent().

Here is the call graph for this function:

◆ insertItem() [2/2]

template<typename T >
T * SessionModel::insertItem ( SessionItem parent = nullptr,
int  row = -1,
QString  tag = "" 
)
inherited

Definition at line 125 of file SessionModel.h.

126 {
127  return static_cast<T*>(insertNewItem(T().modelType(), parent, row, tag));
128 }
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")

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

Referenced by IntensityDataFFTPresenter::IntensityDataFFTPresenter(), FitComparison1DViewController::createDiffViewItem(), FitParameterHelper::createFitParameter(), DetectorMaskDelegate::createIntensityDataItem(), DetectorItem::createMaskContainer(), ParameterTreeUtils::createParameterTree(), DesignerScene::dropEvent(), TestComponentView::init_source(), InstrumentViewActions::initAddInstrumentMenu(), RealDataItem::initDataItem(), JobModelFunctions::initDataView(), TestComponentView::onAddItemRequest(), ProjectionsEditorCanvas::onEnteringColorMap(), ParameterTreeUtils::parameterDictionary(), ParameterTreeUtils::parameterNameToLinkedItem(), GUIObjectBuilder::populateDocumentModel(), ParameterTreeUtils::populateParameterContainer(), MaskGraphicsScene::processHorizontalLineItem(), MaskGraphicsScene::processMaskAllItem(), MaskGraphicsScene::processPolygonItem(), MaskGraphicsScene::processVerticalLineItem(), ApplicationModels::resetModels(), JobModelFunctions::setupJobItemOutput(), JobModelFunctions::setupJobItemSampleData(), TestView::test_MinimizerSettings(), TestView::test_specular_data_widget(), and GUIDomainSampleVisitor::visit().

Here is the call graph for this function:

◆ insertNewItem() [1/2]

SessionItem * SessionModel::insertNewItem ( QString  model_type,
const QModelIndex &  parent_item,
int  row = -1,
QString  tag = "" 
)
inherited

Definition at line 286 of file SessionModel.cpp.

288 {
289  return insertNewItem(model_type, itemForIndex(parent_item), row, tag);
290 }

References SessionModel::insertNewItem(), and SessionModel::itemForIndex().

Here is the call graph for this function:

◆ insertNewItem() [2/2]

SessionItem * SessionModel::insertNewItem ( QString  model_type,
SessionItem parent_item = nullptr,
int  row = -1,
QString  tag = "" 
)
inherited

Definition at line 260 of file SessionModel.cpp.

262 {
263  if (!parent_item)
264  parent_item = m_root_item;
265  if (row > parent_item->numberOfChildren())
266  return nullptr;
267  if (parent_item != m_root_item) {
268  if (tag.isEmpty())
269  tag = parent_item->defaultTag();
270 
271  if (!parent_item->sessionItemTags()->isValid(tag, model_type))
272  return nullptr;
273  }
274 
276 
277  if (!new_item)
278  throw GUIHelpers::Error("SessionModel::insertNewItem() -> Wrong model type " + model_type);
279 
280  if (!parent_item->insertItem(row, new_item, tag))
281  throw GUIHelpers::Error("SessionModel::insertNewItem -> Error. Can't insert item");
282 
283  return new_item;
284 }
bool isValid(const QString &tagName, const QString &modelType="") const
Returns true if there is a registered tag with such name.
SessionItemTags * sessionItemTags()
bool insertItem(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.
int numberOfChildren() const
Returns total number of children.
Definition: SessionItem.cpp:94
SessionItem * CreateItem(const QString &model_name, SessionItem *parent=nullptr)
create SessionItem of specific type and parent
Definition: ItemFactory.cpp:30

References ItemFactory::CreateItem(), SessionItem::defaultTag(), SessionItem::insertItem(), SessionItemTags::isValid(), SessionModel::m_root_item, SessionItem::numberOfChildren(), and SessionItem::sessionItemTags().

Referenced by SampleTreeWidget::addItem(), FitParameterHelper::addToFitParameter(), DesignerScene::dropEvent(), MultiLayerView::dropEvent(), GUIDomainSampleVisitor::InsertIParticle(), SessionModel::insertItem(), SessionModel::insertNewItem(), RealDataMaskWidget::maskContainer(), InstrumentViewActions::onCloneInstrument(), MaskGraphicsScene::processRectangleShapeItem(), and IntensityDataProjectionsWidget::projectionContainer().

Here is the call graph for this function:

◆ itemForIndex()

SessionItem * SessionModel::itemForIndex ( const QModelIndex &  index) const
inherited

Definition at line 347 of file SessionModel.cpp.

348 {
349  if (index.isValid())
350  if (SessionItem* item = static_cast<SessionItem*>(index.internalPointer()))
351  return item;
352 
353  return m_root_item;
354 }

References SessionModel::index(), and SessionModel::m_root_item.

Referenced by SessionModel::acceptableDefaultItemTypes(), MaskEditorActions::changeMaskStackingOrder(), SessionDecorationModel::createIcon(), MaskResultsPresenter::createMaskPresentation(), SessionModel::data(), DataProperties::dataItem(), DesignerScene::deleteSelectedItems(), MaskGraphicsScene::deleteViews(), DesignerScene::deleteViews(), SessionModel::dropMimeData(), SessionModel::flags(), generateJobName(), ModelPath::getItemFromPath(), getJobItemForIndex(), ParameterTuningModel::getParameterItem(), SampleViewAligner::getViewForIndex(), SessionModel::index(), SessionModel::insertItem(), SessionModel::insertNewItem(), MaskEditorActions::isSendToBackPossible(), ModelPath::isValidItem(), ParameterItem::linkedItem(), MaterialModel::materialFromIndex(), SessionModel::mimeData(), ModelMapper::onBeginRemoveRows(), InstrumentViewActions::onCloneInstrument(), PySampleWidget::onDataChanged(), RealSpaceCanvas::onDataChanged(), ComponentFlatView::onDataChanged(), ModelMapper::onDataChanged(), MaterialPropertyController::onMaterialDataChanged(), MaterialPropertyController::onMaterialRowsAboutToBeRemoved(), ModelMapper::onRowRemoved(), ItemStackWidget::onRowsAboutToBeRemoved(), ModelMapper::onRowsInserted(), ItemSelectorWidget::onSelectionChanged(), MaskEditorPropertyPanel::onSelectionChanged(), MaterialEditor::onSelectionChanged(), TestComponentView::onSelectionChanged(), FitParameterProxyModel::onSourceDataChanged(), MaskEditorActions::onToggleMaskValueAction(), SessionModel::parent(), ComponentProxyStrategy::processSourceIndex(), MaterialPropertyController::relatedSampleItems(), SessionModel::removeRows(), SessionModel::rowCount(), SessionModel::setData(), MaskGraphicsScene::setItemName(), MaskEditor::setMaskContext(), MaskGraphicsScene::setMaskContext(), MaskEditorPropertyPanel::setPanelHidden(), MaskGraphicsScene::setZValues(), ComponentProxyModel::sourceDataChanged(), SessionDecorationModel::textColor(), SessionModel::topItems(), MaskGraphicsScene::updateScene(), RealSpaceCanvas::updateScene(), MaskGraphicsScene::updateViews(), and DesignerScene::updateViews().

Here is the call graph for this function:

◆ jobItems()

QVector< JobItem * > JobModel::jobItems ( ) const

Definition at line 105 of file JobModel.cpp.

106 {
107  return topItems<JobItem>();
108 }

Referenced by readFrom().

◆ load()

void SessionModel::load ( const QString &  filename = "")
inherited

Definition at line 316 of file SessionModel.cpp.

317 {
318  beginResetModel();
319  QFile file(filename);
320  if (!file.open(QIODevice::ReadOnly))
321  throw GUIHelpers::Error(file.errorString());
322  clear();
324  QXmlStreamReader reader(&file);
326  if (reader.hasError())
327  throw GUIHelpers::Error(reader.errorString());
328  endResetModel();
329 }
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")

References SessionModel::clear(), ItemFactory::CreateEmptyItem(), FileSystemUtils::filename(), SessionModel::m_root_item, and SessionXML::readItems().

Here is the call graph for this function:

◆ mimeData()

QMimeData * SessionModel::mimeData ( const QModelIndexList &  indexes) const
virtualinherited

Definition at line 183 of file SessionModel.cpp.

184 {
185  if (indices.count() != 2)
186  return 0;
187 
188  if (SessionItem* item = itemForIndex(indices.at(0))) {
189  QMimeData* mime_data = new QMimeData;
190  QByteArray xml_data;
191  QXmlStreamWriter writer(&xml_data);
192  SessionXML::writeItemAndChildItems(&writer, item);
193  mime_data->setData(SessionXML::ItemMimeType, qCompress(xml_data, MaxCompression));
194  return mime_data;
195  }
196  return 0;
197 }

References SessionModel::itemForIndex(), SessionXML::ItemMimeType, and SessionXML::writeItemAndChildItems().

Here is the call graph for this function:

◆ mimeTypes()

QStringList SessionModel::mimeTypes ( ) const
virtualinherited

Definition at line 178 of file SessionModel.cpp.

179 {
180  return QStringList() << SessionXML::ItemMimeType;
181 }

References SessionXML::ItemMimeType.

◆ modelLoaded

void SessionModel::modelLoaded ( )
signalinherited

◆ moveItem()

SessionItem * SessionModel::moveItem ( SessionItem item,
SessionItem new_parent = 0,
int  row = -1,
const QString &  tag = "" 
)
inherited

Move given parameterized item to the new_parent at given row.

If new_parent is not defined, use root_item as a new parent.

Definition at line 384 of file SessionModel.cpp.

386 {
387  if (!new_parent)
388  new_parent = m_root_item;
389 
390  const QString tagName = tag.isEmpty() ? new_parent->defaultTag() : tag;
391 
392  if (!new_parent->sessionItemTags()->isValid(tagName, item->modelType()))
393  return 0;
394 
395  if (item->parent() == new_parent) {
396  // take care of indexes when moving item within same parent
397  int previousIndex = item->parent()->getItems(tagName).indexOf(item);
398  if (row == previousIndex)
399  return item;
400  else if (previousIndex >= 0 && row > previousIndex)
401  row--;
402  }
403 
404  if (new_parent->sessionItemTags()->maximumReached(tagName)) {
405  SessionItem* prev = new_parent->takeItem(0, tagName);
406  m_root_item->insertItem(-1, prev);
407  }
408 
409  // removing item from previous parent and inserting to the new one
410  item->parent()->takeRow(item->parent()->rowOfChild(item));
411  new_parent->insertItem(row, item, tagName);
412 
413  return item;
414 }
bool maximumReached(const QString &tagName) const
SessionItem * takeRow(int row)
Removes row from item and returns the item.
SessionItem * takeItem(int row, const QString &tag)
Remove item from given row from given tag.
QString modelType() const
Get model type.

References SessionItem::defaultTag(), SessionItem::getItems(), SessionItem::insertItem(), SessionItemTags::isValid(), SessionModel::m_root_item, SessionItemTags::maximumReached(), SessionItem::modelType(), SessionItem::parent(), SessionItem::rowOfChild(), SessionItem::sessionItemTags(), SessionItem::takeItem(), and SessionItem::takeRow().

Referenced by MaskEditorActions::changeMaskStackingOrder(), ILayerView::mouseReleaseEvent(), DesignerScene::onEstablishedConnection(), and DesignerScene::removeConnection().

Here is the call graph for this function:

◆ nonXMLItems()

QVector< SessionItem * > JobModel::nonXMLItems ( ) const
overridevirtual

Reimplemented from SessionModel.

Definition at line 135 of file JobModel.cpp.

136 {
137  QVector<SessionItem*> result;
138 
139  for (auto jobItem : topItems<JobItem>()) {
140  if (auto intensityItem = jobItem->getItem(JobItem::T_OUTPUT))
141  result.push_back(intensityItem);
142 
143  if (auto real_data = dynamic_cast<RealDataItem*>(jobItem->getItem(JobItem::T_REALDATA))) {
144  if (auto data_item = real_data->dataItem())
145  result.push_back(data_item);
146  if (auto native_data = real_data->nativeData())
147  result.push_back(native_data);
148  }
149 
150  auto instrument =
151  dynamic_cast<SpecularInstrumentItem*>(jobItem->getItem(JobItem::T_INSTRUMENT));
152  if (instrument) {
153  auto axis_group = instrument->beamItem()->inclinationAxisGroup();
154  result.push_back(axis_group->getChildOfType("PointwiseAxis"));
155  }
156  }
157 
158  return result;
159 }
static const QString T_OUTPUT
Definition: JobItem.h:50
static const QString T_INSTRUMENT
Definition: JobItem.h:49
static const QString T_REALDATA
Definition: JobItem.h:51
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
GroupItem * inclinationAxisGroup()
Definition: BeamItems.cpp:155
SpecularBeamItem * beamItem() const override

References SpecularInstrumentItem::beamItem(), SpecularBeamItem::inclinationAxisGroup(), JobItem::T_INSTRUMENT, JobItem::T_OUTPUT, and JobItem::T_REALDATA.

Referenced by ApplicationModels::nonXMLItems().

Here is the call graph for this function:

◆ onCancelAllJobs

void JobModel::onCancelAllJobs ( )
slot

Definition at line 174 of file JobModel.cpp.

175 {
177 }
void onCancelAllJobs()
Cancels all running jobs.

References m_queue_data, and JobQueueData::onCancelAllJobs().

Here is the call graph for this function:

◆ parent()

QModelIndex SessionModel::parent ( const QModelIndex &  child) const
virtualinherited

Definition at line 139 of file SessionModel.cpp.

140 {
141  if (!child.isValid())
142  return QModelIndex();
143 
144  if (SessionItem* child_item = itemForIndex(child)) {
145  if (SessionItem* parent_item = child_item->parent()) {
146  if (parent_item == m_root_item)
147  return QModelIndex();
148 
149  return createIndex(ParentRow(*parent_item), 0, parent_item);
150  }
151  }
152  return QModelIndex();
153 }
int ParentRow(const SessionItem &item)
Returns the index of the given item within its parent. Returns -1 when no parent is set.

References SessionModel::itemForIndex(), SessionModel::m_root_item, SessionItem::parent(), and SessionItemUtils::ParentRow().

Referenced by SessionModel::acceptableDefaultItemTypes(), SessionModel::canDropMimeData(), SessionModel::columnCount(), SessionModel::createCopy(), MaterialModel::createCopy(), SampleModel::createCopy(), InstrumentModel::createCopy(), SampleTreeWidget::deleteItem(), SessionModel::dropMimeData(), SampleTreeWidget::getIndexAtColumnZero(), SessionModel::index(), SessionModel::insertItem(), InstrumentModel::onRowsChange(), RealDataModel::onRowsChange(), SessionModel::removeRows(), SessionModel::rowCount(), and SessionModel::writeTo().

Here is the call graph for this function:

◆ readFrom()

void JobModel::readFrom ( QXmlStreamReader *  reader,
MessageService messageService = 0 
)
overridevirtual

Reimplemented from SessionModel.

Definition at line 161 of file JobModel.cpp.

162 {
163  SessionModel::readFrom(reader, messageService);
164 
165  // Set & check instrument links. JobItem and realDataItem have to reference the same instrument
166  // (which is the one contained in this job item, not contained in the instrument model)
167  for (auto jobItem : jobItems())
168  if (RealDataItem* refItem = jobItem->realDataItem()) {
169  refItem->setInstrumentId(jobItem->instrumentItem()->id());
170  ASSERT(refItem->linkedInstrument() == jobItem->instrumentItem());
171  }
172 }
QVector< JobItem * > jobItems() const
Definition: JobModel.cpp:105

References ASSERT, jobItems(), and SessionModel::readFrom().

Here is the call graph for this function:

◆ removeItem()

void SessionModel::removeItem ( SessionItem item)
inherited

Definition at line 292 of file SessionModel.cpp.

293 {
294  QModelIndex index = indexOfItem(item);
295  if (index.isValid())
296  removeRows(index.row(), 1, QModelIndex());
297 }
virtual bool removeRows(int row, int count, const QModelIndex &parent)
QModelIndex indexOfItem(SessionItem *item) const

References SessionModel::index(), SessionModel::indexOfItem(), and SessionModel::removeRows().

Referenced by RealDataTreeModel::removeItem().

Here is the call graph for this function:

◆ removeJob

void JobModel::removeJob ( const QModelIndex &  index)
slot

Definition at line 189 of file JobModel.cpp.

190 {
191  JobItem* jobItem = getJobItemForIndex(index);
192  ASSERT(jobItem);
193  m_queue_data->removeJob(jobItem->getIdentifier());
194 
195  emit aboutToDeleteJobItem(jobItem);
196  removeRows(index.row(), 1, QModelIndex());
197 }
void aboutToDeleteJobItem(JobItem *item)
void removeJob(const QString &identifier)
Remove job from list completely.

References aboutToDeleteJobItem(), ASSERT, JobItem::getIdentifier(), getJobItemForIndex(), SessionModel::index(), m_queue_data, JobQueueData::removeJob(), and SessionModel::removeRows().

Referenced by clear(), and JobSelectorActions::onRemoveJob().

Here is the call graph for this function:

◆ removeRows()

bool SessionModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent 
)
virtualinherited

Definition at line 168 of file SessionModel.cpp.

169 {
170  if (!m_root_item)
171  return false;
172  SessionItem* item = parent.isValid() ? itemForIndex(parent) : m_root_item;
173  for (int i = 0; i < count; ++i)
174  delete item->takeRow(row);
175  return true;
176 }

References SessionModel::itemForIndex(), SessionModel::m_root_item, SessionModel::parent(), and SessionItem::takeRow().

Referenced by MaskGraphicsScene::cancelCurrentDrawing(), SampleTreeWidget::deleteItem(), DesignerScene::deleteSelectedItems(), ProjectionsEditorActions::onDeleteAction(), MaskEditorActions::onDeleteMaskAction(), InstrumentViewActions::onRemoveInstrument(), MaterialEditorToolBar::onRemoveMaterialAction(), SessionModel::removeItem(), and removeJob().

Here is the call graph for this function:

◆ restore()

void JobModel::restore ( JobItem jobItem)

restore instrument and sample model from backup for given JobItem

Definition at line 111 of file JobModel.cpp.

112 {
114 }
static const QString T_PARAMETER_TREE
Definition: JobItem.h:53
void restoreItem(SessionItem *item)
Definition: JobModel.cpp:221
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.

References SessionItem::getItem(), restoreItem(), and JobItem::T_PARAMETER_TREE.

Referenced by ParameterTuningWidget::restoreModelsOfCurrentJobItem().

Here is the call graph for this function:

◆ restoreItem()

void JobModel::restoreItem ( SessionItem item)
private

Definition at line 221 of file JobModel.cpp.

222 {
223  if (ParameterItem* parameter = dynamic_cast<ParameterItem*>(item))
224  parameter->restoreFromBackup();
225 
226  for (auto child : item->children())
227  restoreItem(child);
228 }
The ParameterItem class represent a tuning value in a parameter tuning tree.
QVector< SessionItem * > children() const
Returns vector of all children.

References SessionItem::children().

Referenced by restore().

Here is the call graph for this function:

◆ rootItem()

SessionItem * SessionModel::rootItem ( ) const
inherited

Definition at line 461 of file SessionModel.cpp.

462 {
463  return m_root_item;
464 }

References SessionModel::m_root_item.

Referenced by ModelPath::getIndexFromPath(), and ModelMapper::nestlingDepth().

◆ rowCount()

int SessionModel::rowCount ( const QModelIndex &  parent) const
virtualinherited

◆ runJob

void JobModel::runJob ( const QModelIndex &  index)
slot

Definition at line 179 of file JobModel.cpp.

180 {
182 }
void runJob(JobItem *jobItem)
Submits job and run it in a thread.

References getJobItemForIndex(), SessionModel::index(), m_queue_data, and JobQueueData::runJob().

Referenced by ParameterTuningWidget::onCurrentLinkChanged(), JobSelectorActions::onRunJob(), SimulationSetupWidget::onRunSimulation(), and ParameterTuningWidget::restoreModelsOfCurrentJobItem().

Here is the call graph for this function:

◆ save()

void SessionModel::save ( const QString &  filename = "")
inherited

Definition at line 331 of file SessionModel.cpp.

332 {
333  QFile file(filename);
334  if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
335  throw GUIHelpers::Error(file.errorString());
336 
337  QXmlStreamWriter writer(&file);
338  writer.setAutoFormatting(true);
339  writer.writeStartDocument();
340  writer.writeStartElement("BornAgain");
341  writer.writeAttribute("Version", GUIHelpers::getBornAgainVersionString());
343  writer.writeEndElement(); // BornAgain
344  writer.writeEndDocument();
345 }
QString getBornAgainVersionString()
Definition: GUIHelpers.cpp:130

References FileSystemUtils::filename(), GUIHelpers::getBornAgainVersionString(), SessionModel::m_root_item, and SessionXML::writeItemAndChildItems().

Here is the call graph for this function:

◆ setData()

bool SessionModel::setData ( const QModelIndex &  index,
const QVariant &  value,
int  role 
)
virtualinherited

Definition at line 155 of file SessionModel.cpp.

156 {
157  if (!index.isValid())
158  return false;
159 
160  QModelIndex dataIndex = index;
161  if (SessionItem* item = itemForIndex(dataIndex))
162  if (item->setRoleProperty(role, value))
163  return true;
164 
165  return false;
166 }

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

Here is the call graph for this function:

◆ setDraggedItemType()

void SessionModel::setDraggedItemType ( const QString &  type)
inlineinherited

Definition at line 201 of file SessionModel.h.

202 {
203  m_dragged_item_type = type;
204 }

References SessionModel::m_dragged_item_type.

Referenced by ItemTreeView::dragMoveEvent().

◆ setHeaderData()

bool SessionModel::setHeaderData ( int  ,
Qt::Orientation  ,
const QVariant &  ,
int  = Qt::EditRole 
)
inlinevirtualinherited

Definition at line 176 of file SessionModel.h.

177 {
178  return false;
179 }

◆ setRootItem()

void SessionModel::setRootItem ( SessionItem root)
inlineprotectedinherited

Definition at line 112 of file SessionModel.h.

112 { m_root_item = root; }

References SessionModel::m_root_item.

◆ supportedDragActions()

Qt::DropActions SessionModel::supportedDragActions ( ) const
inlinevirtualinherited

Definition at line 181 of file SessionModel.h.

182 {
183  return Qt::MoveAction;
184 }

◆ supportedDropActions()

Qt::DropActions SessionModel::supportedDropActions ( ) const
inlinevirtualinherited

Definition at line 186 of file SessionModel.h.

187 {
188  return Qt::MoveAction;
189 }

◆ topItem()

template<typename T >
T * SessionModel::topItem
inherited

Returns first item in list of topItems.

Definition at line 141 of file SessionModel.h.

142 {
143  auto items = topItems<T>();
144  return items.isEmpty() ? nullptr : items.front();
145 }

◆ topItems() [1/2]

template<typename T >
QVector< T * > SessionModel::topItems
inherited

Definition at line 147 of file SessionModel.h.

148 {
149  QVector<T*> result;
150 
151  QModelIndex parentIndex;
152  for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) {
153  QModelIndex itemIndex = index(i_row, 0, parentIndex);
154  if (auto item = dynamic_cast<T*>(itemForIndex(itemIndex)))
155  result.push_back(item);
156  }
157 
158  return result;
159 }

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

Referenced by clear(), MaterialItemUtils::defaultMaterialProperty(), PySampleWidget::generateCodeSnippet(), SimulationDataSelectorWidget::selectedInstrumentItem(), SimulationDataSelectorWidget::selectedMultiLayerItem(), and ModelUtils::topItemNames().

Here is the call graph for this function:

◆ topItems() [2/2]

template<typename T >
QVector< T * > SessionModel::topItems ( std::function< bool(const T &)>  accept) const
inherited

Definition at line 161 of file SessionModel.h.

162 {
163  QVector<T*> result;
164 
165  QModelIndex parentIndex;
166  for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) {
167  QModelIndex itemIndex = index(i_row, 0, parentIndex);
168  if (auto item = dynamic_cast<T*>(itemForIndex(itemIndex)))
169  if (accept(*item))
170  result.push_back(item);
171  }
172 
173  return result;
174 }

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

Here is the call graph for this function:

◆ writeTo()

void SessionModel::writeTo ( QXmlStreamWriter *  writer,
SessionItem parent = 0 
)
virtualinherited

Definition at line 374 of file SessionModel.cpp.

375 {
376  if (!parent)
378  SessionXML::writeTo(writer, parent);
379 }
void writeTo(QXmlStreamWriter *writer, SessionItem *parent)
Definition: SessionXML.cpp:39

References SessionModel::m_root_item, SessionModel::parent(), and SessionXML::writeTo().

Referenced by SessionModel::initFrom().

Here is the call graph for this function:

Member Data Documentation

◆ m_dragged_item_type

QString SessionModel::m_dragged_item_type
privateinherited

Definition at line 120 of file SessionModel.h.

Referenced by SessionModel::flags(), and SessionModel::setDraggedItemType().

◆ m_model_tag

QString SessionModel::m_model_tag
privateinherited

model tag (SampleModel, InstrumentModel)

Definition at line 122 of file SessionModel.h.

Referenced by SessionModel::getModelTag(), and SessionModel::readFrom().

◆ m_name

QString SessionModel::m_name
privateinherited

model name

Definition at line 121 of file SessionModel.h.

Referenced by SessionModel::getModelName(), and SessionModel::readFrom().

◆ m_queue_data

JobQueueData* JobModel::m_queue_data
private

◆ m_root_item


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