BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ComponentTreeActions.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/PropertyEditor/ComponentTreeActions.cpp
6 //! @brief Implements class ComponentTreeActions
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
17 #include <QAction>
18 #include <QMenu>
19 
20 ComponentTreeActions::ComponentTreeActions(QObject* parent) : QObject(parent) {}
21 
22 //! Creates right-mouse-click context menu on top of ComponentTreeView
23 //! which will allow user to switch between scientific notation and the notation
24 //! with a specified number of decimals.
25 
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 }
Defines class ComponentTreeActions.
Defines class SessionItem.
ComponentTreeActions(QObject *parent=nullptr)
void onCustomContextMenuRequested(const QPoint &point, SessionItem &item)
Creates right-mouse-click context menu on top of ComponentTreeView which will allow user to switch be...
int decimals() const
SessionItem & setDecimals(int n)
SessionItem & setEditorType(const QString &editorType)
QString editorType() const