-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.h
165 lines (118 loc) · 4.76 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Copyright (C) 2017 - 2018 Fábio Bento (fabiobento512)
*
* This library is distributed under the MIT License. See notice at the end
* of this file.
*
*/
#ifndef UTIL_H
#define UTIL_H
#include <QString>
#include <QCoreApplication>
#include <QCryptographicHash>
#ifdef QT_GUI_LIB
#include <QMessageBox>
#include <QFileDialog>
#include <QDesktopServices>
#include <QStatusBar>
#include <QTableWidget>
#endif
/**
Utilities functions (global)
**/
namespace Util{
namespace FileSystem {
QString normalizePath(QString path);
QString cutName(QString path);
QString cutNameWithoutBackSlash(QString path);
QString normalizeAndQuote(QString path);
bool copyDir(const QString &fromPath, QString toPath, const bool isRecursive = false);
bool rmDir(const QString &dirPath);
QStringList getFolderFilesByWildcard(const QString &entryFolder, const QString &wildcard, bool isRecursive = false);
QStringList filterFilesByWildcard(const QStringList &filePaths, const QString &wildcard);
QString fileHash(const QString &fileName, QCryptographicHash::Algorithm hashAlgorithm);
QString getAppPath();
bool backupFile(const QString &file, QString newFilename="");
}
namespace String {
#ifndef QSTR_TO_TEMPORARY_CSTR
# define QSTR_TO_TEMPORARY_CSTR qUtf8Printable
#endif
QString insertApostrophes(const QString &currString);
QString insertQuotes(const QString &currString);
QString fullTrim(QString str);
QStringList substring(QString myString, QString separator, Qt::CaseSensitivity cs = Qt::CaseSensitive);
QString normalizeDecimalSeparator(QString value);
// no problem here with "temporary" cstr
// https://stackoverflow.com/questions/1971183/when-does-c-allocate-deallocate-string-literals
const char* boolToCstr(bool currentBoolean);
}
#ifdef QT_GUI_LIB
namespace Dialogs {
void showInfo(const QString &message, const bool richText = false);
void showWarning(const QString &message, const bool richText = false);
void showError(const QString &message, const bool richText = false);
bool showQuestion(QWidget * parent, QString message, QMessageBox::StandardButton standardButton=QMessageBox::NoButton);
QMessageBox::StandardButton showQuestionWithCancel(QWidget * parent, QString message, QMessageBox::StandardButton standardButton=QMessageBox::NoButton);
QStringList multipleDirSelection(const QString &title);
}
#endif
namespace Validation {
bool checkEmptySpaces(QStringList toCheck);
bool checkIfIntegers(QStringList toCheck);
bool checkIfDoubles(QStringList toCheck);
bool isStringInteger(QString myString);
bool isStringDouble(QString myString);
}
#ifdef QT_GUI_LIB
namespace TableWidget {
void addRow(QTableWidget *myTable, QStringList &columns);
QModelIndexList getSelectedRows(QTableWidget *myTable);
QModelIndexList getCurrentRows(QTableWidget *myTable);
int getNumberSelectedRows(QTableWidget *myTable);
void clearContents(QTableWidget *myTable, const QString ¬hingToClearMessage, const QString &questionToClear);
void clearContentsNoPrompt(QTableWidget *myTable);
void addCheckBox(QTableWidget *myTable, int row, int column, QCheckBox *checkbox = nullptr);
QCheckBox* getCheckBoxFromCell(QTableWidget *myTable, int row, int column);
void swapRows(QTableWidget *myTable, const int indexSourceRow, const int indexDestinationRow, bool selectSwappedRow);
void deleteSelectedRows(QTableWidget *myTable);
}
#endif
namespace System {
#ifdef QT_GUI_LIB
QRect getScreenResolution();
#endif
}
#ifdef QT_GUI_LIB
namespace StatusBar {
void showInfo(QStatusBar * const statusBar, const QString &message);
void showError(QStatusBar * const statusBar, const QString &message);
void showSuccess(QStatusBar * const statusBar,const QString &message);
}
#endif
}
#endif // UTIL_H
/**
* Copyright (c) 2017 - 2018 Fábio Bento (fabiobento512)
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/