-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdjann.cpp
248 lines (203 loc) · 6.76 KB
/
tdjann.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
/*
The Daily Journal - A PIM program
Qt version
begin : 12 July 2013
copyright : (C) Kartik Patel
email : letapk@gmail.com
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*/
//Last modified 19 June 2022
#include "tdj.h"
extern int get_month_int (QString s);
extern Anniversary anniversary[];
int anniversary_compare (const void *a, const void *b);
void MainWindow::fill_anniversary_items ()
{
int i, days;
QDate *date;
date = new QDate (calendar->yearShown(), calendar->monthShown(), 1);
days = date->daysInYear();
for (i = 0; i < days; i++){
anncol0[i].setText (anniversary[i+1].month);
anncol1[i].setText (anniversary[i+1].date);
anncol2[i].setText (anniversary[i+1].description);
}
}
void MainWindow::sort_anniversaries (void)
{
if (max_anniversaries > 0)
qsort (&(anniversary[1]), max_anniversaries, sizeof (Anniversary), anniversary_compare);
}
int anniversary_compare (const void *a, const void *b)
{
int idate, imonth;
int jdate, jmonth;
Anniversary *c, *d;
c = (Anniversary *) a;
d = (Anniversary *) b;
//find out the integer month in which the holiday falls
imonth = get_month_int (c->month);
if (imonth == 0)
return 0;
jmonth = get_month_int (d->month);
if (imonth < jmonth)
return -1;
if (imonth > jmonth)
return 1;
//if the months are the same, check the date
if (imonth == jmonth) {
idate = c->date.toInt();
jdate = d->date.toInt();
if (idate < jdate)
return -1;
if (idate == jdate)
return 0;
if (idate > jdate)
return 1;
}
return 0;
}
void MainWindow::get_anniversary_items ()
{
int i = 0, j, row, days;
//QString s;
QDate *date;
date = new QDate (calendar->yearShown(), calendar->monthShown(), 1);
days = date->daysInYear();
for (i = 1; i < 367; i++) {
anniversary[i].date.clear();
anniversary[i].month.clear();
anniversary[i].description.clear();
}
//table rows run from 0 onwards
//but are numbered from 1 onwards on the screen
j = 1;
for (row = 0; row < days; row++) {
//s.clear();
i = anncol2[row].text().length();
if (i != 0) {//something to save
anniversary[j].month = anncol0[row].text();
anniversary[j].date = anncol1[row].text();
anniversary[j].description = anncol2[row].text();
j++;
i = 0;
}
}
}
void MainWindow::save_ann_cell (QTableWidgetItem *it)
{
int row, col;
QString s;
row = anntable->currentRow();
col = anntable->currentColumn();
if (col == -1 || row == -1)
return;
s.clear();
s = it->text();
if (s.size() != 0) {//something in the cell
if (col == 0) {
anncol0[row].setText(s);
s.clear();
}
if (col == 1){
anncol1[row].setText(s);
s.clear();
}
if (col == 2) {
anncol2[row].setText(it->text());
s.clear();
}
}
}
ComboBoxItemDelegate::ComboBoxItemDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
ComboBoxItemDelegate::~ComboBoxItemDelegate()
{
}
QWidget* ComboBoxItemDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
QDate d;
// Create the combobox
QComboBox *cb = new QComboBox(parent);
if(index.column() == 0) {
//populate it
cb->addItem(QString (tr("")));
cb->addItem(QString(tr("January")));
cb->addItem(QString(tr("February")));
cb->addItem(QString(tr("March")));
cb->addItem(QString(tr("April")));
cb->addItem(QString(tr("May")));
cb->addItem(QString(tr("June")));
cb->addItem(QString(tr("July")));
cb->addItem(QString(tr("August")));
cb->addItem(QString(tr("September")));
cb->addItem(QString(tr("October")));
cb->addItem(QString(tr("November")));
cb->addItem(QString(tr("December")));
}
if(index.column() == 1) {
cb->addItem(QString(tr("")));
cb->addItem(QString(tr("1")));
cb->addItem(QString(tr("2")));
cb->addItem(QString(tr("3")));
cb->addItem(QString(tr("4")));
cb->addItem(QString(tr("5")));
cb->addItem(QString(tr("6")));
cb->addItem(QString(tr("7")));
cb->addItem(QString(tr("8")));
cb->addItem(QString(tr("9")));
cb->addItem(QString(tr("10")));
cb->addItem(QString(tr("11")));
cb->addItem(QString(tr("12")));
cb->addItem(QString(tr("13")));
cb->addItem(QString(tr("14")));
cb->addItem(QString(tr("15")));
cb->addItem(QString(tr("16")));
cb->addItem(QString(tr("17")));
cb->addItem(QString(tr("18")));
cb->addItem(QString(tr("19")));
cb->addItem(QString(tr("20")));
cb->addItem(QString(tr("21")));
cb->addItem(QString(tr("22")));
cb->addItem(QString(tr("23")));
cb->addItem(QString(tr("24")));
cb->addItem(QString(tr("25")));
cb->addItem(QString(tr("26")));
cb->addItem(QString(tr("27")));
cb->addItem(QString(tr("28")));
cb->addItem(QString(tr("29")));
cb->addItem(QString(tr("30")));
cb->addItem(QString(tr("31")));
}
if(index.column() == 2)
return QStyledItemDelegate::createEditor(parent, option, index);
return cb;
}
void ComboBoxItemDelegate::setEditorData ( QWidget *editor, const QModelIndex &index ) const
{
if(QComboBox *cb = qobject_cast<QComboBox *>(editor)) {
// get the index of the text in the combobox that matches the current value of the item
QString currentText = index.data(Qt::EditRole).toString();
int cbIndex = cb->findText(currentText);
// if it is valid, adjust the combobox
if(cbIndex >= 0)
cb->setCurrentIndex(cbIndex);
} else {
QStyledItemDelegate::setEditorData(editor, index);
}
}
void ComboBoxItemDelegate::setModelData ( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
if(QComboBox *cb = qobject_cast<QComboBox *>(editor))
// save the current text of the combo box as the current value of the item
model->setData(index, cb->currentText(), Qt::EditRole);
else
QStyledItemDelegate::setModelData(editor, model, index);
}