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

The ItemSelectorWidget class holds QListView to show top level items of SessionModel. More...

Inheritance diagram for ItemSelectorWidget:
[legend]
Collaboration diagram for ItemSelectorWidget:
[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

 ItemSelectorWidget (QWidget *parent=0)
 
 ~ItemSelectorWidget ()
 
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

The ItemSelectorWidget class holds QListView to show top level items of SessionModel.

Used in InstrumentView and JobSelectorView to switch between items.

Definition at line 33 of file ItemSelectorWidget.h.

Constructor & Destructor Documentation

◆ ItemSelectorWidget()

ItemSelectorWidget::ItemSelectorWidget ( QWidget *  parent = 0)

Definition at line 22 of file ItemSelectorWidget.cpp.

23  : QWidget(parent), m_listView(new QListView), m_model(nullptr)
24 {
25  setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
26 
27  QVBoxLayout* layout = new QVBoxLayout;
28  layout->setMargin(0);
29 
30  layout->addWidget(m_listView);
31  setLayout(layout);
32 
33  m_listView->setContextMenuPolicy(Qt::CustomContextMenu);
34  m_listView->setAttribute(Qt::WA_MacShowFocusRect, false);
35 
36  connect(m_listView, &QListView::customContextMenuRequested, this,
38 }
void onCustomContextMenuRequested(const QPoint &point)
SessionModel * m_model

References m_listView, and onCustomContextMenuRequested().

Here is the call graph for this function:

◆ ~ItemSelectorWidget()

ItemSelectorWidget::~ItemSelectorWidget ( )
default

Member Function Documentation

◆ connectModel()

void ItemSelectorWidget::connectModel ( )
protected

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 &)

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

Referenced by setModel().

Here is the call graph for this function:

◆ contextMenuRequest

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

◆ disconnectModel()

void ItemSelectorWidget::disconnectModel ( )
protected

Definition at line 125 of file ItemSelectorWidget.cpp.

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

References m_listView, and m_model.

Referenced by setModel().

◆ listView()

QListView * ItemSelectorWidget::listView ( )

Definition at line 72 of file ItemSelectorWidget.cpp.

73 {
74  return m_listView;
75 }

References m_listView.

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

◆ minimumSizeHint()

QSize ItemSelectorWidget::minimumSizeHint ( ) const

Definition at line 47 of file ItemSelectorWidget.cpp.

48 {
49  return QSize(25, 25);
50 }

◆ onCustomContextMenuRequested

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

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 contextMenuRequest(), and m_listView.

Referenced by ItemSelectorWidget().

◆ onSelectionChanged

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

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(), m_model, and selectionChanged().

Referenced by connectModel().

Here is the call graph for this function:

◆ select

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

Definition at line 77 of file ItemSelectorWidget.cpp.

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

References selectionModel().

Here is the call graph for this function:

◆ selectionChanged

void ItemSelectorWidget::selectionChanged ( SessionItem item)
signal

◆ selectionModel()

QItemSelectionModel * ItemSelectorWidget::selectionModel ( )

◆ selectLast

void ItemSelectorWidget::selectLast ( )
slot

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(), m_model, SessionModel::rowCount(), and selectionModel().

Referenced by updateSelection().

Here is the call graph for this function:

◆ setItemDelegate()

void ItemSelectorWidget::setItemDelegate ( QAbstractItemDelegate *  delegate)

Definition at line 62 of file ItemSelectorWidget.cpp.

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

References m_listView.

◆ setModel()

void ItemSelectorWidget::setModel ( SessionModel model)

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 connectModel(), disconnectModel(), and m_model.

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

Here is the call graph for this function:

◆ showEvent()

void ItemSelectorWidget::showEvent ( class QShowEvent *  )
protected

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(), m_model, SessionModel::rowCount(), and selectionModel().

Here is the call graph for this function:

◆ sizeHint()

QSize ItemSelectorWidget::sizeHint ( ) const

Definition at line 42 of file ItemSelectorWidget.cpp.

43 {
45 }
const unsigned int ITEM_SELECTOR_WIDGET_WIDTH
const unsigned int ITEM_SELECTOR_WIDGET_HEIGHT

References Constants::ITEM_SELECTOR_WIDGET_HEIGHT, and Constants::ITEM_SELECTOR_WIDGET_WIDTH.

◆ updateSelection

void ItemSelectorWidget::updateSelection ( )
slot

select last item if no selection exists

Definition at line 85 of file ItemSelectorWidget.cpp.

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

References selectionModel(), and 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
protected

Definition at line 69 of file ItemSelectorWidget.h.

Referenced by connectModel().

◆ m_listView

QListView* ItemSelectorWidget::m_listView
protected

◆ m_model

SessionModel* ItemSelectorWidget::m_model
protected

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