annotate src/main.cpp @ 122:f0db8267911b

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