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

Description

Definition at line 27 of file JobModel.h.

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

Signals

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

Public Member Functions

 JobModel (QObject *parent=nullptr)
 
 ~JobModel () override
 
QVector< QString > acceptableDefaultItemTypes (const QModelIndex &parent) const
 
JobItemaddJob (const MultiLayerItem *sampleItem, const InstrumentItem *instrumentItem, const RealDataItem *realDataItem, const SimulationOptionsItem &optionItem)
 Main method to add a job. More...
 
void cancelJob (JobItem *jobItem)
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 
void clear () override
 
int columnCount (const QModelIndex &parent) const override
 
SessionItemcopy (const SessionItem *item_to_copy, SessionItem *new_parent=nullptr, const QString &tag="")
 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. More...
 
template<typename T >
T * copyItem (const T *item_to_copy, SessionItem *new_parent=nullptr, const QString &tag="")
 
void createRootItem ()
 
QVariant data (const QModelIndex &index, int role) const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
JobItemgetJobItemForIdentifier (const QString &identifier)
 
QString getModelTag () const
 
bool hasUnfinishedJobs ()
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
QModelIndex index (int row, int column, const QModelIndex &parent) const override
 
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
 
QMimeData * mimeData (const QModelIndexList &indices) const override
 
QStringList mimeTypes () const override
 
SessionItemmoveItem (SessionItem *item, SessionItem *new_parent=nullptr, int row=-1, const QString &tag="")
 Move given parameterized item to the new_parent at given row. If new_parent is not defined, use root_item as a new parent. More...
 
QVector< SessionItem * > nonXMLItems () const override
 
QModelIndex parent (const QModelIndex &child) const override
 
void readFrom (QXmlStreamReader *reader, MessageService *messageService=nullptr) override
 
void removeItem (SessionItem *item)
 
void removeJob (JobItem *jobItem)
 
bool removeRows (int row, int count, const QModelIndex &parent) override
 
void restore (JobItem *jobItem)
 restore instrument and sample model from backup for given JobItem More...
 
SessionItemrootItem () const
 
int rowCount (const QModelIndex &parent) const override
 
void runJob (JobItem *jobItem)
 
bool setData (const QModelIndex &index, const QVariant &value, int role) override
 
void setDraggedItemType (const QString &type)
 
Qt::DropActions supportedDragActions () const override
 
Qt::DropActions supportedDropActions () const override
 
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)
 

Protected Member Functions

void setRootItem (SessionItem *root)
 

Private Member Functions

QString generateJobName ()
 generates numbered job name with new/unused number More...
 

Private Attributes

QString m_dragged_item_type
 
QString m_model_tag
 
JobQueueDatam_queue_data
 
SessionItemm_root_item
 

Constructor & Destructor Documentation

◆ JobModel()

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

Definition at line 28 of file JobModel.cpp.

30  , m_queue_data(nullptr)
31 {
32  m_queue_data = new JobQueueData(this);
35  setObjectName(GUI::Session::XML::JobModelTag);
36 }
void focusRequest(JobItem *item)
void globalProgress(int)
JobQueueData * m_queue_data
Definition: JobModel.h:60
The JobQueueData class holds all objects/logic to run simulation in a thread.
Definition: JobQueueData.h:28
void focusRequest(JobItem *jobItem)
void globalProgress(int)
QModelIndex parent(const QModelIndex &child) const override
SessionModel(QString model_tag, QObject *parent=nullptr)
constexpr auto JobModelTag("JobModel")

References focusRequest(), JobQueueData::focusRequest(), globalProgress(), JobQueueData::globalProgress(), GUI::Session::XML::JobModelTag(), and m_queue_data.

Here is the call graph for this function:

◆ ~JobModel()

JobModel::~JobModel ( )
override

Definition at line 37 of file JobModel.cpp.

38 {
39  delete m_queue_data;
40 }

References m_queue_data.

Member Function Documentation

◆ acceptableDefaultItemTypes()

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

Definition at line 310 of file SessionModel.cpp.

311 {
312  QVector<QString> result;
313  if (SessionItem* parent_item = itemForIndex(parent))
314  result = parent_item->acceptableDefaultItemTypes();
315 
316  return result;
317 }
Base class for a GUI data item.
Definition: SessionItem.h:204
SessionItem * itemForIndex(const QModelIndex &index) const

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

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

Here is the call graph for this function:

