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

Additional action for ComponentTreeView. More...

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

Public Slots

void onCustomContextMenuRequested (const QPoint &point, SessionItem &item)
 Creates right-mouse-click context menu on top of ComponentTreeView which will allow user to switch between scientific notation and the notation with a specified number of decimals. More...
 

Public Member Functions

 ComponentTreeActions (QObject *parent=nullptr)
 

Detailed Description

Additional action for ComponentTreeView.

Definition at line 24 of file ComponentTreeActions.h.

Constructor & Destructor Documentation

◆ ComponentTreeActions()

ComponentTreeActions::ComponentTreeActions ( QObject *  parent = nullptr)

Definition at line 20 of file ComponentTreeActions.cpp.

20 : QObject(parent) {}

Member Function Documentation

◆ onCustomContextMenuRequested

void ComponentTreeActions::onCustomContextMenuRequested ( const QPoint &  point,
SessionItem item 
)
slot

Creates right-mouse-click context menu on top of ComponentTreeView which will allow user to switch between scientific notation and the notation with a specified number of decimals.

Definition at line 26 of file ComponentTreeActions.cpp.

27 {
28  bool sc_editor = item.editorType() == "ScientificDouble";
29 
30  QMenu menu;
31  QAction* scientificAction = menu.addAction("Scientific presentation");
32  scientificAction->setCheckable(true);
33  auto doubleMenu = menu.addMenu("Double presentation");
34 
35  // To select scientific notation
36  scientificAction->setChecked(sc_editor);
37  connect(scientificAction, &QAction::triggered, [&]() {
38  if (scientificAction->isChecked())
39  item.setEditorType("ScientificDouble");
40  else
41  item.setEditorType("Default");
42  });
43 
44  // to select number of decimals
45  const int nmaxdigits = 8;
46  for (int i = 1; i <= nmaxdigits; ++i) {
47  auto action = doubleMenu->addAction(QString("%1 digits").arg(i));
48  if (!sc_editor && item.decimals() == i)
49  action->setChecked(true);
50  connect(action, &QAction::triggered, [i, &item] {
51  item.setEditorType("Default");
52  item.setDecimals(i);
53  });
54  }
55  menu.exec(point);
56 }
int decimals() const
SessionItem & setDecimals(int n)
SessionItem & setEditorType(const QString &editorType)
QString editorType() const

References SessionItem::decimals(), SessionItem::editorType(), SessionItem::setDecimals(), and SessionItem::setEditorType().

Referenced by ComponentTreeView::onCustomContextMenuRequested().

Here is the call graph for this function:

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