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

Description

List of MaskItems.

Makes it possible to keep a list of MaskItems in a class which itself is not using SessionModel and which is not derived from SessionItem.

This class is only for migration away from SessionModel. To keep a list of items which are derived from SessionItem, right now a containing SessionModel is necessary. Once MaskItem is not derived from SessionItem any more, this class can be replaced by e.g. a simple QVector<MaskItem*>

Definition at line 232 of file MaskItems.h.

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

Public Member Functions

 MaskItems ()
 
void clear ()
 Removes all maskItems. More...
 
void copy (const MaskContainerItem *maskContainer)
 Copy the mask items stored in the given maskContainer. More...
 
void insertMask (int index, MaskItem *maskItem)
 Takes ownership of maskItem. More...
 
QVector< MaskItem * > maskItems () const
 
void serialize (Streamer &s)
 

Protected Member Functions

QVector< QString > acceptableDefaultItemTypes (const QModelIndex &parent) const
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const 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
 
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)
 
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
 
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...
 
virtual QVector< SessionItem * > nonXMLItems () const
 
QModelIndex parent (const QModelIndex &child) const override
 
virtual void readFrom (QXmlStreamReader *reader, MessageService *messageService=nullptr)
 
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)
 
void setRootItem (SessionItem *root)
 
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)
 

Private Attributes

QString m_dragged_item_type
 
MaskContainerItemm_maskContainer
 
QString m_model_tag
 
SessionItemm_root_item
 

Constructor & Destructor Documentation

◆ MaskItems()

MaskItems::MaskItems ( )

Definition at line 491 of file MaskItems.cpp.

492  : SessionModel("MaskItems")
493 {
494  m_maskContainer = insertItem<MaskContainerItem>();
495 }
MaskContainerItem * m_maskContainer
Definition: MaskItems.h:252
SessionModel(QString model_tag, QObject *parent=nullptr)

References m_maskContainer.

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
QModelIndex parent(const QModelIndex &child) const override
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 MaskItems::clear ( )
virtual

Removes all maskItems.

Reimplemented from SessionModel.

Definition at line 515 of file MaskItems.cpp.

516 {
518  m_maskContainer = insertItem<MaskContainerItem>();
519 }
virtual void clear()

References SessionModel::clear(), and m_maskContainer.

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() [1/2]

void MaskItems::copy ( const MaskContainerItem maskContainer)

Copy the mask items stored in the given maskContainer.

maskContainer can be nullptr.

Definition at line 507 of file MaskItems.cpp.

508 {
510  if (maskContainer)
511  for (auto mask : maskContainer->maskItems())
512  copyItem(mask, m_maskContainer);
513 }
void clear()
Remove all masks.
Definition: MaskItems.cpp:63
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:38
T * copyItem(const T *item_to_copy, SessionItem *new_parent=nullptr, const QString &tag="")
Definition: SessionModel.h:149

References MaskContainerItem::clear(), SessionModel::copyItem(), m_maskContainer, and MaskContainerItem::maskItems().

Referenced by DetectorItem::importMasks().

Here is the call graph for this function:

◆ copy() [2/2]

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 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(), 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

◆ insertMask()

void MaskItems::insertMask ( int  index,
MaskItem maskItem 
)

Takes ownership of maskItem.

Definition at line 497 of file MaskItems.cpp.

498 {
499  m_maskContainer->insertChild(index, maskItem);
500 }
void insertChild(int row, SessionItem *item, const QString &tag="")
Insert item into given tag into given row.

References SessionModel::index(), SessionItem::insertChild(), and m_maskContainer.

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

◆ maskItems()

QVector< MaskItem * > MaskItems::maskItems ( ) const

Definition at line 502 of file MaskItems.cpp.

503 {
504  return m_maskContainer->maskItems();
505 }

References m_maskContainer, and MaskContainerItem::maskItems().

Referenced by DetectorItem::addMasksToCore(), and serialize().

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 * > SessionModel::nonXMLItems ( ) const
virtualinherited

Reimplemented in RealDataModel, and JobModel.

Definition at line 436 of file SessionModel.cpp.

437 {
438  return QVector<SessionItem*>();
439 }

◆ 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 SessionModel::readFrom ( QXmlStreamReader *  reader,
MessageService messageService = nullptr 
)
virtualinherited

Reimplemented in RealDataModel, and JobModel.

Definition at line 336 of file SessionModel.cpp.

337 {
338  ASSERT(reader);
339 
340  if (reader->name() != m_model_tag)
341  throw Error("SessionModel::readFrom() -> Format error in p1");
342 
343  beginResetModel();
344  clear();
345 
346  GUI::Session::XML::readItems(reader, m_root_item, QString(), messageService);
347  if (reader->hasError())
348  throw Error(reader->errorString());
349  endResetModel();
350 }

References SessionModel::clear(), Error, SessionModel::m_model_tag, SessionModel::m_root_item, and GUI::Session::XML::readItems().

Referenced by SessionModel::initFrom(), JobModel::readFrom(), and RealDataModel::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:

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

◆ serialize()

void MaskItems::serialize ( Streamer s)

Definition at line 521 of file MaskItems.cpp.

522 {
523  QVector<MaskItem*> items;
524  if (!s.xmlReader())
525  items = maskItems();
526 
527  s.assertVersion(0);
528  Serialize::rwCatalogized<MaskItemCatalog>(s, "maskItems", items);
529 
530  if (s.xmlReader())
531  for (auto m : items)
533 }
void addMask(MaskItem *maskItem)
Definition: MaskItems.cpp:53
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:502
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26

References MaskContainerItem::addMask(), Streamer::assertVersion(), m_maskContainer, maskItems(), and Streamer::xmlReader().

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_maskContainer

MaskContainerItem* MaskItems::m_maskContainer
private

Definition at line 252 of file MaskItems.h.

Referenced by MaskItems(), clear(), copy(), insertMask(), maskItems(), and serialize().

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