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

Description

The RealDataModel class is a model to store all imported RealDataItem's.

Definition at line 24 of file RealDataModel.h.

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

Signals

void realDataAddedOrRemoved ()
 

Public Member Functions

 RealDataModel (QObject *parent=nullptr)
 
QVector< QString > acceptableDefaultItemTypes (const QModelIndex &parent) const
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 
virtual void clear ()
 
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
 
QString getModelTag () const
 
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)
 
RealDataIteminsertDataItem (int rank)
 
RealDataIteminsertIntensityDataItem ()
 
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="")
 
RealDataIteminsertSpecularDataItem ()
 
SessionItemitemForIndex (const QModelIndex &index) 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
 
QVector< RealDataItem * > realDataItems () const
 
QVector< RealDataItem * > realDataItems (int rank) const
 
QVector< RealDataItem * > realDataItems1D () const
 
QVector< RealDataItem * > realDataItems2D () const
 
QStringList realDataNames () const
 
void remove (RealDataItem *item)
 
void removeItem (SessionItem *item)
 
bool removeRows (int row, int count, const QModelIndex &parent) override
 
SessionItemrootItem () const
 
int rowCount (const QModelIndex &parent) const override
 
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

SessionItemitemForIndex (const QModelIndex &index) const
 
void onRowsChange (const QModelIndex &parent, int, int)
 
void removeItem (SessionItem *item)
 
bool removeRows (int row, int count, const QModelIndex &parent) override
 

Private Attributes

QString m_dragged_item_type
 
QString m_model_tag
 
SessionItemm_root_item
 

Constructor & Destructor Documentation

◆ RealDataModel()

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

Definition at line 20 of file RealDataModel.cpp.

22 {
24 
25  connect(this, &SessionModel::rowsInserted, this, &RealDataModel::onRowsChange);
26  connect(this, &SessionModel::rowsRemoved, this, &RealDataModel::onRowsChange);
27 }
void onRowsChange(const QModelIndex &parent, int, int)
QModelIndex parent(const QModelIndex &child) const override
SessionModel(QString model_tag, QObject *parent=nullptr)
constexpr auto RealDataModelTag("RealDataModel")

References onRowsChange(), and GUI::Session::XML::RealDataModelTag().

Here is the call graph for this function:

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:

◆ 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 SessionModel::clear ( )
virtualinherited

Reimplemented in JobModel, and MaskItems.

Definition at line 319 of file SessionModel.cpp.

320 {
321  beginResetModel();
322  delete m_root_item;
323  createRootItem();
324  endResetModel();
325 }
void createRootItem()
SessionItem * m_root_item
Definition: SessionModel.h:131

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

Referenced by MaskItems::clear(), JobModel::clear(), ApplicationModels::readFrom(), and SessionModel::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.
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:

◆ 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().

◆ 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:

◆ insertDataItem()

RealDataItem * RealDataModel::insertDataItem ( int  rank)

Definition at line 71 of file RealDataModel.cpp.

72 {
73  return (rank == 1) ? insertSpecularDataItem() : insertIntensityDataItem();
74 }
RealDataItem * insertIntensityDataItem()
RealDataItem * insertSpecularDataItem()

References insertIntensityDataItem(), and insertSpecularDataItem().

Referenced by RealDataTreeModel::insertDataItem().

Here is the call graph for this function:

◆ insertIntensityDataItem()

RealDataItem * RealDataModel::insertIntensityDataItem ( )

Definition at line 64 of file RealDataModel.cpp.

65 {
66  auto* r = insertItem<RealDataItem>();
67  r->initAsIntensityItem();
68  return r;
69 }

Referenced by insertDataItem().

◆ 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:

◆ insertSpecularDataItem()

RealDataItem * RealDataModel::insertSpecularDataItem ( )

Definition at line 57 of file RealDataModel.cpp.

58 {
59  auto* r = insertItem<RealDataItem>();
60  r->initAsSpecularItem();
61  return r;
62 }

Referenced by insertDataItem().

◆ itemForIndex() [1/2]

SessionItem * SessionModel::itemForIndex
private

Definition at line 100 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 }

◆ itemForIndex() [2/2]

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:

◆ 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 * > RealDataModel::nonXMLItems ( ) const
overridevirtual

Reimplemented from SessionModel.

Definition at line 29 of file RealDataModel.cpp.

