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

Main class to coordinate all activity on user's request to create new project, open existing one, or choose one of recent projects on disk. More...

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

Public Slots

bool canCloseProject () const
 Returns 'true' if current project can be closed. More...
 
void clearRecentProjectsList ()
 
void onCreateNewProject ()
 
void onOpenExistingProject (const QString &dirname={})
 
void onSaveCurrentProject ()
 
void onSaveProjectAs ()
 
void updateNames ()
 Update names (name of the current project, recent project name list, notifies the world). More...
 

Signals

void currentProjectModified (const QString &project_dir, bool is_modified)
 
void recentProjectsListModified (const QStringList &projects)
 

Public Member Functions

 ProjectHandler (ApplicationModels *models, QWidget *parent)
 
 ~ProjectHandler () override
 

Private Member Functions

void initProjectManager ()
 
void updateCurrentProjectName ()
 Updates the name of the current project on main window, notifies the world. More...
 
void updateRecentProjectNames ()
 Update recent project list in settings, notifies the world. More...
 

Private Attributes

ApplicationModelsm_models {nullptr}
 
std::unique_ptr< ModelView::ProjectManagerInterfacem_projectManager
 
std::unique_ptr< RecentProjectSettingsm_recentProjectSettings
 
std::unique_ptr< UserInteractorm_userInteractor
 

Detailed Description

Main class to coordinate all activity on user's request to create new project, open existing one, or choose one of recent projects on disk.

Definition at line 39 of file projecthandler.h.

Constructor & Destructor Documentation

◆ ProjectHandler()

gui2::ProjectHandler::ProjectHandler ( ApplicationModels models,
QWidget *  parent 
)
explicit

Definition at line 29 of file projecthandler.cpp.

30  : QObject(parent)
31  , m_recentProjectSettings(std::make_unique<RecentProjectSettings>())
32  , m_userInteractor(std::make_unique<UserInteractor>(m_recentProjectSettings.get(), parent))
33  , m_models(models)
34 {
37 }
ApplicationModels * m_models
std::unique_ptr< RecentProjectSettings > m_recentProjectSettings
void updateRecentProjectNames()
Update recent project list in settings, notifies the world.
std::unique_ptr< UserInteractor > m_userInteractor

References initProjectManager(), and updateRecentProjectNames().

Here is the call graph for this function:

◆ ~ProjectHandler()

gui2::ProjectHandler::~ProjectHandler ( )
overridedefault

Member Function Documentation

◆ canCloseProject

bool gui2::ProjectHandler::canCloseProject ( ) const
slot

Returns 'true' if current project can be closed.

Internally will perform check for unsaved data, and proceed via save/discard/cancel dialog.

Definition at line 52 of file projecthandler.cpp.

53 {
54  return m_projectManager->closeCurrentProject();
55 }
std::unique_ptr< ModelView::ProjectManagerInterface > m_projectManager

References m_projectManager.

Referenced by gui2::WelcomeView::canCloseProject().

◆ clearRecentProjectsList

void gui2::ProjectHandler::clearRecentProjectsList ( )
slot

Definition at line 81 of file projecthandler.cpp.

82 {
83  m_recentProjectSettings->clearRecentProjectsList();
84  updateNames();
85 }
void updateNames()
Update names (name of the current project, recent project name list, notifies the world).

References m_recentProjectSettings, and updateNames().

Referenced by gui2::WelcomeView::onClearRecentProjectsList().

Here is the call graph for this function:

◆ currentProjectModified

void gui2::ProjectHandler::currentProjectModified ( const QString &  project_dir,
bool  is_modified 
)
signal

◆ initProjectManager()

void gui2::ProjectHandler::initProjectManager ( )
private

Definition at line 87 of file projecthandler.cpp.

88 {
89  auto modified_callback = [this]() { updateCurrentProjectName(); };
90  auto models_callback = [this]() { return m_models->persistent_models(); };
91  ProjectContext project_context{modified_callback, models_callback};
92 
93  auto select_dir_callback = [this]() { return m_userInteractor->onSelectDirRequest(); };
94  auto create_dir_callback = [this]() { return m_userInteractor->onCreateDirRequest(); };
95  auto answer_callback = [this]() { return m_userInteractor->onSaveChangesRequest(); };
96  UserInteractionContext user_context{select_dir_callback, create_dir_callback, answer_callback};
97 
98  m_projectManager = CreateProjectManager(project_context, user_context);
99 }
std::vector< ModelView::SessionModel * > persistent_models() const override
Returns vector of models intended for saving on disk.
void updateCurrentProjectName()
Updates the name of the current project on main window, notifies the world.
std::unique_ptr< ProjectManagerInterface > CreateProjectManager(const ProjectContext &project_context, const UserInteractionContext &user_context)
Creates default ProjectManager to save and load models.
Provides necessary information for Project construction.
Definition: project_types.h:32
Defines the context to interact with the user regarding save/save-as/create-new project scenarious.
Definition: project_types.h:48

References ModelView::CreateProjectManager(), m_models, m_projectManager, m_userInteractor, gui2::ApplicationModels::persistent_models(), and updateCurrentProjectName().

Referenced by ProjectHandler().

Here is the call graph for this function:

◆ onCreateNewProject

void gui2::ProjectHandler::onCreateNewProject ( )
slot

Definition at line 57 of file projecthandler.cpp.

58 {
59  if (m_projectManager->createNewProject())
60  updateNames();
61 }

References m_projectManager, and updateNames().

Referenced by gui2::WelcomeView::onCreateNewProject().

Here is the call graph for this function:

◆ onOpenExistingProject

void gui2::ProjectHandler::onOpenExistingProject ( const QString &  dirname = {})
slot

Definition at line 63 of file projecthandler.cpp.

64 {
65  if (m_projectManager->openExistingProject(dirname.toStdString()))
66  updateNames();
67 }

References m_projectManager, and updateNames().

Referenced by gui2::WelcomeView::onOpenExistingProject().

Here is the call graph for this function:

◆ onSaveCurrentProject

void gui2::ProjectHandler::onSaveCurrentProject ( )
slot

Definition at line 69 of file projecthandler.cpp.

70 {
71  if (m_projectManager->saveCurrentProject())
72  updateNames();
73 }

References m_projectManager, and updateNames().

Referenced by gui2::WelcomeView::onSaveCurrentProject().

Here is the call graph for this function:

◆ onSaveProjectAs

void gui2::ProjectHandler::onSaveProjectAs ( )
slot

Definition at line 75 of file projecthandler.cpp.

76 {
77  if (m_projectManager->saveProjectAs())
78  updateNames();
79 }

References m_projectManager, and updateNames().

Referenced by gui2::WelcomeView::onSaveProjectAs().

Here is the call graph for this function:

◆ recentProjectsListModified

void gui2::ProjectHandler::recentProjectsListModified ( const QStringList &  projects)
signal

◆ updateCurrentProjectName()

void gui2::ProjectHandler::updateCurrentProjectName ( )
private

Updates the name of the current project on main window, notifies the world.

Definition at line 103 of file projecthandler.cpp.

104 {
105  const auto current_project_dir = QString::fromStdString(m_projectManager->currentProjectDir());
106  const auto is_modified = m_projectManager->isModified();
107 
108  // set main window title
109  auto title = ModelView::Utils::ProjectWindowTitle(current_project_dir, is_modified);
110  if (auto main_window = ModelView::Utils::FindMainWindow(); main_window)
111  main_window->setWindowTitle(title);
112 
113  currentProjectModified(current_project_dir, is_modified);
114 }
void currentProjectModified(const QString &project_dir, bool is_modified)
MVVM_VIEW_EXPORT QMainWindow * FindMainWindow()
Finds main window.
MVVM_VIEW_EXPORT QString ProjectWindowTitle(const QString &project_dir, bool is_modified)
Returns a title composed from last part of project path, and is_modified flag.
Definition: widgetutils.cpp:98

References currentProjectModified(), ModelView::Utils::FindMainWindow(), m_projectManager, and ModelView::Utils::ProjectWindowTitle().

Referenced by initProjectManager(), and updateNames().

Here is the call graph for this function:

◆ updateNames

void gui2::ProjectHandler::updateNames ( )
slot

Update names (name of the current project, recent project name list, notifies the world).

Definition at line 43 of file projecthandler.cpp.

References updateCurrentProjectName(), and updateRecentProjectNames().

Referenced by clearRecentProjectsList(), onCreateNewProject(), onOpenExistingProject(), onSaveCurrentProject(), onSaveProjectAs(), and gui2::WelcomeView::updateNames().

Here is the call graph for this function:

◆ updateRecentProjectNames()

void gui2::ProjectHandler::updateRecentProjectNames ( )
private

Update recent project list in settings, notifies the world.

Definition at line 118 of file projecthandler.cpp.

119 {
120  m_recentProjectSettings->addToRecentProjects(
121  QString::fromStdString(m_projectManager->currentProjectDir()));
123 }
void recentProjectsListModified(const QStringList &projects)

References m_projectManager, m_recentProjectSettings, and recentProjectsListModified().

Referenced by ProjectHandler(), and updateNames().

Member Data Documentation

◆ m_models

ApplicationModels* gui2::ProjectHandler::m_models {nullptr}
private

Definition at line 68 of file projecthandler.h.

Referenced by initProjectManager().

◆ m_projectManager

◆ m_recentProjectSettings

std::unique_ptr<RecentProjectSettings> gui2::ProjectHandler::m_recentProjectSettings
private

Definition at line 65 of file projecthandler.h.

Referenced by clearRecentProjectsList(), and updateRecentProjectNames().

◆ m_userInteractor

std::unique_ptr<UserInteractor> gui2::ProjectHandler::m_userInteractor
private

Definition at line 66 of file projecthandler.h.

Referenced by initProjectManager().


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