annotate src/main.cpp @ 138:5e6bcabfa380

Oops, old datapath variable used. Fix it.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Aug 2017 11:39:34 +0300
parents 1a480e947598
children d5d1549e47fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 // Syntilista - velkalistasovellus Kampus-kahvilaan
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
893f69fcf050 Add license.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
6 // Distributed under 3-clause BSD style license, refer to
893f69fcf050 Add license.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
7 // included file "COPYING" for exact terms.
893f69fcf050 Add license.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
8 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <QApplication>
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <QMessageBox>
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <QSettings>
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
12 #include <QPrintDialog>
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
13 #include <QPrintPreviewDialog>
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
14 #include <QProgressDialog>
129
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
15 #include <QStandardPaths>
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #include "main.h"
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #include "ui_mainwindow.h"
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #include "ui_editperson.h"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
19 #include "ui_aboutwindow.h"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
20
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
22 //
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
23 // Application settings struct
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
24 //
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
25 struct
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
26 {
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
27 double uiScale; // Global UI scale factor
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
28 QString dataPath; // Application data path/directory
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
29 } settings;
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
30
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
31
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
33 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
34 // Convert QString to a double value, replacing comma
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
35 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
36 double slMoneyStrToValue(const QString &str)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 QString str2 = str;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 return str2.replace(",", ".").toDouble();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
43 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
44 // Convert double value to formatted QString
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
45 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
46 QString slMoneyValueToStr(double val)
0
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 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
49 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
52 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
53 // Trim and cleanup given QString (removing double whitespace etc.)
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
54 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
55 QString slCleanupStr(const QString &str)
0
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 return str.simplified().trimmed();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
61 //
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
62 // Manipulate given QDateTime value to get desired
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
63 // correct timestamp.
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
64 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
65 const QDateTime slDateTimeToLocal(const QDateTime &val)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 QDateTime tmp = val;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 tmp.setOffsetFromUtc(0);
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
69 return tmp.toLocalTime();
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
70 }
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
71
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
72
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
73 //
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
74 // Return a string representation of given QDateTime
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
75 // converted to local time.
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
76 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
77 const QString slDateTimeToStr(const QDateTime &val)
84
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 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
80 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
83 //
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
84 // Error logging
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
85 //
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
86 void slLog(const QString &mtype, const QString &msg)
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
87 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
88 QString filename = settings.dataPath + QDir::separator() + APP_LOG_FILE;
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
89 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
90 if (fh.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
91 {
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
92 QTextStream out(&fh);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
93 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
94 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
95 toString(QStringLiteral("yyyy-MM-dd hh:mm:ss"))
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
96 << " [" << mtype << "]: " << msg << "\n";
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
97 fh.close();
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
98 }
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
99 }
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
100
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
101
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
102 //
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
103 // Display an error dialog with given title and message
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
104 //
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
105 int slErrorMsg(QString title, QString msg)
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
106 {
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
107 QMessageBox dlg;
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
108
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
109 slLog("ERROR", msg);
128
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
110
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
111 dlg.setText(title);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
112 dlg.setInformativeText(msg);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
113 dlg.setTextFormat(Qt::RichText);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
114 dlg.setIcon(QMessageBox::Critical);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
115 dlg.setStandardButtons(QMessageBox::Ok);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
116 dlg.setDefaultButton(QMessageBox::Ok);
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
117
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
118 return dlg.exec();
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
119 }
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
120
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
121
d77779789e76 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
122 //
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
123 // Check if an SQL error has occured (for given QSqlError) and
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
124 // report it to stdout if so. Return "false" if error has occured,
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
125 // true otherwise.
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
126 //
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
127 bool slCheckAndReportSQLError(const QString where, const QSqlError &err, bool report = false)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 if (err.isValid())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
131 slLog("ERROR",
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
132 QStringLiteral("SQL %1: %2").
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
133 arg(where).arg(err.text()));
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
134 return false;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 else
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
137 {
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
138 if (report)
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
139 {
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
140 slLog("NOTE",
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
141 QStringLiteral("SQL OK %1").arg(where));
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
142 }
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
143 return true;
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
144 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
148 void PersonInfo::dump()
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
149 {
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
150 printf(
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
151 "PersonInfo() #%lld '%s %s' (added=%s, updated=%s, balance %1.2f)\n#%s#\n",
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
152 id,
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
153 firstName.toUtf8().constData(),
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
154 lastName.toUtf8().constData(),
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
155 slDateTimeToStr(added).toUtf8().constData(),
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
156 slDateTimeToStr(updated).toUtf8().constData(),
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
157 balance,
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
158 extraInfo.toUtf8().constData());
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
159 }
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
160
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
161
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
162 //
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
163 // Get PersonInfo record from SQL query object
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
164 //
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
165 void slGetPersonInfoRec(QSqlQuery &query, PersonInfo &info)
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
166 {
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
167 info.id = query.value(0).toInt();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
168 info.firstName = query.value(1).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
169 info.lastName = query.value(2).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
170 info.extraInfo = query.value(3).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
171 info.added = query.value(4).toDateTime();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
172 info.updated = query.value(5).toDateTime();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
173 info.balance = query.value(6).toDouble();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
174 }
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
175
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
176
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
177 //
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
178 // Get PersonInfo record from SQL database for specified person ID #
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
179 //
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
180 bool slGetPersonInfo(qint64 id, PersonInfo &info)
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
181 {
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
182 QSqlQuery query;
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
183 query.prepare(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
184 "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
185 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance "
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
186 "FROM people WHERE id=?");
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
187
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
188 query.addBindValue(id);
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
189 query.exec();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
190 if (!query.next())
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
191 return false;
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
192
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
193 slGetPersonInfoRec(query, info);
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
194 query.finish();
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
195 return true;
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
196 }
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
197
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
198
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
199 void slSetCommonStyleSheet(QWidget *widget)
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
200 {
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
201 // Clamp scale value
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
202 if (settings.uiScale < 0.5f)
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
203 settings.uiScale = 0.5f;
103
ce86ea4b08aa Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
204
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
205 if (settings.uiScale > 3.0f)
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
206 settings.uiScale = 3.0f;
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
207
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
208 // Set the stylesheet
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
209 widget->setStyleSheet(
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
210 QStringLiteral(
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
211 "* { font-size: %1pt; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
212 "QPushButton { font-size: %2pt; padding: 0.25em; }"
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
213 "#button_AddDebt[enabled='true'] { font-size: %3pt; background-color: #900; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
214 "#button_PayDebt[enabled='true'] { font-size: %3pt; background-color: #090; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
215 "#button_PayFullDebt[enabled='true'] { background-color: #060; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
216
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
217 "#button_AddDebt[enabled='false'] { font-size: %3pt; background-color: #622; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
218 "#button_PayDebt[enabled='false'] { font-size: %3pt; background-color: #262; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
219 "#button_PayFullDebt[enabled='false'] { background-color: #131; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
220
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
221 "#label_PersonName { font-size: %5pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
222 "#label_BalanceValue { font-size: %4pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
223 "#label_EUR { font-size: %4pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
224 "#edit_Amount { font-size: %4pt; margin: 0.5em; padding: 0.5em; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
225 ).
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
226 arg(12 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
227 arg(14 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
228 arg(16 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
229 arg(18 * settings.uiScale).
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
230 arg(20 * settings.uiScale)
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
231 );
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
232 }
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
233
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
234
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 int main(int argc, char *argv[])
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 QApplication sapp(argc, argv);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 //
129
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
240 // Create logfile and data directory
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
241 //
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
242 settings.dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
243 QDir path(settings.dataPath);
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
244 if (!path.exists(settings.dataPath))
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
245 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
246
f6685c2eb75d Store SQLite database and log file in application data directory instead of
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
247 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 // Initialize / open SQL database connection
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
251 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
252
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 if (!db.open())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
255 slErrorMsg(
9
1f442052d332 Oops, 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
256 QObject::tr("Tietokantaa ei voitu avata"),
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
257 QObject::tr("Yhteyttä SQL-tietokantaan ei saatu.<br><br>Virhe: %1<br><br>").
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
258 arg(db.lastError().text())
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 );
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
260 return 1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 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
264 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
265 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
266 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
267 "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
268 "first_name VARCHAR(%1) NOT NULL, "
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
269 "last_name VARCHAR(%2) NOT NULL, "
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
270 "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
271 "added DATETIME NOT NULL, "
113
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
272 "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
273 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
274 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
275 arg(SQL_LEN_EXTRA_INFO));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
277 slCheckAndReportSQLError("CREATE TABLE people", query.lastError(), true);
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
278 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
280 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
281 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
282 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
283 "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
284 "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
285 "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
286 "value REAL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
287 "added DATETIME NOT NULL)"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
289 slCheckAndReportSQLError("CREATE TABLE transactions", query.lastError(), true);
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
290 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
292 query.finish();
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
293
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 SyntilistaMainWindow swin;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 swin.show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 return sapp.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 // Main application window code
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 SyntilistaMainWindow::SyntilistaMainWindow(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 QMainWindow(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 ui(new Ui::SyntilistaMainWindow)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 {
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
307 // Setup UI
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 ui->setupUi(this);
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
309
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
310 // Read config
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
311 readSettings();
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
312
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
313 // Setup application icon and window title
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
314 setWindowIcon(QIcon(QPixmap(":/img/icon-64.png")));
64
73fd86778014 Version number display etc. changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
315 setWindowTitle(tr("%1 versio %3").
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
316 arg(tr(APP_NAME)).
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
317 arg(tr(APP_VERSION)));
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
318
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
319 // Setup large logo in the main window
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
320 QPixmap logoImage(":/img/logo.png");
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
321 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
322 ui->button_LogoImage->setAlignment(Qt::AlignCenter);
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
323
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
324 slSetCommonStyleSheet(this);
22
c23241a3e160 UI polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
325
68
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
326 // Validator for amount input
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
327 //ui->edit_Amount->setValidator(new QDoubleValidator(0, 1000, 2, this));
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
328 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
329 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
330
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
331 // Setup person list filtering and sorting
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 peopleSortIndex = 1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 peopleSortOrder = Qt::AscendingOrder;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334 peopleFilter = "";
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 model_People = new PersonSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 ui->tableview_People->setModel(model_People);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 ui->tableview_People->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 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
342 ui->tableview_People->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 ui->tableview_People->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 ui->tableview_People->setSortingEnabled(true);
25
a7e746642599 Fix initial sorting.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
345 ui->tableview_People->sortByColumn(peopleSortIndex, peopleSortOrder);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
347 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
348 ui->tableview_People->selectionModel(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
350 this,
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
351 SLOT(selectedPersonChanged(const QModelIndex &, const QModelIndex &)));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
353 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
354 ui->tableview_People->horizontalHeader(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 this,
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 SLOT(updateSortOrder(int, Qt::SortOrder)));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 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
360
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 model_Latest = new TransactionSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 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
364 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
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 setActivePerson(-1);
17
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
368
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
369 // Keyboard shortcuts
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
370 ui->button_Quit->setShortcut(QKeySequence(Qt::Key_F10));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
371 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(on_button_Quit_clicked()));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
372
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
373 ui->button_AddPerson->setShortcut(QKeySequence(Qt::Key_F5));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
374 ui->button_DeletePerson->setShortcut(QKeySequence(Qt::Key_F8));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
375 ui->button_EditPerson->setShortcut(QKeySequence(Qt::Key_F6));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
376 ui->button_ClearFilter->setShortcut(QKeySequence(Qt::Key_Escape));
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
377 ui->button_About->setShortcut(QKeySequence(Qt::Key_F1));
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
378
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
379 new QShortcut(QKeySequence(QKeySequence::ZoomIn), this, SLOT(changeUIZoomIn()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
380 new QShortcut(QKeySequence(QKeySequence::ZoomOut), this, SLOT(changeUIZoomOut()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
381 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
382 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
383 new QShortcut(QKeySequence(Qt::CTRL + Qt::KeypadModifier + Qt::Key_0), this, SLOT(changeUIZoomReset()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
384 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_0), this, SLOT(changeUIZoomReset()));
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
385
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
386 new QShortcut(QKeySequence(Qt::Key_PageUp), this, SLOT(selectRowPrev()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
387 new QShortcut(QKeySequence(Qt::Key_PageDown), this, SLOT(selectRowNext()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
388
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
389 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
390
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
391 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_P), this, SLOT(on_button_Print_clicked()));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
395 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
396 // Application main window destructor
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
397 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 SyntilistaMainWindow::~SyntilistaMainWindow()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 {
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
400 // Save current settings and free resources
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 saveSettings();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 delete model_People;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 delete model_Latest;
134
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
406
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
407 // Commit and close database
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
408 QSqlDatabase::database().commit();
478ce4c94f6b Commit and close() the database at exit, just in case.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
409 QSqlDatabase::database().close();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
413 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
414 // Helper function for showing messages in the statusbar/line
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
415 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 void SyntilistaMainWindow::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 {
133
df03ab8b6413 Improve logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
418 slLog("STATUS", msg);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 ui->statusbar->showMessage(msg);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
423 //
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
424 // Restoring and saving of current settings
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
425 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 void SyntilistaMainWindow::readSettings()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
428 QSettings tmpst(APP_VENDOR, APP_ID);
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
429
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
430 // Restore window size and position
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
431 move(tmpst.value("pos", QPoint(100, 100)).toPoint());
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
432 resize(tmpst.value("size", QSize(1000, 600)).toSize());
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
433
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
434 // Other settings
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
435 settings.uiScale = tmpst.value("scale", 1.0f).toDouble();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 void SyntilistaMainWindow::saveSettings()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
441 QSettings tmpst(APP_VENDOR, APP_ID);
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
442
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
443 // Save window size and position
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
444 tmpst.setValue("pos", pos());
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
445 tmpst.setValue("size", size());
136
32c8408eb0cb Cosmetic comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
446
32c8408eb0cb Cosmetic comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
447 // Other settings
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
448 tmpst.setValue("scale", settings.uiScale);
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
449 }
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
450
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
451
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
452 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
453 // Window scale / zoom changing
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
454 //
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
455 void SyntilistaMainWindow::changeUIZoomIn()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
456 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
457 settings.uiScale += 0.1f;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
458 slSetCommonStyleSheet(this);
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
459 }
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
460
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
461
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
462 void SyntilistaMainWindow::changeUIZoomOut()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
463 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
464 settings.uiScale -= 0.1f;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
465 slSetCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
469 void SyntilistaMainWindow::changeUIZoomReset()
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
470 {
135
45e17cdde93a Move application global settings to a struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
471 settings.uiScale = 1.0f;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
472 slSetCommonStyleSheet(this);
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
473 }
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
474
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
475
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
476 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
477 // Slot for changed selection of person entry
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
478 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 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
480 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 (void) prev;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 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
487 focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 setActivePerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493
122
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
494 //
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
495 // Set currently active person to given SQL id
f0db8267911b Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
496 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 void SyntilistaMainWindow::setActivePerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
499 currPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
1
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
501 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
502
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
505 if (!slGetPersonInfo(id, currPerson))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
507 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
508 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 ui->personGB->setEnabled(true);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
512 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
513
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
514 ui->label_BalanceValue->setText(slMoneyValueToStr(currPerson.balance));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
515 ui->label_BalanceValue->setStyleSheet(currPerson.balance < 0 ? "color: red;" : "color: green;");
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
516 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
517
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 QSqlQuery query;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 query.prepare("SELECT id,value,added FROM transactions WHERE person=? ORDER BY added DESC LIMIT 5");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 query.addBindValue(id);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
522 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
523
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 model_Latest->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
526 model_Latest->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
527 model_Latest->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
528 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
529
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 ui->tableview_Latest->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
535 slSetCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 ui->personGB->setEnabled(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 ui->edit_Amount->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 ui->label_BalanceValue->setText("--");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 ui->label_BalanceValue->setStyleSheet(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 ui->label_PersonName->setText("???");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 ui->tableview_Latest->setModel(NULL);
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
547 slSetCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
552 // 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
553 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
554 void SyntilistaMainWindow::updateSortOrder(int index, Qt::SortOrder order)
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
555 {
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
556 peopleSortIndex = index;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
557 peopleSortOrder = order;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
558 updatePersonList();
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
559 }
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
560
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
561
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 void SyntilistaMainWindow::on_button_Quit_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
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
568 void SyntilistaMainWindow::on_button_About_clicked()
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
569 {
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
570 new AboutWindow(this);
74
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
571 }
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
572
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
573
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
574 void SyntilistaMainWindow::on_button_Print_clicked()
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
575 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
576 // Create a printer object and force some basic settings
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
577 QPrinter printer(QPrinter::HighResolution);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
578 printer.setPageSize(QPageSize(QPageSize::A4));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
579 printer.setColorMode(QPrinter::GrayScale);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
580 printer.setResolution(300);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
581
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
582 // We need to get the page count here, and also need it again in
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
583 // printDocument(), but there is no sane way to pass that there,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
584 // so some code duplication is unfortunately necessary
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
585 SLPageInfo pinfo;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
586 pinfo.npages = 0;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
587 pinfo.nlinesPerPage = 0;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
588
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
589 QPixmap tmpPixmap(1000, 1300);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
590 QPainter tmpPainter;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
591 tmpPainter.begin(&tmpPixmap);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
592 bool ret = printDocumentPage(pinfo, true, -1, &tmpPainter, &printer);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
593 tmpPainter.end();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
594
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
595 if (!ret)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
596 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
597 // Some kind of error occured
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
598 return;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
599 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
600
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
601
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
602 // Set available pages
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
603 printer.setFromTo(1, pinfo.npages);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
604
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
605 // Create print preview dialog and show it
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
606 QPrintPreviewDialog preview(&printer, this);
124
a063cb8a171b Set print preview dialog window modality before initializing progress dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
607 preview.setWindowModality(Qt::ApplicationModal);
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
608 preview.setSizeGripEnabled(true);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
609
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
610 connect(
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
611 &preview,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
612 SIGNAL(paintRequested(QPrinter *)),
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
613 this,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
614 SLOT(printDocument(QPrinter *)));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
615
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
616 preview.exec();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
617 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
618
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
619
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
620 void SyntilistaMainWindow::printDocument(QPrinter *printer)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
621 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
622 // Create progress dialog
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
623 QProgressDialog progress(
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
624 tr("Tulostetaan ..."),
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
625 tr("Peruuta"),
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
626 0,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
627 1,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
628 this);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
629
124
a063cb8a171b Set print preview dialog window modality before initializing progress dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
630 progress.setWindowModality(Qt::ApplicationModal);
a063cb8a171b Set print preview dialog window modality before initializing progress dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
631
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
632 // Again, get the page info here .. we need the number of lines per page
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
633 SLPageInfo pinfo;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
634 pinfo.npages = 0;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
635 pinfo.nlinesPerPage = 0;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
636
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
637 QPixmap tmpPixmap(1000, 1300);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
638 QPainter tmpPainter;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
639 tmpPainter.begin(&tmpPixmap);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
640 bool ret = printDocumentPage(pinfo, true, -1, &tmpPainter, printer);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
641 tmpPainter.end();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
642
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
643 if (!ret)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
644 return;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
645
117
71cfb7d96cfc If printer object->fromPage() and toPage() return 0, we are supposed to
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
646 // If from and to are 0, we are supposed to print all pages
71cfb7d96cfc If printer object->fromPage() and toPage() return 0, we are supposed to
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
647 if (printer->fromPage() == 0 && printer->toPage() == 0)
71cfb7d96cfc If printer object->fromPage() and toPage() return 0, we are supposed to
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
648 printer->setFromTo(1, pinfo.npages);
71cfb7d96cfc If printer object->fromPage() and toPage() return 0, we are supposed to
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
649
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
650 // Setup rest of the progress dialog here
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
651 progress.setMinimum(printer->fromPage() - 1);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
652 progress.setMaximum(printer->toPage());
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
653
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
654 // Begin painting to the printer (or preview)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
655 QPainter painter;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
656 painter.begin(printer);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
657
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
658 bool firstPage = true;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
659 for (int page = printer->fromPage(); page <= printer->toPage(); page++)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
660 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
661 if (!firstPage)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
662 printer->newPage();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
663
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
664 qApp->processEvents();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
665 if (progress.wasCanceled())
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
666 break;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
667
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
668 printDocumentPage(pinfo, false, page, &painter, printer);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
669 progress.setValue(page);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
670 firstPage = false;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
671 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
672
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
673 painter.end();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
674 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
675
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
676
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
677 bool SyntilistaMainWindow::printDocumentPage(SLPageInfo &pinfo, const bool getPageInfo, const int npage, QPainter *pt, QPrinter *printer)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
678 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
679 // Form the SQL query for list of users
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
680 QString querystr = QStringLiteral(
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
681 "SELECT id,first_name,last_name,extra_info,added,updated, "
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
682 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance "
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
683 "FROM people ORDER BY last_name ASC,first_name ASC");
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
684
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
685 // If we are fetching page info, we need to process all entries
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
686 if (!getPageInfo)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
687 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
688 // Otherwise we can limit to given page number
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
689 querystr += QStringLiteral(" LIMIT %1 OFFSET %2").
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
690 arg(pinfo.nlinesPerPage).
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
691 arg((npage - 1) * pinfo.nlinesPerPage);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
692 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
693
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
694 QSqlQuery query;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
695 query.prepare(querystr);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
696 query.setForwardOnly(true);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
697 query.exec();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
698
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
699 if (!slCheckAndReportSQLError("printDocumentPage()", query.lastError()))
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
700 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
701 slErrorMsg(
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
702 tr("SQL-tietokantavirhe"),
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
703 tr("Tietokantaa selattaessa tapahtui virhe."));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
704
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
705 return false;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
706 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
707
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
708 pt->save();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
709 if (!getPageInfo)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
710 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
711 pt->scale(
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
712 printer->pageRect().width() / 1000.0f,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
713 printer->pageRect().height() / 1300.0f);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
714 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
715
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
716 QFont font1("Arial", 5);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
717 SLDrawContext ctx(pt);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
718 ctx.setFont(font1);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
719
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
720 int nline = 0;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
721 while (query.next())
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
722 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
723 PersonInfo info;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
724 slGetPersonInfoRec(query, info);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
725
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
726 // Check for end of page
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
727 // KLUDGE for now
125
6e2d26e7a0b4 Add few helpers.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
728 if (getPageInfo && ctx.lfq(10) >= 1300.0f)
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
729 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
730 if (nline > pinfo.nlinesPerPage)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
731 pinfo.nlinesPerPage = nline;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
732
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
733 pinfo.npages++;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
734 nline = 0;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
735 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
736
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
737 if (nline == 0)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
738 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
739 // If we are at the start of the page, we shall draw a header
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
740 pt->setBrush(QBrush(Qt::black));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
741 pt->setPen(QPen(Qt::black, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
742
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
743 ctx.setPos(0, 0);
118
b982ac0fdae4 Make printed header title strings etc. translatable.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
744 ctx.drawText( 5, 180, tr("Etunimi"));
b982ac0fdae4 Make printed header title strings etc. translatable.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
745 ctx.drawText( 200, 230, tr("Sukunimi"));
b982ac0fdae4 Make printed header title strings etc. translatable.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
746 ctx.drawText( 450, 190, tr("Lisätty"));
b982ac0fdae4 Make printed header title strings etc. translatable.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
747 ctx.drawText( 650, 190, tr("Päivitetty"));
b982ac0fdae4 Make printed header title strings etc. translatable.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
748 ctx.drawText( 870, 120, tr("Tase"));
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
749 ctx.lf();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
750
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
751 pt->drawLine(0, ctx.m_pos.y(), 1000, ctx.m_pos.y());
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
752
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
753 ctx.move(0, 5);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
754 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
755
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
756 // Draw a gray bar under every second line
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
757 if (nline % 2 == 0)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
758 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
759 pt->fillRect(
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
760 0,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
761 ctx.m_pos.y() - 1,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
762 1000,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
763 ctx.boundRect().height() + 4,
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
764 QColor(0, 0, 0, 40));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
765 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
766
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
767 ctx.drawText( 5, 180, info.firstName);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
768 ctx.drawText( 200, 230, info.lastName);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
769 ctx.drawText( 450, 190, slDateTimeToStr(info.added));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
770 ctx.drawText( 650, 190, slDateTimeToStr(info.updated));
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
771 ctx.drawText( 870, 120, slMoneyValueToStr(info.balance), Qt::AlignRight);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
772
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
773 ctx.lf(10);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
774 nline++;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
775 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
776
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
777 query.finish();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
778
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
779 if (getPageInfo)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
780 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
781 if (nline > pinfo.nlinesPerPage)
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
782 pinfo.nlinesPerPage = nline;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
783
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
784 pinfo.npages++;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
785 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
786 else
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
787 {
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
788 ctx.setPos(0, 1240);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
789 ctx.drawText(0, 1000,
120
2ff2ad720474 Improve page numbers in printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
790 tr("Sivu %1 / %2 (%3 / %4)").
2ff2ad720474 Improve page numbers in printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
791 arg(npage - printer->fromPage() + 1).
2ff2ad720474 Improve page numbers in printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
792 arg(printer->toPage() - printer->fromPage() + 1).
2ff2ad720474 Improve page numbers in printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
793 arg(npage).
2ff2ad720474 Improve page numbers in printing.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
794 arg(printer->toPage()),
114
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
795 Qt::AlignHCenter);
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
796 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
797
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
798 pt->restore();
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
799 return true;
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
800 }
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
801
a5c8741b8662 Initial prototype support for printing list of users + print preview dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
802
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
803 void SyntilistaMainWindow::on_button_DeletePerson_clicked()
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
804 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
805 if (currPerson.id <= 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
806 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
807 statusMsg(tr("Ei valittua henkilöä!"));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
808 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
809 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
810
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
811 PersonInfo info;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
812 if (!slGetPersonInfo(currPerson.id, info))
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
813 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
814 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
815 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
816 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
817
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
818 QMessageBox dlg;
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
819 slSetCommonStyleSheet(&dlg);
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
820 dlg.setText(tr("Varmistus"));
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
821 dlg.setInformativeText(
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
822 tr("<br>Haluatko varmasti poistaa henkilön:<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
823 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
824 "<b>'%1, %2'</b> <i>(ID #%3)</i>?<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
825 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
826 "Tämä poistaa sekä henkilön ja hänen koko tapahtumahistoriansa PYSYVÄSTI!<br>").
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
827 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
828
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
829 dlg.setTextFormat(Qt::RichText);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
830 dlg.setIcon(QMessageBox::Question);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
831 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
71
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
832 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä"));
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
833 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta"));
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
834 dlg.setDefaultButton(QMessageBox::No);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
835
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
836 if (dlg.exec() == QMessageBox::Yes)
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
837 {
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
838 int rv = model_People->deletePerson(info.id);
14
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
839 updatePersonList();
24
0e0948aec438 De-select active person when deleting.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
840 setActivePerson(-1);
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
841 if (rv != 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
842 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
843 slErrorMsg(tr("SQL-tietokantavirhe"),
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
844 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
845 arg(rv));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
846 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
847 else
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
848 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
849 statusMsg(tr("Henkilö '%1 %2' (ID #%3) poistettu.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
850 arg(info.firstName).arg(info.lastName).
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
851 arg(info.id));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
852 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
853 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
854 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
855
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
856
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 void SyntilistaMainWindow::on_button_AddPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859 EditPerson *person = new EditPerson(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860 person->setPerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 void SyntilistaMainWindow::on_button_EditPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
866 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
867 {
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
868 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
869 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
870 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
872
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
873
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
874 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
875 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
878 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
879 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
880 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
881
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
883 person->setPerson(currPerson.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
884 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
885 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886 setActivePerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
887 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
888
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
889
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
890 void SyntilistaMainWindow::on_button_ClearFilter_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
891 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
892 ui->edit_PersonFilter->clear();
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
893 ui->edit_PersonFilter->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
894 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
895
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
896
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
897 void SyntilistaMainWindow::focusDebtEdit()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
898 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
899 if (currPerson.id >= 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
900 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
901 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
902
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
903
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
904 void SyntilistaMainWindow::selectRowPrev()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
905 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
906 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
907 int row = sel->currentIndex().row() - 1;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
908 if (row < 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
909 row = 0;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
910
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
911 sel->setCurrentIndex(model_People->index(row, 0),
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
912 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
913 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
914
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
915
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
916 void SyntilistaMainWindow::selectRowNext()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
917 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
918 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
919 int row = sel->currentIndex().row() + 1;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
920 if (row >= model_People->rowCount())
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
921 row = model_People->rowCount() - 1;
112
2524434a7193 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
922
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
923 sel->setCurrentIndex(model_People->index(row, 0),
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
924 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
925 }
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
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
928 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
929 // Update visible person list/query based on the current
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
930 // filtering and sorting settings.
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
931 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
932 void SyntilistaMainWindow::updatePersonList()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933 {
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
934 static const QString queryBase =
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
935 "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
936 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance,"
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
937 "updated FROM people";
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
938
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
939 QString queryOrderDir, queryOrderBy;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
940
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
941 // Sort order
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
942 if (peopleSortOrder == Qt::AscendingOrder)
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
943 queryOrderDir = QStringLiteral("ASC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944 else
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
945 queryOrderDir = QStringLiteral("DESC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
946
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
947 // Sort by which column
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 switch (peopleSortIndex)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950 case 1:
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
951 case 2:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
952 queryOrderBy = QStringLiteral(" ORDER BY last_name ") + queryOrderDir + QStringLiteral(",first_name ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
953 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
954
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 case 3:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
956 queryOrderBy = QStringLiteral(" ORDER BY balance ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
957 break;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
958
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
959 case 4:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
960 queryOrderBy = QStringLiteral(" ORDER BY updated ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
961 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
962
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
963 default:
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
964 queryOrderBy = "";
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
965 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
966
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
967 // Are we filtering or not?
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
968 QSqlQuery query;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
969 if (peopleFilter != "")
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
971 // Filter by name(s)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
972 QString tmp = "%"+ peopleFilter +"%";
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
973 query.prepare(queryBase +" 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
974
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
975 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
976 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
977 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
978 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
979 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
980 // No filter
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
981 query.prepare(queryBase + queryOrderBy);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
982 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
984 // Execute the query and update model
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
985 slCheckAndReportSQLError("updatePersonList() before exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
986 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
987 slCheckAndReportSQLError("updatePersonList() after exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
988
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 model_People->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
990
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
991 model_People->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
992 model_People->setHeaderData(1, Qt::Horizontal, tr("Sukunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
993 model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
994 model_People->setHeaderData(3, Qt::Horizontal, tr("Tase"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
995 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
996
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
997 updateTotalBalance();
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
998 }
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
999
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
1000
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
1001 //
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1002 // Update total balance value in the UI
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
1003 //
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
1004 void SyntilistaMainWindow::updateTotalBalance()
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
1005 {
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
1006 // 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
1007 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
1008 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
1009 query.exec();
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
1010 if (!slCheckAndReportSQLError("updatePersonList() get total balance query", query.lastError()))
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
1011 {
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
1012 slErrorMsg(
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
1013 tr("SQL-tietokantavirhe"),
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
1014 tr("Tietokantaa kyseltäessä tapahtui virhe."));
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
1015 }
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
1016 else
10c6bd84eb32 Add "total balance" information in the UI, which displays the total sum balance of all people.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
1017 {
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
1018 double 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
1019 QString tmp ;
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
1020 if (query.next())
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
1021 {
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
1022 balance = query.value(0).toDouble();;
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
1023 tmp = slMoneyValueToStr(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
1024 }
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
1025 else
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
1026 {
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
1027 balance = -1;
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
1028 tmp = "?";
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
1029 }
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
1030
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
1031 ui->label_TotalBalanceValue->setText(tmp);
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
1032 ui->label_TotalBalanceValue->setStyleSheet(balance < 0 ? "color: red;" : "color: green;");
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
1033 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1035
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1036
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1037 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1038 // Update the list of people when filter parameter changes
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1039 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1040 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
1041 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1042 peopleFilter = slCleanupStr(str);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1044 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1045
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1046
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1047 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1048 // Add one transaction to given person id
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1049 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1050 int SyntilistaMainWindow::addTransaction(qint64 id, double value, PersonInfo &info)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1051 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
1052 if (!slGetPersonInfo(id, info))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1053 return -1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1054
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1055 QSqlDatabase::database().transaction();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1056
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1057 QSqlQuery query;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1058 query.prepare("INSERT INTO transactions (person,value,added) VALUES (?,?,?)");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1059 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1060 query.addBindValue(value);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1061 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1062 query.exec();
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1063 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
1064 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1065 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1066 return -2;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1067 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1068
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1069 query.prepare("UPDATE people SET updated=? WHERE id=?");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1070 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1071 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1072 query.exec();
126
b51cee929416 Add program debug logging.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
1073 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError(), true))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1074 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1075 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1076 return -3;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1077 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1078
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1079 QSqlDatabase::database().commit();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
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 updateTotalBalance();
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
1082
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1083 return 0;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1084 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1085
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1086
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1087 int SyntilistaMainWindow::addTransactionGUI(qint64 id, bool debt, double value)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1088 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1089 PersonInfo info;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1090
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1091 // Check if person is selected
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1092 if (id <= 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1093 return -1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1094
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1095 // Check value
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1096 if (value == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1097 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1098 QString tmp = (debt ? "lisätty" : "vähennetty");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1099 statusMsg("Velkaa ei "+ tmp +" koska summaa ei määritetty.");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1100 return 1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1101 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1102
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1103 // Perform transaction insert
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1104 int ret = addTransaction(id, debt ? -value : value, info);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1105 if (ret == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1106 {
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1107 // 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
1108 ui->edit_Amount->clear();
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1109 if (info.id == currPerson.id)
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1110 setActivePerson(info.id);
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1111
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1112 model_People->updateModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1113
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1114 QString str;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1115 if (debt)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1116 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1117 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
1118 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1119 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1120 arg(info.lastName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1121 arg(info.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1122 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1123 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1124 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1125 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
1126 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1127 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1128 arg(info.lastName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1129 arg(info.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1130 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1131 statusMsg(str);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1132 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1133 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1134 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1135 slErrorMsg(
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1136 tr("SQL-tietokantavirhe"),
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1137 tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1138 arg(ret));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1139 }
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1140
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1141 return ret;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1142 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1143
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1144
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1145 void SyntilistaMainWindow::on_button_AddDebt_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1146 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1147 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
1148 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1149
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1150
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1151 void SyntilistaMainWindow::on_button_PayDebt_clicked()
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1152 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1153 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
1154 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1155
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1156
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1157 void SyntilistaMainWindow::on_button_PayFullDebt_clicked()
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1158 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1159 if (currPerson.balance < 0)
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1160 addTransactionGUI(currPerson.id, false, -currPerson.balance);
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1161 else
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1162 {
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1163 statusMsg(
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1164 tr("Valitulla henkilöllä '%1, %2' ei ole velkaa.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1165 arg(currPerson.lastName).
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1166 arg(currPerson.firstName));
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
1167 }
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1168 }
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1169
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
1170
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1171 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1172 // Edit person dialog
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1173 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1174 EditPerson::EditPerson(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1175 QDialog(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1176 ui(new Ui::EditPerson)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1177 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1178 ui->setupUi(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1179
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
1180 slSetCommonStyleSheet(this);
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
1181
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1182 setModal(true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1183 setAttribute(Qt::WA_DeleteOnClose);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1184 show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1185 activateWindow();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1186 raise();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1187 setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1188
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1189 model_Transactions = new TransactionSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1190 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1191 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
1192 ui->tableview_Transactions->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1193 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1194
123
e76d85ea87ac Rename SQL_MAX_* defines to SQL_LEN_* for being more descriptive .. maybe.
Matti Hamalainen <ccr@tnsp.org>
parents: 122
diff changeset
1195 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
1196 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
1197
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1198 connect(
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1199 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
1200 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
1201 this,
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1202 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
1203
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1204 validateForm();
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 EditPerson::~EditPerson()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1209 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1210 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1211 delete model_Transactions;
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1214
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1215 void EditPerson::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1216 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1217 dynamic_cast<SyntilistaMainWindow *>(parent())->statusMsg(msg);
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1220
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1221 bool EditPerson::validateForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1222 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1223 selPerson.firstName = slCleanupStr(ui->edit_FirstName->text());
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1224 selPerson.lastName = slCleanupStr(ui->edit_LastName->text());
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1225 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
1226 bool extraInfoValid = selPerson.extraInfo.length() < SQL_LEN_EXTRA_INFO;
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1227
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1228 ui->textedit_ExtraInfo->setStyleSheet(!extraInfoValid ? "background-color: red;" : NULL);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1229 ui->edit_FirstName->setStyleSheet(selPerson.firstName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1230 ui->edit_LastName->setStyleSheet(selPerson.lastName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1231
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1232 return selPerson.firstName != "" && selPerson.lastName != "" && extraInfoValid;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1233 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1234
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1235
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1236 void EditPerson::on_button_Cancel_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1237 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1238 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1239 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1240
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1241
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1242 void EditPerson::on_button_OK_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1243 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1244 if (!validateForm())
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1245 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1246 slErrorMsg(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1247 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
1248 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
1249
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1250 return;
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1251 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1252
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1253 if (selPerson.id >= 0)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1254 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1255 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1256 person.prepare("SELECT * FROM people WHERE id <> ? AND first_name=? AND last_name=?");
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1257 person.addBindValue(selPerson.id);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1258 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1259 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1260 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1261
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1262 slCheckAndReportSQLError("SELECT check for existing person by same name (UPDATE)", person.lastError());
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1263
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1264 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1265 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1266 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1267 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1268 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
1269 arg(selPerson.firstName).arg(selPerson.lastName));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1270 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1271 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1272
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1273 dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->updatePerson(selPerson);
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
1274 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
1275
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1276 statusMsg(tr("Päivitettiin henkilö '%1 %2' (#%3).").
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1277 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
1278 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1279 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1280 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1281 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1282 person.prepare("SELECT * FROM people WHERE first_name=? AND last_name=?");
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1283 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1284 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1285 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1286
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1287 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
1288
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1289 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1290 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1291 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1292 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1293 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
1294 arg(selPerson.firstName).arg(selPerson.lastName));
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1295
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1296 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1297 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1298
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1299 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
1300 if (nid < 0)
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1301 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1302 slErrorMsg(
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1303 tr("Virhe!"),
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1304 tr("Tietokannan käsittelyssä tapahtui virhe (#%1).").
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1305 arg(nid));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1306 }
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1307 else
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1308 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1309 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
1310 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
1311 dynamic_cast<SyntilistaMainWindow *>(parent())->focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1312
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1313 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
1314 arg(selPerson.firstName).arg(selPerson.lastName));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
1315 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1316 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1317
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1318 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1319 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1320
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1321
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1322 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
1323 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1324 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1325 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1326 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1327
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1328
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1329 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
1330 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1331 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1332 validateForm();
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1335
121
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1336 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
1337 {
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1338 validateForm();
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1339 }
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1340
404d567edaab Validate the length of extra info field in the add/edit person dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
1341
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1342 void EditPerson::clearForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1343 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1344 ui->edit_FirstName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1345 ui->edit_LastName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1346 ui->textedit_ExtraInfo->document()->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1347 ui->edit_FirstName->setFocus();
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1350
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1351 void EditPerson::setPerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1352 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1353 selPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1354
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1355 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1356 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1357 PersonInfo pinfo;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
1358 if (!slGetPersonInfo(id, pinfo))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1359 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1360 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(id));
104
1997cc07a7ae Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
1361 // Intentional fall-through below
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1362 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1363 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1364 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1365 ui->edit_FirstName->setText(pinfo.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1366 ui->edit_LastName->setText(pinfo.lastName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1367 ui->textedit_ExtraInfo->document()->setPlainText(pinfo.extraInfo);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1368
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1369 QSqlQuery query;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1370 query.prepare("SELECT id,value,added FROM transactions WHERE person=? ORDER BY added DESC");
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1371 query.addBindValue(pinfo.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1372 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1373 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
1374
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1375 model_Transactions->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1376
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1377 model_Transactions->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1378 model_Transactions->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1379 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
1380
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1381 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1382 ui->tableview_Transactions->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1383
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1384 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1385 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1386 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1387
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1388 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1389 clearForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1390 ui->tableview_Transactions->setModel(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1391 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1392
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1393
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1394 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1395 // Custom SQL models
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1396 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1397 PersonSQLModel::PersonSQLModel(QObject *parent) : QSqlQueryModel(parent)
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 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1400
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1401
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1402 QVariant PersonSQLModel::data(const QModelIndex &index, int role) const
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1403 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1404 QVariant value = QSqlQueryModel::data(index, role);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1405
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1406 if (value.isValid() && role == Qt::DisplayRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1407 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1408 switch (index.column())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1409 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1410 case 3:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1411 return slMoneyValueToStr(value.toDouble());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1412
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1413 case 4:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1414 return slDateTimeToStr(value.toDateTime());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1415 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1416 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1417
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1418 if (index.column() == 3 && role == Qt::ForegroundRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1419 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1420 double val = QSqlQueryModel::data(index, Qt::DisplayRole).toDouble();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1421 if (val < 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1422 return QVariant::fromValue(QColor(Qt::red));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1423 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1424 return QVariant::fromValue(QColor(Qt::green));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1425 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1426
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1427 return value;
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
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1431 int PersonSQLModel::updatePerson(const PersonInfo &info)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1432 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1433 QSqlQuery np;
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1434
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1435 np.prepare("UPDATE people SET first_name=?,last_name=?,extra_info=?,updated=? WHERE id=?");
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1436 np.addBindValue(info.firstName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1437 np.addBindValue(info.lastName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1438 np.addBindValue(info.extraInfo);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1439 np.addBindValue(QDateTime::currentDateTimeUtc());
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1440 np.addBindValue(info.id);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1441 np.exec();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1442
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1443 if (!slCheckAndReportSQLError("PersonSQLModel::updatePerson()", np.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1444 return -1;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1445
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1446 QSqlDatabase::database().commit();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1447 updateModel();
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1448 return 0;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1449 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1450
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1451
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1452 qint64 PersonSQLModel::addPerson(const PersonInfo &info)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1453 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1454 // beginInsertRows(QModelIndex(), rowCount(), rowCount());
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 QSqlQuery np;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1457 np.prepare("INSERT INTO people (first_name,last_name,extra_info,added,updated) VALUES (?,?,?,?,?)");
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1458 np.addBindValue(info.firstName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1459 np.addBindValue(info.lastName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1460 np.addBindValue(info.extraInfo);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1461 np.addBindValue(QDateTime::currentDateTimeUtc());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1462 np.addBindValue(QDateTime::currentDateTimeUtc());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1463 np.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1464
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1465 if (!slCheckAndReportSQLError("PersonSQLModel::addPerson()", np.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1466 return -1;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1467
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1468 QSqlDatabase::database().commit();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1469
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1470 QVariant idp = np.lastInsertId();
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1471
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1472 // endInsertRows();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1473 updateModel();
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1474 return idp.isValid() ? idp.toInt() : -2;
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1475 }
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1476
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1477
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1478 int PersonSQLModel::deletePerson(qint64 id)
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1479 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1480 QSqlDatabase::database().transaction();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1481 QSqlQuery del;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1482
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1483 del.prepare("DELETE FROM people WHERE id=?");
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1484 del.addBindValue(id);
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1485 del.exec();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1486
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1487 if (!slCheckAndReportSQLError("delete user", del.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1488 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1489 QSqlDatabase::database().rollback();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1490 return -1;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1491 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1492
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1493 del.prepare("DELETE FROM transactions WHERE person=?");
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1494 del.addBindValue(id);
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1495 del.exec();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1496
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1497 if (!slCheckAndReportSQLError("delete user transactions", del.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1498 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1499 QSqlDatabase::database().rollback();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1500 return -2;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1501 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1502
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1503 QSqlDatabase::database().commit();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1504 updateModel();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1505 return 0;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1506 }
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 void PersonSQLModel::updateModel()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1510 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1511 query().exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1512 emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1513 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1514
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1515
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1516 TransactionSQLModel::TransactionSQLModel(QObject *parent) : QSqlQueryModel(parent)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1517 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1518 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1519
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1520
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1521 QVariant TransactionSQLModel::data(const QModelIndex &index, int role) const
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1522 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1523 QVariant value = QSqlQueryModel::data(index, role);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1524
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1525 if (value.isValid() && role == Qt::DisplayRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1526 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1527 switch (index.column())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1528 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1529 case 1:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1530 return slMoneyValueToStr(value.toDouble());
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1531
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1532 case 2:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1533 return slDateTimeToStr(value.toDateTime());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1534 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1535 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1536
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1537 if (index.column() == 1 && role == Qt::ForegroundRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1538 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1539 double val = QSqlQueryModel::data(index, Qt::DisplayRole).toDouble();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1540 if (val < 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1541 return QVariant::fromValue(QColor(Qt::red));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1542 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1543 return QVariant::fromValue(QColor(Qt::green));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1544 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1545
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1546 return value;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1547 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1548
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1549
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1550 void TransactionSQLModel::updateModel()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1551 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1552 query().exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1553 emit dataChanged(QModelIndex(), QModelIndex());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1554 }
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1555
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1556
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1557 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1558 // About window
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1559 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1560 AboutWindow::AboutWindow(QWidget *parent) :
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1561 QDialog(parent),
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1562 ui(new Ui::AboutWindow)
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1563 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1564 ui->setupUi(this);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1565
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1566 ui->label_Logo->setPixmap(QPixmap(":/img/icon-64.png"));
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1567 ui->label_Logo->setAlignment(Qt::AlignCenter);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1568
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1569 ui->label_About->setWordWrap(true);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1570 ui->label_About->setTextFormat(Qt::RichText);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1571 ui->label_About->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1572 "<h1>%1 v%2</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1573 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1574 "<b>Ohjelmoinut ja kehittänyt Matti Hämäläinen &lt;ccr@tnsp.org&gt;<br>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1575 "(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
1576 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1577 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1578 "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
1579 "alaisuudessa Café Kampuksen käyttöön."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1580 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1581 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1582 "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
1583 "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
1584 "nähdäksesi täydelliset lisenssiehdot."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1585 "</p>"
137
1a480e947598 Show application data path in the about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
1586 "<p>AppDataPath: %3</p>"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1587 ).
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1588 arg(tr(APP_NAME)).
137
1a480e947598 Show application data path in the about dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 136
diff changeset
1589 arg(APP_VERSION).
138
5e6bcabfa380 Oops, old datapath variable used. Fix it.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
1590 arg(settings.dataPath)
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1591 );
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1592
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1593 ui->label_ShortCuts->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1594 "<h1>Pikanäppäimet</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1595 "<table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1596 "<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
1597 "<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
1598 "<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
1599 "<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
1600 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1601 "<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
1602 "<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
1603 "<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
1604 "<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
1605 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1606 "<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
1607 "<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
1608 "<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
1609 "</table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1610 ));
95
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1611
132
dc9fe580da42 Rename setCommonStyleSheet() to slSetCommonStyleSheet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
1612 // slSetCommonStyleSheet(this);
95
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1613 setModal(true);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1614 setAttribute(Qt::WA_DeleteOnClose);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1615 show();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1616 activateWindow();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1617 raise();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1618 setFocus();
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1619 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1620
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1621
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1622 AboutWindow::~AboutWindow()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1623 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1624 delete ui;
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1625 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1626
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1627
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1628 void AboutWindow::on_button_Close_clicked()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1629 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1630 close();
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1631 }