◆ addJob()

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

Main method to add a job.

Definition at line 52 of file JobModel.cpp.

54 {
55  ASSERT(sampleItem);
56  ASSERT(instrumentItem);
57 
58  auto* jobItem = insertItem<JobItem>();
59  jobItem->setItemName(generateJobName());
60  jobItem->setIdentifier(QUuid::createUuid().toString());
61 
62  jobItem->copySampleIntoJob(sampleItem);
63  GUI::Model::JobFunctions::setupJobItemInstrument(jobItem, instrumentItem);
64 
65  jobItem->copySimulationOptionsIntoJob(optionItem);
66 
67  ParameterTreeBuilder(jobItem, true).build();
68 
70 
71  if (realDataItem)
72  GUI::Model::JobFunctions::setupJobItemForFit(jobItem, realDataItem);
73 
74  return jobItem;
75 }
QString generateJobName()
generates numbered job name with new/unused number
Definition: JobModel.cpp:160
The ParameterTreeBuilder contains helper functions to create container with ParameterItems....
void setupJobItemOutput(JobItem *jobItem)
Setup items intended for storing results of the job.
void setupJobItemForFit(JobItem *jobItem, const RealDataItem *realDataItem)
Setups JobItem for fit.
void setupJobItemInstrument(JobItem *jobItem, const InstrumentItem *from)
Properly copies instrument into job item.
QString toString(const QModelIndex &index)
Provides string representation of index data.

References ParameterTreeBuilder::build(), generateJobName(), GUI::Model::JobFunctions::setupJobItemForFit(), GUI::Model::JobFunctions::setupJobItemInstrument(), GUI::Model::JobFunctions::setupJobItemOutput(), and GUI::View::PropertyEditorFactory::toString().

Referenced by SimulationView::simulate().

Here is the call graph for this function:

◆ cancelJob()

void JobModel::cancelJob ( JobItem jobItem)

Definition at line 147 of file JobModel.cpp.

148 {
149  m_queue_data->cancelJob(jobItem->getIdentifier());
150 }
QString getIdentifier() const
Definition: JobItem.cpp:73
void cancelJob(const QString &identifier)
Cancels running job.

References JobQueueData::cancelJob(), JobItem::getIdentifier(), and m_queue_data.

Referenced by JobListModel::cancelJob().

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
overrideinherited

Definition at line 213 of file SessionModel.cpp.

215 {
216  Q_UNUSED(row);
217 
218  if (action == Qt::IgnoreAction)
219  return true;
220  if (action != Qt::MoveAction || column > 0 || !data
221  || !data->hasFormat(GUI::Session::XML::ItemMimeType))
222  return false;
223  if (!parent.isValid())
224  return true;
225  QVector<QString> acceptable_child_items = acceptableDefaultItemTypes(parent);
226  QByteArray xml_data = qUncompress(data->data(GUI::Session::XML::ItemMimeType));
227  QXmlStreamReader reader(xml_data);
228  while (!reader.atEnd()) {
229  reader.readNext();
230  if (reader.isStartElement()) {
231  if (reader.name() == GUI::Session::XML::ItemTag) {
232  const QString model_type =
233  reader.attributes().value(GUI::Session::XML::ModelTypeAttribute).toString();
234  return acceptable_child_items.contains(model_type);
235  }
236  }
237  }
238  return false;
239 }
QVariant data(const QModelIndex &index, int role) const override
QVector< QString > acceptableDefaultItemTypes(const QModelIndex &parent) const
constexpr auto ItemMimeType
Definition: SessionXML.h:30
constexpr auto ModelTypeAttribute("ModelType")
constexpr auto ItemTag("Item")

References SessionModel::acceptableDefaultItemTypes(), SessionModel::data(), GUI::Session::XML::ItemMimeType, GUI::Session::XML::ItemTag(), GUI::Session::XML::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 100 of file JobModel.cpp.

101 {
102  for (auto* job : jobItems())
103  removeJob(job);
104 
106 }
QVector< JobItem * > jobItems() const
Definition: JobModel.cpp:77
void removeJob(JobItem *jobItem)
Definition: JobModel.cpp:152
virtual void clear()

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

Referenced by ApplicationModels::readFrom().

Here is the call graph for this function:

◆ columnCount()

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

Definition at line 134 of file SessionModel.cpp.

