BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
gui2::MaterialTableView Class Reference

Extension of QTableView for material editing. More...

Inheritance diagram for gui2::MaterialTableView:
[legend]
Collaboration diagram for gui2::MaterialTableView:
[legend]

Public Member Functions

 ~MaterialTableView () override
 
void setModel (QAbstractItemModel *model) override
 

Protected Member Functions

void keyPressEvent (QKeyEvent *event) override
 
QModelIndex moveCursor (QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override
 

Private Member Functions

bool isKeyboardEditable (const QModelIndex &index) const
 
bool isTextField (const QModelIndex &index) const
 

Detailed Description

Extension of QTableView for material editing.

Provide better user experinece while navigating between cells. Part of MaterialTableWidget.

Definition at line 27 of file materialtableview.h.

Constructor & Destructor Documentation

◆ ~MaterialTableView()

gui2::MaterialTableView::~MaterialTableView ( )
overridedefault

Member Function Documentation

◆ isKeyboardEditable()

bool gui2::MaterialTableView::isKeyboardEditable ( const QModelIndex &  index) const
private

Definition at line 64 of file materialtableview.cpp.

65 {
66  return index.isValid();
67 }

Referenced by keyPressEvent().

◆ isTextField()

bool gui2::MaterialTableView::isTextField ( const QModelIndex &  index) const
private

Definition at line 59 of file materialtableview.cpp.

60 {
61  return index.isValid() && index.column() > 1; // color and checkbox are not keyboard editable
62 }

Referenced by moveCursor().

◆ keyPressEvent()

void gui2::MaterialTableView::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Definition at line 31 of file materialtableview.cpp.

32 {
33  if (!event || event->key() != Qt::Key_Return || state() == QAbstractItemView::EditingState)
34  return QTableView::keyPressEvent(event);
35 
36  const QModelIndex index = currentIndex();
37  if (isKeyboardEditable(index))
38  edit(index);
39 }
bool isKeyboardEditable(const QModelIndex &index) const

References isKeyboardEditable().

Here is the call graph for this function:

◆ moveCursor()

QModelIndex gui2::MaterialTableView::moveCursor ( QAbstractItemView::CursorAction  cursorAction,
Qt::KeyboardModifiers  modifiers 
)
overrideprotected

Definition at line 41 of file materialtableview.cpp.

43 {
44  const QModelIndex current_index = currentIndex();
45  bool filtered_action = cursorAction == QAbstractItemView::MoveNext
46  || cursorAction == QAbstractItemView::MovePrevious;
47 
48  if (!current_index.isValid() || !isTextField(current_index) || !filtered_action)
49  return QTableView::moveCursor(cursorAction, modifiers);
50 
51  QModelIndex next = current_index;
52  do {
53  setCurrentIndex(next);
54  next = QTableView::moveCursor(cursorAction, modifiers);
55  } while (!isTextField(next));
56  return next;
57 }
bool isTextField(const QModelIndex &index) const

References isTextField().

Here is the call graph for this function:

◆ setModel()

void gui2::MaterialTableView::setModel ( QAbstractItemModel *  model)
override

Definition at line 23 of file materialtableview.cpp.

24 {
25  QTableView::setModel(model);
26  setAlternatingRowColors(true);
27  horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
28  horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
29 }

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