Sun, 17 Jul 2022 22:14:41 +0200
Made the Hardness function more precise. Removed RA_ppm function, was doubles with ResidualAlkalinity. Added RA_CaCO3 and Bicarbonate functions.
1 | 1 | /** |
2 | * main.cpp is part of bmsapp. | |
3 | * | |
4 | * bmsapp is free software: you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation, either version 3 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * bmsapp is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | #include <QApplication> | |
18 | #include <QCommandLineParser> | |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
19 | #include <QDebug> |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
20 | #include <QDate> |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
21 | #include <QMessageBox> |
90
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
22 | #include <QSettings> |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
23 | |
90
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
24 | #include "MainWindow.h" |
1 | 25 | #include "config.h" |
26 | ||
254
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
27 | void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
28 | { |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
29 | static QMutex mutex; |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
30 | QMutexLocker lock(&mutex); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
31 | |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
32 | static QFile logFile("bmsapp.log"); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
33 | static bool logFileIsOpen = logFile.open(QIODevice::Append | QIODevice::Text); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
34 | |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
35 | fprintf(stderr, "%s\n", qPrintable(qFormatLogMessage(type, context, msg))); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
36 | |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
37 | if ((type != QtDebugMsg) && logFileIsOpen) { |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
38 | QDateTime dateTime(QDateTime::currentDateTime()); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
39 | QString timeStr(dateTime.toString("dd-MM-yyyy HH:mm:ss:zzz")); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
40 | logFile.write(timeStr.toUtf8()); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
41 | switch (type) { |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
42 | case QtInfoMsg: logFile.write(" INFO "); break; |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
43 | case QtDebugMsg: logFile.write(" DEBUG "); break; |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
44 | case QtWarningMsg: logFile.write(" WARN "); break; |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
45 | case QtCriticalMsg: logFile.write(" CRIT "); break; |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
46 | case QtFatalMsg: logFile.write(" FATAL "); break; |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
47 | } |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
48 | logFile.write(qFormatLogMessage(type, context, msg).toUtf8() + '\n'); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
49 | logFile.flush(); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
50 | } |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
51 | } |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
52 | |
1 | 53 | |
54 | int main(int argc, char *argv[]) | |
55 | { | |
56 | QApplication app(argc, argv); | |
31
ab17a56a47dd
Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
57 | QString locale = QLocale::system().name(); |
ab17a56a47dd
Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
58 | |
254
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
59 | qInstallMessageHandler(myMessageOutput); |
85 | 60 | app.setApplicationName("bmsapp"); |
1 | 61 | app.setApplicationVersion(VERSIONSTRING); |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
62 | app.setOrganizationName("mbse"); |
1 | 63 | |
15
c58b82549713
Started adding the global setup screen.
Michiel Broek <mbroek@mbse.eu>
parents:
14
diff
changeset
|
64 | /* Stylesheet setup */ |
18
d0ca50776b0b
Fixed missing arrows on combobox and spinboxes in the qdarkstyle theme. Changed suppliers editor icon in the menu.
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
65 | QFile f(":/qdarkstyle/theme/style.qss"); |
16
a5d8e783a7b0
Completed the global setup editor.
Michiel Broek <mbroek@mbse.eu>
parents:
15
diff
changeset
|
66 | //QFile f(":dummy"); |
14
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
67 | if (!f.exists()) { |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
68 | printf("Unable to set stylesheet, file not found\n"); |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
69 | } else { |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
70 | f.open(QFile::ReadOnly | QFile::Text); |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
71 | QTextStream ts(&f); |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
72 | qApp->setStyleSheet(ts.readAll()); |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
73 | } |
8a304c898a75
Added QDarkStyle stylesheet and images. Updated About window. Some minor layout improvements.
Michiel Broek <mbroek@mbse.eu>
parents:
6
diff
changeset
|
74 | |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
75 | /* Setup user ini format */ |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
76 | QSettings::setDefaultFormat(QSettings::IniFormat); |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
77 | |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
78 | /* Setup commandline parser */ |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
79 | QCommandLineParser parser; |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
80 | parser.setApplicationDescription("Brewery Management System Application."); |
6
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
2
diff
changeset
|
81 | QCommandLineOption const startConfigOption({"c", "config"}, "Start the configuration editor."); |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
2
diff
changeset
|
82 | parser.addOption(startConfigOption); |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
2
diff
changeset
|
83 | QCommandLineOption const useDevelopOption({"d", "develop"}, "Use the development database."); |
f8474f2c5db9
We can fetch a list of suppliers and show it in the wrong window. Still a lot to learn about Qt5
Michiel Broek <mbroek@mbse.eu>
parents:
2
diff
changeset
|
84 | parser.addOption(useDevelopOption); |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
85 | parser.addHelpOption(); |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
86 | parser.addVersionOption(); |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
87 | parser.process(app); |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
88 | |
245
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
89 | QString langFile = QString("bmsapp_") + locale; |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
90 | QStringList searchDirs = QStringList() << qApp->applicationDirPath() << qApp->applicationDirPath() + "/../share/bmsapp/translations"; |
31
ab17a56a47dd
Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
91 | QTranslator translator; |
245
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
92 | |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
93 | for (int i = 0; i < searchDirs.size(); i++) { |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
94 | if (translator.load(langFile, searchDirs[i])) { |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
95 | app.installTranslator(&translator); |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
96 | qDebug() << "lang from" << searchDirs[i]; |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
97 | break; |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
98 | } |
f58543ef3fed
Install translations in /bmsapp/translations. Use a searchpath to try to load a translation.
Michiel Broek <mbroek@mbse.eu>
parents:
242
diff
changeset
|
99 | } |
31
ab17a56a47dd
Setup translation system and started the Dutch translation
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
100 | |
254
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
101 | qInfo().noquote() << "Starting" << app.applicationName() << app.applicationVersion(); |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
102 | |
90
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
103 | MainWindow w(parser.isSet(useDevelopOption), parser.isSet(startConfigOption)); |
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
104 | w.show(); |
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
105 | |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
106 | try { |
90
2396457a8167
Moved functions from bmsapp.cpp to MainWindow.cpp
Michiel Broek <mbroek@mbse.eu>
parents:
85
diff
changeset
|
107 | auto mainAppReturnValue = app.exec(); |
254
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
108 | qInfo().noquote() << "Finished" << app.applicationName() << app.applicationVersion(); |
b0adda0053c5
Installed MessageHandler for logging
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
109 | qInfo() << ""; |
2
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
110 | return mainAppReturnValue; |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
111 | } |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
112 | catch (const QString &error) { |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
113 | QMessageBox::critical(0, |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
114 | QApplication::tr("Application terminates"), |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
115 | QApplication::tr("The application encountered a fatal error.\nError message:\n%1").arg(error)); |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
116 | } |
a1e435907f3a
Added commandline parameters. Added initial app functions. Added user configuration read/write/create.
Michiel Broek <mbroek@mbse.eu>
parents:
1
diff
changeset
|
117 | return EXIT_FAILURE; |
1 | 118 | } |