30 {
31  QVector<SessionItem*> result;
32 
33  for (auto* realData : topItems<RealDataItem>()) {
34  if (auto* intensityItem = realData->dataItem())
35  result.push_back(intensityItem);
36  if (auto* native_data_item = realData->nativeData())
37  result.push_back(native_data_item);
38  }
39 
40  return result;
41 }

Referenced by ApplicationModels::nonXMLItems().

◆ onRowsChange()

void RealDataModel::onRowsChange ( const QModelIndex &  parent,
int  ,
int   
)
private

Definition at line 110 of file RealDataModel.cpp.

111 {
112  // valid parent means not a data (which is top level item) but something below
113  if (parent.isValid())
114  return;
115 
116  emit realDataAddedOrRemoved();
117 }
void realDataAddedOrRemoved()

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

Referenced by RealDataModel(), and readFrom().

Here is the call graph for this function:

◆ 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(), onRowsChange(), SessionModel::removeRows(), and SessionModel::rowCount().

Here is the call graph for this function:

◆ readFrom()

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

Reimplemented from SessionModel.

Definition at line 43 of file RealDataModel.cpp.

44 {
45  // do not send added-notifications until completely read - otherwise partially
46  // initialized items will be notified
47  disconnect(this, &SessionModel::rowsInserted, this, &RealDataModel::onRowsChange);
48 
49  SessionModel::readFrom(reader, messageService);
50 
51  connect(this, &SessionModel::rowsInserted, this, &RealDataModel::onRowsChange);
52 
53  if (!realDataItems().isEmpty())
55 }
QVector< RealDataItem * > realDataItems() const

References onRowsChange(), SessionModel::readFrom(), realDataAddedOrRemoved(), and realDataItems().

Referenced by ApplicationModels::readFrom().

Here is the call graph for this function:

◆ realDataAddedOrRemoved

void RealDataModel::realDataAddedOrRemoved ( )
signal

Referenced by onRowsChange(), and readFrom().

◆ realDataItems() [1/2]

◆ realDataItems() [2/2]

QVector< RealDataItem * > RealDataModel::realDataItems ( int  rank) const

Definition at line 82 of file RealDataModel.cpp.

83 {
84  return rank == 1 ? realDataItems1D() : realDataItems2D();
85 }
QVector< RealDataItem * > realDataItems2D() const
QVector< RealDataItem * > realDataItems1D() const

References realDataItems1D(), and realDataItems2D().

Here is the call graph for this function:

◆ realDataItems1D()

QVector< RealDataItem * > RealDataModel::realDataItems1D ( ) const

Definition at line 87 of file RealDataModel.cpp.

88 {
89  return topItems<RealDataItem>([](const RealDataItem& item) { return item.isSpecularData(); });
90 }
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
bool isSpecularData() const

References RealDataItem::isSpecularData().

Referenced by realDataItems().

Here is the call graph for this function:

◆ realDataItems2D()

QVector< RealDataItem * > RealDataModel::realDataItems2D ( ) const

Definition at line 92 of file RealDataModel.cpp.

93 {
94  return topItems<RealDataItem>([](const RealDataItem& item) { return !item.isSpecularData(); });
95 }

References RealDataItem::isSpecularData().

Referenced by realDataItems().

Here is the call graph for this function:

◆ realDataNames()

QStringList RealDataModel::realDataNames ( ) const

Definition at line 102 of file RealDataModel.cpp.

103 {
104  QStringList result;
105  for (auto item : realDataItems())
106  result.append(item->dataName());
107  return result;
108 }

References realDataItems().

Referenced by SimulationView::writeOptionsToUI().

Here is the call graph for this function:

◆ remove()

void RealDataModel::remove ( RealDataItem item)

Definition at line 97 of file RealDataModel.cpp.

98 {
99  removeItem(item);
100 }
void removeItem(SessionItem *item)

References removeItem().

Referenced by RealDataTreeModel::removeItem().

Here is the call graph for this function:

◆ removeItem() [1/2]

void SessionModel::removeItem
private

Definition at line 88 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

Referenced by remove().

◆ removeItem() [2/2]

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

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

Here is the call graph for this function:

◆ removeRows() [1/2]

bool SessionModel::removeRows
overrideprivate

Definition at line 61 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 }
SessionItem * itemForIndex(const QModelIndex &index) const

◆ removeRows() [2/2]

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 JobModel::removeJob().

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:

◆ 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_root_item


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