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

Collection of utility functions to handle project saving and loading. More...

Functions

MVVM_MODEL_EXPORT std::unique_ptr< ProjectInterfaceCreateUntitledProject (const ProjectContext &context)
 Creates new untitled project. More...
 
MVVM_MODEL_EXPORT bool IsPossibleProjectDir (const std::string &project_dir)
 Returns 'true' if given directory might be a project directory. More...
 
MVVM_MODEL_EXPORT std::string ProjectWindowTitle (const ProjectInterface &project)
 Returns a MainWindow title for given project. More...
 
MVVM_MODEL_EXPORT std::string ProjectWindowTitle (const std::string &project_dir, bool is_modified)
 Returns a title composed from last part of project path, and is_modified flag. More...
 
MVVM_MODEL_EXPORT std::string SuggestFileName (const SessionModel &model)
 Suggests file name which can be used to store json content of given model. More...
 

Detailed Description

Collection of utility functions to handle project saving and loading.

Function Documentation

◆ CreateUntitledProject()

std::unique_ptr< ProjectInterface > ModelView::ProjectUtils::CreateUntitledProject ( const ProjectContext context)

Creates new untitled project.

Definition at line 50 of file projectutils.cpp.

51 {
52  return std::make_unique<Project>(context);
53 }

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

◆ IsPossibleProjectDir()

bool ModelView::ProjectUtils::IsPossibleProjectDir ( const std::string &  project_dir)

Returns 'true' if given directory might be a project directory.

This simplified check counts number of files with json extention.

Definition at line 43 of file projectutils.cpp.

44 {
45  return !Utils::FindFiles(project_dir, json_extention).empty();
46 }
MVVM_MODEL_EXPORT std::vector< std::string > FindFiles(const std::string &dirname, const std::string &ext)
Returns list of files with given extention found in given directory.
Definition: fileutils.cpp:87

References ModelView::Utils::FindFiles().

Referenced by gui2::UserInteractor::onSelectDirRequest(), and TEST_F().

Here is the call graph for this function:

◆ ProjectWindowTitle() [1/2]

std::string ModelView::ProjectUtils::ProjectWindowTitle ( const ProjectInterface project)

Returns a MainWindow title for given project.

Definition at line 57 of file projectutils.cpp.

58 {
59  return ProjectWindowTitle(project.projectDir(), project.isModified());
60 }
MVVM_MODEL_EXPORT std::string ProjectWindowTitle(const ProjectInterface &project)
Returns a MainWindow title for given project.
@ project
selective copying for saving/loading the project (tags and data created by item, updated from JSON)

References ModelView::project.

Referenced by TEST_F().

◆ ProjectWindowTitle() [2/2]

std::string ModelView::ProjectUtils::ProjectWindowTitle ( const std::string &  project_dir,
bool  is_modified 
)

Returns a title composed from last part of project path, and is_modified flag.

Project without projectDir will be "Untitled", modified project will be "*Untitled". Project with projectDir in "/home/user/project1" will get title "project1".

Definition at line 66 of file projectutils.cpp.

67 {
68  auto pos = project_dir.find_last_of('/');
69  auto project_name = (pos == std::string::npos ? untitled_name : project_dir.substr(pos + 1));
70  auto unsaved_status = is_modified ? "*" : "";
71  return unsaved_status + project_name;
72 }

◆ SuggestFileName()

std::string ModelView::ProjectUtils::SuggestFileName ( const SessionModel model)

Suggests file name which can be used to store json content of given model.

Uses the model type to construct a filename: MaterialModel -> materialmodel.json

Definition at line 33 of file projectutils.cpp.

34 {
35  std::string result = model.modelType();
36  std::transform(result.begin(), result.end(), result.begin(), ::tolower);
37  return result + json_extention;
38 }

References ModelView::SessionModel::modelType().

Referenced by ModelView::Project::ProjectImpl::process(), and TEST_F().

Here is the call graph for this function: