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