135 {
136  if (parent.isValid() && parent.column() != 0)
137  return 0;
139 }

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 = nullptr,
const QString &  tag = "" 
)
inherited

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 395 of file SessionModel.cpp.

397 {
398  if (!new_parent)
399  new_parent = m_root_item;
400 
401  const QString tagName = tag.isEmpty() ? new_parent->defaultTag() : tag;
402 
403  QByteArray xml_data;
404  QXmlStreamWriter writer(&xml_data);
405  GUI::Session::XML::writeItemAndChildItems(&writer, item_to_copy);
406 
407  QXmlStreamReader reader(xml_data);
408  GUI::Session::XML::readItems(&reader, new_parent, tagName);
409 
410  return new_parent->getItems(tagName).back();
411 }
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:131
void writeItemAndChildItems(QXmlStreamWriter *writer, const SessionItem *item)
Definition: SessionXML.cpp:70
void readItems(QXmlStreamReader *reader, SessionItem *parent, QString topTag="", MessageService *messageService=nullptr)
Definition: SessionXML.cpp:113

References SessionItem::defaultTag(), SessionItem::getItems(), SessionModel::m_root_item, GUI::Session::XML::readItems(), and GUI::Session::XML::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 = nullptr,
const QString &  tag = "" 
)
inherited

Definition at line 149 of file SessionModel.h.

150 {
151  return static_cast<T*>(copy(item_to_copy, new_parent, tag));
152 }
SessionItem * copy(const SessionItem *item_to_copy, SessionItem *new_parent=nullptr, const QString &tag="")
Copy given item to the new_parent at given row. Item intended for copying can belong to another model...

References SessionModel::copy().

Referenced by MaskItems::copy(), and JobItem::copyRealDataIntoJob().

Here is the call graph for this function:

◆ createRootItem()

void SessionModel::createRootItem ( )
inherited

Definition at line 56 of file SessionModel.cpp.

57 {
58  m_root_item = new SessionItem("ROOT_ITEM");
59  m_root_item->setModel(this);
60  m_root_item->registerTag("rootTag");
61  m_root_item->setDefaultTag("rootTag");
62 }
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. max = -1 -> unlimited,...
void setDefaultTag(const QString &tag)
Set default tag.
void setModel(SessionModel *model)
friend class SessionItem
Definition: SessionModel.h:44

References SessionModel::m_root_item, SessionItem::registerTag(), SessionModel::SessionItem, 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
overrideinherited

Definition at line 88 of file SessionModel.cpp.

89 {
90  ASSERT(m_root_item);
91  if (!index.isValid() || index.column() < 0 || index.column() >= columnCount(QModelIndex()))
92  return {};
93  if (SessionItem* item = itemForIndex(index)) {
94  if (role == Qt::DisplayRole || role == Qt::EditRole) {
95  if (index.column() == SessionFlags::ITEM_VALUE)
96  return item->value();
97  if (index.column() == SessionFlags::ITEM_NAME)
98  return item->itemName();
99  } else if (role == Qt::ToolTipRole)
100  return toolTipRole(*item, index.column());
101  else if (role == Qt::ForegroundRole)
102  return item->isEnabled() ? QVariant() : QColor(Qt::gray);
103  else if (role == Qt::CheckStateRole && index.column() == SessionFlags::ITEM_VALUE) {
104  if (item->value().type() == QVariant::Bool)
105  return item->value().toBool() ? Qt::Checked : Qt::Unchecked;
106  } else
107  return item->roleProperty(role);
108  }
109  return {};
110 }
QModelIndex index(int row, int column, const QModelIndex &parent) const override
int columnCount(const QModelIndex &parent) const override

References SessionModel::columnCount(), SessionModel::index(), SessionFlags::ITEM_NAME, SessionFlags::ITEM_VALUE, SessionModel::itemForIndex(), SessionItem::itemName(), SessionModel::m_root_item, and SessionItem::value().

Referenced by SessionModel::canDropMimeData(), and SessionModel::dropMimeData().

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 
)
overrideinherited

Definition at line 241 of file SessionModel.cpp.

