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

Public Member Functions

 ProjectImpl (const ProjectContext &context)
 
std::vector< SessionModel * > models () const
 Returns list of models which are subject to save/load. More...
 
template<typename T >
bool process (const std::string &dirname, T method)
 Processes all models one by one and either save or load them to/from given directory. More...
 

Public Attributes

ProjectChangedController m_change_controller
 
ProjectContext m_context
 
std::string m_project_dir
 

Detailed Description

Definition at line 25 of file project.cpp.

Constructor & Destructor Documentation

◆ ProjectImpl()

ModelView::Project::ProjectImpl::ProjectImpl ( const ProjectContext context)
inline

Definition at line 30 of file project.cpp.

31  : m_context(context)
33  {
34  }
modified_callback_t m_modified_callback
Definition: project_types.h:41
models_callback_t m_models_callback
Definition: project_types.h:42
ProjectChangedController m_change_controller
Definition: project.cpp:28

Member Function Documentation

◆ models()

std::vector<SessionModel*> ModelView::Project::ProjectImpl::models ( ) const
inline

Returns list of models which are subject to save/load.

Definition at line 37 of file project.cpp.

37 { return m_context.m_models_callback(); }

References ModelView::Project::ProjectImpl::m_context, and ModelView::ProjectContext::m_models_callback.

Referenced by ModelView::Project::ProjectImpl::process().

◆ process()

template<typename T >
bool ModelView::Project::ProjectImpl::process ( const std::string &  dirname,
method 
)
inline

Processes all models one by one and either save or load them to/from given directory.

Template parameter method specifies ModelDocumentInterface's method to use.

Definition at line 41 of file project.cpp.

42  {
43  if (!Utils::exists(dirname))
44  return false;
45 
46  for (auto model : models()) {
47  auto document = CreateJsonDocument({model});
48  auto filename = Utils::join(dirname, ProjectUtils::SuggestFileName(*model));
49  std::invoke(method, document, filename);
50  }
51  m_project_dir = dirname;
53  return true;
54  }
void resetChanged()
Reset controller to initial state, pretending that no changes has been registered.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
MVVM_MODEL_EXPORT std::string SuggestFileName(const SessionModel &model)
Suggests file name which can be used to store json content of given model.
std::unique_ptr< ModelDocumentInterface > CreateJsonDocument(const std::vector< SessionModel * > &models)
Creates JsonDocument to save and load models.
bool exists(const QString &fileName)
Returns true if file exists.
std::string join(const std::vector< std::string > &joinable, const std::string &joint)
Returns string obtain by joining vector elements.
Definition: StringUtils.cpp:71
std::vector< SessionModel * > models() const
Returns list of models which are subject to save/load.
Definition: project.cpp:37

References ModelView::CreateJsonDocument(), ModelView::Utils::exists(), FileSystemUtils::filename(), ModelView::Utils::join(), ModelView::Project::ProjectImpl::m_change_controller, ModelView::Project::ProjectImpl::m_project_dir, ModelView::Project::ProjectImpl::models(), ModelView::ProjectChangedController::resetChanged(), and ModelView::ProjectUtils::SuggestFileName().

Here is the call graph for this function:

Member Data Documentation

◆ m_change_controller

ProjectChangedController ModelView::Project::ProjectImpl::m_change_controller

Definition at line 28 of file project.cpp.

Referenced by ModelView::Project::ProjectImpl::process().

◆ m_context

ProjectContext ModelView::Project::ProjectImpl::m_context

Definition at line 27 of file project.cpp.

Referenced by ModelView::Project::ProjectImpl::models().

◆ m_project_dir

std::string ModelView::Project::ProjectImpl::m_project_dir

Definition at line 26 of file project.cpp.

Referenced by ModelView::Project::ProjectImpl::process().


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