BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentSelectorWidget Class Reference

Instrument selector on the left side of InstrumentView. More...

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

Public Slots

void select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 
void selectLast ()
 
void updateSelection ()
 select last item if no selection exists More...
 

Signals

void contextMenuRequest (const QPoint &point, const QModelIndex &index)
 
void selectionChanged (SessionItem *item)
 

Public Member Functions

 InstrumentSelectorWidget (InstrumentModel *model=nullptr, QWidget *parent=nullptr)
 
QListView * listView ()
 
QSize minimumSizeHint () const
 
QItemSelectionModel * selectionModel ()
 
void setItemDelegate (QAbstractItemDelegate *delegate)
 
void setModel (SessionModel *model)
 
QSize sizeHint () const
 

Protected Member Functions

void connectModel ()
 
void disconnectModel ()
 
void showEvent (class QShowEvent *)
 provide default selection when widget is shown More...
 

Protected Attributes

std::unique_ptr< SessionDecorationModelm_decorationModel
 
QListView * m_listView
 
SessionModelm_model
 

Private Slots

void onCustomContextMenuRequested (const QPoint &point)
 
void onSelectionChanged (const QItemSelection &selected, const QItemSelection &)
 

Detailed Description

Instrument selector on the left side of InstrumentView.

Definition at line 24 of file InstrumentSelectorWidget.h.

Constructor & Destructor Documentation

◆ InstrumentSelectorWidget()

InstrumentSelectorWidget::InstrumentSelectorWidget ( InstrumentModel model = nullptr,
QWidget *  parent = nullptr 
)

Definition at line 23 of file InstrumentSelectorWidget.cpp.

24  : ItemSelectorWidget(parent)
25 {
26  setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
27 
28  listView()->setViewMode(QListView::IconMode);
29  listView()->setIconSize(QSize(96, 84));
30  listView()->setMovement(QListView::Static);
31  listView()->setMaximumWidth(200);
32  listView()->setSpacing(12);
33 
34  listView()->setObjectName("listView");
35  listView()->setStyleSheet(
36  QString::fromUtf8("QListView#listView\n"
37  "{\n"
38  " selection-background-color : rgb(98,100,105); \n"
39  " selection-color: rgb(255,255,255);\n"
40  " border: 1px solid rgb(98,100,105);\n"
41  "}\n"));
42 
43  setModel(model);
44  layout()->setMargin(10);
45 }
ItemSelectorWidget(QWidget *parent=0)
void setModel(SessionModel *model)

References ItemSelectorWidget::listView(), and ItemSelectorWidget::setModel().

Here is the call graph for this function:

Member Function Documentation

◆ connectModel()

void ItemSelectorWidget::connectModel ( )
protectedinherited

Definition at line 113 of file ItemSelectorWidget.cpp.

114 {
115  if (!m_model)
116  return;
117 
118  m_decorationModel = std::make_unique<SessionDecorationModel>(nullptr, m_model);
119  m_listView->setModel(m_decorationModel.get());
120 
121  connect(m_listView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
122  &ItemSelectorWidget::onSelectionChanged, Qt::UniqueConnection);
123 }
std::unique_ptr< SessionDecorationModel > m_decorationModel
void onSelectionChanged(const QItemSelection &selected, const QItemSelection &)
SessionModel * m_model

References ItemSelectorWidget::m_decorationModel, ItemSelectorWidget::m_listView, ItemSelectorWidget::m_model, and ItemSelectorWidget::onSelectionChanged().

Referenced by ItemSelectorWidget::setModel().

Here is the call graph for this function:

◆ contextMenuRequest

void ItemSelectorWidget::contextMenuRequest ( const QPoint &  point,
const QModelIndex &  index 
)
signalinherited

◆ disconnectModel()

void ItemSelectorWidget::disconnectModel ( )
protectedinherited

Definition at line 125 of file ItemSelectorWidget.cpp.

126 {
127  m_listView->setModel(nullptr);
128  m_model = nullptr;
129 }

References ItemSelectorWidget::m_listView, and ItemSelectorWidget::m_model.

Referenced by ItemSelectorWidget::setModel().

◆ listView()

QListView * ItemSelectorWidget::listView ( )
inherited

Definition at line 72 of file ItemSelectorWidget.cpp.

73 {
74  return m_listView;
75 }

References ItemSelectorWidget::m_listView.

Referenced by InstrumentSelectorWidget(), and JobListWidget::JobListWidget().

◆ minimumSizeHint()

QSize InstrumentSelectorWidget::minimumSizeHint ( ) const

Definition at line 52 of file InstrumentSelectorWidget.cpp.

53 {
54  return QSize(96, 200);
55 }

◆ onCustomContextMenuRequested

void ItemSelectorWidget::onCustomContextMenuRequested ( const QPoint &  point)
privateslotinherited

Definition at line 108 of file ItemSelectorWidget.cpp.

