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

Actions for MainWindow. More...

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

Public Slots

void setRecentProjectsList (const QStringList &projects)
 

Signals

void clearResentProjectListRequest ()
 
void createNewProjectRequest ()
 
void openExistingProjectRequest (const QString &dirname)
 
void saveCurrentProjectRequest ()
 
void saveProjectAsRequest ()
 

Public Member Functions

 ActionManager (QMainWindow *mainwindow=nullptr)
 

Private Slots

void aboutToShowFileMenu ()
 

Private Member Functions

void createActions ()
 Creates application-wise actions to create, open, save, and save-as projects. More...
 
void setupMenus (QMenuBar *menubar)
 Equips menu with actions. More...
 

Private Attributes

QAction * m_createNewProjectAction {nullptr}
 
QAction * m_exitAction {nullptr}
 
QMainWindow * m_mainWindow {nullptr}
 
QAction * m_openExistingProjectAction {nullptr}
 
QMenu * m_recentProjectMenu {nullptr}
 
QStringList m_recentProjects
 
QAction * m_saveCurrentProjectAction {nullptr}
 
QAction * m_saveProjectAsAction {nullptr}
 

Detailed Description

Actions for MainWindow.

Equips toolbar and menubar with actions to create, open, save, and save-as projects. It doesn't have logic and simply forwards requests further.

Definition at line 31 of file actionmanager.h.

Constructor & Destructor Documentation

◆ ActionManager()

ActionManager::ActionManager ( QMainWindow *  mainwindow = nullptr)

Definition at line 24 of file actionmanager.cpp.

25  : QObject(mainwindow), m_mainWindow(mainwindow)
26 {
27  createActions();
28  setupMenus(m_mainWindow->menuBar());
29 }
void setupMenus(QMenuBar *menubar)
Equips menu with actions.
void createActions()
Creates application-wise actions to create, open, save, and save-as projects.
QMainWindow * m_mainWindow
Definition: actionmanager.h:54

References createActions(), m_mainWindow, and setupMenus().

Here is the call graph for this function:

Member Function Documentation

◆ aboutToShowFileMenu

void ActionManager::aboutToShowFileMenu ( )
privateslot

Definition at line 31 of file actionmanager.cpp.

32 {
33  m_recentProjectMenu->clear();
34  m_recentProjectMenu->setEnabled(!m_recentProjects.isEmpty());
35 
36  for (auto project_dir : m_recentProjects) {
37  auto trimmed_project_dir = ModelView::Utils::WithTildeHomePath(project_dir);
38  auto action = m_recentProjectMenu->addAction(trimmed_project_dir);
39  action->setData(QVariant::fromValue(project_dir));
40  auto on_project_selected = [this, project_dir]() {
41  openExistingProjectRequest(project_dir);
42  };
43  connect(action, &QAction::triggered, on_project_selected);
44  }
45 
46  if (!m_recentProjects.empty()) {
47  m_recentProjectMenu->addSeparator();
48  auto action = m_recentProjectMenu->addAction("Clear Menu");
49  connect(action, &QAction::triggered, [this]() { clearResentProjectListRequest(); });
50  }
51 }
void clearResentProjectListRequest()
QStringList m_recentProjects
Definition: actionmanager.h:64
QMenu * m_recentProjectMenu
Definition: actionmanager.h:62
void openExistingProjectRequest(const QString &dirname)
MVVM_VIEW_EXPORT QString WithTildeHomePath(const QString &path)
Returns a string where Linux path to the file is striped using '~/'.
Definition: widgetutils.cpp:79

References clearResentProjectListRequest(), m_recentProjectMenu, m_recentProjects, openExistingProjectRequest(), and ModelView::Utils::WithTildeHomePath().

Referenced by setupMenus().

Here is the call graph for this function:

◆ clearResentProjectListRequest

void gui2::ActionManager::clearResentProjectListRequest ( )
signal

◆ createActions()

void ActionManager::createActions ( )
private

Creates application-wise actions to create, open, save, and save-as projects.

Definition at line 60 of file actionmanager.cpp.

