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

Class to handle MainWindow's menu and corresponding actions. More...

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

Public Member Functions

 ActionManager (MainWindow *parent)
 

Private Slots

void onAboutApplication ()
 
void onAboutToShowFileMenu ()
 
void onAboutToShowSettingsMenu ()
 
void onAboutToShowViewMenu ()
 
void onCurrentViewChanged ()
 
void onImportFromPythonScript ()
 
void setSessionModelViewActive (bool status)
 
void toggleCheckForUpdates (bool status)
 

Private Member Functions

void createActions ()
 
void createGlobalShortcuts ()
 
void createMenus ()
 

Private Attributes

QAction * m_aboutAction
 
QAction * m_exitAction
 
QMenu * m_fileMenu
 
QMenu * m_helpMenu
 
QMenu * m_importMenu
 
MainWindowm_mainWindow
 
QMenuBar * m_menuBar
 
QAction * m_newAction
 
QAction * m_openAction
 
QMenu * m_recentProjectsMenu
 
QShortcut * m_runSimulationShortcut
 
QAction * m_saveAction
 
QAction * m_saveAsAction
 
QMenu * m_settingsMenu
 
QMenu * m_viewMenu
 

Detailed Description

Class to handle MainWindow's menu and corresponding actions.

Definition at line 28 of file actionmanager.h.

Constructor & Destructor Documentation

◆ ActionManager()

ActionManager::ActionManager ( MainWindow parent)

Definition at line 34 of file actionmanager.cpp.

35  : QObject(parent)
36  , m_mainWindow(parent)
37  , m_newAction(nullptr)
38  , m_openAction(nullptr)
39  , m_saveAction(nullptr)
40  , m_saveAsAction(nullptr)
41  , m_exitAction(nullptr)
42  , m_aboutAction(nullptr)
43  , m_menuBar(nullptr)
44  , m_fileMenu(nullptr)
45  , m_settingsMenu(nullptr)
46  , m_viewMenu(nullptr)
47  , m_recentProjectsMenu(nullptr)
48  , m_helpMenu(nullptr)
49  , m_importMenu(nullptr)
50  , m_runSimulationShortcut(nullptr)
51 {
52  createActions();
53  createMenus();
55 
58 }
MainWindow * m_mainWindow
Definition: actionmanager.h:46
void onCurrentViewChanged()
QMenu * m_viewMenu
Definition: actionmanager.h:58
void createGlobalShortcuts()
QAction * m_exitAction
Definition: actionmanager.h:52
QMenu * m_helpMenu
Definition: actionmanager.h:60
QAction * m_newAction
Definition: actionmanager.h:48
QMenu * m_settingsMenu
Definition: actionmanager.h:57
QAction * m_saveAsAction
Definition: actionmanager.h:51
void createActions()
QMenu * m_importMenu
Definition: actionmanager.h:61
QMenu * m_fileMenu
Definition: actionmanager.h:56
QMenu * m_recentProjectsMenu
Definition: actionmanager.h:59
QAction * m_openAction
Definition: actionmanager.h:49
QShortcut * m_runSimulationShortcut
Definition: actionmanager.h:63
QAction * m_saveAction
Definition: actionmanager.h:50
QMenuBar * m_menuBar
Definition: actionmanager.h:55
QAction * m_aboutAction
Definition: actionmanager.h:53
void currentViewChanged(ViewId newView)

References createActions(), createGlobalShortcuts(), createMenus(), MainWindow::currentViewChanged(), m_mainWindow, and onCurrentViewChanged().

Here is the call graph for this function:

Member Function Documentation

◆ createActions()

void ActionManager::createActions ( )
private

Definition at line 60 of file actionmanager.cpp.