243 {
244  if (action == Qt::IgnoreAction)
245  return true;
246  if (action != Qt::MoveAction || column > 0 || !data
247  || !data->hasFormat(GUI::Session::XML::ItemMimeType))
248  return false;
249  if (!canDropMimeData(data, action, row, column, parent))
250  return false;
251  if (SessionItem* item = itemForIndex(parent)) {
252  QByteArray xml_data = qUncompress(data->data(GUI::Session::XML::ItemMimeType));
253  QXmlStreamReader reader(xml_data);
254  if (row == -1)
255  row = item->numberOfChildren();
256  beginInsertRows(parent, row, row);
257  // this code block is currently not in use. The row parameter of the reader is removed
258  // SessionReader::readItems(&reader, item, row);
259  endInsertRows();
260  return true;
261  }
262  return false;
263 }
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override

References SessionModel::canDropMimeData(), SessionModel::data(), SessionModel::itemForIndex(), GUI::Session::XML::ItemMimeType, SessionItem::numberOfChildren(), and SessionModel::parent().

Here is the call graph for this function:

◆ flags()

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

Definition at line 71 of file SessionModel.cpp.

72 {
73  Qt::ItemFlags result_flags = QAbstractItemModel::flags(index);
74  if (index.isValid()) {
75  result_flags |= Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
77  if (index.column() == SessionFlags::ITEM_VALUE && item->value().isValid()
78  && item->isEditable() && item->isEnabled())
79  result_flags |= Qt::ItemIsEditable;
80  QVector<QString> acceptable_child_items = acceptableDefaultItemTypes(index);
81  if (acceptable_child_items.contains(m_dragged_item_type))
82  result_flags |= Qt::ItemIsDropEnabled;
83  } else
84  result_flags |= Qt::ItemIsDropEnabled;
85  return result_flags;
86 }
QVariant value() const
Get value.
bool isEnabled() const
bool isEditable() const
QString m_dragged_item_type
Definition: SessionModel.h:132

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

Here is the call graph for this function:

◆ focusRequest

void JobModel::focusRequest ( JobItem item)
signal

◆ generateJobName()

QString JobModel::generateJobName ( )
private

generates numbered job name with new/unused number

Definition at line 160 of file JobModel.cpp.

161 {
162  int maxJobIndex = 0;
163  for (const auto* jobItem : jobItems()) {
164  if (jobItem->itemName().startsWith("job"))
165  maxJobIndex = std::max(maxJobIndex, jobItem->itemName().mid(3).toInt());
166  }
167  return QString("job%1").arg(maxJobIndex + 1);
168 }

References jobItems().

Referenced by addJob().

Here is the call graph for this function:

◆ getJobItemForIdentifier()

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

Definition at line 42 of file JobModel.cpp.

43 {
44  for (auto* jobItem : jobItems())
45  if (jobItem->getIdentifier() == identifier)
46  return jobItem;
47 
48  return nullptr;
49 }

References jobItems().

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

Here is the call graph for this function:

◆ getModelTag()

QString SessionModel::getModelTag ( ) const
inlineinherited

Definition at line 202 of file SessionModel.h.

203 {
204  return m_model_tag;
205 }
QString m_model_tag
Definition: SessionModel.h:133

References SessionModel::m_model_tag.

Referenced by ApplicationModels::readFrom(), GUI::Session::XML::readItems(), and GUI::Session::XML::writeModel().

◆ globalProgress

void JobModel::globalProgress ( int  )
signal

◆ hasUnfinishedJobs()

bool JobModel::hasUnfinishedJobs ( )

Definition at line 88 of file JobModel.cpp.

89 {
91  return true;
92 
93  for (auto* jobItem : jobItems())
94  if (jobItem->getStatus() == JobStatus::Fitting)
95  return true;
96 
97  return false;
98 }
@ Fitting
the job is busy fitting
bool hasUnfinishedJobs()

References Fitting, JobQueueData::hasUnfinishedJobs(), jobItems(), and m_queue_data.

Here is the call graph for this function:

◆ headerData()

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

Definition at line 112 of file SessionModel.cpp.

113 {
114  if (orientation != Qt::Horizontal || role != Qt::DisplayRole)
115  return {};
116  switch (section) {
118  return "Name";
120  return "Value";
121  default:
122  return {};
123  }
124 }

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

◆ index()

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

Definition at line 141 of file SessionModel.cpp.