109 {
110  emit contextMenuRequest(m_listView->mapToGlobal(point), m_listView->indexAt(point));
111 }
void contextMenuRequest(const QPoint &point, const QModelIndex &index)

References ItemSelectorWidget::contextMenuRequest(), and ItemSelectorWidget::m_listView.

Referenced by ItemSelectorWidget::ItemSelectorWidget().

◆ onSelectionChanged

void ItemSelectorWidget::onSelectionChanged ( const QItemSelection &  selected,
const QItemSelection &   
)
privateslotinherited

Definition at line 97 of file ItemSelectorWidget.cpp.

98 {
99  QModelIndexList indexes = selected.indexes();
100  SessionItem* selectedItem(0);
101 
102  if (!indexes.empty())
103  selectedItem = m_model->itemForIndex(indexes.back());
104 
105  emit selectionChanged(selectedItem);
106 }
void selectionChanged(SessionItem *item)
SessionItem * itemForIndex(const QModelIndex &index) const

References SessionModel::itemForIndex(), ItemSelectorWidget::m_model, and ItemSelectorWidget::selectionChanged().

Referenced by ItemSelectorWidget::connectModel().

Here is the call graph for this function:

◆ select

void ItemSelectorWidget::select ( const QModelIndex &  index,
QItemSelectionModel::SelectionFlags  command 
)
slotinherited

Definition at line 77 of file ItemSelectorWidget.cpp.

79 {
80  selectionModel()->select(index, command);
81 }
QItemSelectionModel * selectionModel()

References ItemSelectorWidget::selectionModel().

Here is the call graph for this function:

◆ selectionChanged

void ItemSelectorWidget::selectionChanged ( SessionItem item)
signalinherited

◆ selectionModel()

◆ selectLast

void ItemSelectorWidget::selectLast ( )
slotinherited

Definition at line 91 of file ItemSelectorWidget.cpp.

92 {
93  QModelIndex itemIndex = m_model->index(m_model->rowCount(QModelIndex()) - 1, 0, QModelIndex());
94  selectionModel()->select(itemIndex, QItemSelectionModel::ClearAndSelect);
95 }
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual int rowCount(const QModelIndex &parent) const

References SessionModel::index(), ItemSelectorWidget::m_model, SessionModel::rowCount(), and ItemSelectorWidget::selectionModel().

Referenced by ItemSelectorWidget::updateSelection().

Here is the call graph for this function:

◆ setItemDelegate()

void ItemSelectorWidget::setItemDelegate ( QAbstractItemDelegate *  delegate)
inherited

Definition at line 62 of file ItemSelectorWidget.cpp.

63 {
64  m_listView->setItemDelegate(delegate);
65 }

References ItemSelectorWidget::m_listView.

◆ setModel()

void ItemSelectorWidget::setModel ( SessionModel model)
inherited

Definition at line 52 of file ItemSelectorWidget.cpp.

53 {
54  if (model == m_model)
55  return;
56 
58  m_model = model;
59  connectModel();
60 }

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

Referenced by InstrumentSelectorWidget(), InstrumentView::InstrumentView(), and JobListWidget::setModel().

Here is the call graph for this function:

◆ showEvent()

void ItemSelectorWidget::showEvent ( class QShowEvent *  )
protectedinherited

provide default selection when widget is shown

Definition at line 132 of file ItemSelectorWidget.cpp.

133 {
134  if (!m_model || !selectionModel())
135  return;
136 
137  if (selectionModel()->selectedIndexes().isEmpty() && m_model->rowCount(QModelIndex()) != 0)
138  selectionModel()->select(m_model->index(0, 0, QModelIndex()), QItemSelectionModel::Select);
139 }

References SessionModel::index(), ItemSelectorWidget::m_model, SessionModel::rowCount(), and ItemSelectorWidget::selectionModel().

Here is the call graph for this function:

◆ sizeHint()

QSize InstrumentSelectorWidget::sizeHint ( ) const

Definition at line 47 of file InstrumentSelectorWidget.cpp.

48 {
49  return QSize(170, 400);
50 }

◆ updateSelection

void ItemSelectorWidget::updateSelection ( )
slotinherited

select last item if no selection exists

Definition at line 85 of file ItemSelectorWidget.cpp.

86 {
87  if (!selectionModel()->hasSelection())
88  selectLast();
89 }

References ItemSelectorWidget::selectionModel(), and ItemSelectorWidget::selectLast().

Referenced by InstrumentView::showEvent().

Here is the call graph for this function:

Member Data Documentation

◆ m_decorationModel

std::unique_ptr<SessionDecorationModel> ItemSelectorWidget::m_decorationModel
protectedinherited

Definition at line 69 of file ItemSelectorWidget.h.

Referenced by ItemSelectorWidget::connectModel().

◆ m_listView

◆ m_model


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