61 {
62  m_createNewProjectAction = new QAction("&New Project", this);
63  m_createNewProjectAction->setShortcuts(QKeySequence::New);
64  m_createNewProjectAction->setStatusTip("Create a new project");
65  connect(m_createNewProjectAction, &QAction::triggered, this,
67 
68  m_openExistingProjectAction = new QAction("&Open Project", this);
69  m_openExistingProjectAction->setShortcuts(QKeySequence::Open);
70  m_openExistingProjectAction->setStatusTip("Open an existing project");
71  connect(m_openExistingProjectAction, &QAction::triggered,
72  [this]() { openExistingProjectRequest({}); });
73 
74  m_saveCurrentProjectAction = new QAction("&Save Project", this);
75  m_saveCurrentProjectAction->setShortcuts(QKeySequence::Save);
76  m_saveCurrentProjectAction->setStatusTip("Save project");
77  m_saveCurrentProjectAction->setShortcutContext(Qt::ApplicationShortcut);
78  connect(m_saveCurrentProjectAction, &QAction::triggered, this,
80 
81  m_saveProjectAsAction = new QAction("Save &As...", this);
82  m_saveProjectAsAction->setShortcuts(QKeySequence::SaveAs);
83  m_saveProjectAsAction->setStatusTip("Save project under different name");
84  connect(m_saveProjectAsAction, &QAction::triggered, this, &ActionManager::saveProjectAsRequest);
85 
86  m_exitAction = new QAction("E&xit Application", this);
87  m_exitAction->setShortcuts(QKeySequence::Quit);
88  m_exitAction->setStatusTip("Exit the application");
89  connect(m_exitAction, &QAction::triggered, m_mainWindow, &QMainWindow::close);
90 }
QAction * m_exitAction
Definition: actionmanager.h:60
void saveCurrentProjectRequest()
QAction * m_saveCurrentProjectAction
Definition: actionmanager.h:58
QAction * m_saveProjectAsAction
Definition: actionmanager.h:59
QAction * m_createNewProjectAction
Definition: actionmanager.h:56
void createNewProjectRequest()
QAction * m_openExistingProjectAction
Definition: actionmanager.h:57

References createNewProjectRequest(), m_createNewProjectAction, m_exitAction, m_mainWindow, m_openExistingProjectAction, m_saveCurrentProjectAction, m_saveProjectAsAction, openExistingProjectRequest(), saveCurrentProjectRequest(), and saveProjectAsRequest().

Referenced by ActionManager().

◆ createNewProjectRequest

void gui2::ActionManager::createNewProjectRequest ( )
signal

◆ openExistingProjectRequest

void gui2::ActionManager::openExistingProjectRequest ( const QString &  dirname)
signal

◆ saveCurrentProjectRequest

void gui2::ActionManager::saveCurrentProjectRequest ( )
signal

◆ saveProjectAsRequest

void gui2::ActionManager::saveProjectAsRequest ( )
signal

◆ setRecentProjectsList

void ActionManager::setRecentProjectsList ( const QStringList &  projects)
slot

Definition at line 53 of file actionmanager.cpp.

54 {
55  m_recentProjects = projects;
56 }

References m_recentProjects.

Referenced by gui2::MainWindow::init_connections().

◆ setupMenus()

void ActionManager::setupMenus ( QMenuBar *  menubar)
private

Equips menu with actions.

Definition at line 94 of file actionmanager.cpp.

95 {
96  auto fileMenu = menubar->addMenu("&File");
97  connect(fileMenu, &QMenu::aboutToShow, this, &ActionManager::aboutToShowFileMenu);
98  fileMenu->addAction(m_createNewProjectAction);
99  fileMenu->addAction(m_openExistingProjectAction);
100  m_recentProjectMenu = fileMenu->addMenu("Recent Projects");
101 
102  fileMenu->addSeparator();
103  fileMenu->addAction(m_saveCurrentProjectAction);
104  fileMenu->addAction(m_saveProjectAsAction);
105 
106  fileMenu->addSeparator();
107  fileMenu->addAction(m_exitAction);
108 }

References aboutToShowFileMenu(), m_createNewProjectAction, m_exitAction, m_openExistingProjectAction, m_recentProjectMenu, m_saveCurrentProjectAction, and m_saveProjectAsAction.

Referenced by ActionManager().

Here is the call graph for this function:

Member Data Documentation

◆ m_createNewProjectAction

QAction* gui2::ActionManager::m_createNewProjectAction {nullptr}
private

Definition at line 56 of file actionmanager.h.

Referenced by createActions(), and setupMenus().

◆ m_exitAction

QAction* gui2::ActionManager::m_exitAction {nullptr}
private

Definition at line 60 of file actionmanager.h.

Referenced by createActions(), and setupMenus().

◆ m_mainWindow

QMainWindow* gui2::ActionManager::m_mainWindow {nullptr}
private

Definition at line 54 of file actionmanager.h.

Referenced by ActionManager(), and createActions().

◆ m_openExistingProjectAction

QAction* gui2::ActionManager::m_openExistingProjectAction {nullptr}
private

Definition at line 57 of file actionmanager.h.

Referenced by createActions(), and setupMenus().

◆ m_recentProjectMenu

QMenu* gui2::ActionManager::m_recentProjectMenu {nullptr}
private

Definition at line 62 of file actionmanager.h.

Referenced by aboutToShowFileMenu(), and setupMenus().

◆ m_recentProjects

QStringList gui2::ActionManager::m_recentProjects
private

Definition at line 64 of file actionmanager.h.

Referenced by aboutToShowFileMenu(), and setRecentProjectsList().

◆ m_saveCurrentProjectAction

QAction* gui2::ActionManager::m_saveCurrentProjectAction {nullptr}
private

Definition at line 58 of file actionmanager.h.

Referenced by createActions(), and setupMenus().

◆ m_saveProjectAsAction

QAction* gui2::ActionManager::m_saveProjectAsAction {nullptr}
private

Definition at line 59 of file actionmanager.h.

Referenced by createActions(), and setupMenus().


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