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

Description

Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel). Every model is implementing a Qt item model, therefore the "model" in the class name. Each model is populated by objects derived from SessionItem.

Purpose of a model is to

  • Keep the root item of the contained data (which then keeps the tree of all items in this model)
  • adding/removing items
  • iteration over contained items
  • load/store the items in the project file as XML
  • use Qt mechanisms for GUI representation in different views
  • notification of data changes to any listener

Definition at line 42 of file SessionModel.h.

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

Public Member Functions

 SessionModel (QString model_tag, QObject *parent=nullptr)
 
 ~SessionModel () override
 
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)
 
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)
 
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 Attributes

QString m_dragged_item_type
 
QString m_model_tag
 
SessionItemm_root_item
 

Friends

class SessionItem
 

Constructor & Destructor Documentation

◆ SessionModel()

SessionModel::SessionModel ( QString  model_tag,
QObject *  parent = nullptr 
)
explicit

Definition at line 49 of file SessionModel.cpp.

50  : QAbstractItemModel(parent)
51  , m_model_tag(std::move(model_tag))
52 {
54 }
QModelIndex parent(const QModelIndex &child) const override
void createRootItem()
QString m_model_tag
Definition: SessionModel.h:133

References createRootItem().

Here is the call graph for this function:

◆ ~SessionModel()

SessionModel::~SessionModel ( )
override

Definition at line 64 of file SessionModel.cpp.

65 {
66  delete m_root_item;
67 }
SessionItem * m_root_item
Definition: SessionModel.h:131

References m_root_item.

Member Function Documentation

◆ acceptableDefaultItemTypes()

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

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 itemForIndex(), and parent().

Referenced by canDropMimeData(), and 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
override

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 acceptableDefaultItemTypes(), data(), GUI::Session::XML::ItemMimeType, GUI::Session::XML::ItemTag(), GUI::Session::XML::ModelTypeAttribute(), and parent().

Referenced by dropMimeData().

Here is the call graph for this function:

◆ clear()

void SessionModel::clear ( )
virtual

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 }

References createRootItem(), and m_root_item.

Referenced by MaskItems::clear(), JobModel::clear(), ApplicationModels::readFrom(), and readFrom().

Here is the call graph for this function:

◆ columnCount()

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

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

Referenced by data(), and 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 = "" 
)

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(), m_root_item, GUI::Session::XML::readItems(), and GUI::Session::XML::writeItemAndChildItems().

Referenced by 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 = "" 
)

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

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

Here is the call graph for this function:

◆ createRootItem()

void SessionModel::createRootItem ( )

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 m_root_item, SessionItem::registerTag(), SessionItem, and SessionItem::setModel().

Referenced by SessionModel(), and clear().

Here is the call graph for this function:

◆ data()

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

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 columnCount(), index(), SessionFlags::ITEM_NAME, SessionFlags::ITEM_VALUE, itemForIndex(), SessionItem::itemName(), m_root_item, and SessionItem::value().

Referenced by canDropMimeData(), and 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 
)
override

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 canDropMimeData(), data(), itemForIndex(), GUI::Session::XML::ItemMimeType, SessionItem::numberOfChildren(), and parent().

Here is the call graph for this function:

◆ flags()

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

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 acceptableDefaultItemTypes(), index(), SessionItem::isEditable(), SessionItem::isEnabled(), SessionFlags::ITEM_VALUE, itemForIndex(), m_dragged_item_type, and SessionItem::value().

Here is the call graph for this function:

◆ getModelTag()

QString SessionModel::getModelTag ( ) const
inline

Definition at line 202 of file SessionModel.h.

203 {
204  return m_model_tag;
205 }

References 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
override

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
override

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(), columnCount(), itemForIndex(), m_root_item, and parent().

Referenced by MaskResultsPresenter::createMaskPresentation(), data(), MaskGraphicsScene::deleteViews(), flags(), MaskItems::insertMask(), GUI::Model::Path::isValidItem(), itemForIndex(), ModelMapper::onBeginRemoveRows(), ModelMapper::onRowRemoved(), MaskGraphicsScene::onRowsAboutToBeRemoved(), ItemStackWidget::onRowsAboutToBeRemoved(), ModelMapper::onRowsInserted(), removeItem(), setData(), MaskGraphicsScene::setItemName(), MaskGraphicsScene::setZValues(), topItems(), and MaskGraphicsScene::updateViews().

