annotate src/main.cpp @ 113:907f2ddf6801

Use #defines for SQL table field lengths.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Jul 2017 09:52:10 +0300
parents 2524434a7193
children a5c8741b8662
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>
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include "main.h"
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "ui_mainwindow.h"
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include "ui_editperson.h"
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
15 #include "ui_aboutwindow.h"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
16
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
103
ce86ea4b08aa Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
18 // Global UI scale factor
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
19 double setScale;
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
20
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
22 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
23 // Display an error dialog with given title and message
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
24 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
25 int slErrorMsg(QString title, QString msg)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 {
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
27 QMessageBox dlg;
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
28
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
29 dlg.setText(title);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
30 dlg.setInformativeText(msg);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
31 dlg.setTextFormat(Qt::RichText);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
32 dlg.setIcon(QMessageBox::Critical);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
33 dlg.setStandardButtons(QMessageBox::Ok);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
34 dlg.setDefaultButton(QMessageBox::Ok);
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
35
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
36 return dlg.exec();
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
40 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
41 // Convert QString to a double value, replacing comma
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
42 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
43 double slMoneyStrToValue(const QString &str)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 QString str2 = str;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 return str2.replace(",", ".").toDouble();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
50 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
51 // Convert double value to formatted QString
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
52 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
53 QString slMoneyValueToStr(double val)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 return QStringLiteral("%1").arg(val, 1, 'f', 2);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
59 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
60 // Trim and cleanup given QString (removing double whitespace etc.)
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
61 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
62 QString slCleanupStr(const QString &str)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 return str.simplified().trimmed();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 }
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
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
68 //
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
69 // Manipulate given QDateTime value to get desired
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
70 // correct timestamp.
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
71 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
72 const QDateTime slDateTimeToLocal(const QDateTime &val)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 QDateTime tmp = val;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 tmp.setOffsetFromUtc(0);
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
76 return tmp.toLocalTime();
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
77 }
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
78
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
79
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
80 //
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
81 // Return a string representation of given QDateTime
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
82 // converted to local time.
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
83 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
84 const QString slDateTimeToStr(const QDateTime &val)
84
00db2c012481 Add dateTimeToLocal() and some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 83
diff changeset
85 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
86 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
87 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89
83
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
90 //
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
91 // Check if an SQL error has occured (for given QSqlError) and
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
92 // 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
93 // true otherwise.
83044206479e Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
94 //
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
95 bool slCheckAndReportSQLError(const QString where, const QSqlError &err)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 if (err.isValid())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 printf("SQL Error in %s: %s\n",
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 where.toUtf8().constData(),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 err.text().toUtf8().constData());
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
102 return false;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 else
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
105 return true;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
109 void PersonInfo::dump()
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
110 {
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
111 printf("PersonInfo() #%lld '%s %s' (added=%s, updated=%s, balance %1.2f)\n#%s#\n",
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
112 id,
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
113 firstName.toUtf8().constData(),
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
114 lastName.toUtf8().constData(),
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
115 slDateTimeToStr(added).toUtf8().constData(),
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
116 slDateTimeToStr(updated).toUtf8().constData(),
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
117 balance,
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
118 extraInfo.toUtf8().constData());
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
119 }
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
120
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
121
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
122 //
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
123 // Get PersonInfo record from SQL query object
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
124 //
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
125 void slGetPersonInfoRec(QSqlQuery &query, PersonInfo &info)
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
126 {
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
127 info.id = query.value(0).toInt();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
128 info.firstName = query.value(1).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
129 info.lastName = query.value(2).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
130 info.extraInfo = query.value(3).toString();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
131 info.added = query.value(4).toDateTime();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
132 info.updated = query.value(5).toDateTime();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
133 info.balance = query.value(6).toDouble();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
134 }
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
135
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
136
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
137 //
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
138 // 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
139 //
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
140 bool slGetPersonInfo(qint64 id, PersonInfo &info)
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
141 {
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
142 QSqlQuery query;
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
143 query.prepare(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
144 "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
145 "(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
146 "FROM people WHERE id=?");
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
147
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
148 query.addBindValue(id);
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
149 query.exec();
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
150 if (!query.next())
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
151 return false;
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
152
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
153 slGetPersonInfoRec(query, info);
101
2477f46282c8 Split getPersonInfo() to getPersonInfoRec().
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
154 query.finish();
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
155 return true;
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
156 }
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
157
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
158
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
159 void setCommonStyleSheet(QWidget *widget)
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
160 {
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
161 // Clamp scale value
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
162 if (setScale < 0.5f)
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
163 setScale = 0.5f;
103
ce86ea4b08aa Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 102
diff changeset
164
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
165 if (setScale > 3.0f)
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
166 setScale = 3.0f;
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
167
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
168 // Set the stylesheet
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
169 widget->setStyleSheet(
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
170 QStringLiteral(
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
171 "* { font-size: %1pt; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
172 "QPushButton { font-size: %2pt; padding: 0.25em; }"
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
173 "#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
174 "#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
175 "#button_PayFullDebt[enabled='true'] { background-color: #060; color: white; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
176
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
177 "#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
178 "#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
179 "#button_PayFullDebt[enabled='false'] { background-color: #131; color: black; }"
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
180
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
181 "#label_PersonName { font-size: %5pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
182 "#label_BalanceValue { font-size: %4pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
183 "#label_EUR { font-size: %4pt; font-weight: bold; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
184 "#edit_Amount { font-size: %4pt; margin: 0.5em; padding: 0.5em; }"
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
185 ).
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
186 arg(12 * setScale).
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
187 arg(14 * setScale).
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
188 arg(16 * setScale).
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
189 arg(18 * setScale).
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
190 arg(20 * setScale)
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
191 );
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
192 }
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
193
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
194
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 int main(int argc, char *argv[])
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 QApplication sapp(argc, argv);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 // Initialize / open SQL database connection
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
42
60ffa45b4014 Use #define APP_SQLITE_FILE for the application Sqlite3 database filename.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
203 db.setDatabaseName(qApp->applicationDirPath() +
60ffa45b4014 Use #define APP_SQLITE_FILE for the application Sqlite3 database filename.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
204 QDir::separator() + APP_SQLITE_FILE);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 if (!db.open())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
208 slErrorMsg(
9
1f442052d332 Oops, 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
209 QObject::tr("Tietokantaa ei voitu avata"),
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
210 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
211 arg(db.lastError().text())
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 );
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
213 return 1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 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
217 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
218 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
219 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
220 "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
221 "first_name VARCHAR(%1) NOT NULL, "
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
222 "last_name VARCHAR(%2) NOT NULL, "
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
223 "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
224 "added DATETIME NOT NULL, "
113
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
225 "updated DATETIME NOT NULL)").
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
226 arg(SQL_MAX_FIRST_NAME).
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
227 arg(SQL_MAX_LAST_NAME).
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
228 arg(SQL_MAX_EXTRA_INFO));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
230 slCheckAndReportSQLError("CREATE TABLE people", query.lastError());
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
231 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
233 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
234 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
235 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
236 "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
237 "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
238 "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
239 "value REAL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
240 "added DATETIME NOT NULL)"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
242 slCheckAndReportSQLError("CREATE TABLE transactions", query.lastError());
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
243 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 SyntilistaMainWindow swin;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 swin.show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 return sapp.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 // Main application window code
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 SyntilistaMainWindow::SyntilistaMainWindow(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 QMainWindow(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 ui(new Ui::SyntilistaMainWindow)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 {
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
258 // Setup UI
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 ui->setupUi(this);
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
260
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
261 // Read config
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
262 readSettings();
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
263
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
264 // Setup other UI things
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
265 setWindowIcon(QIcon(QPixmap(":/img/icon-64.png")));
64
73fd86778014 Version number display etc. changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
266 setWindowTitle(tr("%1 versio %3").
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
267 arg(tr(APP_NAME)).
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
268 arg(tr(APP_VERSION)));
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
269
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
270 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
271 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
272 ui->button_LogoImage->setAlignment(Qt::AlignCenter);
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
273
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
274 setCommonStyleSheet(this);
22
c23241a3e160 UI polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
275
68
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
276 // Validator for amount input
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
277 //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
278 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
279 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
280
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
281 // Setup person list filtering and sorting
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 peopleSortIndex = 1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 peopleSortOrder = Qt::AscendingOrder;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 peopleFilter = "";
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 model_People = new PersonSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 ui->tableview_People->setModel(model_People);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 ui->tableview_People->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 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
292 ui->tableview_People->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 ui->tableview_People->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 ui->tableview_People->setSortingEnabled(true);
25
a7e746642599 Fix initial sorting.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
295 ui->tableview_People->sortByColumn(peopleSortIndex, peopleSortOrder);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
297 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
298 ui->tableview_People->selectionModel(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
300 this,
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
301 SLOT(selectedPersonChanged(const QModelIndex &, const QModelIndex &)));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
303 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
304 ui->tableview_People->horizontalHeader(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 this,
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 SLOT(updateSortOrder(int, Qt::SortOrder)));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 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
310
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 model_Latest = new TransactionSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 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
314 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 setActivePerson(-1);
17
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
318
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
319 // Keyboard shortcuts
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
320 ui->button_Quit->setShortcut(QKeySequence(Qt::Key_F10));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
321 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
322
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
323 ui->button_AddPerson->setShortcut(QKeySequence(Qt::Key_F5));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
324 ui->button_DeletePerson->setShortcut(QKeySequence(Qt::Key_F8));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
325 ui->button_EditPerson->setShortcut(QKeySequence(Qt::Key_F6));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
326 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
327 ui->button_About->setShortcut(QKeySequence(Qt::Key_F1));
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
328
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
329 new QShortcut(QKeySequence(QKeySequence::ZoomIn), this, SLOT(changeUIZoomIn()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
330 new QShortcut(QKeySequence(QKeySequence::ZoomOut), this, SLOT(changeUIZoomOut()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
331 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
332 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
333 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
334 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
335
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
336 new QShortcut(QKeySequence(Qt::Key_PageUp), this, SLOT(selectRowPrev()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
337 new QShortcut(QKeySequence(Qt::Key_PageDown), this, SLOT(selectRowNext()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
338
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
339 new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Return), this, SLOT(focusDebtEdit()));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
343 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
344 // Application main window destructor
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
345 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 SyntilistaMainWindow::~SyntilistaMainWindow()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 {
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
348 // Save current settings and free resources
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 saveSettings();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 delete model_People;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 delete model_Latest;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
357 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
358 // Helper function for showing messages in the statusbar/line
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
359 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 void SyntilistaMainWindow::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 ui->statusbar->showMessage(msg);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 void SyntilistaMainWindow::readSettings()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 {
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
368 QSettings settings(APP_VENDOR, APP_ID);
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
369
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
370 // Restore window size and position
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 move(settings.value("pos", QPoint(100, 100)).toPoint());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 resize(settings.value("size", QSize(1000, 600)).toSize());
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
373
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
374 // Other settings
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
375 setScale = settings.value("scale", 1.0f).toDouble();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 void SyntilistaMainWindow::saveSettings()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 {
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
381 QSettings settings(APP_VENDOR, APP_ID);
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
382
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
383 // Save window size and position
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 settings.setValue("pos", pos());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 settings.setValue("size", size());
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
386 settings.setValue("scale", setScale);
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
387 }
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
388
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
389
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
390 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
391 // Window scale / zoom changing
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
392 //
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
393 void SyntilistaMainWindow::changeUIZoomIn()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
394 {
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
395 setScale += 0.1f;
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
396 setCommonStyleSheet(this);
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
397 }
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
398
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
399
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
400 void SyntilistaMainWindow::changeUIZoomOut()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
401 {
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
402 setScale -= 0.1f;
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
403 setCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
407 void SyntilistaMainWindow::changeUIZoomReset()
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
408 {
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
409 setScale = 1.0f;
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
410 setCommonStyleSheet(this);
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
411 }
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
412
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
413
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
414 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
415 // Slot for changed selection of person entry
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
416 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 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
418 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 (void) prev;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 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
425 focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 setActivePerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 void SyntilistaMainWindow::setActivePerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
434 currPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435
1
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
436 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
437
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
440 if (!slGetPersonInfo(id, currPerson))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
442 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
443 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 ui->personGB->setEnabled(true);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
447 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
448
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
449 ui->label_BalanceValue->setText(slMoneyValueToStr(currPerson.balance));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
450 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
451 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
452
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 QSqlQuery query;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 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
455 query.addBindValue(id);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
457 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
458
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 model_Latest->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
461 model_Latest->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
462 model_Latest->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
463 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
464
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 ui->tableview_Latest->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
470 setCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 ui->personGB->setEnabled(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 ui->edit_Amount->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 ui->label_BalanceValue->setText("--");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 ui->label_BalanceValue->setStyleSheet(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 ui->label_PersonName->setText("???");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 ui->tableview_Latest->setModel(NULL);
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
482 setCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 }
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
487 // 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
488 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
489 void SyntilistaMainWindow::updateSortOrder(int index, Qt::SortOrder order)
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
490 {
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
491 peopleSortIndex = index;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
492 peopleSortOrder = order;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
493 updatePersonList();
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
494 }
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
495
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
496
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 void SyntilistaMainWindow::on_button_Quit_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502
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
503 void SyntilistaMainWindow::on_button_About_clicked()
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
504 {
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
505 new AboutWindow(this);
74
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
506 }
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
507
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
508
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
509 void SyntilistaMainWindow::on_button_DeletePerson_clicked()
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
510 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
511 if (currPerson.id <= 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
512 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
513 statusMsg(tr("Ei valittua henkilöä!"));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
514 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
515 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
516
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
517 PersonInfo info;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
518 if (!slGetPersonInfo(currPerson.id, info))
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
519 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
520 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
521 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
522 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
523
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
524 QMessageBox dlg;
71
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
525 setCommonStyleSheet(&dlg);
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
526 dlg.setText(tr("Varmistus"));
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
527 dlg.setInformativeText(
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
528 tr("<br>Haluatko varmasti poistaa henkilön:<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
529 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
530 "<b>'%1, %2'</b> <i>(ID #%3)</i>?<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
531 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
532 "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
533 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
534
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
535 dlg.setTextFormat(Qt::RichText);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
536 dlg.setIcon(QMessageBox::Question);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
537 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
71
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
538 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä"));
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
539 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta"));
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
540 dlg.setDefaultButton(QMessageBox::No);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
541
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
542 if (dlg.exec() == QMessageBox::Yes)
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
543 {
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
544 int rv = model_People->deletePerson(info.id);
14
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
545 updatePersonList();
24
0e0948aec438 De-select active person when deleting.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
546 setActivePerson(-1);
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
547 if (rv != 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
548 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
549 slErrorMsg(tr("SQL-tietokantavirhe"),
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
550 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
551 arg(rv));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
552 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
553 else
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
554 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
555 statusMsg(tr("Henkilö '%1 %2' (ID #%3) poistettu.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
556 arg(info.firstName).arg(info.lastName).
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
557 arg(info.id));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
558 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
559 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
560 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
561
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
562
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 void SyntilistaMainWindow::on_button_AddPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 EditPerson *person = new EditPerson(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 person->setPerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 void SyntilistaMainWindow::on_button_EditPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
572 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
573 {
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
574 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
575 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
576 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 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
581 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 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
587
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
589 person->setPerson(currPerson.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 setActivePerson(-1);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 void SyntilistaMainWindow::on_button_ClearFilter_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598 ui->edit_PersonFilter->clear();
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
599 ui->edit_PersonFilter->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
600 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
601
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
602
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
603 void SyntilistaMainWindow::focusDebtEdit()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
604 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
605 if (currPerson.id >= 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
606 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
607 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
608
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
609
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
610 void SyntilistaMainWindow::selectRowPrev()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
611 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
612 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
613 int row = sel->currentIndex().row() - 1;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
614 if (row < 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
615 row = 0;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
616
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
617 sel->setCurrentIndex(model_People->index(row, 0),
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
618 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
619 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
620
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
621
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
622 void SyntilistaMainWindow::selectRowNext()
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
623 {
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
624 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
625 int row = sel->currentIndex().row() + 1;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
626 if (row >= model_People->rowCount())
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
627 row = model_People->rowCount() - 1;
112
2524434a7193 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
628
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
629 sel->setCurrentIndex(model_People->index(row, 0),
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
630 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
631 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
632
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
634 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
635 // Update visible person list/query based on the current
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
636 // filtering and sorting settings.
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
637 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638 void SyntilistaMainWindow::updatePersonList()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
639 {
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
640 static QString queryBase =
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
641 "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
642 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance,"
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
643 "updated FROM people";
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
644
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 QSqlQuery query;
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
646 QString queryOrderDir, queryOrderBy;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
648 // Sort order
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 if (peopleSortOrder == Qt::AscendingOrder)
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
650 queryOrderDir = QStringLiteral("ASC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651 else
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
652 queryOrderDir = QStringLiteral("DESC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
654 // Sort by which column
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 switch (peopleSortIndex)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 case 1:
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 case 2:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
659 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
660 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
661
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 case 3:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
663 queryOrderBy = QStringLiteral(" ORDER BY balance ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
664 break;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 case 4:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
667 queryOrderBy = QStringLiteral(" ORDER BY updated ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
669
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
670 default:
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
671 queryOrderBy = "";
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
674 // Are we filtering or not?
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 if (peopleFilter != "")
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
677 // Filter by name(s)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 QString tmp = "%"+ peopleFilter +"%";
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
679 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
680
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
681 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
683 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
684 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
686 // No filter
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
687 query.prepare(queryBase + queryOrderBy);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
688 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
690 // Execute the query and update model
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
691 slCheckAndReportSQLError("updatePersonList() before exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
693 slCheckAndReportSQLError("updatePersonList() after exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 model_People->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
697 model_People->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
698 model_People->setHeaderData(1, Qt::Horizontal, tr("Sukunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
699 model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
700 model_People->setHeaderData(3, Qt::Horizontal, tr("Tase"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
701 model_People->setHeaderData(4, Qt::Horizontal, tr("Muutettu"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
705 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
706 // Update the list of people when filter parameter changes
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
707 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 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
709 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
710 peopleFilter = slCleanupStr(str);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
715 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
716 // Add one transaction to given person id
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
717 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
718 int SyntilistaMainWindow::addTransaction(qint64 id, double value, PersonInfo &info)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
719 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
720 if (!slGetPersonInfo(id, info))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
721 return -1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
722
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
723 QSqlDatabase::database().transaction();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
724
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
725 QSqlQuery query;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
726 query.prepare("INSERT INTO transactions (person,value,added) VALUES (?,?,?)");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
727 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
728 query.addBindValue(value);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
729 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
730 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
731 if (!slCheckAndReportSQLError("addTransaction()", query.lastError()))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
732 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
733 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
734 return -2;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
735 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
736
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
737 query.prepare("UPDATE people SET updated=? WHERE id=?");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
738 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
739 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
740 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
741 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError()))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
742 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
743 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
744 return -3;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
745 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
746
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
747 QSqlDatabase::database().commit();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
748
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
749 return 0;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
750 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
751
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
753 int SyntilistaMainWindow::addTransactionGUI(qint64 id, bool debt, double value)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
754 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
755 PersonInfo info;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
756
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
757 // Check if person is selected
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
758 if (id <= 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
759 return -1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
761 // Check value
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
762 if (value == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
763 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
764 QString tmp = (debt ? "lisätty" : "vähennetty");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
765 statusMsg("Velkaa ei "+ tmp +" koska summaa ei määritetty.");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
766 return 1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
767 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
769 // Perform transaction insert
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
770 int ret = addTransaction(id, debt ? -value : value, info);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
771 if (ret == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
772 {
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
773 // 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
774 ui->edit_Amount->clear();
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
775 if (info.id == currPerson.id)
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
776 setActivePerson(info.id);
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
777
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
778 model_People->updateModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 QString str;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 if (debt)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 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
784 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
785 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
786 arg(info.lastName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
787 arg(info.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 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
792 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
793 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
794 arg(info.lastName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
795 arg(info.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 statusMsg(str);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
799 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
800 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
801 slErrorMsg(
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
802 tr("SQL-tietokantavirhe"),
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
803 tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
804 arg(ret));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 }
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
806
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
807 return ret;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 void SyntilistaMainWindow::on_button_AddDebt_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
813 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
814 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
817 void SyntilistaMainWindow::on_button_PayDebt_clicked()
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
819 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
820 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
822
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
823 void SyntilistaMainWindow::on_button_PayFullDebt_clicked()
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
824 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
825 if (currPerson.balance < 0)
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
826 addTransactionGUI(currPerson.id, false, -currPerson.balance);
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
827 else
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
828 {
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
829 statusMsg(
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
830 tr("Valitulla henkilöllä '%1, %2' ei ole velkaa.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
831 arg(currPerson.lastName).
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
832 arg(currPerson.firstName));
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
833 }
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
834 }
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
835
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
836
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838 // Edit person dialog
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 EditPerson::EditPerson(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841 QDialog(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 ui(new Ui::EditPerson)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 ui->setupUi(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
846 setCommonStyleSheet(this);
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
847
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848 setModal(true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 setAttribute(Qt::WA_DeleteOnClose);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850 show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851 activateWindow();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 raise();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 model_Transactions = new TransactionSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 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
858 ui->tableview_Transactions->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860
113
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
861 ui->edit_FirstName->setMaxLength(SQL_MAX_FIRST_NAME);
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
862 ui->edit_LastName->setMaxLength(SQL_MAX_LAST_NAME);
907f2ddf6801 Use #defines for SQL table field lengths.
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
863
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
866
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
868 EditPerson::~EditPerson()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
869 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 delete model_Transactions;
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
875 void EditPerson::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
877 dynamic_cast<SyntilistaMainWindow *>(parent())->statusMsg(msg);
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
880
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
881 bool EditPerson::validateForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
882 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
883 selPerson.firstName = slCleanupStr(ui->edit_FirstName->text());
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
884 selPerson.lastName = slCleanupStr(ui->edit_LastName->text());
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
885 selPerson.extraInfo = ui->textedit_ExtraInfo->document()->toPlainText();
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
886
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
887 ui->edit_FirstName->setStyleSheet(selPerson.firstName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
888 ui->edit_LastName->setStyleSheet(selPerson.lastName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
889
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
890 return selPerson.firstName != "" && selPerson.lastName != "";
0
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
893
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
894 void EditPerson::on_button_Cancel_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
896 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
897 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
898
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
899
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
900 void EditPerson::on_button_OK_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
901 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
902 if (!validateForm())
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
903 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
904 slErrorMsg(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
905 tr("Virhe!"),
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
906 tr("Vaaditut kentät (etunimi, sukunimi) eivät ole täytetty."));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
907
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
908 return;
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
909 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
910
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
911 if (selPerson.id >= 0)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
912 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
913 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
914 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
915 person.addBindValue(selPerson.id);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
916 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
917 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
918 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
919
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
920 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
921
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
922 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
923 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
924 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
925 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
926 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
927 arg(selPerson.firstName).arg(selPerson.lastName));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
929 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
930
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
931 dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->updatePerson(selPerson);
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
932 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
933
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934 statusMsg(tr("Päivitettiin henkilö '%1 %2' (#%3).").
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
935 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
936 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
937 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
938 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
939 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
940 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
941 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
942 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
943 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
944
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
945 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
946
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
947 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
949 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
950 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
951 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
952 arg(selPerson.firstName).arg(selPerson.lastName));
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
953
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
954 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
955 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
956
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
957 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
958 if (nid < 0)
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
959 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
960 slErrorMsg(
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
961 tr("Virhe!"),
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
962 tr("Tietokannan käsittelyssä tapahtui virhe (#%1).").
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
963 arg(nid));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
964 }
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
965 else
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
966 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
967 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
968 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
969 dynamic_cast<SyntilistaMainWindow *>(parent())->focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
971 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
972 arg(selPerson.firstName).arg(selPerson.lastName));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
973 }
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
976 close();
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
979
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
980 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
981 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
982 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
985
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
986
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
987 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
988 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
990 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 void EditPerson::clearForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
995 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
996 ui->edit_FirstName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
997 ui->edit_LastName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998 ui->textedit_ExtraInfo->document()->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
999 ui->edit_FirstName->setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1000 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1001
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1003 void EditPerson::setPerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1004 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1005 selPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1006
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1007 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1008 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1009 PersonInfo pinfo;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
1010 if (!slGetPersonInfo(id, pinfo))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1011 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1012 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(id));
104
1997cc07a7ae Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
1013 // Intentional fall-through below
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1014 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1015 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1016 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1017 ui->edit_FirstName->setText(pinfo.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1018 ui->edit_LastName->setText(pinfo.lastName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1019 ui->textedit_ExtraInfo->document()->setPlainText(pinfo.extraInfo);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1020
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1021 QSqlQuery query;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1022 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
1023 query.addBindValue(pinfo.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1024 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1025 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
1026
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027 model_Transactions->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1029 model_Transactions->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1030 model_Transactions->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1031 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
1032
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1033 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034 ui->tableview_Transactions->setColumnHidden(0, true);
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 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1037 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1038 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1039
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1040 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1041 clearForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1042 ui->tableview_Transactions->setModel(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043 }
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 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1047 // Custom SQL models
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1048 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1049 PersonSQLModel::PersonSQLModel(QObject *parent) : QSqlQueryModel(parent)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1050 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1051 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1052
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1053
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1054 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
1055 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1056 QVariant value = QSqlQueryModel::data(index, role);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1057
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1058 if (value.isValid() && role == Qt::DisplayRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1060 switch (index.column())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1061 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1062 case 3:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1063 return slMoneyValueToStr(value.toDouble());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1064
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1065 case 4:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1066 return slDateTimeToStr(value.toDateTime());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1067 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1068 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1069
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1070 if (index.column() == 3 && role == Qt::ForegroundRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1071 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1072 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
1073 if (val < 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1074 return QVariant::fromValue(QColor(Qt::red));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1075 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076 return QVariant::fromValue(QColor(Qt::green));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1077 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1078
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1079 return value;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1080 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1081
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1082
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1083 int PersonSQLModel::updatePerson(const PersonInfo &info)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1084 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1085 QSqlQuery np;
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1086
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1087 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
1088 np.addBindValue(info.firstName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1089 np.addBindValue(info.lastName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1090 np.addBindValue(info.extraInfo);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1091 np.addBindValue(QDateTime::currentDateTimeUtc());
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1092 np.addBindValue(info.id);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1093 np.exec();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1094
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1095 if (!slCheckAndReportSQLError("PersonSQLModel::updatePerson()", np.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1096 return -1;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1097
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1098 QSqlDatabase::database().commit();
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1099
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1100 updateModel();
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1101 return 0;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1102 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1103
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1104
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1105 qint64 PersonSQLModel::addPerson(const PersonInfo &info)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1106 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1107 // beginInsertRows(QModelIndex(), rowCount(), rowCount());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1108
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1109 QSqlQuery np;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1110 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
1111 np.addBindValue(info.firstName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1112 np.addBindValue(info.lastName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1113 np.addBindValue(info.extraInfo);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1114 np.addBindValue(QDateTime::currentDateTimeUtc());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1115 np.addBindValue(QDateTime::currentDateTimeUtc());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1116 np.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1117
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1118 if (!slCheckAndReportSQLError("PersonSQLModel::addPerson()", np.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1119 return -1;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1120
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1121 QSqlDatabase::database().commit();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1122
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1123 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
1124
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1125 // endInsertRows();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1126 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
1127 return idp.isValid() ? idp.toInt() : -2;
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1128 }
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1129
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1130
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1131 int PersonSQLModel::deletePerson(qint64 id)
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1132 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1133 QSqlDatabase::database().transaction();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1134 QSqlQuery del;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1135
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1136 del.prepare("DELETE FROM people WHERE id=?");
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1137 del.addBindValue(id);
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1138 del.exec();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1139
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1140 if (!slCheckAndReportSQLError("delete user", del.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1141 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1142 QSqlDatabase::database().rollback();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1143 return -1;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1144 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1145
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1146 del.prepare("DELETE FROM transactions WHERE person=?");
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1147 del.addBindValue(id);
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1148 del.exec();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1149
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1150 if (!slCheckAndReportSQLError("delete user transactions", del.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1151 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1152 QSqlDatabase::database().rollback();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1153 return -2;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1154 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1155
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1156 QSqlDatabase::database().commit();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1157 updateModel();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1158 return 0;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1159 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1160
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1161
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1162 void PersonSQLModel::updateModel()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1163 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1164 query().exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1165 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
1166 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1167
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1168
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1169 TransactionSQLModel::TransactionSQLModel(QObject *parent) : QSqlQueryModel(parent)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1170 {
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
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 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
1175 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1176 QVariant value = QSqlQueryModel::data(index, role);
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 if (value.isValid() && role == Qt::DisplayRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1179 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1180 switch (index.column())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1181 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1182 case 1:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1183 return slMoneyValueToStr(value.toDouble());
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1184
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1185 case 2:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1186 return slDateTimeToStr(value.toDateTime());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1187 }
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1190 if (index.column() == 1 && role == Qt::ForegroundRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1191 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1192 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
1193 if (val < 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1194 return QVariant::fromValue(QColor(Qt::red));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1195 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1196 return QVariant::fromValue(QColor(Qt::green));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1197 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1198
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1199 return value;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1200 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1201
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1202
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1203 void TransactionSQLModel::updateModel()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1204 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1205 query().exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1206 emit dataChanged(QModelIndex(), QModelIndex());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1207 }
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1208
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1209
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1210 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1211 // About window
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1212 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1213 AboutWindow::AboutWindow(QWidget *parent) :
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1214 QDialog(parent),
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1215 ui(new Ui::AboutWindow)
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1216 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1217 ui->setupUi(this);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1218
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1219 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
1220 ui->label_Logo->setAlignment(Qt::AlignCenter);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1221
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1222 ui->label_About->setWordWrap(true);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1223 ui->label_About->setTextFormat(Qt::RichText);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1224 ui->label_About->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1225 "<h1>%1 v%2</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1226 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1227 "<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
1228 "(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
1229 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1230 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1231 "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
1232 "alaisuudessa Café Kampuksen käyttöön."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1233 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1234 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1235 "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
1236 "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
1237 "nähdäksesi täydelliset lisenssiehdot."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1238 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1239 ).
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1240 arg(tr(APP_NAME)).
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1241 arg(APP_VERSION)
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1242 );
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1243
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1244 ui->label_ShortCuts->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1245 "<h1>Pikanäppäimet</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1246 "<table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1247 "<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
1248 "<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
1249 "<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
1250 "<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
1251 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1252 "<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
1253 "<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
1254 "<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
1255 "<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
1256 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1257 "<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
1258 "<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
1259 "<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
1260 "</table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1261 ));
95
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1262
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1263 // setCommonStyleSheet(this);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1264 setModal(true);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1265 setAttribute(Qt::WA_DeleteOnClose);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1266 show();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1267 activateWindow();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1268 raise();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1269 setFocus();
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1270 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1271
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1272
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1273 AboutWindow::~AboutWindow()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1274 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1275 delete ui;
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1276 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1277
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1278
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1279 void AboutWindow::on_button_Close_clicked()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1280 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1281 close();
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1282 }