142 {
143  ASSERT(m_root_item);
144  if (row < 0 || column < 0 || column >= columnCount(QModelIndex())
145  || (parent.isValid() && parent.column() != 0))
146  return QModelIndex();
147 
148  SessionItem* parent_item = itemForIndex(parent);
149 
150  if (SessionItem* item = parent_item->childAt(row))
151  return createIndex(row, column, item);
152  return QModelIndex();
153 }
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 MaskResultsPresenter::createMaskPresentation(), SessionModel::data(), MaskGraphicsScene::deleteViews(), SessionModel::flags(), MaskItems::insertMask(), GUI::Model::Path::isValidItem(), SessionModel::itemForIndex(), ModelMapper::onBeginRemoveRows(), ModelMapper::onRowRemoved(), MaskGraphicsScene::onRowsAboutToBeRemoved(), ItemStackWidget::onRowsAboutToBeRemoved(), ModelMapper::onRowsInserted(), SessionModel::removeItem(), SessionModel::setData(), MaskGraphicsScene::setItemName(), MaskGraphicsScene::setZValues(), SessionModel::topItems(), and MaskGraphicsScene::updateViews().

Here is the call graph for this function:

◆ indexOfItem()

QModelIndex SessionModel::indexOfItem ( SessionItem item) const
inherited

Definition at line 265 of file SessionModel.cpp.

266 {
267  if (!item || item == m_root_item || !item->parentItem())
268  return QModelIndex();
269  SessionItem* parent_item = item->parentItem();
270  int row = parent_item->rowOfChild(item);
271  return createIndex(row, 0, item);
272 }
int rowOfChild(SessionItem *child) const
Returns row index of given child.
SessionItem * parentItem() const
Returns parent of this item.
Definition: SessionItem.cpp:67

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

Referenced by MaskGraphicsScene::cancelCurrentDrawing(), MaskEditorActions::changeMaskStackingOrder(), SessionItem::emitDataChanged(), SessionItem::index(), MaskGraphicsScene::onSceneSelectionChanged(), MaskGraphicsScene::onSessionSelectionChanged(), MaskGraphicsScene::processLineItem(), MaskGraphicsScene::processPolygonItem(), and SessionModel::removeItem().

Here is the call graph for this function:

◆ initFrom()

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

Definition at line 413 of file SessionModel.cpp.

414 {
415  QByteArray byte_array;
416  QXmlStreamWriter writer(&byte_array);
417  writer.setAutoFormatting(true);
418 
419  model->writeTo(&writer);
420 
421  QXmlStreamReader reader(byte_array);
422 
423  while (!reader.atEnd()) {
424  reader.readNext();
425  if (reader.isStartElement())
426  readFrom(&reader);
427  }
428 }
virtual void readFrom(QXmlStreamReader *reader, MessageService *messageService=nullptr)
virtual void writeTo(QXmlStreamWriter *writer)

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

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 143 of file SessionModel.h.

144 {
145  return insertItem<T>(itemForIndex(parent), row, tag);
146 }

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

◆ insertNewItem() [1/2]

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

Definition at line 297 of file SessionModel.cpp.

299 {
300  return insertNewItem(model_type, itemForIndex(parent_item), row, tag);
301 }

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 274 of file SessionModel.cpp.

