16 #include "BAVersion.h"
21 #include <QModelIndex>
22 #include <QStandardPaths>
27 QMap<QString, QString> initializeCharacterMap()
29 QMap<QString, QString> result;
30 result[
"\\"] =
"_backslash_";
31 result[
"/"] =
"_slash_";
32 result[
"\""] =
"_quote_";
33 result[
"<"] =
"_lessthan_";
34 result[
">"] =
"_greaterthan_";
35 result[
"|"] =
"_pipe_";
36 result[
"?"] =
"_questionmark_";
40 const QMap<QString, QString> invalidCharacterMap = initializeCharacterMap();
51 static const QString homePath = QDir::homePath();
53 QFileInfo fi(QDir::cleanPath(path));
54 QString outPath = fi.absoluteFilePath();
55 if (outPath.startsWith(homePath))
56 return QLatin1Char(
'~') + outPath.mid(homePath.size());
62 return QString::fromStdString(BornAgain::GetVersionNumber());
76 QString result = proposed_name;
77 for (
auto it = invalidCharacterMap.begin(); it != invalidCharacterMap.end(); ++it)
78 result.replace(it.key(), it.value());
86 major_num = minor_num = patch_num = 0;
88 QStringList nums = version.split(
".");
93 major_num = nums.at(0).toInt(&ok);
95 minor_num = nums.at(1).toInt(&ok);
97 patch_num = nums.at(2).toInt(&ok);
107 int ba_major(0), ba_minor(0), ba_patch(0);
108 if (!
parseVersion(version, ba_major, ba_minor, ba_patch))
111 result = ba_major * 10000 + ba_minor * 100 + ba_patch;
125 QFileInfo info(fileName);
127 return info.dir().path();
135 QFileInfo info(fileName);
136 return info.baseName();
141 return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
146 if (!index.isValid())
149 QStringList namePath;
150 QModelIndex cur = index;
151 while (cur.isValid()) {
152 namePath << cur.data().toString();
155 std::reverse(namePath.begin(), namePath.end());
156 return namePath.join(
"/");
Defines class Helpers functions.
QString appDataFolder()
The folder where persistent application data shall be stored. Under Windows this is the AppData/Roami...
int versionCode(const QString &version)
QString baseName(const QString &fileName)
Returns base name of file.
QString fileDir(const QString &fileName)
Returns file directory from the full file path.
QString getValidFileName(const QString &proposed_name)
Returns valid file name to be saved on disk. This name is constructed from proposed_name by replacing...
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
bool isVersionMatchMinimal(const QString &version, const QString &minimal_version)
Returns true if current BornAgain version match minimal required version.
QString withTildeHomePath(const QString &path)
QString getBornAgainVersionString()
QString getPathFromIndex(const QModelIndex &index)