source: s10k/CommonUtils/util.h@ 1115

Last change on this file since 1115 was 1109, checked in by s10k, 6 years ago

small dialogs functions changes, now they have an optional value to set as rich text

File size: 5.5 KB
Line 
1/**
2 * Copyright (C) 2017 - 2018 Fábio Bento (fabiobento512)
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(const QString &file, QString newFilename="");
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, const bool richText = false);
99
100void showWarning(const QString &message, const bool richText = false);
101
102void showError(const QString &message, const bool richText = false);
103
104bool showQuestion(QWidget * parent, QString message, QMessageBox::StandardButton standardButton=QMessageBox::NoButton);
105
106QMessageBox::StandardButton showQuestionWithCancel(QWidget * parent, QString message, QMessageBox::StandardButton standardButton=QMessageBox::NoButton);
107
108QStringList multipleDirSelection(const QString &title);
109
110}
111#endif
112
113namespace Validation {
114
115bool checkEmptySpaces(QStringList toCheck);
116bool checkIfIntegers(QStringList toCheck);
117bool checkIfDoubles(QStringList toCheck);
118bool isStringInteger(QString myString);
119bool isStringDouble(QString myString);
120
121}
122
123#ifdef QT_GUI_LIB
124namespace TableWidget {
125
126void addRow(QTableWidget *myTable, QStringList &columns);
127QModelIndexList getSelectedRows(QTableWidget *myTable);
128QModelIndexList getCurrentRows(QTableWidget *myTable);
129int getNumberSelectedRows(QTableWidget *myTable);
130void clearContents(QTableWidget *myTable, const QString &nothingToClearMessage, const QString &questionToClear);
131void clearContentsNoPrompt(QTableWidget *myTable);
132void addCheckBox(QTableWidget *myTable, int row, int column, QCheckBox *checkbox = nullptr);
133QCheckBox* getCheckBoxFromCell(QTableWidget *myTable, int row, int column);
134void swapRows(QTableWidget *myTable, const int indexSourceRow, const int indexDestinationRow, bool selectSwappedRow);
135void deleteSelectedRows(QTableWidget *myTable);
136
137}
138#endif
139
140namespace System {
141#ifdef QT_GUI_LIB
142QRect getScreenResolution();
143#endif
144}
145
146#ifdef QT_GUI_LIB
147namespace StatusBar {
148
149void showInfo(QStatusBar * const statusBar, const QString &message);
150void showError(QStatusBar * const statusBar, const QString &message);
151void showSuccess(QStatusBar * const statusBar,const QString &message);
152
153}
154#endif
155
156
157}
158#endif // UTIL_H
159
160/**
161 * Copyright (c) 2017 - 2018 Fábio Bento (fabiobento512)
162 *
163 * Permission is hereby granted, free of charge, to any person
164 * obtaining a copy of this software and associated documentation
165 * files (the "Software"), to deal in the Software without
166 * restriction, including without limitation the rights to use,
167 * copy, modify, merge, publish, distribute, sublicense, and/or sell
168 * copies of the Software, and to permit persons to whom the
169 * Software is furnished to do so, subject to the following
170 * conditions:
171 *
172 * The above copyright notice and this permission notice shall be
173 * included in all copies or substantial portions of the Software.
174 *
175 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
176 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
177 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
178 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
179 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
180 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
181 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
182 * OTHER DEALINGS IN THE SOFTWARE.
183 */
Note: See TracBrowser for help on using the repository browser.