annotate src/main.cpp @ 112:2524434a7193

Cosmetics.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 04 Jul 2017 12:43:43 +0300
parents ec01c5b0eaa8
children 907f2ddf6801
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, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
221 "first_name VARCHAR(128) NOT NULL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
222 "last_name VARCHAR(128) NOT NULL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
223 "extra_info VARCHAR(2048), "
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, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
225 "updated DATETIME NOT NULL)"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
227 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
228 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
44
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
230 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
231 {
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
232 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
233 "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
234 "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
235 "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
236 "value REAL, "
8fb2230fe860 Do not attempt to create the SQL tables if they already exist.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
237 "added DATETIME NOT NULL)"));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
239 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
240 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 SyntilistaMainWindow swin;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 swin.show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 return sapp.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
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 // Main application window code
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 SyntilistaMainWindow::SyntilistaMainWindow(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 QMainWindow(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 ui(new Ui::SyntilistaMainWindow)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 {
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
255 // Setup UI
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 ui->setupUi(this);
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
257
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
258 // Read config
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
259 readSettings();
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 // Setup other UI things
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
262 setWindowIcon(QIcon(QPixmap(":/img/icon-64.png")));
64
73fd86778014 Version number display etc. changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
263 setWindowTitle(tr("%1 versio %3").
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
264 arg(tr(APP_NAME)).
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
265 arg(tr(APP_VERSION)));
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
266
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
267 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
268 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
269 ui->button_LogoImage->setAlignment(Qt::AlignCenter);
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
270
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
271 setCommonStyleSheet(this);
22
c23241a3e160 UI polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
272
68
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
273 // Validator for amount input
597bf29c5898 Use a better validator (regexp) for the amount input field.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
274 //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
275 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
276 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
277
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
278 // Setup person list filtering and sorting
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 peopleSortIndex = 1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 peopleSortOrder = Qt::AscendingOrder;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 peopleFilter = "";
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 model_People = new PersonSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 updatePersonList();
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 ui->tableview_People->setModel(model_People);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 ui->tableview_People->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 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
289 ui->tableview_People->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 ui->tableview_People->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 ui->tableview_People->setSortingEnabled(true);
25
a7e746642599 Fix initial sorting.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
292 ui->tableview_People->sortByColumn(peopleSortIndex, peopleSortOrder);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
294 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
295 ui->tableview_People->selectionModel(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
297 this,
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
298 SLOT(selectedPersonChanged(const QModelIndex &, const QModelIndex &)));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
10
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
300 connect(
0b291bd77de5 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
301 ui->tableview_People->horizontalHeader(),
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 this,
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 SLOT(updateSortOrder(int, Qt::SortOrder)));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 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
307
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 model_Latest = new TransactionSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 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
311 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 setActivePerson(-1);
17
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
315
d40345d63733 Implement some keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 16
diff changeset
316 // Keyboard shortcuts
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
317 ui->button_Quit->setShortcut(QKeySequence(Qt::Key_F10));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
318 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
319
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
320 ui->button_AddPerson->setShortcut(QKeySequence(Qt::Key_F5));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
321 ui->button_DeletePerson->setShortcut(QKeySequence(Qt::Key_F8));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
322 ui->button_EditPerson->setShortcut(QKeySequence(Qt::Key_F6));
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
323 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
324 ui->button_About->setShortcut(QKeySequence(Qt::Key_F1));
63
fc633e7c83a9 Improve keyboard shortcuts.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
325
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
326 new QShortcut(QKeySequence(QKeySequence::ZoomIn), this, SLOT(changeUIZoomIn()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
327 new QShortcut(QKeySequence(QKeySequence::ZoomOut), this, SLOT(changeUIZoomOut()));
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
328 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
329 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
330 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
331 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
332
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
333 new QShortcut(QKeySequence(Qt::Key_PageUp), this, SLOT(selectRowPrev()));
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
334 new QShortcut(QKeySequence(Qt::Key_PageDown), this, SLOT(selectRowNext()));
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::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
337 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
340 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
341 // Application main window destructor
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
342 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 SyntilistaMainWindow::~SyntilistaMainWindow()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 {
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
345 // Save current settings and free resources
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 saveSettings();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 delete model_People;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 delete model_Latest;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
354 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
355 // Helper function for showing messages in the statusbar/line
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
356 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 void SyntilistaMainWindow::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 ui->statusbar->showMessage(msg);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 void SyntilistaMainWindow::readSettings()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 {
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
365 QSettings settings(APP_VENDOR, APP_ID);
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
366
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
367 // Restore window size and position
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 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
369 resize(settings.value("size", QSize(1000, 600)).toSize());
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
370
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
371 // Other settings
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
372 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
373 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 void SyntilistaMainWindow::saveSettings()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377 {
39
2cc7c89ab649 Version information, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
378 QSettings settings(APP_VENDOR, APP_ID);
97
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
379
65ffedde7dec Comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
380 // Save window size and position
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 settings.setValue("pos", pos());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 settings.setValue("size", size());
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
383 settings.setValue("scale", setScale);
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
384 }
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
385
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
386
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
387 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
388 // Window scale / zoom changing
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
389 //
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
390 void SyntilistaMainWindow::changeUIZoomIn()
34
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
391 {
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
392 setScale += 0.1f;
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
393 setCommonStyleSheet(this);
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
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
396
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
397 void SyntilistaMainWindow::changeUIZoomOut()
34
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 setScale -= 0.1f;
87f098892804 Make the UI scale with undocumented hotkeys.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
400 setCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403
46
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
404 void SyntilistaMainWindow::changeUIZoomReset()
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
405 {
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
406 setScale = 1.0f;
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
407 setCommonStyleSheet(this);
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
372c1be58996 Improve shortcuts functionality a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
410
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
411 //
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
412 // Slot for changed selection of person entry
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
413 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 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
415 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 (void) prev;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 if (row >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 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
422 focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 setActivePerson(-1);
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 void SyntilistaMainWindow::setActivePerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
431 currPerson.id = id;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
1
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
433 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
434
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
437 if (!slGetPersonInfo(id, currPerson))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
438 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
439 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
440 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 ui->personGB->setEnabled(true);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
444 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
445
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
446 ui->label_BalanceValue->setText(slMoneyValueToStr(currPerson.balance));
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
447 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
448 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
449
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 QSqlQuery query;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 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
452 query.addBindValue(id);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
454 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
455
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 model_Latest->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
458 model_Latest->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
459 model_Latest->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
460 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
461
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 ui->tableview_Latest->setModel(model_Latest);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 ui->tableview_Latest->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 ui->tableview_Latest->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 ui->tableview_Latest->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
467 setCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 ui->personGB->setEnabled(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 ui->edit_Amount->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 ui->label_BalanceValue->setText("--");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 ui->label_BalanceValue->setStyleSheet(NULL);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 ui->label_PersonName->setText("???");
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 ui->tableview_Latest->setModel(NULL);
40
d565867f2b0b UI visual improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
479 setCommonStyleSheet(this);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
484 // 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
485 //
98
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
486 void SyntilistaMainWindow::updateSortOrder(int index, Qt::SortOrder order)
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
487 {
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
488 peopleSortIndex = index;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
489 peopleSortOrder = order;
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
490 updatePersonList();
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
491 }
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
492
3baea5b17dc9 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
493
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 void SyntilistaMainWindow::on_button_Quit_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 }
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
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
500 void SyntilistaMainWindow::on_button_About_clicked()
47
08c0d5116e82 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
501 {
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
502 new AboutWindow(this);
74
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
503 }
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
504
cc8fbf9a61b2 Add a help dialog.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
505
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
506 void SyntilistaMainWindow::on_button_DeletePerson_clicked()
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
507 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
508 if (currPerson.id <= 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
509 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
510 statusMsg(tr("Ei valittua henkilöä!"));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
511 return;
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
512 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
513
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
514 PersonInfo info;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
515 if (!slGetPersonInfo(currPerson.id, info))
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
516 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
517 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
518 return;
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
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
521 QMessageBox dlg;
71
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
522 setCommonStyleSheet(&dlg);
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
523 dlg.setText(tr("Varmistus"));
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
524 dlg.setInformativeText(
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
525 tr("<br>Haluatko varmasti poistaa henkilön:<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
526 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
527 "<b>'%1, %2'</b> <i>(ID #%3)</i>?<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
528 "<br>"
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
529 "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
530 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
531
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
532 dlg.setTextFormat(Qt::RichText);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
533 dlg.setIcon(QMessageBox::Question);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
534 dlg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
71
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
535 dlg.setButtonText(QMessageBox::Yes, tr("Kyllä"));
2d12c12a7b89 More UI improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
536 dlg.setButtonText(QMessageBox::No, tr("Ei / peruuta"));
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
537 dlg.setDefaultButton(QMessageBox::No);
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
538
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
539 if (dlg.exec() == QMessageBox::Yes)
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
540 {
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
541 int rv = model_People->deletePerson(info.id);
14
Matti Hamalainen <ccr@tnsp.org>
parents: 13
diff changeset
542 updatePersonList();
24
0e0948aec438 De-select active person when deleting.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
543 setActivePerson(-1);
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
544 if (rv != 0)
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
545 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
546 slErrorMsg(tr("SQL-tietokantavirhe"),
6
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
547 tr("Henkilön tietoja poistettaessa tapahtui virhe #%1.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
548 arg(rv));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
549 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
550 else
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
551 {
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
552 statusMsg(tr("Henkilö '%1 %2' (ID #%3) poistettu.").
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
553 arg(info.firstName).arg(info.lastName).
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
554 arg(info.id));
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
555 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
556 }
0315a3b9f560 Implement person and transaction history deletion.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
557 }
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
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 void SyntilistaMainWindow::on_button_AddPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 EditPerson *person = new EditPerson(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563 person->setPerson(-1);
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 void SyntilistaMainWindow::on_button_EditPerson_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
569 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
570 {
db8f47446713 Disable the edit person push button when no person is selected.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
571 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
572 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
573 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 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
578 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 int row = curr.row();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 if (row >= 0)
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 const QAbstractItemModel *model = curr.model();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 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
584
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 EditPerson *person = new EditPerson(this);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
586 person->setPerson(currPerson.id);
0
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 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 setActivePerson(-1);
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 void SyntilistaMainWindow::on_button_ClearFilter_clicked()
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 ui->edit_PersonFilter->clear();
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
596 ui->edit_PersonFilter->setFocus(Qt::ShortcutFocusReason);
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
597 }
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
598
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
599
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
600 void SyntilistaMainWindow::focusDebtEdit()
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 if (currPerson.id >= 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
603 ui->edit_Amount->setFocus(Qt::ShortcutFocusReason);
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
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
606
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
607 void SyntilistaMainWindow::selectRowPrev()
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 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
610 int row = sel->currentIndex().row() - 1;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
611 if (row < 0)
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
612 row = 0;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
613
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
614 sel->setCurrentIndex(model_People->index(row, 0),
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
615 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
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
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
618
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
619 void SyntilistaMainWindow::selectRowNext()
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 QItemSelectionModel *sel = ui->tableview_People->selectionModel();
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
622 int row = sel->currentIndex().row() + 1;
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
623 if (row >= model_People->rowCount())
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
624 row = model_People->rowCount() - 1;
112
2524434a7193 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
625
65
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
626 sel->setCurrentIndex(model_People->index(row, 0),
f9a1d33ed4a8 Add more keyboard controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
627 QItemSelectionModel::ClearAndSelect|QItemSelectionModel::Rows);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
631 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
632 // Update visible person list/query based on the current
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
633 // filtering and sorting settings.
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
634 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
635 void SyntilistaMainWindow::updatePersonList()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
636 {
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
637 static QString queryBase =
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
638 "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
639 "(SELECT TOTAL(value) FROM transactions WHERE transactions.person=people.id) AS balance,"
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
640 "updated FROM people";
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
641
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
642 QSqlQuery query;
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
643 QString queryOrderDir, queryOrderBy;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
645 // Sort order
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 if (peopleSortOrder == Qt::AscendingOrder)
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
647 queryOrderDir = QStringLiteral("ASC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 else
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
649 queryOrderDir = QStringLiteral("DESC");
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
651 // Sort by which column
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 switch (peopleSortIndex)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
653 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 case 1:
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655 case 2:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
656 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
657 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
658
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 case 3:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
660 queryOrderBy = QStringLiteral(" ORDER BY balance ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 break;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 case 4:
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
664 queryOrderBy = QStringLiteral(" ORDER BY updated ") + queryOrderDir;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 break;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
666
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
667 default:
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
668 queryOrderBy = "";
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
671 // Are we filtering or not?
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
672 if (peopleFilter != "")
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 // Filter by name(s)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 QString tmp = "%"+ peopleFilter +"%";
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
676 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
677
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 query.addBindValue(tmp);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679 query.addBindValue(tmp);
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 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
682 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
683 // No filter
16
8765397e45f4 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
684 query.prepare(queryBase + queryOrderBy);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
687 // Execute the query and update model
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
688 slCheckAndReportSQLError("updatePersonList() before exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
690 slCheckAndReportSQLError("updatePersonList() after exec", query.lastError());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 model_People->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
694 model_People->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
695 model_People->setHeaderData(1, Qt::Horizontal, tr("Sukunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
696 model_People->setHeaderData(2, Qt::Horizontal, tr("Etunimi"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
697 model_People->setHeaderData(3, Qt::Horizontal, tr("Tase"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
698 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
699 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
702 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
703 // Update the list of people when filter parameter changes
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
704 //
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 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
706 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
707 peopleFilter = slCleanupStr(str);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 updatePersonList();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
712 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
713 // Add one transaction to given person id
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
714 //
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
715 int SyntilistaMainWindow::addTransaction(qint64 id, double value, PersonInfo &info)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
716 {
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
717 if (!slGetPersonInfo(id, info))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
718 return -1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
719
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
720 QSqlDatabase::database().transaction();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
721
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
722 QSqlQuery query;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
723 query.prepare("INSERT INTO transactions (person,value,added) VALUES (?,?,?)");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
724 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
725 query.addBindValue(value);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
726 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
727 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
728 if (!slCheckAndReportSQLError("addTransaction()", query.lastError()))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 {
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
730 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
731 return -2;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
732 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
733
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
734 query.prepare("UPDATE people SET updated=? WHERE id=?");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
735 query.addBindValue(QDateTime::currentDateTimeUtc());
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
736 query.addBindValue(id);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
737 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
738 if (!slCheckAndReportSQLError("addTransaction update timestamp", query.lastError()))
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
739 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
740 QSqlDatabase::database().rollback();
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
741 return -3;
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
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
744 QSqlDatabase::database().commit();
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 return 0;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
747 }
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
748
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
750 int SyntilistaMainWindow::addTransactionGUI(qint64 id, bool debt, double value)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
751 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
752 PersonInfo info;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
753
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
754 // Check if person is selected
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
755 if (id <= 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
756 return -1;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
758 // Check value
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
759 if (value == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
760 {
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
761 QString tmp = (debt ? "lisätty" : "vähennetty");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
762 statusMsg("Velkaa ei "+ tmp +" koska summaa ei määritetty.");
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
763 return 1;
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
764 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
765
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
766 // Perform transaction insert
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
767 int ret = addTransaction(id, debt ? -value : value, info);
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
768 if (ret == 0)
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
769 {
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
770 // 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
771 ui->edit_Amount->clear();
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
772 if (info.id == currPerson.id)
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
773 setActivePerson(info.id);
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
774
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
775 model_People->updateModel();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 QString str;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 if (debt)
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 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
781 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
782 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
783 arg(info.lastName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
784 arg(info.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 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
789 arg(slMoneyValueToStr(value)).
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
790 arg(info.firstName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
791 arg(info.lastName).
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
792 arg(info.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 statusMsg(str);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
798 slErrorMsg(
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
799 tr("SQL-tietokantavirhe"),
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
800 tr("Tietokantaan tapahtumaa lisättäessa tapahtui virhe #%1.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
801 arg(ret));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802 }
4
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
803
f2404a9987dc Cleaning up the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
804 return ret;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 void SyntilistaMainWindow::on_button_AddDebt_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
810 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
811 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
814 void SyntilistaMainWindow::on_button_PayDebt_clicked()
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
816 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
817 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
820 void SyntilistaMainWindow::on_button_PayFullDebt_clicked()
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
821 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
822 if (currPerson.balance < 0)
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
823 addTransactionGUI(currPerson.id, false, -currPerson.balance);
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
824 else
8
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
825 {
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
826 statusMsg(
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
827 tr("Valitulla henkilöllä '%1, %2' ei ole velkaa.").
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
828 arg(currPerson.lastName).
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
829 arg(currPerson.firstName));
466d89a2a629 More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
830 }
2
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
831 }
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
832
edc1e8cf6e2c Implement "pay debt in full" button.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
833
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
834 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 // Edit person dialog
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837 EditPerson::EditPerson(QWidget *parent) :
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838 QDialog(parent),
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 ui(new Ui::EditPerson)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841 ui->setupUi(this);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842
32
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
843 setCommonStyleSheet(this);
7fd15537b12d Commonize stylesheet code.
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
844
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 setModal(true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
846 setAttribute(Qt::WA_DeleteOnClose);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
847 show();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848 activateWindow();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849 raise();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850 setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
851
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 model_Transactions = new TransactionSQLModel();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
854 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
855 ui->tableview_Transactions->verticalHeader()->setVisible(false);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
856 ui->tableview_Transactions->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 validateForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
859 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862 EditPerson::~EditPerson()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 delete ui;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865 delete model_Transactions;
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
869 void EditPerson::statusMsg(const QString &msg)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
871 dynamic_cast<SyntilistaMainWindow *>(parent())->statusMsg(msg);
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 bool EditPerson::validateForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
876 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
877 selPerson.firstName = slCleanupStr(ui->edit_FirstName->text());
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
878 selPerson.lastName = slCleanupStr(ui->edit_LastName->text());
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
879 selPerson.extraInfo = ui->textedit_ExtraInfo->document()->toPlainText();
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
880
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
881 ui->edit_FirstName->setStyleSheet(selPerson.firstName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
882 ui->edit_LastName->setStyleSheet(selPerson.lastName == "" ? "background-color: red;" : NULL);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
883
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
884 return selPerson.firstName != "" && selPerson.lastName != "";
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
885 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
886
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
887
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
888 void EditPerson::on_button_Cancel_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
889 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
890 close();
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_OK_clicked()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
895 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
896 if (!validateForm())
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
897 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
898 slErrorMsg(
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
899 tr("Virhe!"),
18
8282142605e0 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
900 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
901
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
902 return;
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
903 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
904
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
905 if (selPerson.id >= 0)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
906 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
907 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
908 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
909 person.addBindValue(selPerson.id);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
910 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
911 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
912 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
913
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
914 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
915
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
916 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
917 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
918 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
919 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
920 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
921 arg(selPerson.firstName).arg(selPerson.lastName));
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
922 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
923 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
924
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
925 dynamic_cast<SyntilistaMainWindow *>(parent())->model_People->updatePerson(selPerson);
12
07db1a0bbdc7 More cleanups, fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
926 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
927
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
928 statusMsg(tr("Päivitettiin henkilö '%1 %2' (#%3).").
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
929 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
930 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
931 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
932 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
933 QSqlQuery person;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
934 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
935 person.addBindValue(selPerson.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
936 person.addBindValue(selPerson.lastName);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
937 person.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
938
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
939 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
940
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
941 if (person.next())
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
942 {
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
943 slErrorMsg(
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
944 tr("Virhe!"),
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
945 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
946 arg(selPerson.firstName).arg(selPerson.lastName));
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
947
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
948 return;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
949 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
950
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
951 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
952 if (nid < 0)
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
953 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
954 slErrorMsg(
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
955 tr("Virhe!"),
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
956 tr("Tietokannan käsittelyssä tapahtui virhe (#%1).").
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
957 arg(nid));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
958 }
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
959 else
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
960 {
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
961 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
962 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
963 dynamic_cast<SyntilistaMainWindow *>(parent())->focusDebtEdit();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
964
110
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
965 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
966 arg(selPerson.firstName).arg(selPerson.lastName));
7a3e9d4c9b71 Improve error handling when adding new persons.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
967 }
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
968 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
969
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
970 close();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
971 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
972
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
973
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
974 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
975 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
976 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
977 validateForm();
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
981 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
982 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
983 (void) arg1;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984 validateForm();
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
988 void EditPerson::clearForm()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
989 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
990 ui->edit_FirstName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 ui->edit_LastName->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992 ui->textedit_ExtraInfo->document()->clear();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993 ui->edit_FirstName->setFocus();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
995
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
996
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
997 void EditPerson::setPerson(qint64 id)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
998 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
999 selPerson.id = id;
0
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 if (id >= 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1003 PersonInfo pinfo;
102
064138b6d34e Rename getPersonInfo*() to slGetPersonInfo*().
Matti Hamalainen <ccr@tnsp.org>
parents: 101
diff changeset
1004 if (!slGetPersonInfo(id, pinfo))
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1005 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1006 statusMsg(tr("Virhe! Ei henkilöä ID:llä #%1").arg(id));
104
1997cc07a7ae Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
1007 // Intentional fall-through below
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1008 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1009 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1010 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1011 ui->edit_FirstName->setText(pinfo.firstName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1012 ui->edit_LastName->setText(pinfo.lastName);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1013 ui->textedit_ExtraInfo->document()->setPlainText(pinfo.extraInfo);
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1014
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1015 QSqlQuery query;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1016 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
1017 query.addBindValue(pinfo.id);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1018 query.exec();
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1019 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
1020
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1021 model_Transactions->setQuery(query);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1022
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1023 model_Transactions->setHeaderData(0, Qt::Horizontal, tr("ID"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1024 model_Transactions->setHeaderData(1, Qt::Horizontal, tr("Summa"));
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1025 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
1026
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1027 ui->tableview_Transactions->setModel(model_Transactions);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028 ui->tableview_Transactions->setColumnHidden(0, true);
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1029
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1030 return; // Ugly
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1031 }
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1034 // In case of id < 0 or errors ..
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1035 clearForm();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1036 ui->tableview_Transactions->setModel(NULL);
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 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1041 // Custom SQL models
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1042 //
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1043 PersonSQLModel::PersonSQLModel(QObject *parent) : QSqlQueryModel(parent)
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1048 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
1049 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1050 QVariant value = QSqlQueryModel::data(index, role);
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 if (value.isValid() && role == Qt::DisplayRole)
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 switch (index.column())
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 case 3:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1057 return slMoneyValueToStr(value.toDouble());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1058
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059 case 4:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1060 return slDateTimeToStr(value.toDateTime());
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1061 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1062 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1063
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1064 if (index.column() == 3 && role == Qt::ForegroundRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1065 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1066 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
1067 if (val < 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1068 return QVariant::fromValue(QColor(Qt::red));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1069 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1070 return QVariant::fromValue(QColor(Qt::green));
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1073 return value;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1074 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1075
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1076
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1077 int PersonSQLModel::updatePerson(const PersonInfo &info)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1078 {
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1079 QSqlQuery np;
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1080
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1081 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
1082 np.addBindValue(info.firstName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1083 np.addBindValue(info.lastName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1084 np.addBindValue(info.extraInfo);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1085 np.addBindValue(QDateTime::currentDateTimeUtc());
11
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1086 np.addBindValue(info.id);
5
a5a3baee3043 More cleanups and fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
1087 np.exec();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1088
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1089 if (!slCheckAndReportSQLError("PersonSQLModel::updatePerson()", np.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1090 return -1;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1091
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1092 QSqlDatabase::database().commit();
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1093
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1094 updateModel();
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1095 return 0;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1096 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1097
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1098
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1099 qint64 PersonSQLModel::addPerson(const PersonInfo &info)
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1100 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1101 // beginInsertRows(QModelIndex(), rowCount(), rowCount());
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 QSqlQuery np;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1104 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
1105 np.addBindValue(info.firstName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1106 np.addBindValue(info.lastName);
4e8a960e3975 More cleanups, better error dialogs.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
1107 np.addBindValue(info.extraInfo);
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1108 np.addBindValue(QDateTime::currentDateTimeUtc());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1109 np.addBindValue(QDateTime::currentDateTimeUtc());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1110 np.exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1111
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1112 if (!slCheckAndReportSQLError("PersonSQLModel::addPerson()", np.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1113 return -1;
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1114
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1115 QSqlDatabase::database().commit();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1116
109
62e570222f66 Return inserted person ID from addPerson() (or negative value in case of errors.)
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
1117 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
1118
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1119 // endInsertRows();
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1120 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
1121 return idp.isValid() ? idp.toInt() : -2;
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1122 }
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1123
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1124
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1125 int PersonSQLModel::deletePerson(qint64 id)
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1126 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1127 QSqlDatabase::database().transaction();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1128 QSqlQuery del;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1129
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1130 del.prepare("DELETE FROM people WHERE id=?");
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1131 del.addBindValue(id);
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1132 del.exec();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1133
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1134 if (!slCheckAndReportSQLError("delete user", del.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1135 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1136 QSqlDatabase::database().rollback();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1137 return -1;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1138 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1139
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1140 del.prepare("DELETE FROM transactions WHERE person=?");
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1141 del.addBindValue(id);
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1142 del.exec();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1143
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1144 if (!slCheckAndReportSQLError("delete user transactions", del.lastError()))
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1145 {
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1146 QSqlDatabase::database().rollback();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1147 return -2;
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1148 }
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1149
13
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1150 QSqlDatabase::database().commit();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1151 updateModel();
ca5ce74c0563 Refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
1152 return 0;
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1153 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1154
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1155
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1156 void PersonSQLModel::updateModel()
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1157 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1158 query().exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1159 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
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1163 TransactionSQLModel::TransactionSQLModel(QObject *parent) : QSqlQueryModel(parent)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1164 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1165 }
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 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
1169 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1170 QVariant value = QSqlQueryModel::data(index, role);
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 if (value.isValid() && role == Qt::DisplayRole)
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 switch (index.column())
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 case 1:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1177 return slMoneyValueToStr(value.toDouble());
19
2ee61a6b78f8 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
1178
0
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1179 case 2:
99
7b8755801111 Rename some utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1180 return slDateTimeToStr(value.toDateTime());
0
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 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1183
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1184 if (index.column() == 1 && role == Qt::ForegroundRole)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1185 {
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1186 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
1187 if (val < 0)
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1188 return QVariant::fromValue(QColor(Qt::red));
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1189 else
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1190 return QVariant::fromValue(QColor(Qt::green));
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
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1193 return value;
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1194 }
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1195
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1196
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1197 void TransactionSQLModel::updateModel()
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 query().exec();
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1200 emit dataChanged(QModelIndex(), QModelIndex());
fec4d0c461f2 Initial import of the post-prototyping phase code.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1201 }
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1202
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1203
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1204 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1205 // About window
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1206 //
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1207 AboutWindow::AboutWindow(QWidget *parent) :
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1208 QDialog(parent),
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1209 ui(new Ui::AboutWindow)
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 ui->setupUi(this);
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 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
1214 ui->label_Logo->setAlignment(Qt::AlignCenter);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1215
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1216 ui->label_About->setWordWrap(true);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1217 ui->label_About->setTextFormat(Qt::RichText);
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1218 ui->label_About->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1219 "<h1>%1 v%2</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1220 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1221 "<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
1222 "(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
1223 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1224 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1225 "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
1226 "alaisuudessa Café Kampuksen käyttöön."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1227 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1228 "<p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1229 "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
1230 "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
1231 "nähdäksesi täydelliset lisenssiehdot."
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1232 "</p>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1233 ).
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1234 arg(tr(APP_NAME)).
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1235 arg(APP_VERSION)
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1236 );
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1237
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1238 ui->label_ShortCuts->setText(tr(
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1239 "<h1>Pikanäppäimet</h1>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1240 "<table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1241 "<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
1242 "<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
1243 "<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
1244 "<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
1245 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1246 "<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
1247 "<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
1248 "<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
1249 "<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
1250 "<tr></tr>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1251 "<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
1252 "<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
1253 "<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
1254 "</table>"
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1255 ));
95
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1256
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1257 // setCommonStyleSheet(this);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1258 setModal(true);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1259 setAttribute(Qt::WA_DeleteOnClose);
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1260 show();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1261 activateWindow();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1262 raise();
fb5227b415e6 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1263 setFocus();
90
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1264 }
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1265
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1266
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1267 AboutWindow::~AboutWindow()
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1268 {
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1269 delete ui;
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 void AboutWindow::on_button_Close_clicked()
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 close();
efab68769c75 Implement new separate About dialog/help window.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
1276 }