-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbview2.cpp
279 lines (217 loc) · 7.58 KB
/
dbview2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
*
* qenes genealogy software
*
* Copyright (C) 2009-2010 Ari Tähti
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License veasion 2 as
* published by the Free Software Foundation.
*/
#include "dbview2.h"
#include <QDebug>
#include "mainwindow.h"
#include <QSettings>
#include "macro.h"
extern GeneData * geneData;
extern QSettings sets;
int DbView2::getId()
{
int id;
if ( !this->uiTableView2->selectionModel()->selection().isEmpty() ) {
QModelIndex qmi = proxyModel->mapToSource(this->uiTableView2->selectionModel()->selection().indexes().at(0));
id = qmi.row();
} else id = 0;
return id;
}
void DbView2::slotGoTo()
{
int id = getId();
this->done(id);
}
void DbView2::slotSearch(QString search)
{
proxyModel->setFilterRegExp(QRegExp(QRegExp(search, Qt::CaseInsensitive, QRegExp::FixedString)));
this->slotUpdate();
}
void DbView2::slotUpdate()
{
personModel->slotUpdate();
}
DbView2::DbView2(Date dateLimits, bool male, bool female, QWidget *parent) : QDialog(parent)
{
showFemales = female;
showMales = male;
setFont(GeneData::panelFont);
setup(dateLimits);
//setup(dateLimits, male, female);
}
DbView2::DbView2(QWidget *parent) : QDialog(parent)
{
Date date;
date.setDate1(GET_ALLMINDAY);
date.setDate2(GET_ALLMAXDAY);
this->setup(date);
//this->setup(date, true, true);
}
bool DbView2::acceptRow(int sourceRow)
{
QString nameSearch = this->uiSearch2->text();
if (INDI(sourceRow).deleted) return false;
if (!showFemales && INDI(sourceRow).sex == FEMALE ) return false;
if (!showMales && INDI(sourceRow).sex == MALE ) return false;
if ( !( ( INDI(sourceRow).estimatedBirth.day1 >= dateMin && INDI(sourceRow).estimatedBirth.day1 <= dateMax )
|| ( INDI(sourceRow).estimatedBirth.day2 >= dateMin && INDI(sourceRow).estimatedBirth.day2 <= dateMax ) ) )
return false;
if (nameSearch == "" ) return true;
if ( INDI(sourceRow).nameFirst.contains(nameSearch)
|| (INDI(sourceRow).name2nd.contains(nameSearch))
|| (INDI(sourceRow).name3rd.contains(nameSearch))
|| (INDI(sourceRow).nameFamily.contains(nameSearch)) ) return true;
return false;
}
void DbView2::slotClose()
{
INDI(GENE.currentId).selectNone();
close();
}
void DbView2::updateBegin()
{
this->personModel->updateBegin();
}
void DbView2::slotSelection()
{
INDI(GENE.currentId).selectNone();
}
void DbView2::slotDateChanged()
{
dateMin = uiDateMin2->date();
dateMax = uiDateMax2->date();
slotUpdate();
}
void DbView2::setup(Date dateLimits)
{
setupUi(this);
connect(uiExit2, SIGNAL(clicked()), this, SLOT(slotClose()));
// create a person view model and install it
personModel = new PersonTableModel2(this);
proxyModel = new MyProxyModel2(personModel, this);
proxyModel->setSourceModel(personModel);
uiTableView2->setModel(proxyModel);
uiTableView2->setColumnWidth(0, 80); // familyname
uiTableView2->setColumnWidth(1, 100); // first name
uiTableView2->setColumnWidth(2, 200); // birthday
for (quint16 i=1 ; i<=GENE.indiLastUsed+1 ; i++) idList.append(i);
proxyModel->setFilterKeyColumn(0);
proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
// connect signals & slots
connect(uiSearch2, SIGNAL(textChanged(QString)), this, SLOT(updateBegin()));
connect(uiSearch2, SIGNAL(textChanged(QString)), this, SLOT(slotSearch(QString)));
connect(uiGoTo2, SIGNAL(clicked()), this, SLOT(slotGoTo()));
connect(uiDateMin2, SIGNAL(dateChanged(QDate)), this, SLOT(updateBegin()));
connect(uiDateMin2, SIGNAL(dateChanged(QDate)), this, SLOT(slotDateChanged()));
connect(uiDateMax2, SIGNAL(dateChanged(QDate)), this, SLOT(updateBegin()));
connect(uiDateMax2, SIGNAL(dateChanged(QDate)), this, SLOT(slotDateChanged()));
uiDateMin2->setMinimumDate(GET_ALLMINDAY);
uiDateMin2->setMaximumDate(GET_ALLMAXDAY);
uiDateMax2->setMinimumDate(GET_ALLMINDAY);
uiDateMax2->setMaximumDate(GET_ALLMAXDAY);
uiDateMin2->setDate(dateLimits.day1);
uiDateMax2->setDate(dateLimits.day2);
slotUpdate(); //tämä jossain tapauksessa kaataa softan eikä näköjään edes tarvita, miksi tää oli tässä?
}
// -----------------------------------------------------------------------------------------------------------
int PersonTableModel2::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
const int tmp = GENE.indiLastUsed + 1;
return tmp;
}
int PersonTableModel2::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 3;
}
QVariant PersonTableModel2::data(const QModelIndex &index, int role) const
{
int row = index.row();
QVariant result;
result = QVariant();
if (index.isValid()) {
if ( role == Qt::BackgroundColorRole ) {
if (INDI(row).sex == FEMALE ) {
if (INDI(row).selected) result = ( QColor(255, 240, 240));
else result = ( QColor(255, 199, 199) );
}
if (INDI(row).sex == MALE ) {
if (INDI(row).selected) result = ( QColor(240, 240, 255));
else result = ( QColor(199, 199, 225) );
}
if (INDI(row).sex == UNKNOWN) {
if (INDI(row).selected) result = ( QColor(240, 240, 240));
else result = ( QColor(180, 180, 180) );
}
}
if ( role == Qt::TextAlignmentRole ) { result = ( Qt::AlignLeft ) ; }
if ( role == Qt::DisplayRole ) {
if (index.column() == 0) result = INDI(row).nameFamily;
if (index.column() == 1) result = INDI(row).nameFirst;
if (index.column() == 2) result = INDI(row).estimatedBirth.toString(true);
}
}
return result;
}
bool PersonTableModel2::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (index.isValid() && role == Qt::EditRole) {
int row = index.row();
int column = index.column();
if ( column == 0 ) INDI(row).nameFamily = value.toString();
if ( column == 1 ) INDI(row).nameFirst = value.toString();
emit(dataChanged(index, index));
return true;
}
return false;
}
void PersonTableModel2::updateBegin()
{
emit(this->layoutAboutToBeChanged());
}
void PersonTableModel2::slotUpdate()
{
this->layoutChanged();
}
QModelIndex PersonTableModel2::index( int row, int column, const QModelIndex & parent ) const
{
Q_UNUSED(parent);
return this->createIndex(row, column, row);
}
Qt::ItemFlags PersonTableModel2::flags(const QModelIndex &index) const
{
if (!index.isValid()) return Qt::ItemIsEnabled;
return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable;
}
QVariant PersonTableModel2::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole) return QVariant();
if (orientation == Qt::Horizontal) {
switch (section) {
case 0: return "Family Name";
case 1: return "First Name";
case 2: return "Birth Day";
default:
return QVariant();
}
}
if (orientation == Qt::Vertical) {
return section;
}
return QVariant();
}
// --------------------------------------------------------------------------------------------------------
bool MyProxyModel2::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
Q_UNUSED(sourceParent);
// sourcerow equals to id-number of the individual
return p->acceptRow(sourceRow);
}