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

Defines convenience function for project manager and document. More...

Functions

QString autosaveDir (const QString &projectFileName)
 Returns name of autosave directory for project with given project file name. More...
 
QString autosaveName (const QString &projectFileName)
 Returns name of project for autoSave from given project file name. More...
 
QString autosaveSubdir ()
 Returns fixed name for autosave sub-directory. More...
 
bool exists (const QString &fileName)
 Returns true if file exists. More...
 
bool hasAutosavedData (const QString &projectFileName)
 Returns true if project with given projectFileName contains autosaved data. More...
 
QString lastModified (const QString &fileName)
 Returns a string representing modification time of given file. More...
 
QStringList nonXMLDataInDir (const QString &dirname)
 Returns list of files on disk representing nonXML data. More...
 
QString projectDir (const QString &projectFileName)
 Returns project directory deduced from project file name. More...
 
QString projectName (const QString &projectFileName)
 Returns project name deduced from project file name. More...
 
QString readTextFile (const QString &fileName)
 Returns multi-lione string representing content of text file. More...
 
bool removeFile (const QString &dirname, const QString &filename)
 Remove file from given directory. More...
 
bool removeFiles (const QString &dirname, const QStringList &filenames)
 
bool removeRecursively (const QString &dirname)
 Removes recursively directory with given name. More...
 
QStringList substract (const QStringList &lhs, const QStringList &rhs)
 Returns list of string from lhs, which are not in rhs. More...
 
QString userExportDir ()
 Returns directory which user is normally using to export files. More...
 

Detailed Description

Defines convenience function for project manager and document.

Function Documentation

◆ autosaveDir()

QString ProjectUtils::autosaveDir ( const QString &  projectFileName)

Returns name of autosave directory for project with given project file name.

From '/projects/Untitled2/Untitled2.pro' returns '/projects/Untitled2/autosave'.

Definition at line 45 of file ProjectUtils.cpp.

46 {
47  return ProjectUtils::projectDir(projectFileName) + "/" + autosaveSubdir();
48 }
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.
QString autosaveSubdir()
Returns fixed name for autosave sub-directory.

References autosaveSubdir(), and projectDir().

Referenced by AutosaveController::autosaveDir(), and autosaveName().

Here is the call graph for this function:

◆ autosaveName()

QString ProjectUtils::autosaveName ( const QString &  projectFileName)

Returns name of project for autoSave from given project file name.

From '/projects/Untitled2/Untitled2.pro' returns '/projects/Untitled2/autosave/Untitled2.pro'.

Definition at line 52 of file ProjectUtils.cpp.

53 {
54  return ProjectUtils::autosaveDir(projectFileName) + "/"
56 }
static QString projectFileExtension()
QString projectName(const QString &projectFileName)
Returns project name deduced from project file name.
QString autosaveDir(const QString &projectFileName)
Returns name of autosave directory for project with given project file name.

References autosaveDir(), ProjectDocument::projectFileExtension(), and projectName().

Referenced by AutosaveController::autosaveName(), hasAutosavedData(), ProjectManager::loadProject(), and ProjectManager::restoreProjectDialog().

Here is the call graph for this function:

◆ autosaveSubdir()

QString ProjectUtils::autosaveSubdir ( )

Returns fixed name for autosave sub-directory.

Definition at line 38 of file ProjectUtils.cpp.

39 {
40  return "autosave";
41 }

Referenced by AutosaveController::assureAutoSaveDirExists(), autosaveDir(), and SaveService::process_queue().

◆ exists()

bool ProjectUtils::exists ( const QString &  fileName)

Returns true if file exists.

Definition at line 58 of file ProjectUtils.cpp.

59 {
60  QFileInfo info(fileName);
61  return info.exists();
62 }

Referenced by NewProjectDialog::checkIfProjectPathIsValid(), ModelView::Utils::exists(), FileSystemUtils::filesInDirectory(), hasAutosavedData(), and FileSystemUtils::IsFileExists().

◆ hasAutosavedData()

bool ProjectUtils::hasAutosavedData ( const QString &  projectFileName)

Returns true if project with given projectFileName contains autosaved data.

Definition at line 64 of file ProjectUtils.cpp.

65 {
66  return exists(projectFileName) && exists(autosaveName(projectFileName));
67 }
bool exists(const QString &fileName)
Returns true if file exists.
QString autosaveName(const QString &projectFileName)
Returns name of project for autoSave from given project file name.

References autosaveName(), and exists().

Referenced by ProjectManager::loadProject().

Here is the call graph for this function:

◆ lastModified()

QString ProjectUtils::lastModified ( const QString &  fileName)

Returns a string representing modification time of given file.

Definition at line 69 of file ProjectUtils.cpp.

70 {
71  QFileInfo info(fileName);
72  return info.lastModified().toString("hh:mm:ss, MMMM d, yyyy");
73 }

Referenced by ProjectManager::restoreProjectDialog().

◆ nonXMLDataInDir()

QStringList ProjectUtils::nonXMLDataInDir ( const QString &  dirname)

Returns list of files on disk representing nonXML data.

Definition at line 75 of file ProjectUtils.cpp.

76 {
77  QDir dir(dirname);
78 
79  if (!dir.exists())
80  throw GUIHelpers::Error("ProjectUtils::nonXMLDataInDir() -> Error. Non existing "
81  "directory '"
82  + dirname + "'.");
83 
84  return dir.entryList(ItemFileNameUtils::nonXMLFileNameFilters());
85 }
QStringList nonXMLFileNameFilters()
Returns list of fileName filters related to nonXML data stored by JobModel and RealDataModel.

References ItemFileNameUtils::nonXMLFileNameFilters().

Here is the call graph for this function:

◆ projectDir()

◆ projectName()

QString ProjectUtils::projectName ( const QString &  projectFileName)

Returns project name deduced from project file name.

Definition at line 26 of file ProjectUtils.cpp.

27 {
28  QFileInfo info(projectFileName);
29  return info.baseName();
30 }

Referenced by NewProjectDialog::NewProjectDialog(), autosaveName(), NewProjectDialog::checkIfProjectNameIsValid(), ProjectManager::restoreProjectDialog(), and ProjectDocument::setProjectFileName().

◆ readTextFile()

QString ProjectUtils::readTextFile ( const QString &  fileName)

Returns multi-lione string representing content of text file.

Definition at line 135 of file ProjectUtils.cpp.

136 {
137  QFile file(fileName);
138  if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
139  throw GUIHelpers::Error("ProjectUtils::readTextFile -> Error. Can't open the file '"
140  + fileName + "' for reading.");
141  QTextStream in(&file);
142  return in.readAll();
143 }

Referenced by PyImportAssistant::readFile().

◆ removeFile()

bool ProjectUtils::removeFile ( const QString &  dirname,
const QString &  filename 
)

Remove file from given directory.

Definition at line 99 of file ProjectUtils.cpp.

100 {
101  QString name = dirname + "/" + filename;
102  QFile fin(name);
103 
104  if (!fin.exists())
105  throw GUIHelpers::Error("ProjectUtils::removeFile() -> Error. Non existing "
106  "file '"
107  + name + "'.");
108 
109  return fin.remove();
110 }
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
QString const & name(EShape k)
Definition: particles.cpp:21

References FileSystemUtils::filename(), and RealSpace::Particles::name().

Referenced by removeFiles().

Here is the call graph for this function:

◆ removeFiles()

bool ProjectUtils::removeFiles ( const QString &  dirname,
const QStringList &  filenames 
)

Definition at line 112 of file ProjectUtils.cpp.

113 {
114  bool success(true);
115 
116  for (auto& name : filenames)
117  success &= removeFile(dirname, name);
118 
119  return success;
120 }
bool removeFile(const QString &dirname, const QString &filename)
Remove file from given directory.

References RealSpace::Particles::name(), and removeFile().

Referenced by OutputDataIOService::cleanOldFiles().

Here is the call graph for this function:

◆ removeRecursively()

bool ProjectUtils::removeRecursively ( const QString &  dirname)

Removes recursively directory with given name.

Directory name is relative to the parent (working directory of the executable).

Definition at line 87 of file ProjectUtils.cpp.

88 {
89  QDir dir(dirname);
90 
91  if (!dir.exists())
92  throw GUIHelpers::Error("ProjectUtils::removeRecursively() -> Error. Non existing "
93  "directory '"
94  + dirname + "'.");
95 
96  return dir.removeRecursively();
97 }

◆ substract()

QStringList ProjectUtils::substract ( const QStringList &  lhs,
const QStringList &  rhs 
)

Returns list of string from lhs, which are not in rhs.

Definition at line 122 of file ProjectUtils.cpp.

123 {
124 #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
125  auto lhs_set = QSet<QString>{lhs.begin(), lhs.end()};
126  auto rhs_set = QSet<QString>{rhs.begin(), rhs.end()};
127  QSet<QString> diff = lhs_set.subtract(rhs_set);
128  return diff.values();
129 #else
130  QSet<QString> diff = lhs.toSet().subtract(rhs.toSet());
131  return diff.toList();
132 #endif
133 }

Referenced by OutputDataIOService::cleanOldFiles().

◆ userExportDir()

QString ProjectUtils::userExportDir ( )

Returns directory which user is normally using to export files.

Definition at line 145 of file ProjectUtils.cpp.

146 {
148 }
static ProjectManager * projectManager()
Definition: AppSvc.cpp:18
QString userExportDir() const
Returns directory name suitable for saving plots.

References AppSvc::projectManager(), and ProjectManager::userExportDir().

Referenced by SaveProjectionsAssistant::saveProjections().

Here is the call graph for this function: