BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUI::Util::Path Namespace Reference

Functions

QString appDataFolder ()
 The folder where persistent application data shall be stored. Under Windows this is the AppData/Roaming location. Used e.g. for storing the instrument library. More...
 
QString baseName (const QString &fileName)
 Returns base name of file. More...
 
QString fileDir (const QString &fileName)
 Returns file directory from the full file path. More...
 
QString getBornAgainVersionString ()
 
QString getPathFromIndex (const QModelIndex &index)
 
QString getValidFileName (const QString &proposed_name)
 Returns valid file name to be saved on disk. This name is constructed from proposed_name by replacing all special characters with text representation \ backslash / slash " quote < lessthan

greaterthan

| pipe ? questionmark. More...

 
bool isVersionMatchMinimal (const QString &version, const QString &minimal_version)
 Returns true if current BornAgain version match minimal required version. More...
 
bool parseVersion (const QString &version, int &major_num, int &minor_num, int &patch_num)
 parses version string into 3 numbers, returns true in the case of success More...
 
int versionCode (const QString &version)
 
QString withTildeHomePath (const QString &path)
 

Function Documentation

◆ appDataFolder()

QString GUI::Util::Path::appDataFolder ( )

The folder where persistent application data shall be stored. Under Windows this is the AppData/Roaming location. Used e.g. for storing the instrument library.

Definition at line 139 of file Path.cpp.

140 {
141  return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
142 }

Referenced by main().

◆ baseName()

QString GUI::Util::Path::baseName ( const QString &  fileName)

Returns base name of file.

Definition at line 133 of file Path.cpp.

134 {
135  QFileInfo info(fileName);
136  return info.baseName();
137 }

Referenced by RealDataSelectorWidget::importData1D(), RealDataSelectorWidget::importData2D(), PyImportAssistant::importMultiLayer(), InstrumentCollection::suggestInstrumentName(), GUI::Util::String::suggestName(), and WelcomeView::updateRecentProjectPanel().

◆ fileDir()

QString GUI::Util::Path::fileDir ( const QString &  fileName)

Returns file directory from the full file path.

Definition at line 123 of file Path.cpp.

124 {
125  QFileInfo info(fileName);
126  if (info.exists())
127  return info.dir().path();
128  return "";
129 }

◆ getBornAgainVersionString()

QString GUI::Util::Path::getBornAgainVersionString ( )

Definition at line 60 of file Path.cpp.

61 {
62  return QString::fromStdString(BornAgain::GetVersionNumber());
63 }

Referenced by AboutDialog::createTextLayout(), ProjectDocument::documentVersion(), ProjectLoadProblemDialog::explanationText(), main(), ApplicationOptions::processOptions(), and ProjectDocument::writeTo().

◆ getPathFromIndex()

QString GUI::Util::Path::getPathFromIndex ( const QModelIndex &  index)

Definition at line 144 of file Path.cpp.

145 {
146  if (!index.isValid())
147  return "";
148 
149  QStringList namePath;
150  QModelIndex cur = index;
151  while (cur.isValid()) {
152  namePath << cur.data().toString();
153  cur = cur.parent();
154  }
155  std::reverse(namePath.begin(), namePath.end());
156  return namePath.join("/");
157 }

Referenced by ParameterItem::linkToSessionItem(), and DataProperties::setDataItem().

◆ getValidFileName()

QString GUI::Util::Path::getValidFileName ( const QString &  proposed_name)

Returns valid file name to be saved on disk. This name is constructed from proposed_name by replacing all special characters with text representation \ backslash / slash " quote < lessthan

greaterthan

| pipe ? questionmark.

Definition at line 74 of file Path.cpp.

75 {
76  QString result = proposed_name;
77  for (auto it = invalidCharacterMap.begin(); it != invalidCharacterMap.end(); ++it)
78  result.replace(it.key(), it.value());
79  return result;
80 }

◆ isVersionMatchMinimal()

bool GUI::Util::Path::isVersionMatchMinimal ( const QString &  version,
const QString &  minimal_version 
)

Returns true if current BornAgain version match minimal required version.

Definition at line 117 of file Path.cpp.

118 {
119  return versionCode(version) >= versionCode(minimal_version);
120 }
int versionCode(const QString &version)
Definition: Path.cpp:103

References versionCode().

Referenced by ProjectDocument::readProject().

Here is the call graph for this function:

◆ parseVersion()

bool GUI::Util::Path::parseVersion ( const QString &  version,
int &  major_num,
int &  minor_num,
int &  patch_num 
)

parses version string into 3 numbers, returns true in the case of success

Definition at line 83 of file Path.cpp.

85 {
86  major_num = minor_num = patch_num = 0;
87  bool success(true);
88  QStringList nums = version.split(".");
89  if (nums.size() != 3)
90  return false;
91 
92  bool ok(false);
93  major_num = nums.at(0).toInt(&ok);
94  success &= ok;
95  minor_num = nums.at(1).toInt(&ok);
96  success &= ok;
97  patch_num = nums.at(2).toInt(&ok);
98  success &= ok;
99 
100  return success;
101 }

Referenced by versionCode().

◆ versionCode()

int GUI::Util::Path::versionCode ( const QString &  version)

Definition at line 103 of file Path.cpp.

104 {
105  int result(-1);
106 
107  int ba_major(0), ba_minor(0), ba_patch(0);
108  if (!parseVersion(version, ba_major, ba_minor, ba_patch))
109  return result;
110 
111  result = ba_major * 10000 + ba_minor * 100 + ba_patch;
112 
113  return result;
114 }
bool parseVersion(const QString &version, int &major_num, int &minor_num, int &patch_num)
parses version string into 3 numbers, returns true in the case of success
Definition: Path.cpp:83

References parseVersion().

Referenced by isVersionMatchMinimal().

Here is the call graph for this function:

◆ withTildeHomePath()

QString GUI::Util::Path::withTildeHomePath ( const QString &  path)

Definition at line 45 of file Path.cpp.

46 {
47 #ifdef Q_OS_WIN
48  return path;
49 #endif
50 
51  static const QString homePath = QDir::homePath();
52 
53  QFileInfo fi(QDir::cleanPath(path));
54  QString outPath = fi.absoluteFilePath();
55  if (outPath.startsWith(homePath))
56  return QLatin1Char('~') + outPath.mid(homePath.size());
57  return path;
58 }

Referenced by ActionManager::onAboutToShowFileMenu(), ProjectSettingsView::updateInformation(), and WelcomeView::updateRecentProjectPanel().