1 | #ifndef UTIL_H
|
---|
2 | #define UTIL_H
|
---|
3 |
|
---|
4 | #include <QFile>
|
---|
5 | #include <QDir>
|
---|
6 | #include <QString>
|
---|
7 | #include <QStringList>
|
---|
8 | #include <iostream> // cout, cin etc.
|
---|
9 |
|
---|
10 | namespace GlobalVars{
|
---|
11 | extern QString AppName;
|
---|
12 | extern QString AppExecutable;
|
---|
13 | extern QString AppVersion;
|
---|
14 | }
|
---|
15 |
|
---|
16 | /**
|
---|
17 | Utilities functions (global)
|
---|
18 | **/
|
---|
19 | namespace Util{
|
---|
20 | QString normalizePath(QString path);
|
---|
21 | QString cutName(QString path);
|
---|
22 | QString insertQuotes(QString path);
|
---|
23 | QString normalizeAndQuote(QString path);
|
---|
24 | QString fullTrim(QString str);
|
---|
25 | QString normalizeDecimalSeparator(QString value);
|
---|
26 | QStringList substring(const QString &myString, const QString &separator, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
---|
27 | QStringList qStringListFromSpacedString(const QString &mySpacedString);
|
---|
28 | QStringList getAllFilesByWildcard(const QString &wildcard);
|
---|
29 | QList<int> qListIntFromSpacedString(const QString &mySpacedString);
|
---|
30 | QList<double> qListDoubleFromSpacedString(const QString &mySpacedString);
|
---|
31 | int indexOfBackward(const QString &myString, const QString &toSearch, int from = -1);
|
---|
32 | bool checkEmptySpaces(QStringList toCheck);
|
---|
33 | bool checkIfIntegers(QStringList toCheck);
|
---|
34 | bool checkIfDoubles(QStringList toCheck);
|
---|
35 | bool isStringInteger(QString myString);
|
---|
36 | bool isStringDouble(QString myString);
|
---|
37 | bool backupFile(QString file);
|
---|
38 | bool copyFile(QString src, QString dest);
|
---|
39 | // The commented code bellow is a big mistake because toLatin1() creates a temp object that gets
|
---|
40 | // destroyed after the semicolon: https://qt-project.org/forums/viewthread/12885 (Volker answer)
|
---|
41 | //// Convert a QString to a c string
|
---|
42 | //// Caution don't use as for example: std::cout << toCstr(a) << " " << toCstr(b);
|
---|
43 | //// as the result will be always a.
|
---|
44 | //inline const char* toCstr(const QString &myString){
|
---|
45 | // return myString.toLatin1().constData();
|
---|
46 | //}
|
---|
47 | // Converts a std::string to QString
|
---|
48 | inline QString toQString(std::string myString){
|
---|
49 | return QString::fromStdString(myString);
|
---|
50 | }
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | #endif // UTIL_H
|
---|