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

Responsible for handling new/save/save-as/close Project logic, where the Project represents a collection of serialized application models in the project directory. More...

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

Public Member Functions

 ProjectManager (const ProjectContext &context)
 Constructor for ProjectManager. More...
 
 ProjectManager (const ProjectManager &other)=delete
 
 ~ProjectManager () override
 
bool closeCurrentProject () const override
 Closes current project (without saving). More...
 
bool createNewProject (const std::string &dirname) override
 Creates a new project, 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...
 
ProjectManageroperator= (const ProjectManager &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< ProjectManagerImpl > p_impl
 

Detailed Description

Responsible for handling new/save/save-as/close Project logic, where the Project represents a collection of serialized application models in the project directory.

This ProjectManager requires certain prerequisites to function properly: for example, the creation of a new project will be possible only if the old project is in a saved state. See description to the class methods.

Definition at line 32 of file projectmanager.h.

Constructor & Destructor Documentation

◆ ProjectManager() [1/2]

ProjectManager::ProjectManager ( const ProjectContext context)

Constructor for ProjectManager.

Definition at line 63 of file projectmanager.cpp.

64  : p_impl(std::make_unique<ProjectManagerImpl>(context))
65 {
66 }
std::unique_ptr< ProjectManagerImpl > p_impl

◆ ~ProjectManager()

ProjectManager::~ProjectManager ( )
overridedefault

◆ ProjectManager() [2/2]

ModelView::ProjectManager::ProjectManager ( const ProjectManager other)
delete

Member Function Documentation

◆ closeCurrentProject()

bool ProjectManager::closeCurrentProject ( ) const
overridevirtual

Closes current project (without saving).

No checks whether it is modified or not being performed.

Implements ModelView::ProjectManagerInterface.

Definition at line 127 of file projectmanager.cpp.

128 {
129  // no special operation is required to close the project
130  p_impl->createNewProject(); // ready for further actions
131  return succeeded;
132 }

References p_impl.

◆ createNewProject()

bool ProjectManager::createNewProject ( const std::string &  dirname)
overridevirtual

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

Current project has to be in a saved state, otherwise will return false.

Implements ModelView::ProjectManagerInterface.

Definition at line 73 of file projectmanager.cpp.

74 {
75  if (p_impl->isModified())
76  return failed;
77  p_impl->createNewProject();
78  return p_impl->saveCurrentProjectAs(dirname);
79 }

References p_impl.

Referenced by ProjectManager::ProjectManagerImpl::ProjectManagerImpl(), and TEST_F().

◆ currentProjectDir()

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

Returns current project directory.

Implements ModelView::ProjectManagerInterface.

Definition at line 112 of file projectmanager.cpp.

113 {
114  return p_impl->m_current_project ? p_impl->m_current_project->projectDir() : std::string();
115 }

References p_impl.

Referenced by TEST_F().

◆ isModified()

bool ProjectManager::isModified ( ) const
overridevirtual

Returns true if project was modified since last save.

Implements ModelView::ProjectManagerInterface.

Definition at line 119 of file projectmanager.cpp.

120 {
121  return p_impl->isModified();
122 }

References p_impl.

Referenced by TEST_F().

◆ openExistingProject()

bool ProjectManager::openExistingProject ( const std::string &  dirname)
overridevirtual

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

Current project should be in a saved state, new project should exist.

Implements ModelView::ProjectManagerInterface.

Definition at line 102 of file projectmanager.cpp.

103 {
104  if (p_impl->isModified())
105  return failed;
106  p_impl->createNewProject();
107  return p_impl->loadFrom(dirname);
108 }

References p_impl.

◆ operator=()

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

◆ saveCurrentProject()

bool ProjectManager::saveCurrentProject ( )
overridevirtual

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

The project should have a project directory defined to succeed.

Implements ModelView::ProjectManagerInterface.

Definition at line 84 of file projectmanager.cpp.

85 {
86  if (!p_impl->projectHasDir())
87  return failed;
88  return p_impl->saveCurrentProject();
89 }

References p_impl.

Referenced by TEST_F().

◆ saveProjectAs()

bool ProjectManager::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.

Implements ModelView::ProjectManagerInterface.

Definition at line 94 of file projectmanager.cpp.

95 {
96  return p_impl->saveCurrentProjectAs(dirname);
97 }

References p_impl.

Referenced by TEST_F().

Member Data Documentation

◆ p_impl

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

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