Here is the call graph for this function:

◆ indexOfItem()

QModelIndex SessionModel::indexOfItem ( SessionItem item) const

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

Here is the call graph for this function:

◆ initFrom()

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

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 readFrom(), and 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 = "" 
)

Definition at line 143 of file SessionModel.h.

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

References itemForIndex(), and parent().

Here is the call graph for this function:

◆ insertItem() [2/2]

◆ insertNewItem() [1/2]

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

Definition at line 297 of file SessionModel.cpp.

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

References insertNewItem(), and 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 = "" 
)

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(), m_root_item, SessionItem::numberOfChildren(), and SessionItem::sessionItemTags().

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

Here is the call graph for this function:

◆ itemForIndex()

◆ mimeData()

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

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 itemForIndex(), GUI::Session::XML::ItemMimeType, and GUI::Session::XML::writeItemAndChildItems().

Here is the call graph for this function:

◆ mimeTypes()

QStringList SessionModel::mimeTypes ( ) const
override

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 = "" 
)

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

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
override

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 itemForIndex(), m_root_item, and SessionItem::parentItem().

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

Here is the call graph for this function:

◆ readFrom()

void SessionModel::readFrom ( QXmlStreamReader *  reader,
MessageService messageService = nullptr 
)
virtual

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 }
virtual void clear()

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

Referenced by initFrom(), JobModel::readFrom(), and RealDataModel::readFrom().

Here is the call graph for this function:

◆ removeItem()

void SessionModel::removeItem ( SessionItem item)

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 index(), indexOfItem(), and removeRows().

Here is the call graph for this function:

◆ removeRows()

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

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 itemForIndex(), m_root_item, parent(), and SessionItem::takeRow().

Referenced by MaskGraphicsScene::cancelCurrentDrawing(), MaskContainerItem::clear(), ProjectionsEditorActions::onDeleteAction(), MaskEditorActions::onDeleteMaskAction(), removeItem(), and JobModel::removeJob().

Here is the call graph for this function:

◆ rootItem()

SessionItem * SessionModel::rootItem ( ) const

Definition at line 430 of file SessionModel.cpp.

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

References m_root_item.

Referenced by ModelMapper::nestlingDepth().

◆ rowCount()

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

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 itemForIndex(), SessionItem::numberOfChildren(), and parent().

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

Here is the call graph for this function:

◆ setData()

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

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 index(), itemForIndex(), and SessionItem::setRoleProperty().

Here is the call graph for this function:

◆ setDraggedItemType()

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

Definition at line 207 of file SessionModel.h.

208 {
209  m_dragged_item_type = type;
210 }

References m_dragged_item_type.

◆ setRootItem()

void SessionModel::setRootItem ( SessionItem root)
inlineprotected

Definition at line 128 of file SessionModel.h.

128 { m_root_item = root; }

References m_root_item.

◆ supportedDragActions()

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

Definition at line 192 of file SessionModel.h.

193 {
194  return Qt::MoveAction;
195 }

◆ supportedDropActions()

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

Definition at line 197 of file SessionModel.h.

198 {
199  return Qt::MoveAction;
200 }

◆ topItem()

template<typename T >
T * SessionModel::topItem

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

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 index(), SessionItem::item(), itemForIndex(), and 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

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 index(), SessionItem::item(), itemForIndex(), and rowCount().

Here is the call graph for this function:

◆ writeTo()

void SessionModel::writeTo ( QXmlStreamWriter *  writer)
virtual

Definition at line 352 of file SessionModel.cpp.

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

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

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

Here is the call graph for this function:

Friends And Related Function Documentation

◆ SessionItem

friend class SessionItem
friend

Definition at line 44 of file SessionModel.h.

Referenced by createRootItem().

Member Data Documentation

◆ m_dragged_item_type

QString SessionModel::m_dragged_item_type
private

Definition at line 132 of file SessionModel.h.

Referenced by flags(), and setDraggedItemType().

◆ m_model_tag

QString SessionModel::m_model_tag
private

Definition at line 133 of file SessionModel.h.

Referenced by getModelTag(), and readFrom().

◆ m_root_item


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