source: s10k/CommonUtils/util.h@ 1078

Last change on this file since 1078 was 1073, checked in by s10k, 7 years ago

added XML Tools latest version (2.0d) and s10k's common libs

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