276 {
277  ASSERT(m_root_item);
278  if (!parent_item)
279  parent_item = m_root_item;
280  if (row > parent_item->numberOfChildren())
281  return nullptr;
282  if (parent_item != m_root_item) {
283  if (tag.isEmpty())
284  tag = parent_item->defaultTag();
285  if (!parent_item->sessionItemTags()->isValid(tag, model_type))
286  return nullptr;
287  }
288 
289  SessionItem* new_item = GUI::Model::ItemFactory::CreateItem(model_type);
290  ASSERT(new_item);
291 
292  parent_item->insertChild(row, new_item, tag);
293 
294  return new_item;
295 }
bool isValid(const QString &tagName, const QString &modelType="") const
Returns true if there is a registered tag with such name. If modelType is not empty,...
int numberOfChildren() const
Returns total number of children.
Definition: SessionItem.cpp:88
void insertChild(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.
const SessionItemTags * sessionItemTags() const
SessionItem * CreateItem(const QString &model_name, SessionItem *parent=nullptr)
create SessionItem of specific type and parent
Definition: ItemFactory.cpp:19

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

Referenced by SessionModel::insertItem(), SessionModel::insertNewItem(), and MaskGraphicsScene::processRectangleShapeItem().

Here is the call graph for this function:

◆ itemForIndex()

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

Definition at line 327 of file SessionModel.cpp.

328 {
329  if (index.isValid())
330  if (auto* item = static_cast<SessionItem*>(index.internalPointer()))
331  return item;
332 
333  return m_root_item;
334 }

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

Referenced by SessionModel::acceptableDefaultItemTypes(), MaskEditorActions::changeMaskStackingOrder(), MaskResultsPresenter::createMaskPresentation(), SessionModel::data(), DataProperties::dataItem(), MaskGraphicsScene::deleteViews(), SessionModel::dropMimeData(), SessionModel::flags(), SessionModel::index(), SessionModel::insertItem(), SessionModel::insertNewItem(), MaskEditorActions::isSendToBackPossible(), GUI::Model::Path::isValidItem(), MaskEditorPropertyPanel::maskItemForIndex(), SessionModel::mimeData(), ModelMapper::onBeginRemoveRows(), ModelMapper::onDataChanged(), ModelMapper::onRowRemoved(), ItemStackWidget::onRowsAboutToBeRemoved(), ModelMapper::onRowsInserted(), FitParameterModel::onSourceDataChanged(), MaskEditorActions::onToggleMaskValueAction(), SessionModel::parent(), SessionModel::removeRows(), SessionModel::rowCount(), SessionModel::setData(), MaskGraphicsScene::setItemName(), MaskEditor::setMaskContext(), MaskGraphicsScene::setMaskContext(), MaskGraphicsScene::setZValues(), SessionDecorationModel::textColor(), SessionModel::topItems(), MaskGraphicsScene::updateScene(), and MaskGraphicsScene::updateViews().

Here is the call graph for this function:

◆ jobItems()

◆ mimeData()

QMimeData * SessionModel::mimeData ( const QModelIndexList &  indices) const
overrideinherited

Definition at line 197 of file SessionModel.cpp.

198 {
199  if (indices.count() != 2)
200  return nullptr;
201 
202  if (SessionItem* item = itemForIndex(indices.at(0))) {
203  auto* mime_data = new QMimeData;
204  QByteArray xml_data;
205  QXmlStreamWriter writer(&xml_data);
207  mime_data->setData(GUI::Session::XML::ItemMimeType, qCompress(xml_data, MaxCompression));
208  return mime_data;
209  }
210  return nullptr;
211 }

References SessionModel::itemForIndex(), GUI::Session::XML::ItemMimeType, and GUI::Session::XML::writeItemAndChildItems().

Here is the call graph for this function:

◆ mimeTypes()

QStringList SessionModel::mimeTypes ( ) const
overrideinherited

Definition at line 192 of file SessionModel.cpp.

193 {
194  return QStringList() << GUI::Session::XML::ItemMimeType;
195 }

References GUI::Session::XML::ItemMimeType.

◆ moveItem()

SessionItem * SessionModel::moveItem ( SessionItem item,
SessionItem new_parent = nullptr,
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 360 of file SessionModel.cpp.

362 {
363  if (!new_parent)
364  new_parent = m_root_item;
365 
366  const QString tagName = tag.isEmpty() ? new_parent->defaultTag() : tag;
367 
368  if (!new_parent->sessionItemTags()->isValid(tagName, item->modelType()))
369  return nullptr;
370 
371  if (item->parentItem() == new_parent) {
372  // take care of indexes when moving item within same parent
373  int previousIndex = item->parentItem()->getItems(tagName).indexOf(item);
374  if (row == previousIndex)
375  return item;
376  if (previousIndex >= 0 && row > previousIndex)
377  row--;
378  }
379 
380  if (new_parent->sessionItemTags()->maximumReached(tagName)) {
381  SessionItem* prev = new_parent->takeItem(0, tagName);
382  m_root_item->insertChild(-1, prev);
383  }
384 
385  // removing item from previous parent and inserting to the new one
386  item->parentItem()->takeRow(item->parentItem()->rowOfChild(item));
387  new_parent->insertChild(row, item, tagName);
388 
389  return item;
390 }
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::insertChild(), SessionItemTags::isValid(), SessionModel::m_root_item, SessionItemTags::maximumReached(), SessionItem::modelType(), SessionItem::parentItem(), SessionItem::rowOfChild(), SessionItem::sessionItemTags(), SessionItem::takeItem(), and SessionItem::takeRow().

Referenced by MaskEditorActions::changeMaskStackingOrder().

Here is the call graph for this function:

◆ nonXMLItems()

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

Reimplemented from SessionModel.

Definition at line 108 of file JobModel.cpp.

109 {
110  QVector<SessionItem*> result;
111 
112  for (auto* jobItem : topItems<JobItem>()) {
113  if (auto* intensityItem = jobItem->dataItem())
114  result.push_back(intensityItem);
115 
116  if (auto* real_data = dynamic_cast<RealDataItem*>(jobItem->realDataItem())) {
117  if (auto* data_item = real_data->dataItem())
118  result.push_back(data_item);
119  if (auto* native_data = real_data->nativeData())
120  result.push_back(native_data);
121  }
122  }
123 
124  return result;
125 }
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33

Referenced by ApplicationModels::nonXMLItems().

◆ parent()

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

Definition at line 155 of file SessionModel.cpp.

156 {
157  if (!child.isValid())
158  return QModelIndex();
159 
160  if (SessionItem* child_item = itemForIndex(child)) {
161  if (SessionItem* parent_item = child_item->parentItem()) {
162  if (parent_item == m_root_item)
163  return QModelIndex();
164  return createIndex(parent_item->parentRow(), 0, parent_item);
165  }
166  }
167  return QModelIndex();
168 }

References SessionModel::itemForIndex(), SessionModel::m_root_item, and SessionItem::parentItem().

Referenced by SessionModel::acceptableDefaultItemTypes(), SessionModel::canDropMimeData(), SessionModel::columnCount(), SessionModel::dropMimeData(), SessionModel::index(), SessionModel::insertItem(), RealDataModel::onRowsChange(), SessionModel::removeRows(), and SessionModel::rowCount().

Here is the call graph for this function:

◆ readFrom()

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

Reimplemented from SessionModel.

Definition at line 127 of file JobModel.cpp.

128 {
129  SessionModel::readFrom(reader, messageService);
130 
131  // Set & check instrument links. JobItem and realDataItem have to reference the same instrument
132  // (which is the one contained in this job item, not contained in the instrument model)
133  for (auto* jobItem : jobItems()) {
134  if (RealDataItem* refItem = jobItem->realDataItem())
135  refItem->linkToInstrument(jobItem->instrumentItem());
136 
137  // Create the not stored parameter tuning tree
138  ParameterTreeBuilder(jobItem, false).build();
139  }
140 }

References ParameterTreeBuilder::build(), jobItems(), and SessionModel::readFrom().

Referenced by ApplicationModels::readFrom().

Here is the call graph for this function:

◆ removeItem()

void SessionModel::removeItem ( SessionItem item)
inherited

Definition at line 303 of file SessionModel.cpp.

304 {
305  QModelIndex index = indexOfItem(item);
306  if (index.isValid())
307  removeRows(index.row(), 1, index.parent());
308 }
bool removeRows(int row, int count, const QModelIndex &parent) override
QModelIndex indexOfItem(SessionItem *item) const

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

Here is the call graph for this function:

◆ removeJob()

void JobModel::removeJob ( JobItem jobItem)

Definition at line 152 of file JobModel.cpp.

153 {
154  ASSERT(jobItem);
155  m_queue_data->removeJob(jobItem->getIdentifier());
156 
157  removeRows(jobItem->index().row(), 1, QModelIndex());
158 }
void removeJob(const QString &identifier)
Remove job from list completely.
QModelIndex index() const
Returns model index of this item.
Definition: SessionItem.cpp:74

References JobItem::getIdentifier(), SessionItem::index(), m_queue_data, JobQueueData::removeJob(), and SessionModel::removeRows().

Referenced by clear(), and JobListModel::removeJob().

Here is the call graph for this function:

◆ removeRows()

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

Definition at line 183 of file SessionModel.cpp.

184 {
185  ASSERT(m_root_item);
186  SessionItem* item = parent.isValid() ? itemForIndex(parent) : m_root_item;
187  for (int i = 0; i < count; ++i)
188  delete item->takeRow(row);
189  return true;
190 }

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

Referenced by MaskGraphicsScene::cancelCurrentDrawing(), MaskContainerItem::clear(), ProjectionsEditorActions::onDeleteAction(), MaskEditorActions::onDeleteMaskAction(), 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 83 of file JobModel.cpp.

84 {
86 }
ParameterContainerItem * parameterContainerItem()
Definition: JobItem.cpp:271

References JobItem::parameterContainerItem(), and ParameterContainerItem::restoreBackupValues().

Referenced by ParameterTuningWidget::restoreModelsOfCurrentJobItem().

Here is the call graph for this function:

◆ rootItem()

SessionItem * SessionModel::rootItem ( ) const
inherited

Definition at line 430 of file SessionModel.cpp.

431 {
432  ASSERT(m_root_item);
433  return m_root_item;
434 }

References SessionModel::m_root_item.

Referenced by ModelMapper::nestlingDepth().

◆ rowCount()

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

Definition at line 126 of file SessionModel.cpp.

127 {
128  if (parent.isValid() && parent.column() != 0)
129  return 0;
130  SessionItem* parent_item = itemForIndex(parent);
131  return parent_item ? parent_item->numberOfChildren() : 0;
132 }

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

Referenced by MaskResultsPresenter::createMaskPresentation(), MaskGraphicsScene::deleteViews(), GUI::Model::Path::isValidItem(), MaskGraphicsScene::setItemName(), MaskGraphicsScene::setZValues(), SessionModel::topItems(), and MaskGraphicsScene::updateViews().

Here is the call graph for this function:

◆ runJob()

void JobModel::runJob ( JobItem jobItem)

Definition at line 142 of file JobModel.cpp.

143 {
144  m_queue_data->runJob(jobItem);
145 }
void runJob(JobItem *jobItem)
Submits job and run it in a thread.

References m_queue_data, and JobQueueData::runJob().

Referenced by ParameterTuningWidget::onCurrentLinkChanged(), ParameterTuningWidget::restoreModelsOfCurrentJobItem(), JobListModel::runJob(), and SimulationView::simulate().

Here is the call graph for this function:

◆ setData()

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

Definition at line 170 of file SessionModel.cpp.

171 {
172  if (!index.isValid())
173  return false;
174 
175  QModelIndex dataIndex = index;
176  if (SessionItem* item = itemForIndex(dataIndex))
177  if (item->setRoleProperty(role, value))
178  return true;
179 
180  return false;
181 }

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

Here is the call graph for this function:

◆ setDraggedItemType()

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

Definition at line 207 of file SessionModel.h.

208 {
209  m_dragged_item_type = type;
210 }

References SessionModel::m_dragged_item_type.

◆ setRootItem()

void SessionModel::setRootItem ( SessionItem root)
inlineprotectedinherited

Definition at line 128 of file SessionModel.h.

128 { m_root_item = root; }

References SessionModel::m_root_item.

◆ supportedDragActions()

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

Definition at line 192 of file SessionModel.h.

193 {
194  return Qt::MoveAction;
195 }

◆ supportedDropActions()

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

Definition at line 197 of file SessionModel.h.

198 {
199  return Qt::MoveAction;
200 }

◆ topItem()

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

Returns first item in list of topItems.

Definition at line 155 of file SessionModel.h.

156 {
157  auto items = topItems<T>();
158  return items.isEmpty() ? nullptr : items.front();
159 }

References SessionItem::items().

Here is the call graph for this function:

◆ topItems() [1/2]

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

Definition at line 162 of file SessionModel.h.

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

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

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 177 of file SessionModel.h.

178 {
179  QVector<T*> result;
180 
181  QModelIndex parentIndex;
182  for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) {
183  QModelIndex itemIndex = index(i_row, 0, parentIndex);
184  if (auto item = dynamic_cast<T*>(itemForIndex(itemIndex)))
185  if (accept(*item))
186  result.push_back(item);
187  }
188 
189  return result;
190 }

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

Here is the call graph for this function:

◆ writeTo()

void SessionModel::writeTo ( QXmlStreamWriter *  writer)
virtualinherited

Definition at line 352 of file SessionModel.cpp.

353 {
355 }
void writeModel(QXmlStreamWriter *writer, SessionItem *modelRootItem)
Definition: SessionXML.cpp:59

References SessionModel::m_root_item, and GUI::Session::XML::writeModel().

Referenced by SessionModel::initFrom(), and ApplicationModels::writeTo().

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 132 of file SessionModel.h.

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

◆ m_model_tag

QString SessionModel::m_model_tag
privateinherited

Definition at line 133 of file SessionModel.h.

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

◆ m_queue_data

JobQueueData* JobModel::m_queue_data
private

Definition at line 60 of file JobModel.h.

Referenced by JobModel(), ~JobModel(), cancelJob(), hasUnfinishedJobs(), removeJob(), and runJob().

◆ m_root_item


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