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

Extension of QTreeView for material editing. More...

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

Public Member Functions

 MaterialTreeView (QWidget *parent=nullptr)
 
 ~MaterialTreeView () 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 QTreeView for material editing.

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

Definition at line 27 of file materialtreeview.h.

Constructor & Destructor Documentation

◆ MaterialTreeView()

gui2::MaterialTreeView::MaterialTreeView ( QWidget *  parent = nullptr)
explicit

Definition at line 23 of file materialtreeview.cpp.

23  : QTreeView(parent)
24 {
25  setAlternatingRowColors(true);
26  setSelectionBehavior(QAbstractItemView::SelectRows);
27  setSelectionMode(QAbstractItemView::ExtendedSelection);
28  // setTabKeyNavigation(true);
29  header()->setSectionResizeMode(QHeaderView::Stretch);
30 }

◆ ~MaterialTreeView()

gui2::MaterialTreeView::~MaterialTreeView ( )
overridedefault

Member Function Documentation

◆ isKeyboardEditable()

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

Definition at line 71 of file materialtreeview.cpp.

72 {
73  return index.isValid();
74 }

Referenced by keyPressEvent().

◆ isTextField()

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

Definition at line 66 of file materialtreeview.cpp.

67 {
68  return index.isValid() && index.column() > 0; // color is not keyboard editable
69 }

Referenced by moveCursor().

◆ keyPressEvent()

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

Definition at line 38 of file materialtreeview.cpp.

39 {
40  if (!event || event->key() != Qt::Key_Return || state() == QAbstractItemView::EditingState)
41  return QTreeView::keyPressEvent(event);
42 
43  const QModelIndex index = currentIndex();
44  if (isKeyboardEditable(index))
45  edit(index);
46 }
bool isKeyboardEditable(const QModelIndex &index) const

References isKeyboardEditable().

Here is the call graph for this function:

◆ moveCursor()

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

Definition at line 48 of file materialtreeview.cpp.

50 {
51  const QModelIndex current_index = currentIndex();
52  bool filtered_action = cursorAction == QAbstractItemView::MoveNext
53  || cursorAction == QAbstractItemView::MovePrevious;
54 
55  if (!current_index.isValid() || !isTextField(current_index) || !filtered_action)
56  return QTreeView::moveCursor(cursorAction, modifiers);
57 
58  QModelIndex next = current_index;
59  do {
60  setCurrentIndex(next);
61  next = QTreeView::moveCursor(cursorAction, modifiers);
62  } while (!isTextField(next));
63  return next;
64 }
bool isTextField(const QModelIndex &index) const

References isTextField().

Here is the call graph for this function:

◆ setModel()

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

Definition at line 32 of file materialtreeview.cpp.

33 {
34  QTreeView::setModel(model);
35  expandAll();
36 }

Referenced by gui2::MaterialEditorWidget::setModels().


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