61 {
62  ProjectManager* projectManager = m_mainWindow->projectManager();
63  ASSERT(projectManager);
64 
65  // new project action
66  m_newAction = new QAction("&New Project", m_mainWindow);
67  m_newAction->setShortcuts(QKeySequence::New);
68  m_newAction->setStatusTip("Create a new project");
69  connect(m_newAction, &QAction::triggered, projectManager, &ProjectManager::newProject);
70 
71  // open project action
72  m_openAction = new QAction("&Open Project", m_mainWindow);
73  m_openAction->setShortcuts(QKeySequence::Open);
74  m_openAction->setStatusTip("Open an existing project");
75  connect(m_openAction, &QAction::triggered, projectManager,
76  [projectManager]() { projectManager->openProject(); });
77 
78  // save project action
79  m_saveAction = new QAction("&Save Project", m_mainWindow);
80  m_saveAction->setShortcuts(QKeySequence::Save);
81  m_saveAction->setStatusTip("Save project");
82  m_saveAction->setShortcutContext(Qt::ApplicationShortcut);
83  connect(m_saveAction, &QAction::triggered, projectManager,
84  [projectManager]() { projectManager->saveProject(); });
85 
86  // save-as project action
87  m_saveAsAction = new QAction("Save &As...", m_mainWindow);
88  m_saveAsAction->setShortcuts(QKeySequence::SaveAs);
89  m_saveAsAction->setStatusTip("Save project under different name");
90  connect(m_saveAsAction, &QAction::triggered, projectManager, &ProjectManager::saveProjectAs);
91 
92  // exit application action
93  m_exitAction = new QAction("E&xit Application", this);
94  m_exitAction->setShortcuts(QKeySequence::Quit);
95  m_exitAction->setStatusTip("Exit the application");
96  connect(m_exitAction, &QAction::triggered, m_mainWindow, &MainWindow::close);
97 
98  // about application action
99  m_aboutAction = new QAction("About &BornAgain", this);
100  m_aboutAction->setStatusTip("About the application");
101  connect(m_aboutAction, &QAction::triggered, this, &ActionManager::onAboutApplication);
102 }
#define ASSERT(condition)
Definition: Assert.h:31
void onAboutApplication()
ProjectManager * projectManager()
Definition: mainwindow.cpp:179
Handles activity related to opening/save projects.
bool saveProject(QString projectFileName="")
Processes save project request.
void openProject(QString fileName="")
Opens existing project. If fileName is empty, will popup file selection dialog.
void newProject()
Processes new project request (close old project, rise dialog for project name, create project).
bool saveProjectAs()
Processes 'save project as' request.

References ASSERT, m_aboutAction, m_exitAction, m_mainWindow, m_newAction, m_openAction, m_saveAction, m_saveAsAction, ProjectManager::newProject(), onAboutApplication(), ProjectManager::openProject(), MainWindow::projectManager(), ProjectManager::saveProject(), and ProjectManager::saveProjectAs().

Referenced by ActionManager().

Here is the call graph for this function:

◆ createGlobalShortcuts()

void ActionManager::createGlobalShortcuts ( )
private

Definition at line 162 of file actionmanager.cpp.

