BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ItemStackWidget Class Referenceabstract

Description

The ItemStackWidget class contains a stack of widgets presenting top level items of SessionModel. Every item corresponds to its own widget.

This is the base for ItemStackPresenter, which actually contains item specific editor's logic. Used in InstrumentView, ImportDataView, JobView to show editors for currently selected items.

Definition at line 30 of file ItemStackWidget.h.

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

Public Slots

virtual void onModelAboutToBeReset ()
 
virtual void onRowsAboutToBeRemoved (const QModelIndex &parent, int first, int)
 

Public Member Functions

 ItemStackWidget (QWidget *parent=nullptr)
 
QSize minimumSizeHint () const override
 
void setModel (SessionModel *model)
 
void setSizeHint (const QSize &size_hint)
 
QSize sizeHint () const override
 

Protected Member Functions

void connectModel ()
 
void disconnectModel ()
 
virtual void removeWidgetForItem (SessionItem *item)=0
 
virtual void removeWidgets ()=0
 
void validateItem (SessionItem *item)
 Checks if model was set correctly. More...
 

Protected Attributes

SessionModelm_model
 
QSize m_size_hint
 
class QStackedWidget * m_stackedWidget
 

Constructor & Destructor Documentation

◆ ItemStackWidget()

ItemStackWidget::ItemStackWidget ( QWidget *  parent = nullptr)

Definition at line 21 of file ItemStackWidget.cpp.

22  : QWidget(parent)
23  , m_stackedWidget(new QStackedWidget)
24  , m_model(nullptr)
25  , m_size_hint(QSize(1024, 1024))
26 {
27  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
28  m_stackedWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
29 
30  auto* layout = new QVBoxLayout;
31  layout->setMargin(0);
32  layout->setSpacing(0);
33  layout->setContentsMargins(0, 0, 0, 0);
34  layout->addWidget(m_stackedWidget);
35  setLayout(layout);
36 }
class QStackedWidget * m_stackedWidget
SessionModel * m_model

References m_stackedWidget.

Member Function Documentation

◆ connectModel()

void ItemStackWidget::connectModel ( )
protected

Definition at line 74 of file ItemStackWidget.cpp.

75 {
76  if (!m_model)
77  return;
78 
79  connect(m_model, &SessionModel::modelAboutToBeReset, this,
80  &ItemStackWidget::onModelAboutToBeReset, Qt::UniqueConnection);
81 
82  connect(m_model, &SessionModel::rowsAboutToBeRemoved, this,
83  &ItemStackWidget::onRowsAboutToBeRemoved, Qt::UniqueConnection);
84 }
virtual void onModelAboutToBeReset()
virtual void onRowsAboutToBeRemoved(const QModelIndex &parent, int first, int)

References m_model, onModelAboutToBeReset(), and onRowsAboutToBeRemoved().

Referenced by setModel().

Here is the call graph for this function:

◆ disconnectModel()

void ItemStackWidget::disconnectModel ( )
protected

Definition at line 86 of file ItemStackWidget.cpp.

87 {
88  if (!m_model)
89  return;
90 
91  disconnect(m_model, &SessionModel::modelAboutToBeReset, this,
93 
94  disconnect(m_model, &SessionModel::rowsAboutToBeRemoved, this,
96 }

References m_model, onModelAboutToBeReset(), and onRowsAboutToBeRemoved().

Referenced by setModel().

Here is the call graph for this function:

◆ minimumSizeHint()

QSize ItemStackWidget::minimumSizeHint ( ) const
override

Definition at line 53 of file ItemStackWidget.cpp.

54 {
55  return QSize(25, 25);
56 }

◆ onModelAboutToBeReset

void ItemStackWidget::onModelAboutToBeReset ( )
virtualslot

Definition at line 63 of file ItemStackWidget.cpp.

64 {
65  removeWidgets();
66 }
virtual void removeWidgets()=0

References removeWidgets().

Referenced by connectModel(), and disconnectModel().

Here is the call graph for this function:

◆ onRowsAboutToBeRemoved

void ItemStackWidget::onRowsAboutToBeRemoved ( const QModelIndex &  parent,
int  first,
int   
)
virtualslot

Definition at line 68 of file ItemStackWidget.cpp.

69 {
70  SessionItem* item = m_model->itemForIndex(m_model->index(first, 0, parent));
71  removeWidgetForItem(item);
72 }
virtual void removeWidgetForItem(SessionItem *item)=0
Base class for a GUI data item.
Definition: SessionItem.h:204
SessionItem * itemForIndex(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent) const override

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

Referenced by connectModel(), and disconnectModel().

Here is the call graph for this function:

◆ removeWidgetForItem()

virtual void ItemStackWidget::removeWidgetForItem ( SessionItem item)
protectedpure virtual

◆ removeWidgets()

virtual void ItemStackWidget::removeWidgets ( )
protectedpure virtual

◆ setModel()

void ItemStackWidget::setModel ( SessionModel model)

Definition at line 38 of file ItemStackWidget.cpp.

39 {
40  if (model == m_model)
41  return;
42 
44  m_model = model;
45  connectModel();
46 }

References connectModel(), disconnectModel(), and m_model.

Referenced by ImportDataView::ImportDataView(), JobRealTimeWidget::JobRealTimeWidget(), and validateItem().

Here is the call graph for this function:

◆ setSizeHint()

void ItemStackWidget::setSizeHint ( const QSize &  size_hint)

Definition at line 58 of file ItemStackWidget.cpp.

59 {
60  m_size_hint = size_hint;
61 }

References m_size_hint.

Referenced by ImportDataView::ImportDataView().

◆ sizeHint()

QSize ItemStackWidget::sizeHint ( ) const
override

Definition at line 48 of file ItemStackWidget.cpp.

49 {
50  return m_size_hint;
51 }

References m_size_hint.

◆ validateItem()

void ItemStackWidget::validateItem ( SessionItem item)
protected

Checks if model was set correctly.

Definition at line 100 of file ItemStackWidget.cpp.

101 {
102  if (!item)
103  return;
104 
105  if (m_model) {
106  if (m_model != item->model())
107  // in principle it should be possible, but should be tested
108  throw Error("ItemStackWidget::validateItem() -> Error. "
109  "Attempt to use items from different models.");
110  } else {
111  setModel(item->model());
112  }
113 }
void setModel(SessionModel *model)
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:60

References Error, m_model, SessionItem::model(), and setModel().

Here is the call graph for this function:

Member Data Documentation

◆ m_model

SessionModel* ItemStackWidget::m_model
protected

◆ m_size_hint

QSize ItemStackWidget::m_size_hint
protected

Definition at line 56 of file ItemStackWidget.h.

Referenced by setSizeHint(), and sizeHint().

◆ m_stackedWidget

class QStackedWidget* ItemStackWidget::m_stackedWidget
protected

Definition at line 54 of file ItemStackWidget.h.

Referenced by ItemStackWidget().


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