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