163 {
164  m_runSimulationShortcut = new QShortcut(QKeySequence("Ctrl+r"), m_mainWindow);
165  m_runSimulationShortcut->setContext((Qt::ApplicationShortcut));
166  connect(m_runSimulationShortcut, &QShortcut::activated, m_mainWindow,
168 }
void onRunSimulationShortcut()
Definition: mainwindow.cpp:215

References m_mainWindow, m_runSimulationShortcut, and MainWindow::onRunSimulationShortcut().

Referenced by ActionManager().

Here is the call graph for this function:

◆ createMenus()

void ActionManager::createMenus ( )
private

Definition at line 104 of file actionmanager.cpp.

105 {
106  m_menuBar = new QMenuBar(0); // No parent (System menu bar on Mac OS X)
107 
109  m_mainWindow->setMenuBar(m_menuBar);
110 
111  // File Menu
112  m_fileMenu = m_menuBar->addMenu("&File");
113  m_fileMenu->addAction(m_newAction);
114  m_fileMenu->addAction(m_openAction);
115  connect(m_fileMenu, &QMenu::aboutToShow, this, &ActionManager::onAboutToShowFileMenu);
116 
117  m_recentProjectsMenu = m_fileMenu->addMenu("&Recent Projects");
118 
119  m_fileMenu->addSeparator();
120  m_fileMenu->addAction(m_saveAction);
121  m_fileMenu->addAction(m_saveAsAction);
122 
123  // Import submenu
124  m_fileMenu->addSeparator();
125  m_importMenu = m_fileMenu->addMenu("&Import");
126  m_importMenu->setToolTipsVisible(true);
127  QAction* action = m_importMenu->addAction("&Import from Python script (experimental)");
128  action->setToolTip("Import sample from Python script.\n The script should contain a function "
129  "returning a valid multi-layer.");
130 
131 #ifdef BORNAGAIN_PYTHON
132  connect(action, &QAction::triggered, this, &ActionManager::onImportFromPythonScript);
134  if (SysUtils::getenv("PYTHONHOME").empty())
135  action->setEnabled(false);
136 #endif // BORNAGAIN_PYTHON
137 
138  m_fileMenu->addSeparator();
139  m_fileMenu->addAction(m_exitAction);
140 
141  // Settings Menu
142  m_settingsMenu = new QMenu("&Settings", m_mainWindow);
143  onAboutToShowSettingsMenu(); // MacOS feature: action should exist already, otherwise menuBar
144  // will not add menu
145  connect(m_settingsMenu, &QMenu::aboutToShow, this, &ActionManager::onAboutToShowSettingsMenu);
146  m_menuBar->addMenu(m_settingsMenu);
147 
148  // View menu
149  m_viewMenu = new QMenu("&View", m_mainWindow);
150  onAboutToShowViewMenu(); // MacOS feature: action should exist already, otherwise menuBar will
151  // not add menu
152  connect(m_viewMenu, &QMenu::aboutToShow, this, &ActionManager::onAboutToShowViewMenu);
153  m_menuBar->addMenu(m_viewMenu);
154 
155  // Help Menu
156  m_helpMenu = m_menuBar->addMenu("&Help");
157  m_helpMenu->addAction(m_aboutAction);
158 
160 }
void onAboutToShowViewMenu()
void onAboutToShowFileMenu()
void onAboutToShowSettingsMenu()
void onImportFromPythonScript()
static bool isMacHost()
Definition: hostosinfo.h:69
std::string getenv(const std::string &name)
Returns environment variable.
Definition: SysUtils.cpp:48

References SysUtils::getenv(), GUI_OS_Utils::HostOsInfo::isMacHost(), m_aboutAction, m_exitAction, m_fileMenu, m_helpMenu, m_importMenu, m_mainWindow, m_menuBar, m_newAction, m_openAction, m_recentProjectsMenu, m_saveAction, m_saveAsAction, m_settingsMenu, m_viewMenu, onAboutToShowFileMenu(), onAboutToShowSettingsMenu(), onAboutToShowViewMenu(), onCurrentViewChanged(), and onImportFromPythonScript().

Referenced by ActionManager().

Here is the call graph for this function:

◆ onAboutApplication

void ActionManager::onAboutApplication ( )
privateslot

Definition at line 254 of file actionmanager.cpp.

255 {
257  dialog.exec();
258 }
About BornAgain dialog.

References m_mainWindow.

Referenced by createActions().

◆ onAboutToShowFileMenu

void ActionManager::onAboutToShowFileMenu ( )
privateslot

Definition at line 170 of file actionmanager.cpp.

171 {
172  m_recentProjectsMenu->clear();
173 
174  bool hasRecentProjects = false;
175  int orderNr = 1;
176  for (QString file : m_mainWindow->projectManager()->recentProjects()) {
177  hasRecentProjects = true;
178  QString actionText = GUI_StringUtils::withTildeHomePath(QDir::toNativeSeparators(file));
179  if (orderNr < 10)
180  actionText = QString("&%1 ").arg(orderNr) + actionText;
181  QAction* action = m_recentProjectsMenu->addAction(actionText);
182  action->setData(QVariant::fromValue(file));
183  connect(action, &QAction::triggered, m_mainWindow, &MainWindow::openRecentProject);
184  orderNr++;
185  }
186  m_recentProjectsMenu->setEnabled(hasRecentProjects);
187 
188  if (hasRecentProjects) {
189  m_recentProjectsMenu->addSeparator();
190  QAction* action = m_recentProjectsMenu->addAction("&Clear Menu");
191  connect(action, &QAction::triggered, m_mainWindow->projectManager(),
193  }
194 }
void openRecentProject()
Definition: mainwindow.cpp:207
void clearRecentProjects()
Clears list of recent projects.
QStringList recentProjects()
Returns list of recent projects, validates if projects still exists on disk.
QString withTildeHomePath(const QString &path)

References ProjectManager::clearRecentProjects(), m_mainWindow, m_recentProjectsMenu, MainWindow::openRecentProject(), MainWindow::projectManager(), ProjectManager::recentProjects(), and GUI_StringUtils::withTildeHomePath().

Referenced by createMenus().

Here is the call graph for this function:

◆ onAboutToShowSettingsMenu

void ActionManager::onAboutToShowSettingsMenu ( )
privateslot

Definition at line 196 of file actionmanager.cpp.

197 {
198  m_settingsMenu->clear();
199  QSettings settings;
200 
201  settings.beginGroup(Constants::S_UPDATES);
202  QAction* action = m_settingsMenu->addAction("&Check for Updates");
203  action->setToolTip("Checks for updates available on GUI startup.");
204  action->setCheckable(true);
205  action->setChecked(settings.value(Constants::S_CHECKFORUPDATES, false).toBool());
206  connect(action, &QAction::toggled, this, &ActionManager::toggleCheckForUpdates);
207  settings.endGroup();
208 
209  settings.beginGroup(Constants::S_SESSIONMODELVIEW);
210  action = m_settingsMenu->addAction("&Model tech view");
211  action->setToolTip("Additional developer's view will appear in left control tab bar");
212  action->setCheckable(true);
213  action->setChecked(settings.value(Constants::S_VIEWISACTIVE, false).toBool());
214  connect(action, &QAction::toggled, this, &ActionManager::setSessionModelViewActive);
215  settings.endGroup();
216 
217  action = m_settingsMenu->addAction("&Enable autosave");
218  action->setToolTip("Project will be saved periodically in project's autosave directory.\n"
219  "When opening project, recover option will be suggested, if possible.");
220  action->setCheckable(true);
221  action->setChecked(m_mainWindow->projectManager()->isAutosaveEnabled());
222  connect(action, &QAction::toggled, m_mainWindow->projectManager(),
224 
225  m_settingsMenu->setToolTipsVisible(true);
226 }
void toggleCheckForUpdates(bool status)
void setSessionModelViewActive(bool status)
void setAutosaveEnabled(bool value)
bool isAutosaveEnabled() const
const char S_CHECKFORUPDATES[]
const char S_SESSIONMODELVIEW[]
const char S_VIEWISACTIVE[]
const char S_UPDATES[]

References ProjectManager::isAutosaveEnabled(), m_mainWindow, m_settingsMenu, MainWindow::projectManager(), Constants::S_CHECKFORUPDATES, Constants::S_SESSIONMODELVIEW, Constants::S_UPDATES, Constants::S_VIEWISACTIVE, ProjectManager::setAutosaveEnabled(), setSessionModelViewActive(), and toggleCheckForUpdates().

Referenced by createMenus().

Here is the call graph for this function:

◆ onAboutToShowViewMenu

void ActionManager::onAboutToShowViewMenu ( )
privateslot

Definition at line 228 of file actionmanager.cpp.

229 {
230  m_viewMenu->clear();
231 
232  auto view = m_mainWindow->currentView();
233  if (auto sampleView = dynamic_cast<SampleView*>(view); sampleView != nullptr)
234  sampleView->fillViewMenu(m_viewMenu);
235  if (auto jobView = dynamic_cast<JobView*>(view); jobView != nullptr)
236  jobView->fillViewMenu(m_viewMenu);
237 }
The JobView class is a main view to show list of jobs, job results and widgets for real time and fitt...
Definition: JobView.h:35
QWidget * currentView() const
Definition: mainwindow.cpp:189

References MainWindow::currentView(), m_mainWindow, and m_viewMenu.

Referenced by createMenus(), and onCurrentViewChanged().

Here is the call graph for this function:

◆ onCurrentViewChanged

void ActionManager::onCurrentViewChanged ( )
privateslot

Definition at line 260 of file actionmanager.cpp.

261 {
262  // not every view support view menu entries -> hide it, if empty
264  m_viewMenu->menuAction()->setVisible(!m_viewMenu->actions().isEmpty());
265 }

References m_viewMenu, and onAboutToShowViewMenu().

Referenced by ActionManager(), and createMenus().

Here is the call graph for this function:

◆ onImportFromPythonScript

void ActionManager::onImportFromPythonScript ( )
privateslot

Definition at line 268 of file actionmanager.cpp.

269 {
270  PyImportAssistant assistant(m_mainWindow);
271  assistant.exec();
272 }
Assists in importing Python object to GUI models.

References PyImportAssistant::exec(), and m_mainWindow.

Referenced by createMenus().

Here is the call graph for this function:

◆ setSessionModelViewActive

void ActionManager::setSessionModelViewActive ( bool  status)
privateslot

Definition at line 245 of file actionmanager.cpp.

246 {
247  QSettings settings;
248  settings.beginGroup(Constants::S_SESSIONMODELVIEW);
249  settings.setValue(Constants::S_VIEWISACTIVE, status);
250  settings.endGroup();
252 }
void onSessionModelViewActive(bool isActive)
Inserts/removes developers SessionModelView on the left tabbar.
Definition: mainwindow.cpp:225

References m_mainWindow, MainWindow::onSessionModelViewActive(), Constants::S_SESSIONMODELVIEW, and Constants::S_VIEWISACTIVE.

Referenced by onAboutToShowSettingsMenu().

Here is the call graph for this function:

◆ toggleCheckForUpdates

void ActionManager::toggleCheckForUpdates ( bool  status)
privateslot

Definition at line 239 of file actionmanager.cpp.

240 {
243 }
UpdateNotifier * updateNotifier()
Definition: mainwindow.cpp:184
void setCheckUpdatesFlag(bool flag)

References UpdateNotifier::checkForUpdates(), m_mainWindow, UpdateNotifier::setCheckUpdatesFlag(), and MainWindow::updateNotifier().

Referenced by onAboutToShowSettingsMenu().

Here is the call graph for this function:

Member Data Documentation

◆ m_aboutAction

QAction* ActionManager::m_aboutAction
private

Definition at line 53 of file actionmanager.h.

Referenced by createActions(), and createMenus().

◆ m_exitAction

QAction* ActionManager::m_exitAction
private

Definition at line 52 of file actionmanager.h.

Referenced by createActions(), and createMenus().

◆ m_fileMenu

QMenu* ActionManager::m_fileMenu
private

Definition at line 56 of file actionmanager.h.

Referenced by createMenus().

◆ m_helpMenu

QMenu* ActionManager::m_helpMenu
private

Definition at line 60 of file actionmanager.h.

Referenced by createMenus().

◆ m_importMenu

QMenu* ActionManager::m_importMenu
private

Definition at line 61 of file actionmanager.h.

Referenced by createMenus().

◆ m_mainWindow

◆ m_menuBar

QMenuBar* ActionManager::m_menuBar
private

Definition at line 55 of file actionmanager.h.

Referenced by createMenus().

◆ m_newAction

QAction* ActionManager::m_newAction
private

Definition at line 48 of file actionmanager.h.

Referenced by createActions(), and createMenus().

◆ m_openAction

QAction* ActionManager::m_openAction
private

Definition at line 49 of file actionmanager.h.

Referenced by createActions(), and createMenus().

◆ m_recentProjectsMenu

QMenu* ActionManager::m_recentProjectsMenu
private

Definition at line 59 of file actionmanager.h.

Referenced by createMenus(), and onAboutToShowFileMenu().

◆ m_runSimulationShortcut

QShortcut* ActionManager::m_runSimulationShortcut
private

Definition at line 63 of file actionmanager.h.

Referenced by createGlobalShortcuts().

◆ m_saveAction

QAction* ActionManager::m_saveAction
private

Definition at line 50 of file actionmanager.h.

Referenced by createActions(), and createMenus().

◆ m_saveAsAction

QAction* ActionManager::m_saveAsAction
private

Definition at line 51 of file actionmanager.h.

Referenced by createActions(), and createMenus().

◆ m_settingsMenu

QMenu* ActionManager::m_settingsMenu
private

Definition at line 57 of file actionmanager.h.

Referenced by createMenus(), and onAboutToShowSettingsMenu().

◆ m_viewMenu

QMenu* ActionManager::m_viewMenu
private

Definition at line 58 of file actionmanager.h.

Referenced by createMenus(), onAboutToShowViewMenu(), and onCurrentViewChanged().


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