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

Decorator for ProjectManager to provide interaction with the user on open/save-as requests. More...

Inheritance diagram for ModelView::ProjectManagerDecorator:
[legend]
Collaboration diagram for ModelView::ProjectManagerDecorator:
[legend]

Classes

struct  ProjectManagerImpl
 

Public Member Functions

 ProjectManagerDecorator (const ProjectContext &project_context, const UserInteractionContext &user_context)
 Constructor for ProjectManagerDecorator. More...
 
 ProjectManagerDecorator (const ProjectManagerDecorator &other)=delete
 
 ~ProjectManagerDecorator () override
 
bool closeCurrentProject () const override
 Closes current project, returns 'true' if succeeded. More...
 
bool createNewProject (const std::string &dirname={}) override
 Creates a new project in the directory 'dirname', returns 'true' in the case of success. More...
 
std::string currentProjectDir () const override
 Returns current project directory. More...
 
bool isModified () const override
 Returns true if project was modified since last save. More...
 
bool openExistingProject (const std::string &dirname={}) override
 Opens existing project, returns 'true' in the case of success. More...
 
ProjectManagerDecoratoroperator= (const ProjectManagerDecorator &other)=delete
 
bool saveCurrentProject () override
 Saves current project, returns 'true' in the case of success. More...
 
bool saveProjectAs (const std::string &dirname={}) override
 Saves the project under a given directory, returns true in the case of success. More...
 

Private Attributes

std::unique_ptr< ProjectManagerImplp_impl
 

Detailed Description

Decorator for ProjectManager to provide interaction with the user on open/save-as requests.

It relies on the same interface and adds additional logic related to "unsaved" data. For example, on createNewProject it will check if previous project is saved, and will call external dialog save/discard/cancel via provided callback.

Definition at line 32 of file projectmanagerdecorator.h.

Constructor & Destructor Documentation

◆ ProjectManagerDecorator() [1/2]

ProjectManagerDecorator::ProjectManagerDecorator ( const ProjectContext project_context,
const UserInteractionContext user_context 
)

Constructor for ProjectManagerDecorator.

Definition at line 111 of file projectmanagerdecorator.cpp.

113  : p_impl(std::make_unique<ProjectManagerImpl>(project_context, user_context))
114 {
115 }
std::unique_ptr< ProjectManagerImpl > p_impl

◆ ~ProjectManagerDecorator()

ProjectManagerDecorator::~ProjectManagerDecorator ( )
overridedefault

◆ ProjectManagerDecorator() [2/2]

ModelView::ProjectManagerDecorator::ProjectManagerDecorator ( const ProjectManagerDecorator other)
delete

Member Function Documentation

◆ closeCurrentProject()

bool ProjectManagerDecorator::closeCurrentProject ( ) const
overridevirtual

Closes current project, returns 'true' if succeeded.

Will show the dialog, via callback provided, asking the user whether to save/discard/cancel. Returns 'false' only if user has selected 'cancel' button.

Implements ModelView::ProjectManagerInterface.

Definition at line 187 of file projectmanagerdecorator.cpp.

188 {
189  if (!p_impl->saveBeforeClosing())
190  return failed;
191  return succeeded;
192 }

References p_impl.

◆ createNewProject()

bool ProjectManagerDecorator::createNewProject ( const std::string &  dirname = {})
overridevirtual

Creates a new project in the directory 'dirname', returns 'true' in the case of success.

The directory should exist. If provided name is empty, will call directory selector dialog using callback provided. If current project is in unsaved state, will perform 'save-before-closing' procedure before proceeding further.

Implements ModelView::ProjectManagerInterface.

Definition at line 125 of file projectmanagerdecorator.cpp.

126 {
127  if (!p_impl->saveBeforeClosing())
128  return failed;
129 
130  auto project_dir = dirname.empty() ? p_impl->acquireNewProjectDir() : dirname;
131  // empty project_dir string denotes 'cancel' during directory creation dialog
132  return project_dir.empty() ? failed : p_impl->project_manager->createNewProject(project_dir);
133 }

References p_impl.

Referenced by TEST_F().

◆ currentProjectDir()

std::string ProjectManagerDecorator::currentProjectDir ( ) const
overridevirtual

Returns current project directory.

Implements ModelView::ProjectManagerInterface.

Definition at line 171 of file projectmanagerdecorator.cpp.

172 {
173  return p_impl->currentProjectDir();
174 }

References p_impl.

Referenced by TEST_F().

◆ isModified()

bool ProjectManagerDecorator::isModified ( ) const
overridevirtual

Returns true if project was modified since last save.

Implements ModelView::ProjectManagerInterface.

Definition at line 178 of file projectmanagerdecorator.cpp.

179 {
180  return p_impl->isModified();
181 }

References p_impl.

Referenced by TEST_F().

◆ openExistingProject()

bool ProjectManagerDecorator::openExistingProject ( const std::string &  dirname = {})
overridevirtual

Opens existing project, returns 'true' in the case of success.

If provided name is empty, will call directory selector dialog using callback provided. If current project is in unsaved state, it will perform 'save-before-closing' procedure before proceeding further.

Implements ModelView::ProjectManagerInterface.

Definition at line 160 of file projectmanagerdecorator.cpp.

161 {
162  if (!p_impl->saveBeforeClosing())
163  return failed;
164  auto project_dir = dirname.empty() ? p_impl->acquireExistingProjectDir() : dirname;
165  // empty project_dir variable denotes 'cancel' during directory selection dialog
166  return project_dir.empty() ? failed : p_impl->project_manager->openExistingProject(project_dir);
167 }

References p_impl.

Referenced by TEST_F().

◆ operator=()

ProjectManagerDecorator& ModelView::ProjectManagerDecorator::operator= ( const ProjectManagerDecorator other)
delete

◆ saveCurrentProject()

bool ProjectManagerDecorator::saveCurrentProject ( )
overridevirtual

Saves current project, returns 'true' in the case of success.

The project should have a project directory defined, if it is not the case, it will launch the procedure of directory selection using callback provided.

Implements ModelView::ProjectManagerInterface.

Definition at line 139 of file projectmanagerdecorator.cpp.

140 {
141  return p_impl->saveCurrentProject();
142 }

References p_impl.

Referenced by TEST_F().

◆ saveProjectAs()

bool ProjectManagerDecorator::saveProjectAs ( const std::string &  dirname = {})
overridevirtual

Saves the project under a given directory, returns true in the case of success.

The directory should exist already. If provided 'dirname' variable is empty, it will acquire a new project directory using dialog provided.

Implements ModelView::ProjectManagerInterface.

Definition at line 148 of file projectmanagerdecorator.cpp.

149 {
150  auto project_dir = dirname.empty() ? p_impl->acquireNewProjectDir() : dirname;
151  // empty project_dir variable denotes 'cancel' during directory creation dialog
152  return project_dir.empty() ? failed : p_impl->saveCurrentProjectAs(project_dir);
153 }

References p_impl.

Referenced by TEST_F().

Member Data Documentation

◆ p_impl

std::unique_ptr<ProjectManagerImpl> ModelView::ProjectManagerDecorator::p_impl
private

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