BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::ProjectManagerDecorator::ProjectManagerImpl Struct Reference
Collaboration diagram for ModelView::ProjectManagerDecorator::ProjectManagerImpl:
[legend]

Public Member Functions

 ProjectManagerImpl (ProjectContext project_context, UserInteractionContext user_context)
 
std::string acquireExistingProjectDir ()
 Acquire the name of the existing project directory using callback provided. More...
 
std::string acquireNewProjectDir ()
 Acquire the name of the new project directory using callback provided. More...
 
SaveChangesAnswer acquireSaveChangesAnswer () const
 Asks the user whether to save/cancel/discard the project using callback provided. More...
 
std::string currentProjectDir () const
 
bool isModified () const
 
bool projectHasDir () const
 Returns true if the project has directory already defined. More...
 
bool saveBeforeClosing ()
 Performs saving of previous project before creating a new one. More...
 
bool saveCurrentProject ()
 Saves project in project directory. More...
 
bool saveCurrentProjectAs (const std::string &dirname)
 Saves current project under directory selected. More...
 

Public Attributes

ProjectContext m_project_context
 
UserInteractionContext m_user_context
 
std::unique_ptr< ProjectManagerproject_manager
 

Detailed Description

Definition at line 28 of file projectmanagerdecorator.cpp.

Constructor & Destructor Documentation

◆ ProjectManagerImpl()

ModelView::ProjectManagerDecorator::ProjectManagerImpl::ProjectManagerImpl ( ProjectContext  project_context,
UserInteractionContext  user_context 
)
inline

Member Function Documentation

◆ acquireExistingProjectDir()

std::string ModelView::ProjectManagerDecorator::ProjectManagerImpl::acquireExistingProjectDir ( )
inline

Acquire the name of the existing project directory using callback provided.

Definition at line 101 of file projectmanagerdecorator.cpp.

102  {
104  throw std::runtime_error("Error in ProjectManager: absent open_dir callback.");
106  }
select_dir_callback_t m_select_dir_callback
Definition: project_types.h:58

References ModelView::UserInteractionContext::m_select_dir_callback, and ModelView::ProjectManagerDecorator::ProjectManagerImpl::m_user_context.

◆ acquireNewProjectDir()

std::string ModelView::ProjectManagerDecorator::ProjectManagerImpl::acquireNewProjectDir ( )
inline

Acquire the name of the new project directory using callback provided.

Definition at line 93 of file projectmanagerdecorator.cpp.

94  {
96  throw std::runtime_error("Error in ProjectManager: absent creat_dir callback.");
98  }
create_dir_callback_t m_create_dir_callback
Definition: project_types.h:59

References ModelView::UserInteractionContext::m_create_dir_callback, and ModelView::ProjectManagerDecorator::ProjectManagerImpl::m_user_context.

Referenced by ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProject().

◆ acquireSaveChangesAnswer()

SaveChangesAnswer ModelView::ProjectManagerDecorator::ProjectManagerImpl::acquireSaveChangesAnswer ( ) const
inline

Asks the user whether to save/cancel/discard the project using callback provided.

Definition at line 85 of file projectmanagerdecorator.cpp.

86  {
88  throw std::runtime_error("Error in ProjectManager: absent save_callback");
90  }
answer_callback_t m_answer_callback
Definition: project_types.h:60

References ModelView::UserInteractionContext::m_answer_callback, and ModelView::ProjectManagerDecorator::ProjectManagerImpl::m_user_context.

Referenced by ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveBeforeClosing().

◆ currentProjectDir()

std::string ModelView::ProjectManagerDecorator::ProjectManagerImpl::currentProjectDir ( ) const
inline

Definition at line 61 of file projectmanagerdecorator.cpp.

61 { return project_manager->currentProjectDir(); }

References ModelView::ProjectManagerDecorator::ProjectManagerImpl::project_manager.

◆ isModified()

bool ModelView::ProjectManagerDecorator::ProjectManagerImpl::isModified ( ) const
inline

◆ projectHasDir()

bool ModelView::ProjectManagerDecorator::ProjectManagerImpl::projectHasDir ( ) const
inline

Returns true if the project has directory already defined.

Definition at line 40 of file projectmanagerdecorator.cpp.

40 { return !project_manager->currentProjectDir().empty(); }

References ModelView::ProjectManagerDecorator::ProjectManagerImpl::project_manager.

Referenced by ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProject().

◆ saveBeforeClosing()

bool ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveBeforeClosing ( )
inline

Performs saving of previous project before creating a new one.

Definition at line 66 of file projectmanagerdecorator.cpp.

67  {
68  if (isModified()) {
69  switch (acquireSaveChangesAnswer()) {
70  case SaveChangesAnswer::SAVE:
71  return saveCurrentProject();
72  case SaveChangesAnswer::CANCEL:
73  return failed; // saving was interrupted by the 'cancel' button
74  case SaveChangesAnswer::DISCARD:
75  project_manager->closeCurrentProject();
76  return succeeded;
77  default:
78  throw std::runtime_error("Error in ProjectManager: unexpected answer.");
79  }
80  }
81  return succeeded;
82  }
SaveChangesAnswer acquireSaveChangesAnswer() const
Asks the user whether to save/cancel/discard the project using callback provided.
bool saveCurrentProject()
Saves project in project directory.

References ModelView::ProjectManagerDecorator::ProjectManagerImpl::acquireSaveChangesAnswer(), ModelView::CANCEL, ModelView::DISCARD, ModelView::ProjectManagerDecorator::ProjectManagerImpl::isModified(), ModelView::ProjectManagerDecorator::ProjectManagerImpl::project_manager, ModelView::SAVE, and ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProject().

Here is the call graph for this function:

◆ saveCurrentProject()

bool ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProject ( )
inline

Saves project in project directory.

If directory is not defined, will acquire directory susing callback provided.

Definition at line 44 of file projectmanagerdecorator.cpp.

45  {
46  // Feature FIXME?: already saved project (i.e. isModified=false) will be saved again.
47  // Files will be same, but creation date will be changed.
48 
49  auto save_dir =
50  projectHasDir() ? project_manager->currentProjectDir() : acquireNewProjectDir();
51  return saveCurrentProjectAs(save_dir);
52  }
bool projectHasDir() const
Returns true if the project has directory already defined.
std::string acquireNewProjectDir()
Acquire the name of the new project directory using callback provided.
bool saveCurrentProjectAs(const std::string &dirname)
Saves current project under directory selected.

References ModelView::ProjectManagerDecorator::ProjectManagerImpl::acquireNewProjectDir(), ModelView::ProjectManagerDecorator::ProjectManagerImpl::project_manager, ModelView::ProjectManagerDecorator::ProjectManagerImpl::projectHasDir(), and ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProjectAs().

Referenced by ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveBeforeClosing().

Here is the call graph for this function:

◆ saveCurrentProjectAs()

bool ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProjectAs ( const std::string &  dirname)
inline

Saves current project under directory selected.

Definition at line 55 of file projectmanagerdecorator.cpp.

56  {
57  // empty dirname varible means 'cancel' during directory selection
58  return dirname.empty() ? failed : project_manager->saveProjectAs(dirname);
59  }

References ModelView::ProjectManagerDecorator::ProjectManagerImpl::project_manager.

Referenced by ModelView::ProjectManagerDecorator::ProjectManagerImpl::saveCurrentProject().

Member Data Documentation

◆ m_project_context

ProjectContext ModelView::ProjectManagerDecorator::ProjectManagerImpl::m_project_context

◆ m_user_context

◆ project_manager


The documentation for this struct was generated from the following file: