annotate src/main.cpp @ 232:07d837442c55

Open the links in about dialog via external web browser.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 11 Apr 2018 12:42:11 +0300
parents e90dba0cd12a
children 54ab3f3e28c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 //
140
783417da6da3 Change the program description to english etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
2 // Syntilista - debt list/management database program
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 // Programmed and designed by Matti Hämäläinen <ccr@tnsp.org>
217
58af72da7f60 Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
4 // (C) Copyright 2017-2018 Tecnic Software productions (TNSP)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 //
57
893f69fcf050 Add license.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
6 // Distributed under 3-clause BSD style license, refer to
893f69fcf050 Add license.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
7 // included file "COPYING" for exact terms.
893f69fcf050 Add license.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
8 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <QApplication>
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <QMessageBox>
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <QSettings>
129
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
12 #include <QStandardPaths>
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "main.h"
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include "ui_mainwindow.h"
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include "ui_editperson.h"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
16 #include "ui_aboutwindow.h"
218
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
17 #include "ui_viewtransactions.h"
228
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
18 #include "runguard.h"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
19
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
21 //
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
22 // Application settings struct
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
23 //
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
24 struct
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
25 {
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
26 QPoint uiPos;
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
27 QSize uiSize;
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
28 double uiScale; // Global UI scale factor
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
29
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
30 QString dataPath; // Application data path/directory
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
31
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
32 // Backup related settings
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
33 int dbBackupMode;
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
34 QString dbBackupURL;
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
35 QString dbBackupSecret;
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
36 QDateTime dbLastBackup;
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
37 } settings;
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
38
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
39
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
41 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
42 // Convert QString to a double value, replacing comma
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
43 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
44 double slMoneyStrToValue(const QString &str)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 QString str2 = str;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 return str2.replace(",", ".").toDouble();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
51 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
52 // Convert double value to formatted QString
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
53 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
54 QString slMoneyValueToStr(double val)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 return QStringLiteral("%1").arg(val, 1, 'f', 2);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
205
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
60 QString slMoneyValueToStrSign(double val)
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
61 {
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
62 return QStringLiteral("%1%2").
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
63 arg(val > 0 ? "+" : "").
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
64 arg(val, 1, 'f', 2);
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
65 }
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
66
3d21d789b40b Show transaction list values always with a sign prefix (+/-).
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
67
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
68 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
69 // Trim and cleanup given QString (removing double whitespace etc.)
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
70 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
71 QString slCleanupStr(const QString &str)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 return str.simplified().trimmed();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
77 //
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
78 // Manipulate given QDateTime value to get desired
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
79 // correct timestamp.
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
80 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
81 const QDateTime slDateTimeToLocal(const QDateTime &val)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 QDateTime tmp = val;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 tmp.setOffsetFromUtc(0);
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
85 return tmp.toLocalTime();
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
86 }
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
87
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
88
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
89 //
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
90 // Return a string representation of given QDateTime
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
91 // converted to local time.
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
92 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
93 const QString slDateTimeToStr(const QDateTime &val)
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
94 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
95 return slDateTimeToLocal(val).toString(QStringLiteral("yyyy-MM-dd hh:mm"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
99 //
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
100 // Error logging
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
101 //
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
102 void slLog(const QString &mtype, const QString &msg)
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
103 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
104 QString filename = settings.dataPath + QDir::separator() + APP_LOG_FILE;
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
105 QFile fh(filename);
129
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
106 if (fh.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
107 {
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
108 QTextStream out(&fh);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
109 out <<
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
110 slDateTimeToLocal(QDateTime::currentDateTimeUtc()).
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
111 toString(QStringLiteral("yyyy-MM-dd hh:mm:ss"))
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
112 << " [" << mtype << "]: " << msg << "\n";
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
113 fh.close();
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
114 }
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
115 }
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
116
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
117
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
118 //
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
119 // Display an error dialog with given title and message
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
120 //
200
98eec4f3838b Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 199
diff changeset
121 int slErrorMsg(const QString &title, const QString &msg)
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
122 {
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
123 QMessageBox dlg;
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
124
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
125 slLog("ERROR", msg);
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
126
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
127 dlg.setText(title);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
128 dlg.setInformativeText(msg);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
129 dlg.setTextFormat(Qt::RichText);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
130 dlg.setIcon(QMessageBox::Critical);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
131 dlg.setStandardButtons(QMessageBox::Ok);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
132 dlg.setDefaultButton(QMessageBox::Ok);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
133
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
134 return dlg.exec();
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
135 }
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
136
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
137
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
138 //
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
139 // Check if an SQL error has occured (for given QSqlError) and
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
140 // report it to stdout if so. Return "false" if error has occured,
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
141 // true otherwise.
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
142 //
157
325e7590f93e Move most of the printing related code to printing.cpp
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
143 bool slCheckAndReportSQLError(const QString where, const QSqlError &err, bool report)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 if (err.isValid())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 {
156
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
147 // If an error has occured, log it
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
148 slLog("ERROR",
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
149 QStringLiteral("SQL %1: %2").
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
150 arg(where).arg(err.text()));
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
151 return false;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 else
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
154 {
156
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
155 // If no error, but event reporting requested, log it
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
156 if (report)
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
157 {
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
158 slLog("NOTE",
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
159 QStringLiteral("SQL OK %1").arg(where));
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
160 }
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
161 return true;
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
162 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
166 void SLPersonInfo::dump()
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
167 {
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
168 printf(
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
169 "SLPersonInfo() #%lld '%s %s' (added=%s, updated=%s, balance %1.2f)\n#%s#\n",
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
170 id,
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
171 firstName.toUtf8().constData(),
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
172 lastName.toUtf8().constData(),
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
173 slDateTimeToStr(added).toUtf8().constData(),
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
174 slDateTimeToStr(updated).toUtf8().constData(),
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
175 balance,
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
176 extraInfo.toUtf8().constData());
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
177 }
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
178
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
179
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
180 //
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
181 // Get SLPersonInfo record from SQL query object
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
182 //
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
183 void slGetPersonInfoRec(QSqlQuery &query, SLPersonInfo &info)
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
184 {
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
185 info.id = query.value(0).toInt();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
186 info.firstName = query.value(1).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
187 info.lastName = query.value(2).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
188 info.extraInfo = query.value(3).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
189 info.added = query.value(4).toDateTime();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
190 info.updated = query.value(5).toDateTime();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
191 info.balance = query.value(6).toDouble();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
192 }
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
193
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
194
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
195 //
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
196 // Get SLPersonInfo record from SQL database for specified person ID #
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
197 //
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
198 bool slGetPersonInfo(qint64 id, SLPersonInfo &info)
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
199 {
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
200 QSqlQuery query;
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
201 query.prepare(QStringLiteral(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
202 "SELECT id,first_name,last_name,extra_info,added,updated, "
107
8ceaafde9b52 Use total() instead of sum() in the SQL queries for better accuracy.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
203 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance "
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
204 "FROM people WHERE id=?"));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
205
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
206 query.addBindValue(id);
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
207 query.exec();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
208 if (!query.next())
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
209 return false;
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
210
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
211 slGetPersonInfoRec(query, info);
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
212 query.finish();
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
213 return true;
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
214 }
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
215
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
216
156
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
217 //
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
218 // Set stylesheet for given QWidget, and scale fonts etc.
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
219 // for some elements based on current UI scale factor.
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
220 //
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
221 void slSetCommonStyleSheet(QWidget *widget)
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
222 {
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
223 // Clamp scale value
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
224 if (settings.uiScale < 0.5f)
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
225 settings.uiScale = 0.5f;
103
ce86ea4b08aa Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
226
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
227 if (settings.uiScale > 3.0f)
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
228 settings.uiScale = 3.0f;
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
229
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
230 // Set the stylesheet
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
231 widget->setStyleSheet(
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
232 QStringLiteral(
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
233 "* { font-size: %1pt; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
234 "QPushButton { font-size: %2pt; padding: 0.25em; }"
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
235 "#button_AddDebt[enabled='true'] { font-size: %3pt; background-color: #900; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
236 "#button_PayDebt[enabled='true'] { font-size: %3pt; background-color: #090; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
237 "#button_PayFullDebt[enabled='true'] { background-color: #060; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
238
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
239 "#button_AddDebt[enabled='false'] { font-size: %3pt; background-color: #622; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
240 "#button_PayDebt[enabled='false'] { font-size: %3pt; background-color: #262; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
241 "#button_PayFullDebt[enabled='false'] { background-color: #131; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
242
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
243 "#label_PersonName { font-size: %5pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
244 "#label_BalanceValue { font-size: %4pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
245 "#label_EUR { font-size: %4pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
246 "#edit_Amount { font-size: %4pt; margin: 0.5em; padding: 0.5em; }"
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
247 "#label_NumPeopleValue { color: green; }"
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
248 ).
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
249 arg(12 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
250 arg(14 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
251 arg(16 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
252 arg(18 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
253 arg(20 * settings.uiScale)
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
254 );
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
255 }
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
256
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
257
156
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
258 //
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
259 // Main program begins
afadc1380fb1 Add few misc. comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
260 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 int main(int argc, char *argv[])
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 QApplication sapp(argc, argv);
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
264 QSettings tmpst(APP_VENDOR, APP_ID);
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
265
228
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
266 // Check for multiple instances
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
267 RunGuard guard(QStringLiteral(APP_VENDOR) + QStringLiteral(APP_ID));
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
268 if (!guard.tryToRun())
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
269 {
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
270 slErrorMsg(
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
271 QObject::tr("Virhe!"),
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
272 QObject::tr(
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
273 "Syntilista-sovellus on jo käynnissä. Sulje tämä ikkuna ja "
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
274 "etsi ajossa oleva Syntilista-sovellus tehtäväpalkista."
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
275 )
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
276 );
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
277 return 1;
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
278 }
37d5f4329449 Implement single running instance check to prevent problems with the SQLite database.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
279
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
280 // Read configuration settings
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
281 settings.uiPos = tmpst.value("pos", QPoint(100, 100)).toPoint();
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
282 settings.uiSize = tmpst.value("size", QSize(1000, 600)).toSize();
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
283 settings.uiScale = tmpst.value("scale", 1.0f).toDouble();
151
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
284 settings.dbBackupMode = tmpst.value("dbBackupMode", BACKUP_NONE).toInt();
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
285 settings.dbBackupURL = tmpst.value("dbBackupURL", QString()).toString();
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
286 settings.dbBackupSecret = tmpst.value("dbBackupSecret", QString()).toString();
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
287 settings.dbLastBackup = tmpst.value("dbLastBackup", QDateTime::fromSecsSinceEpoch(0)).toDateTime();
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
288
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
289 // Check commandline arguments for configuring backup settings
169
d9b9be9c4788 Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
290 if (argc >= 2 && strcmp(argv[1], "config") == 0)
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
291 {
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
292 settings.dbBackupMode = QString(argv[2]).toInt();
169
d9b9be9c4788 Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
293 if (argc >= 5)
d9b9be9c4788 Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
294 {
d9b9be9c4788 Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
295 settings.dbBackupURL = QString(argv[3]);
d9b9be9c4788 Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
296 settings.dbBackupSecret = QString(argv[4]);
d9b9be9c4788 Make 'config' commandline option's backup location and secret settings
Matti Hamalainen <ccr@tnsp.org>
parents: 157
diff changeset
297 }
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
298 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
148
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
300 // Also possibility of resetting the UI settings
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
301 if (argc >= 2 && strcmp(argv[1], "reset") == 0)
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
302 {
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
303 settings.uiPos = QPoint(100, 100);
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
304 settings.uiSize = QSize(1000, 600);
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
305 settings.uiScale = 1.0f;
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
306 }
665421937ec8 Add another commandline option "reset" for reseting the UI position, size and scale to default values.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
307
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 //
170
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
309 // Create logfile and data directory if they do not already exist
129
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
310 //
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
311 settings.dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
312 QDir path(settings.dataPath);
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
313 if (!path.exists(settings.dataPath))
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
314 path.mkpath(settings.dataPath);
129
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
315
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
316 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 // Initialize / open SQL database connection
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
320 db.setDatabaseName(settings.dataPath + QDir::separator() + APP_SQLITE_FILE);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 if (!db.open())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
324 slErrorMsg(
9
1f442052d332 Oops, 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
325 QObject::tr("Tietokantaa ei voitu avata"),
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
326 QObject::tr("Yhteyttä SQL-tietokantaan ei saatu.<br><br>Virhe: %1<br><br>").
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
327 arg(db.lastError().text())
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 );
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
329 return 1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 QSqlQuery query;
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
333 if (!db.tables().contains("people"))
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
334 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
335 query.exec(QStringLiteral(
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
336 "CREATE TABLE people (id INTEGER PRIMARY KEY, "
113
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
337 "first_name VARCHAR(%1) NOT NULL, "
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
338 "last_name VARCHAR(%2) NOT NULL, "
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
339 "extra_info VARCHAR(%3), "
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
340 "added DATETIME NOT NULL, "
113
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
341 "updated DATETIME NOT NULL)").
123
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
342 arg(SQL_LEN_FIRST_NAME).
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
343 arg(SQL_LEN_LAST_NAME).
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
344 arg(SQL_LEN_EXTRA_INFO));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
170
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
346 if (!slCheckAndReportSQLError("CREATE TABLE people", query.lastError(), true))
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
347 {
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
348 slErrorMsg(
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
349 QObject::tr("Tietokantataulua ei voitu luoda"),
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
350 QObject::tr("Virhe: %1<br><br>").
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
351 arg(db.lastError().text())
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
352 );
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
353 return 1;
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
354 }
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
355 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
357 if (!db.tables().contains("transactions"))
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
358 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
359 query.exec(QStringLiteral(
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
360 "CREATE TABLE transactions ("
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
361 "id INTEGER PRIMARY KEY, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
362 "person INT NOT NULL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
363 "value REAL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
364 "added DATETIME NOT NULL)"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365
170
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
366 if (!slCheckAndReportSQLError("CREATE TABLE transactions", query.lastError(), true))
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
367 {
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
368 slErrorMsg(
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
369 QObject::tr("Tietokantataulua ei voitu luoda"),
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
370 QObject::tr("Virhe: %1<br><br>").
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
371 arg(db.lastError().text())
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
372 );
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
373 return 1;
7edbfb2c0089 Add error message dialogs for cases when SQL tables could not be created,
Matti Hamalainen <ccr@tnsp.org>
parents: 169
diff changeset
374 }
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
375 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
377 query.finish();
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
378
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 SyntilistaMainWindow swin;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 swin.show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 return sapp.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 // Main application window code
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 SyntilistaMainWindow::SyntilistaMainWindow(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 QMainWindow(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 ui(new Ui::SyntilistaMainWindow)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 {
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
392 // Setup UI
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 ui->setupUi(this);
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
394
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
395 // Restore window size and position
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
396 move(settings.uiPos);
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
397 resize(settings.uiSize);
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
398
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
399 // Setup application icon and window title
203
5c3e3967bdf3 Use Qt resource aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
400 setWindowIcon(QIcon(QPixmap(":/icon")));
64
73fd86778014 Version number display etc. changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
401 setWindowTitle(tr("%1 versio %3").
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
402 arg(tr(APP_NAME)).
204
fd115ca75ce8 Do not use tr() for APP_VERSION.
Matti Hamalainen <ccr@tnsp.org>
parents: 203
diff changeset
403 arg(APP_VERSION));
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
404
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
405 // Setup large logo in the main window
203
5c3e3967bdf3 Use Qt resource aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
406 QPixmap logoImage(":/logo");
60
d7a2a48ebe24 Add a separate "About" button, don't use the logo as one. Change logo widget
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
407 ui->button_LogoImage->setPixmap(logoImage);
d7a2a48ebe24 Add a separate "About" button, don't use the logo as one. Change logo widget
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
408 ui->button_LogoImage->setAlignment(Qt::AlignCenter);
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
409
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
410 slSetCommonStyleSheet(this);
22
c23241a3e160 UI polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
411
68
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
412 // Validator for amount input
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
413 QRegExp vregex("\\d{0,4}[,.]\\d{0,2}|\\d{0,4}");
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
414 ui->edit_Amount->setValidator(new QRegExpValidator(vregex, this));
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
415
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
416 // Setup person list filtering and sorting
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 peopleSortIndex = 1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 peopleSortOrder = Qt::AscendingOrder;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 peopleFilter = "";
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
421 model_People = new SLPersonSQLModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 ui->tableview_People->setModel(model_People);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 ui->tableview_People->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 ui->tableview_People->setItemDelegate(new QSqlRelationalDelegate(ui->tableview_People));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 ui->tableview_People->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 ui->tableview_People->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 ui->tableview_People->setSortingEnabled(true);
25
a7e746642599 Fix initial sorting.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
430 ui->tableview_People->sortByColumn(peopleSortIndex, peopleSortOrder);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
432 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
433 ui->tableview_People->selectionModel(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
435 this,
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
436 SLOT(selectedPersonChanged(const QModelIndex &, const QModelIndex &)));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
438 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
439 ui->tableview_People->horizontalHeader(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 this,
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 SLOT(updateSortOrder(int, Qt::SortOrder)));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 ui->tableview_People->horizontalHeader()->setSortIndicator(1, Qt::AscendingOrder);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
446 model_Latest = new SLTransactionSQLModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 ui->tableview_Latest->setItemDelegate(new QSqlRelationalDelegate(ui->tableview_Latest));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 setActivePerson(-1);
17
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
453
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
454 // Keyboard shortcuts
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
455 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(on_button_Quit_clicked()));
178
2155e05bf61c Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
456 new QShortcut(QKeySequence(Qt::Key_F10), this, SLOT(on_button_Quit_clicked()));
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
457
178
2155e05bf61c Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
458 new QShortcut(QKeySequence(Qt::Key_F5), this, SLOT(on_button_AddPerson_clicked()));
2155e05bf61c Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
459 new QShortcut(QKeySequence(Qt::Key_F6), this, SLOT(on_button_EditPerson_clicked()));
2155e05bf61c Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
460 new QShortcut(QKeySequence(Qt::Key_F8), this, SLOT(on_button_DeletePerson_clicked()));
2155e05bf61c Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
461 new QShortcut(QKeySequence(Qt::Key_F1), this, SLOT(on_button_About_clicked()));
2155e05bf61c Use QShortcuts() instead of setShortcut().
Matti Hamalainen <ccr@tnsp.org>
parents: 174
diff changeset
462 new QShortcut(QKeySequence(Qt::Key_Escape), this, SLOT(on_button_ClearFilter_clicked()));
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
463
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
464 new QShortcut(QKeySequence(QKeySequence::ZoomIn), this, SLOT(changeUIZoomIn()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
465 new QShortcut(QKeySequence(QKeySequence::ZoomOut), this, SLOT(changeUIZoomOut()));
191
79da81b9e184 Move a line cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
466 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_0), this, SLOT(changeUIZoomReset()));
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
467 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_Plus), this, SLOT(changeUIZoomIn()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
468 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_Minus), this, SLOT(changeUIZoomOut()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
469 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_0), this, SLOT(changeUIZoomReset()));
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
470
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
471 new QShortcut(QKeySequence(Qt::Key_PageUp), this, SLOT(selectRowPrev()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
472 new QShortcut(QKeySequence(Qt::Key_PageDown), this, SLOT(selectRowNext()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
473
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
474 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this, SLOT(focusDebtEdit()));
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
475
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
476 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_P), this, SLOT(on_button_Print_clicked()));
222
5406b8664f00 Add keyboard shortcut ctrl+t for opening the transactions list.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
477 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(on_button_ViewTransactions_clicked()));
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
478
194
ff25f4855afc Better comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 191
diff changeset
479 // Check for latest successful backup time
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
480 qint64 threshold = 7;
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
481 qint64 delta = settings.dbLastBackup.msecsTo(QDateTime::currentDateTimeUtc());
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
482 if (settings.dbBackupMode != BACKUP_NONE &&
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
483 QDateTime::fromSecsSinceEpoch(0).msecsTo(settings.dbLastBackup) > 0 &&
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
484 delta > (1000 * 60 * 60 * 24) * threshold)
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
485 {
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
486 slErrorMsg(
195
930191210416 Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
487 tr("<h1>Huomio!</h1>"),
930191210416 Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
488 tr(
930191210416 Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
489 "<p>Edellisestä onnistuneesta tietokannan varmuuskopioinnista on kulunut <b>%1</b> päivää.</p>"
930191210416 Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
490 "<p>On suositeltavaa että kytket laitteen Kampuksen kiinteään verkkoon, että "
930191210416 Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
491 "varmuuskopiointi voidaan suorittaa. Varmuuskopiointia ei voida tehdä langattoman verkon kautta.</p>"
930191210416 Improve the notice/warning message about last backup having been too long ago.
Matti Hamalainen <ccr@tnsp.org>
parents: 194
diff changeset
492 ).
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
493 arg(delta / (1000 * 60 * 60 * 24)));
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
494 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
498 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
499 // Application main window destructor
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
500 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 SyntilistaMainWindow::~SyntilistaMainWindow()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 {
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
503 QSettings tmpst(APP_VENDOR, APP_ID);
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
504
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
505 // Save window size and position
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
506 tmpst.setValue("pos", pos());
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
507 tmpst.setValue("size", size());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
509 // Other settings
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
510 tmpst.setValue("scale", settings.uiScale);
151
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
511 tmpst.setValue("dbBackupMode", settings.dbBackupMode);
139
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
512 tmpst.setValue("dbBackupURL", settings.dbBackupURL);
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
513 tmpst.setValue("dbBackupSecret", settings.dbBackupSecret);
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
514
d5d1549e47fb Change how settings are restored and saved.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
515 // Free resources
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 delete model_People;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 delete model_Latest;
134
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
519
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
520 // Commit and close database
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
521 QSqlDatabase::database().commit();
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
522 QSqlDatabase::database().close();
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
523
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
524 // Back up the database
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
525 if (settings.dbBackupMode != BACKUP_NONE)
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
526 backupDatabase();
151
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
527 else
201
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
528 {
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
529 slLog("INFO",
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
530 QStringLiteral("Database backup mode is NONE, not performing backup."));
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
531 }
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
532 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
533
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
534
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
535 void SyntilistaMainWindow::backupSuccess()
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
536 {
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
537 QSettings tmpst(APP_VENDOR, APP_ID);
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
538 slLog("INFO", QStringLiteral("Backup successful."));
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
539
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
540 tmpst.setValue("dbLastBackup", QDateTime::currentDateTimeUtc());
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
541 }
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
542
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
543
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
544 void SyntilistaMainWindow::backupDatabase()
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
545 {
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
546 QString dbFilename = settings.dataPath + QDir::separator() + APP_SQLITE_FILE;
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
547 QString backupFilename = APP_SQLITE_FILE;
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
548 backupDialog = NULL;
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
549
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
550 if (settings.dbBackupURL == QString() || settings.dbBackupURL == "")
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
551 {
201
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
552 slLog("ERROR",
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
553 QStringLiteral("Database backup URL not set in configuration."));
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
554 return;
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
555 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
556
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
557 if (settings.dbBackupSecret == QString() || settings.dbBackupSecret == "")
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
558 {
201
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
559 slLog("ERROR",
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
560 QStringLiteral("Database backup secret key not set in configuration."));
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
561 return;
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
562 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
563
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
564 if (settings.dbBackupMode == BACKUP_HTTP)
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
565 {
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
566 #ifdef USE_QTHTTP
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
567 // Check for network access
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
568 httpBackupReply = NULL;
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
569
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
570 QNetworkAccessManager *manager = new QNetworkAccessManager();
154
ef4edd798a45 Disable network availability check for now, it seems to return false values in some cases.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
571 /*
155
6187c36de250 Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
572 // NOTE XXX! For some reason the manager returns not accessible under Wine
6187c36de250 Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
573 // and possibly some version(s) of Windows .. not sure why, thus commented
6187c36de250 Add a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
574 // out for now.
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
575 if (manager->networkAccessible() != QNetworkAccessManager::Accessible)
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
576 {
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
577 slLog("ERROR", QStringLiteral("Network not available, cannot backup the database."));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
578 return;
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
579 }
154
ef4edd798a45 Disable network availability check for now, it seems to return false values in some cases.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
580 */
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
581
199
597a75429818 Stray whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
582 // Attempt to open the database file
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
583 QFile *file = new QFile(dbFilename);
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
584 if (!file->open(QIODevice::ReadOnly))
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
585 {
201
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
586 slLog("ERROR",
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
587 QStringLiteral("Failed to open database file '%1' for backup.").
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
588 arg(dbFilename));
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
589 return;
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
590 }
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
591
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
592 // Okay, we seem to be "go" ..
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
593 slLog("INFO",
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
594 QStringLiteral("Attempting database backup from '%1' to '%2'.").
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
595 arg(dbFilename).arg(settings.dbBackupURL));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
596
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
597 // Create the HTTP POST request
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
598 QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
599
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
600 // The "secret" key as POST parameter
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
601 QHttpPart postPart;
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
602 postPart.setHeader(QNetworkRequest::ContentDispositionHeader,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
603 QVariant("form-data; name=\"secret\";"));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
604 postPart.setBody(QByteArray(settings.dbBackupSecret.toUtf8()));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
605
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
606 // Actual data as binary octet-stream
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
607 QHttpPart dataPart;
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
608 dataPart.setHeader(QNetworkRequest::ContentTypeHeader,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
609 QVariant("binary/octet-stream"));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
610
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
611 dataPart.setHeader(QNetworkRequest::ContentDispositionHeader,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
612 QVariant("form-data; name=\"file\"; filename=\""+ backupFilename +"\""));
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
613
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
614 dataPart.setBodyDevice(file);
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
615 file->setParent(multiPart); // we cannot delete the QFile object now, so delete it with the multiPart
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
616
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
617 multiPart->append(postPart);
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
618 multiPart->append(dataPart);
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
619
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
620 // Attempt to POST the whole thing
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
621 QUrl url(settings.dbBackupURL);
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
622 QNetworkRequest request(url);
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
623 httpBackupReply = manager->post(request, multiPart);
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
624 multiPart->setParent(httpBackupReply);
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
625
153
794a2387e92a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
626 // Connect signals
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
627 connect(
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
628 httpBackupReply,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
629 SIGNAL(finished()),
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
630 this,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
631 SLOT(httpBackupFinished()));
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
632
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
633 connect(
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
634 httpBackupReply,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
635 SIGNAL(uploadProgress(qint64, qint64)),
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
636 this,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
637 SLOT(httpBackupProgress(qint64, qint64)));
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
638
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
639 connect(
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
640 httpBackupReply,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
641 SIGNAL(error(QNetworkReply::NetworkError)),
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
642 this,
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
643 SLOT(httpBackupError(QNetworkReply::NetworkError)));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
644 #else
153
794a2387e92a Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
645 // Disabled
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
646 slLog("ERROR", QStringLiteral("Backup method is HTTP/HTTPS, but support is not compiled in!"));
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
647 return;
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
648 #endif
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
649 }
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
650 else
151
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
651 {
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
652 slLog("ERROR", QStringLiteral("Database backup mode is INVALID! Not performing backup!"));
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
653 return;
753ae3569cb7 Actually save the backup mode setting to configuration, and add some error checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
654 }
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
655
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
656 // Create progress dialog
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
657 backupDialog = new QProgressDialog(
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
658 tr("Varmuuskopioidaan tietokantaa ..."),
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
659 QString(),
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
660 0,
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
661 100,
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
662 this);
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
663
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
664 backupDialog->setAttribute(Qt::WA_DeleteOnClose);
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
665 backupDialog->setAutoClose(false);
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
666 backupDialog->setWindowModality(Qt::ApplicationModal);
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
667 backupDialog->exec();
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
668 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
669
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
670
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
671 #ifdef USE_QTHTTP
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
672 void SyntilistaMainWindow::httpBackupProgress(qint64 bytesSent, qint64 bytesTotal)
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
673 {
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
674 if (bytesTotal > 0)
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
675 {
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
676 slLog("INFO",
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
677 QStringLiteral("Backup sent %1 / %2 bytes.").
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
678 arg(bytesSent).
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
679 arg(bytesTotal));
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
680
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
681 backupDialog->setValue((bytesSent * 100) / bytesTotal);
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
682 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
683 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
684
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
685
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
686 void SyntilistaMainWindow::httpBackupError(QNetworkReply::NetworkError code)
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
687 {
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
688 slLog("ERROR",
147
c722cb0b6662 Remove useless linefeed in an error log message.
Matti Hamalainen <ccr@tnsp.org>
parents: 145
diff changeset
689 QStringLiteral("Backup failed with network error %1.").
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
690 arg(code)
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
691 );
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
692 }
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
693
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
694
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
695 void SyntilistaMainWindow::httpBackupFinished()
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
696 {
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
697 if (httpBackupReply)
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
698 {
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
699 QVariant status = httpBackupReply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
700 if (status.isValid())
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
701 {
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
702 int code = status.toInt();
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
703 switch (code)
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
704 {
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
705 case 200:
190
76afbf6508c8 Add check for last successful database backup, and show a warning dialog at
Matti Hamalainen <ccr@tnsp.org>
parents: 187
diff changeset
706 backupSuccess();
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
707 break;
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
708
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
709 case 403:
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
710 slLog("ERROR",
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
711 QStringLiteral("Backup server authentication failed. Wrong secret or other invalid settings."));
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
712 break;
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
713
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
714 default:
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
715 slLog("ERROR",
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
716 QStringLiteral("Backup server responded with error:\n")+
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
717 QString::fromUtf8(httpBackupReply->readAll()));
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
718 break;
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
719 }
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
720 }
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
721 }
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
722 else
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
723 {
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
724 slLog("WARNING",
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
725 QStringLiteral("Backup finished prematurely (failed)."));
144
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
726 }
75a4faa219a9 Improve backup process error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
727
142
36c9cb759326 Implement simple SQLite database backup at program exit using Qt HTTP/HTTPS
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
728 backupDialog->close();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 }
150
2a8c97753381 Make the backup stuff compile-time optional.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
730 #endif
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
733 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
734 // Helper function for showing messages in the statusbar/line
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
735 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 void SyntilistaMainWindow::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
737 {
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
738 slLog("STATUS", msg);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 ui->statusbar->showMessage(msg);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
743 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
744 // Window scale / zoom changing
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
745 //
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
746 void SyntilistaMainWindow::changeUIZoomIn()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
747 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
748 settings.uiScale += 0.1f;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
749 slSetCommonStyleSheet(this);
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
750 }
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
751
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
752
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
753 void SyntilistaMainWindow::changeUIZoomOut()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
754 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
755 settings.uiScale -= 0.1f;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
756 slSetCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
759
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
760 void SyntilistaMainWindow::changeUIZoomReset()
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
761 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
762 settings.uiScale = 1.0f;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
763 slSetCommonStyleSheet(this);
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
764 }
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
765
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
766
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
767 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
768 // Slot for changed selection of person entry
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
769 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 void SyntilistaMainWindow::selectedPersonChanged(const QModelIndex &curr, const QModelIndex &prev)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 (void) prev;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 setActivePerson(model->data(model->index(row, 0)).toInt());
89
8ec1eb6b00b6 Automatically set focus to debt value edit field after selecting a person.
Matti Hamalainen <ccr@tnsp.org>
parents: 84
diff changeset
778 focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 setActivePerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
784
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
785 //
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
786 // Set currently active person to given SQL id
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
787 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 void SyntilistaMainWindow::setActivePerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
790 currPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791
1
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
792 ui->button_EditPerson->setEnabled(id >= 0);
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
793
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
796 if (!slGetPersonInfo(id, currPerson))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
798 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(id));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 ui->personGB->setEnabled(true);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
803 ui->label_PersonName->setText(currPerson.lastName +", "+ currPerson.firstName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
804
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
805 ui->label_BalanceValue->setText(slMoneyValueToStr(currPerson.balance));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
806 ui->label_BalanceValue->setStyleSheet(currPerson.balance < 0 ? "color: red;" : "color: green;");
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
807 ui->button_PayFullDebt->setEnabled(currPerson.balance < 0);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 QSqlQuery query;
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
810 query.prepare(QStringLiteral("SELECT id,value,added FROM transactions WHERE person=? ORDER BY added DESC LIMIT 5"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 query.addBindValue(id);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
813 slCheckAndReportSQLError("SELECT transactions for tableview_Latest", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 model_Latest->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
817 model_Latest->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
818 model_Latest->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
819 model_Latest->setHeaderData(2, Qt::Horizontal, tr("Aika"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822 ui->tableview_Latest->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
823 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
825
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
826 slSetCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832 ui->personGB->setEnabled(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833 ui->edit_Amount->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
834 ui->label_BalanceValue->setText("--");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 ui->label_BalanceValue->setStyleSheet(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 ui->label_PersonName->setText("???");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 ui->tableview_Latest->setModel(NULL);
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
838 slSetCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
843 // Slot for changing person list sort order
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
845 void SyntilistaMainWindow::updateSortOrder(int index, Qt::SortOrder order)
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
846 {
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
847 peopleSortIndex = index;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
848 peopleSortOrder = order;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
849 updatePersonList();
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
850 }
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
851
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
852
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 void SyntilistaMainWindow::on_button_Quit_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858
60
d7a2a48ebe24 Add a separate "About" button, don't use the logo as one. Change logo widget
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
859 void SyntilistaMainWindow::on_button_About_clicked()
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
860 {
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
861 new AboutWindow(this);
74
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
862 }
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
863
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
864
218
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
865 void SyntilistaMainWindow::on_button_ViewTransactions_clicked()
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
866 {
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
867 new ViewTransactions(this);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
868 }
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
869
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
870
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
871 void SyntilistaMainWindow::on_button_DeletePerson_clicked()
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
872 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
873 if (currPerson.id <= 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
874 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
875 statusMsg(tr("Ei valittua henkilöä!"));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
876 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
877 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
878
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
879 // Internal sanity check
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
880 SLPersonInfo info;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
881 if (!slGetPersonInfo(currPerson.id, info))
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
882 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
883 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(currPerson.id));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
884 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
885 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
886
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
887 // Ask for confirmation
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
888 QMessageBox dlg;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
889 slSetCommonStyleSheet(&dlg);
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
890 dlg.setText(tr("Varmistus"));
201
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
891 dlg.setInformativeText(tr(
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
892 "<h3>Haluatko varmasti poistaa henkilön:</h3>"
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
893 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
894 "<b>'%1, %2'</b> <i>(ID #%3)</i>?<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
895 "<br>"
186
cc3d7745e798 Cosmetic adjustments to the delete person confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 180
diff changeset
896 "<span style='color:#f00;'>Tämä poistaa sekä henkilön ja hänen koko tapahtumahistoriansa PYSYVÄSTI!</span>"
cc3d7745e798 Cosmetic adjustments to the delete person confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 180
diff changeset
897 "<br>").
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
898 arg(info.lastName).arg(info.firstName).arg(info.id));
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
899
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
900 dlg.setTextFormat(Qt::RichText);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
901 dlg.setIcon(QMessageBox::Question);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
902 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
71
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
903 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä"));
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
904 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta"));
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
905 dlg.setDefaultButton(QMessageBox::No);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
906
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
907 if (dlg.exec() == QMessageBox::Yes)
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
908 {
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
909 int rv = model_People->deletePerson(info.id);
14
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
910 updatePersonList();
24
0e0948aec438 De-select active person when deleting.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
911 setActivePerson(-1);
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
912 if (rv != 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
913 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
914 slErrorMsg(tr("SQL-tietokantavirhe"),
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
915 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
916 arg(rv));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
917 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
918 else
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
919 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
920 statusMsg(tr("Henkilö '%1 %2' (ID #%3) poistettu.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
921 arg(info.firstName).arg(info.lastName).
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
922 arg(info.id));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
923 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
924 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
925 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
926
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
927
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 void SyntilistaMainWindow::on_button_AddPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930 EditPerson *person = new EditPerson(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 person->setPerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
932 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
935 void SyntilistaMainWindow::on_button_EditPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
936 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
937 if (currPerson.id >= 0)
1
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
938 {
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
939 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
940 person->setPerson(currPerson.id);
1
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
941 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
942 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
943
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
945 void SyntilistaMainWindow::on_tableview_People_doubleClicked(const QModelIndex &curr)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
946 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
947 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
951 setActivePerson(model->data(model->index(row, 0)).toInt());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
952
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
953 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
954 person->setPerson(currPerson.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
956 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 setActivePerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
958 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
959
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
960
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
961 void SyntilistaMainWindow::on_button_ClearFilter_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
962 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
963 ui->edit_PersonFilter->clear();
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
964 ui->edit_PersonFilter->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
965 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
966
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
967
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
968 void SyntilistaMainWindow::focusDebtEdit()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
969 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
970 if (currPerson.id >= 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
971 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
972 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
973
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
974
211
6585cac42b75 Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
975 void SyntilistaMainWindow::changeSelectedRow(const int delta)
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
976 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
977 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
209
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
978 int prow = sel->currentIndex().row();
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
979 int nrow = prow + delta;
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
980 if (nrow < 0)
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
981 nrow = 0;
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
982 else
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
983 if (nrow >= model_People->rowCount())
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
984 nrow = model_People->rowCount() - 1;
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
985
209
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
986 if (nrow != prow)
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
987 {
212
70317bb39f05 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 211
diff changeset
988 // If row changed, set current index
209
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
989 sel->setCurrentIndex(model_People->index(nrow, 0),
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
990 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
210
02aae61e807e Scroll along with the currently selected person in the person list,
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
991
212
70317bb39f05 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 211
diff changeset
992 // The column must be a visible one (not set "hidden", as the ID field is)
70317bb39f05 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 211
diff changeset
993 // thus we use column index of 1 here for the QModelIndex()
210
02aae61e807e Scroll along with the currently selected person in the person list,
Matti Hamalainen <ccr@tnsp.org>
parents: 209
diff changeset
994 ui->tableview_People->scrollTo(model_People->index(nrow, 1));
209
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
995 }
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
996 }
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
997
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
998
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
999 void SyntilistaMainWindow::selectRowPrev()
6f404158ce8c Get rid of tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 207
diff changeset
1000 {
211
6585cac42b75 Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1001 changeSelectedRow(-1);
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
1002 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
1003
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
1004
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
1005 void SyntilistaMainWindow::selectRowNext()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
1006 {
211
6585cac42b75 Rename selectRowDelta() to clearer void changeSelectedRow().
Matti Hamalainen <ccr@tnsp.org>
parents: 210
diff changeset
1007 changeSelectedRow(1);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1008 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1009
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1010
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1011 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1012 // Update visible person list/query based on the current
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1013 // filtering and sorting settings.
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1014 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1015 void SyntilistaMainWindow::updatePersonList()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1016 {
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1017 static const QString queryBase =
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1018 QStringLiteral("SELECT id,last_name,first_name,"
107
8ceaafde9b52 Use total() instead of sum() in the SQL queries for better accuracy.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1019 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance,"
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1020 "updated FROM people");
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
1021
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1022 QString queryOrderDir, queryOrderBy;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1023
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1024 // Sort order
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1025 if (peopleSortOrder == Qt::AscendingOrder)
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1026 queryOrderDir = QStringLiteral("ASC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027 else
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1028 queryOrderDir = QStringLiteral("DESC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1029
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1030 // Sort by which column
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1031 switch (peopleSortIndex)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1032 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1033 case 1:
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034 case 2:
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1035 queryOrderBy =
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1036 QStringLiteral(" ORDER BY last_name ") + queryOrderDir +
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1037 QStringLiteral(",first_name ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1038 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1039
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1040 case 3:
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1041 queryOrderBy =
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1042 QStringLiteral(" ORDER BY balance ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043 break;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1044
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1045 case 4:
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1046 queryOrderBy =
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1047 QStringLiteral(" ORDER BY updated ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1048 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1049
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1050 default:
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1051 queryOrderBy = "";
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1052 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1053
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1054 // Are we filtering or not?
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1055 QSqlQuery query;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1056 if (peopleFilter != "")
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1057 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1058 // Filter by name(s)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059 QString tmp = "%"+ peopleFilter +"%";
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1060 query.prepare(queryBase + QStringLiteral(" WHERE first_name LIKE ? OR last_name LIKE ?") + queryOrderBy);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1061
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1062 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1063 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1064 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1065 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1066 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1067 // No filter
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
1068 query.prepare(queryBase + queryOrderBy);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1069 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1070
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1071 // Execute the query and update model
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1072 slCheckAndReportSQLError("updatePersonList() before exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1073 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1074 slCheckAndReportSQLError("updatePersonList() after exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1075
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076 model_People->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1077
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1078 model_People->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1079 model_People->setHeaderData(1, Qt::Horizontal, tr("Sukunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1080 model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1081 model_People->setHeaderData(3, Qt::Horizontal, tr("Tase"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1082 model_People->setHeaderData(4, Qt::Horizontal, tr("Muutettu"));
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1083
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1084 updateMiscValues();
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1085 }
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1086
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1087
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1088 //
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1089 // Update some values in the UI
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1090 //
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1091 void SyntilistaMainWindow::updateMiscValues()
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1092 {
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1093 // Update total balance value
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1094 QSqlQuery query;
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1095 query.prepare(QStringLiteral("SELECT TOTAL(value) FROM transactions AS balance"));
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1096 query.exec();
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1097 if (slCheckAndReportSQLError("updateMiscValues() get total balance query", query.lastError()) &&
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1098 query.next())
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1099 {
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1100 totalBalance = query.value(0).toDouble();;
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1101 ui->label_TotalBalanceValue->setText(slMoneyValueToStr(totalBalance));
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1102 ui->label_TotalBalanceValue->setStyleSheet(totalBalance < 0 ? "color: red;" : "color: green;");
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1103 }
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1104
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1105 // Update number of people
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1106 query.finish();
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1107 query.prepare(QStringLiteral("SELECT COUNT(*) FROM people"));
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1108 query.exec();
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1109 if (slCheckAndReportSQLError("updateMiscValues() get people count", query.lastError()) &&
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1110 query.next())
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1111 {
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1112 totalPeople = query.value(0).toInt();
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1113 ui->label_NumPeopleValue->setText(query.value(0).toString());
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1114 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1115 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1116
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1117
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1118 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1119 // Update the list of people when filter parameter changes
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1120 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1121 void SyntilistaMainWindow::on_edit_PersonFilter_textChanged(const QString &str)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1122 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1123 peopleFilter = slCleanupStr(str);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1124 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1125 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1126
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1127
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1128 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1129 // Add one transaction to given person id
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1130 //
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1131 int SyntilistaMainWindow::addTransaction(qint64 id, double value, SLPersonInfo &info)
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1132 {
179
a2f11e6665d6 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
1133 // Sanity check: Check if the given person ID exists
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
1134 if (!slGetPersonInfo(id, info))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1135 return -1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1136
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1137 QSqlDatabase::database().transaction();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1138
179
a2f11e6665d6 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
1139 // Add transaction entry
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1140 QSqlQuery query;
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1141 query.prepare(QStringLiteral("INSERT INTO transactions (person,value,added) VALUES (?,?,?)"));
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1142 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1143 query.addBindValue(value);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1144 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1145 query.exec();
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1146 if (!slCheckAndReportSQLError(QStringLiteral("addTransaction(%1, %2)").arg(id).arg(value), query.lastError(), true))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1147 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1148 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1149 return -2;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1150 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1151
179
a2f11e6665d6 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 178
diff changeset
1152 // Update person record timestamp
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1153 query.prepare(QStringLiteral("UPDATE people SET updated=? WHERE id=?"));
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1154 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1155 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1156 query.exec();
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1157 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError(), true))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1158 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1159 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1160 return -3;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1161 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1162
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1163 QSqlDatabase::database().commit();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1164
145
9f3c0a99bcb1 Add display for total number of people on the database.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
1165 updateMiscValues();
130
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1166
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1167 return 0;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1168 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1169
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1170
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1171 int SyntilistaMainWindow::addTransactionGUI(qint64 id, bool debt, double value)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1172 {
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1173 SLPersonInfo info;
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1174
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1175 // Check if person is selected
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1176 if (id <= 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1177 return -1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1178
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1179 // Check value
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1180 if (value == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1181 {
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1182 QString tmp = debt ? tr("lisätty") : tr("vähennetty");
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1183 statusMsg(tr("Velkaa ei %1 koska summaa ei määritetty.").arg(tmp));
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1184 return 1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1185 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1186
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1187 // Perform transaction insert
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1188 int ret = addTransaction(id, debt ? -value : value, info);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1189 if (ret == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1190 {
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1191 // All ok, clear amount entry and update person data
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1192 ui->edit_Amount->clear();
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1193 if (info.id == currPerson.id)
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1194 setActivePerson(info.id);
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1195
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1196 model_People->updateModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1197
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1198 if (debt)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1199 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1200 // Debt was added
216
8b9d55fb8988 Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 213
diff changeset
1201 statusMsg(
8b9d55fb8988 Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 213
diff changeset
1202 tr("Lisättiin velkaa %1 EUR henkilölle '%2 %3' (#%4).").
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1203 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1204 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1205 arg(info.lastName).
216
8b9d55fb8988 Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 213
diff changeset
1206 arg(info.id));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1207 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1208 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1209 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1210 // Debt was reduced
216
8b9d55fb8988 Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 213
diff changeset
1211 statusMsg(
8b9d55fb8988 Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 213
diff changeset
1212 tr("Vähennettiin velkaa %1 EUR henkilöltä '%2 %3' (#%4).").
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1213 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1214 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1215 arg(info.lastName).
216
8b9d55fb8988 Remove one temporary variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 213
diff changeset
1216 arg(info.id));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1217 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1218 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1219 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1220 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1221 slErrorMsg(
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1222 tr("SQL-tietokantavirhe"),
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1223 tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1224 arg(ret));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1225 }
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1226
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1227 return ret;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1228 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1229
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1230
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1231 void SyntilistaMainWindow::on_button_AddDebt_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1232 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1233 addTransactionGUI(currPerson.id, true, slMoneyStrToValue(ui->edit_Amount->text()));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1234 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1235
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1236
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1237 void SyntilistaMainWindow::on_button_PayDebt_clicked()
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1238 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1239 addTransactionGUI(currPerson.id, false, slMoneyStrToValue(ui->edit_Amount->text()));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1240 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1241
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1242
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1243 void SyntilistaMainWindow::on_button_PayFullDebt_clicked()
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1244 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1245 // Sanity check that there is a selected person
187
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1246 if (currPerson.id <= 0)
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1247 {
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1248 statusMsg(tr("Ei valittua henkilöä!"));
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1249 return;
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1250 }
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1251
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1252 // Check the balance ..
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1253 if (currPerson.balance < 0)
187
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1254 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1255 // And ask confirmation that user really wants to clear the full debt
187
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1256 QMessageBox dlg;
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1257 slSetCommonStyleSheet(&dlg);
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1258 dlg.setText(tr("Varmistus"));
201
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
1259 dlg.setInformativeText(tr(
ea0247fab5a4 Cosmetics/indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 200
diff changeset
1260 "<h3>Haluatko maksaa henkilön koko velan?</h3>"
187
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1261 "<br>"
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1262 "<b>'%1, %2'</b>, velka <span style='color:#f00;'><b>%4 EUR</b></span>"
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1263 "<br>").
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1264 arg(currPerson.lastName).arg(currPerson.firstName).
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1265 arg(slMoneyValueToStr(currPerson.balance)));
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1266
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1267 dlg.setTextFormat(Qt::RichText);
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1268 dlg.setIcon(QMessageBox::Question);
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1269 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1270 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä"));
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1271 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta"));
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1272 dlg.setDefaultButton(QMessageBox::No);
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1273
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1274 if (dlg.exec() == QMessageBox::Yes)
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1275 {
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1276 addTransactionGUI(currPerson.id, false, -currPerson.balance);
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1277 }
7f0a4d5010d1 Add confirmation dialog to "pay full debt".
Matti Hamalainen <ccr@tnsp.org>
parents: 186
diff changeset
1278 }
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1279 else
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1280 {
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1281 statusMsg(
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1282 tr("Valitulla henkilöllä '%1, %2' ei ole velkaa.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1283 arg(currPerson.lastName).
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1284 arg(currPerson.firstName));
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1285 }
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1286 }
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1287
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1288
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1289 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1290 // Edit person dialog
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1291 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1292 EditPerson::EditPerson(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1293 QDialog(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1294 ui(new Ui::EditPerson)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1295 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1296 ui->setupUi(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1297
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
1298 slSetCommonStyleSheet(this);
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
1299
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1300 setModal(true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1301 setAttribute(Qt::WA_DeleteOnClose);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1302 show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1303 activateWindow();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1304 raise();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1305 setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1306
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1307 model_Transactions = new SLTransactionSQLModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1308 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1309 ui->tableview_Transactions->setItemDelegate(new QSqlRelationalDelegate(ui->tableview_Transactions));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1310 ui->tableview_Transactions->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1311 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1312
123
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
1313 ui->edit_FirstName->setMaxLength(SQL_LEN_FIRST_NAME);
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
1314 ui->edit_LastName->setMaxLength(SQL_LEN_LAST_NAME);
113
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
1315
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1316 connect(
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1317 ui->textedit_ExtraInfo,
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1318 SIGNAL(textChanged()),
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1319 this,
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1320 SLOT(on_textedit_ExtraInfo_textChanged()));
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1321
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1322 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1323 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1324
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1325
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1326 EditPerson::~EditPerson()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1327 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1328 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1329 delete model_Transactions;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1330 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1331
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1332
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1333 void EditPerson::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1334 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1335 // Pass the status message to main window
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1336 dynamic_cast<SyntilistaMainWindow *>(parent())->statusMsg(msg);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1337 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1338
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1339
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1340 bool EditPerson::validateForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1341 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1342 selPerson.firstName = slCleanupStr(ui->edit_FirstName->text());
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1343 selPerson.lastName = slCleanupStr(ui->edit_LastName->text());
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1344 selPerson.extraInfo = ui->textedit_ExtraInfo->document()->toPlainText();
123
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
1345 bool extraInfoValid = selPerson.extraInfo.length() < SQL_LEN_EXTRA_INFO;
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1346
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1347 ui->textedit_ExtraInfo->setStyleSheet(!extraInfoValid ? "background-color: red;" : NULL);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1348 ui->edit_FirstName->setStyleSheet(selPerson.firstName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1349 ui->edit_LastName->setStyleSheet(selPerson.lastName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1350
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1351 return selPerson.firstName != "" && selPerson.lastName != "" && extraInfoValid;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1352 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1353
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1354
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1355 void EditPerson::on_button_Cancel_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1356 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1357 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1358 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1359
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1360
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1361 void EditPerson::on_button_OK_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1362 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1363 //
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1364 // Check form validation
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1365 //
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1366 if (!validateForm())
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1367 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1368 slErrorMsg(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1369 tr("Virhe!"),
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1370 tr("Vaaditut kentät (etunimi, sukunimi) eivät ole täytetty tai lisätietojen pituus on liian suuri."));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1371
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1372 return;
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1373 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1374
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1375 if (selPerson.id >= 0)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1376 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1377 //
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1378 // We are in update/edit person mode, thus we check if the
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1379 // first/last name have changed and if there is someone with
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1380 // different ID and same names.
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1381 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1382 QSqlQuery person;
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1383 person.prepare(QStringLiteral("SELECT * FROM people WHERE id <> ? AND first_name=? AND last_name=?"));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1384 person.addBindValue(selPerson.id);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1385 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1386 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1387 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1388
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1389 slCheckAndReportSQLError("SELECT check for existing person by same name (UPDATE)", person.lastError());
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1390
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1391 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1392 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1393 // There exists another person with that name
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1394 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1395 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1396 tr("Ei pysty! Samalla nimellä '%1 %2' on olemassa jo henkilö!").
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1397 arg(selPerson.firstName).arg(selPerson.lastName));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1398 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1399 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1400
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1401 // Allest klar, update the person data
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1402 dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->updatePerson(selPerson);
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1403 dynamic_cast<SyntilistaMainWindow *>(parent())->setActivePerson(selPerson.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1404
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1405 statusMsg(tr("Päivitettiin henkilö '%1 %2' (#%3).").
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1406 arg(selPerson.firstName).arg(selPerson.lastName).arg(selPerson.id));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1407 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1408 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1409 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1410 //
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1411 // We are in "add new person" mode, check if there exists
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1412 // someone with same first+last name.
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1413 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1414 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1415 person.prepare("SELECT * FROM people WHERE first_name=? AND last_name=?");
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1416 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1417 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1418 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1419
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1420 slCheckAndReportSQLError("SELECT check for existing person by same name (ADD)", person.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1421
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1422 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1423 {
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1424 // There exists a record with same name
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1425 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1426 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1427 tr("Ei pysty! Samalla nimellä '%1 %2' on olemassa jo henkilö!").
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1428 arg(selPerson.firstName).arg(selPerson.lastName));
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1429
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1430 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1431 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1432
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1433 // Attempt to add a person
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1434 qint64 nid = dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->addPerson(selPerson);
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1435 if (nid < 0)
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1436 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1437 slErrorMsg(
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1438 tr("Virhe!"),
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1439 tr("Tietokannan käsittelyssä tapahtui virhe (#%1).").
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1440 arg(nid));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1441 }
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1442 else
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1443 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1444 dynamic_cast<SyntilistaMainWindow *>(parent())->updatePersonList();
111
ec01c5b0eaa8 Set focus to newly added person record after adding.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
1445 dynamic_cast<SyntilistaMainWindow *>(parent())->setActivePerson(nid);
ec01c5b0eaa8 Set focus to newly added person record after adding.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
1446 dynamic_cast<SyntilistaMainWindow *>(parent())->focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1447
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1448 statusMsg(tr("Lisättiin uusi henkilö '%1 %2'.").
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1449 arg(selPerson.firstName).arg(selPerson.lastName));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1450 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1451 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1452
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1453 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1454 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1455
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1456
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1457 void EditPerson::on_edit_FirstName_textChanged(const QString &arg1)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1458 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1459 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1460 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1461 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1462
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1463
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1464 void EditPerson::on_edit_LastName_textChanged(const QString &arg1)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1465 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1466 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1467 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1468 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1469
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1470
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1471 void EditPerson::on_textedit_ExtraInfo_textChanged()
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1472 {
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1473 validateForm();
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1474 }
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1475
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1476
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1477 void EditPerson::clearForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1478 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1479 ui->edit_FirstName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1480 ui->edit_LastName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1481 ui->textedit_ExtraInfo->document()->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1482 ui->edit_FirstName->setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1483 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1484
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1485
196
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1486 //
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1487 // Set the person to be edited
416868143486 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1488 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1489 void EditPerson::setPerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1490 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1491 selPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1492
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1493 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1494 {
174
636a24c76232 Rename some classes to add a SL prefix to their names.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
1495 SLPersonInfo pinfo;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
1496 if (!slGetPersonInfo(id, pinfo))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1497 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1498 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(id));
104
1997cc07a7ae Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
1499 // Intentional fall-through below
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1500 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1501 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1502 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1503 ui->edit_FirstName->setText(pinfo.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1504 ui->edit_LastName->setText(pinfo.lastName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1505 ui->textedit_ExtraInfo->document()->setPlainText(pinfo.extraInfo);
180
ee5479079238 Display the 'added to database' timestamp in the edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 179
diff changeset
1506 ui->label_AddedValue->setText(slDateTimeToStr(pinfo.added));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1507
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1508 QSqlQuery query;
202
4e25db3327a7 Use QStringLiteral() some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 201
diff changeset
1509 query.prepare(QStringLiteral("SELECT id,value,added FROM transactions WHERE person=? ORDER BY added DESC"));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1510 query.addBindValue(pinfo.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1511 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1512 slCheckAndReportSQLError("SELECT transactions for tableview_Transactions", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1513
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1514 model_Transactions->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1515
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1516 model_Transactions->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1517 model_Transactions->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1518 model_Transactions->setHeaderData(2, Qt::Horizontal, tr("Aika"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1519
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1520 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1521 ui->tableview_Transactions->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1522
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1523 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1524 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1525 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1526
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1527 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1528 clearForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1529 ui->tableview_Transactions->setModel(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1530 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1531
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1532
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1533 //
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1534 // About window
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1535 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1536 AboutWindow::AboutWindow(QWidget *parent) :
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1537 QDialog(parent),
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1538 ui(new Ui::AboutWindow)
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1539 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1540 ui->setupUi(this);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1541
203
5c3e3967bdf3 Use Qt resource aliases.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
1542 ui->label_Logo->setPixmap(QPixmap(QStringLiteral(":/icon")));
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1543 ui->label_Logo->setAlignment(Qt::AlignCenter);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1544
197
f7da0c030262 Show AppDataPath as a link in the about window.
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
1545 ui->label_About->setOpenExternalLinks(true);
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1546 ui->label_About->setWordWrap(true);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1547 ui->label_About->setTextFormat(Qt::RichText);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1548 ui->label_About->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1549 "<h1>%1 v%2</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1550 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1551 "<b>Ohjelmoinut ja kehittänyt Matti Hämäläinen &lt;ccr@tnsp.org&gt;<br>"
217
58af72da7f60 Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 216
diff changeset
1552 "(C) Copyright 2017-2018 Tecnic Software productions (TNSP)</b>"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1553 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1554 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1555 "Kehitetty Raahen kaupungin Hanketoiminta ja Kehittäminen -yksikön "
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1556 "alaisuudessa Café Kampuksen käyttöön."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1557 "</p>"
197
f7da0c030262 Show AppDataPath as a link in the about window.
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
1558 "<p>AppDataPath: <a href=\"file:///%3\">%3</a></p>"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1559 ).
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1560 arg(tr(APP_NAME)).
137
1a480e947598 Show application data path in the about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
1561 arg(APP_VERSION).
138
5e6bcabfa380 Oops, old datapath variable used. Fix it.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
1562 arg(settings.dataPath)
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1563 );
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1564
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1565 ui->label_ShortCuts->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1566 "<h1>Pikanäppäimet</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1567 "<table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1568 "<tr><td><b>F1</b></td><td>Tämä tietoikkuna</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1569 "<tr><td><b>CTRL + Q</b></td><td>Ohjelman lopetus</td></tr>"
226
c0dfbbd67692 Add information about two keyboard shortcuts to the help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
1570 "<tr><td><b>CTRL + P</b></td><td>Henkilölistan tulostus/esikatselu</td></tr>"
c0dfbbd67692 Add information about two keyboard shortcuts to the help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
1571 "<tr><td><b>CTRL + T</b></td><td>Tapahtumalistaikkuna</td></tr>"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1572 "<tr><td><b>CTRL + Page Up</b></td><td>Suurenna ohjelman tekstejä/käyttöliittymää</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1573 "<tr><td><b>CTRL + Page Down</b></td><td>Pienennä ohjelman tekstejä/käyttöliittymää</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1574 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1575 "<tr><td><b>Esc</b></td><td>Tyhjennä 'Etsi / suodata' kenttä ja siirry siihen</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1576 "<tr><td><b>CTRL + Enter</b></td><td>Siirry summan syöttökenttään</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1577 "<tr><td><b>Page Up</b></td><td>Siirry ylös henkilölistassa</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1578 "<tr><td><b>Page Down</b></td><td>Siirry alas henkilölistassa</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1579 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1580 "<tr><td><b>F5</b></td><td>Lisää uusi henkilö</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1581 "<tr><td><b>F6</b></td><td>Muokkaa henkilöä</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1582 "<tr><td><b>F8</b></td><td>Poista henkilö</td></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1583 "</table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1584 ));
95
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1585
231
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1586 QFile fh(":/license");
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1587 if (fh.open(QIODevice::ReadOnly | QIODevice::Text))
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1588 {
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1589 QString text = "";
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1590 while (!fh.atEnd())
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1591 text += fh.readLine();
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1592
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1593 ui->text_License->setHtml(text);
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1594 fh.close();
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1595 }
e90dba0cd12a Implement HTML stuff for about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
1596
232
07d837442c55 Open the links in about dialog via external web browser.
Matti Hamalainen <ccr@tnsp.org>
parents: 231
diff changeset
1597 ui->text_License->setOpenExternalLinks(true);
95
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1598 setModal(true);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1599 setAttribute(Qt::WA_DeleteOnClose);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1600 show();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1601 activateWindow();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1602 raise();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1603 setFocus();
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1604 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1605
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1606
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1607 AboutWindow::~AboutWindow()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1608 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1609 delete ui;
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1610 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1611
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1612
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1613 void AboutWindow::on_button_Close_clicked()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1614 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1615 close();
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1616 }
218
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1617
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1618
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1619 //
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1620 // Global transactions list viewer
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1621 //
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1622 ViewTransactions::ViewTransactions(QWidget *parent) :
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1623 QDialog(parent),
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1624 ui(new Ui::ViewTransactions)
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1625 {
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1626 ui->setupUi(this);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1627
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1628 slSetCommonStyleSheet(this);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1629
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1630 setModal(true);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1631 setAttribute(Qt::WA_DeleteOnClose);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1632 show();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1633 activateWindow();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1634 raise();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1635 setFocus();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1636
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1637 model_Transactions = new SLTransactionSQLModel();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1638 ui->tableview_Transactions->setModel(model_Transactions);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1639 ui->tableview_Transactions->setItemDelegate(new QSqlRelationalDelegate(ui->tableview_Transactions));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1640 ui->tableview_Transactions->verticalHeader()->setVisible(false);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1641 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1642
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1643 QSqlQuery query;
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1644 query.prepare(QStringLiteral(
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1645 "SELECT transactions.id,transactions.value,transactions.added,"
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1646 "people.last_name,people.first_name FROM transactions "
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1647 "LEFT JOIN people ON transactions.person=people.id ORDER BY transactions.added DESC"
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1648 ));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1649
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1650 query.exec();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1651 slCheckAndReportSQLError("SELECT transactions for tableview_Transactions", query.lastError());
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1652
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1653 model_Transactions->setQuery(query);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1654
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1655 model_Transactions->setHeaderData(0, Qt::Horizontal, tr("ID"));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1656 model_Transactions->setHeaderData(1, Qt::Horizontal, tr("Summa"));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1657 model_Transactions->setHeaderData(2, Qt::Horizontal, tr("Aika"));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1658 model_Transactions->setHeaderData(3, Qt::Horizontal, tr("Sukunimi"));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1659 model_Transactions->setHeaderData(4, Qt::Horizontal, tr("Etunimi"));
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1660
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1661 ui->tableview_Transactions->setModel(model_Transactions);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1662 ui->tableview_Transactions->setColumnHidden(0, true);
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1663 }
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1664
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1665
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1666 ViewTransactions::~ViewTransactions()
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1667 {
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1668 delete ui;
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1669 delete model_Transactions;
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1670 }
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1671
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1672
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1673 void ViewTransactions::on_button_Close_clicked()
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1674 {
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1675 close();
c3f47d489097 Implement global transactions viewer dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 217
diff changeset
1676 }