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