| 134 |
david |
1 |
#include "qmdisqualified.h"
|
| 272 |
david |
2 |
#include "consts.h"
|
|
|
3 |
#include "structs.h"
|
|
|
4 |
#include "proto.h"
|
| 190 |
- |
5 |
#include <QHeaderView>
|
| 272 |
david |
6 |
#include <QLabel>
|
|
|
7 |
#include <QGroupBox>
|
|
|
8 |
#include "mainwindow.h"
|
| 134 |
david |
9 |
|
|
|
10 |
qmDisqualified::qmDisqualified(QWidget *parent) :
|
| 190 |
- |
11 |
QWidget(parent)
|
|
|
12 |
|
| 134 |
david |
13 |
{
|
| 191 |
david |
14 |
inPopulate = false;
|
|
|
15 |
dirty = true;
|
| 190 |
- |
16 |
resize ( 600,400);
|
| 134 |
david |
17 |
|
| 190 |
- |
18 |
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
|
|
|
19 |
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
20 |
|
|
|
21 |
QGroupBox *groupBox = new QGroupBox("Disqualified and Non Equestrian");
|
|
|
22 |
verticalLayout->addWidget(groupBox);
|
|
|
23 |
|
|
|
24 |
QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
|
|
|
25 |
|
|
|
26 |
tableWidget = new QTableWidget(groupBox);
|
|
|
27 |
tableWidget->setObjectName(QString::fromUtf8("tableWidget"));
|
|
|
28 |
//tableWidget->setGeometry(QRect(10, 20, 501, 421));
|
|
|
29 |
tableWidget->setAlternatingRowColors(true);
|
|
|
30 |
tableWidget->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
|
|
|
31 |
tableWidget->verticalHeader()->setDefaultSectionSize(20);
|
|
|
32 |
tableWidget->verticalHeader()->setProperty("showSortIndicator", QVariant(false));
|
|
|
33 |
verticalLayout2->addWidget(tableWidget);
|
|
|
34 |
|
| 272 |
david |
35 |
QHBoxLayout *horizontalLayout;
|
|
|
36 |
horizontalLayout = new QHBoxLayout();
|
|
|
37 |
horizontalLayout->setContentsMargins(0, 0, 0, 5);
|
|
|
38 |
|
|
|
39 |
QGroupBox *groupBox2 = new QGroupBox("Bulk Set");
|
|
|
40 |
verticalLayout2->addLayout(horizontalLayout);
|
|
|
41 |
horizontalLayout->addWidget(groupBox2);
|
|
|
42 |
|
|
|
43 |
QHBoxLayout *horizontalLayout1;
|
|
|
44 |
QSpacerItem *horizontalSpacer1;
|
|
|
45 |
|
|
|
46 |
horizontalLayout1 = new QHBoxLayout();
|
|
|
47 |
horizontalLayout1->setContentsMargins(5, 5, 5, 5);
|
|
|
48 |
groupBox2->setLayout(horizontalLayout1);
|
| 275 |
david |
49 |
groupBox2->setToolTip("Set or clear one or more attributes for the specified team."
|
|
|
50 |
"\nThe attributes have three states: Set,Clear and Do Nothing."
|
|
|
51 |
"\nSelect the required attributes to change. Enter the team number"
|
|
|
52 |
"\nand use 'Set' or <Return> to Set/Clear the selected attributes.");
|
| 272 |
david |
53 |
|
|
|
54 |
cb_disq = new QCheckBox("Disq");
|
|
|
55 |
cb_disq->setTristate(true);
|
|
|
56 |
horizontalLayout1->addWidget(cb_disq);
|
|
|
57 |
|
|
|
58 |
cb_ne = new QCheckBox("Non Equest");
|
|
|
59 |
cb_ne->setTristate(true);
|
|
|
60 |
horizontalLayout1->addWidget(cb_ne);
|
|
|
61 |
|
|
|
62 |
cb_enable = new QCheckBox("Enable");
|
|
|
63 |
cb_enable->setTristate(true);
|
|
|
64 |
horizontalLayout1->addWidget(cb_enable);
|
|
|
65 |
|
|
|
66 |
cb_vetcheck = new QCheckBox("Vet Check");
|
|
|
67 |
cb_vetcheck->setTristate(true);
|
|
|
68 |
horizontalLayout1->addWidget(cb_vetcheck);
|
|
|
69 |
|
|
|
70 |
horizontalLayout1->addWidget(new QLabel("Team"));
|
| 273 |
david |
71 |
teamNumber = new QmTeamSelector();
|
| 272 |
david |
72 |
horizontalLayout1->addWidget(teamNumber);
|
|
|
73 |
|
|
|
74 |
setButton = new QPushButton("Set");
|
|
|
75 |
horizontalLayout1->addWidget(setButton);
|
|
|
76 |
|
|
|
77 |
horizontalSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
| 279 |
david |
78 |
horizontalLayout->addItem(horizontalSpacer1);
|
| 272 |
david |
79 |
|
| 190 |
- |
80 |
buttonBox = new QDialogButtonBox();
|
| 191 |
david |
81 |
pb_restore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
|
|
|
82 |
pb_save = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
|
| 272 |
david |
83 |
horizontalLayout->addWidget(buttonBox);
|
| 190 |
- |
84 |
|
| 191 |
david |
85 |
connect(pb_save, SIGNAL(clicked()), this, SLOT(save()) );
|
|
|
86 |
connect(pb_restore, SIGNAL(clicked()), this, SLOT(cancel()) );
|
| 272 |
david |
87 |
connect(setButton, SIGNAL(clicked()), this, SLOT(bulk_set()) );
|
| 273 |
david |
88 |
connect(teamNumber,SIGNAL(teamSelected()), this, SLOT(bulk_set()) );
|
| 275 |
david |
89 |
connect(teamNumber, SIGNAL(valueChanged(int)), this, SLOT(center_display(int)));
|
| 190 |
- |
90 |
connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
|
| 191 |
david |
91 |
updateChanged (false);
|
| 134 |
david |
92 |
}
|
|
|
93 |
|
|
|
94 |
qmDisqualified::~qmDisqualified()
|
|
|
95 |
{
|
| 190 |
- |
96 |
|
| 134 |
david |
97 |
}
|
|
|
98 |
|
|
|
99 |
void qmDisqualified::save(void)
|
|
|
100 |
{
|
| 136 |
- |
101 |
team_type team_buf;
|
| 190 |
- |
102 |
for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
|
| 136 |
- |
103 |
{
|
|
|
104 |
QTableWidgetItem *item;
|
| 190 |
- |
105 |
item = tableWidget->item(ii, 0);
|
| 136 |
- |
106 |
if ( item )
|
|
|
107 |
{
|
|
|
108 |
if ( item->data(Qt::UserRole + 1).toBool() )
|
|
|
109 |
{
|
|
|
110 |
int team = item->data(Qt::EditRole).toInt();
|
|
|
111 |
if ( team )
|
|
|
112 |
{
|
| 314 |
david |
113 |
//qDebug("Detected change:%d", team);
|
| 136 |
- |
114 |
g_record( team, &team_buf );
|
|
|
115 |
|
| 190 |
- |
116 |
item = tableWidget->item(ii,2);
|
| 136 |
- |
117 |
team_buf.flags.disqualified = ( item->checkState () == Qt::Checked);
|
|
|
118 |
|
| 190 |
- |
119 |
item = tableWidget->item(ii,3);
|
| 136 |
- |
120 |
team_buf.flags.non_equestrian = ( item->checkState () == Qt::Checked);
|
|
|
121 |
|
| 190 |
- |
122 |
item = tableWidget->item(ii,4);
|
| 136 |
- |
123 |
team_buf.flags.valid = ( item->checkState () == Qt::Checked);
|
|
|
124 |
|
| 225 |
- |
125 |
item = tableWidget->item(ii,5);
|
|
|
126 |
team_buf.flags.vet_check = ( item->checkState () == Qt::Checked);
|
|
|
127 |
|
| 136 |
- |
128 |
put_team_record( team, &team_buf );
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
populate();
|
|
|
134 |
|
| 134 |
david |
135 |
}
|
|
|
136 |
|
|
|
137 |
void qmDisqualified::cancel(void)
|
|
|
138 |
{
|
|
|
139 |
populate();
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
void qmDisqualified::populate(void)
|
|
|
143 |
{
|
|
|
144 |
team_type team_buf;
|
|
|
145 |
inPopulate = TRUE;
|
|
|
146 |
|
|
|
147 |
/*
|
|
|
148 |
** Delete existing entries in the table
|
|
|
149 |
*/
|
| 190 |
- |
150 |
tableWidget->clearContents();
|
| 224 |
- |
151 |
tableWidget->setRowCount(config.max_team+1);
|
| 225 |
- |
152 |
tableWidget->setColumnCount(7);
|
| 190 |
- |
153 |
tableWidget->setSortingEnabled(FALSE);
|
| 134 |
david |
154 |
|
|
|
155 |
/*
|
|
|
156 |
** Scan all the team data
|
|
|
157 |
*/
|
|
|
158 |
for ( int team = config.min_team; team <= config.max_team; team++)
|
|
|
159 |
{
|
| 190 |
- |
160 |
tableWidget->hideRow ( team );
|
| 134 |
david |
161 |
if( valid_field( team ) )
|
|
|
162 |
{
|
|
|
163 |
g_record( team, &team_buf );
|
| 136 |
- |
164 |
if( team_buf.flags.valid || true )
|
| 134 |
david |
165 |
{
|
| 178 |
- |
166 |
qmDisqualifiedItem *item;
|
| 134 |
david |
167 |
|
| 190 |
- |
168 |
tableWidget->showRow( team );
|
| 134 |
david |
169 |
|
| 178 |
- |
170 |
item = new qmDisqualifiedItem(team);
|
| 136 |
- |
171 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 190 |
- |
172 |
tableWidget->setItem(team, 0, item );
|
| 134 |
david |
173 |
|
| 178 |
- |
174 |
item = new qmDisqualifiedItem(team_buf.name);
|
| 136 |
- |
175 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 190 |
- |
176 |
tableWidget->setItem(team, 1, item );
|
| 134 |
david |
177 |
|
| 190 |
- |
178 |
tableWidget->setItem(team, 2, new qmDisqualifiedItem("Disq", team_buf.flags.disqualified, team) );
|
|
|
179 |
tableWidget->setItem(team, 3, new qmDisqualifiedItem("Non Equest",team_buf.flags.non_equestrian,team) );
|
|
|
180 |
tableWidget->setItem(team, 4, new qmDisqualifiedItem("Enable", team_buf.flags.valid,team) );
|
| 225 |
- |
181 |
tableWidget->setItem(team, 5, new qmDisqualifiedItem("VetCheck", team_buf.flags.vet_check,team) );
|
| 189 |
- |
182 |
|
|
|
183 |
item = new qmDisqualifiedItem("Bad Times", team_buf.flags.bad_times);
|
|
|
184 |
item->setFlags(Qt::ItemIsSelectable/* | Qt::ItemIsEnabled*/);
|
| 225 |
- |
185 |
tableWidget->setItem(team, 6, item );
|
| 134 |
david |
186 |
}
|
|
|
187 |
}
|
|
|
188 |
}
|
| 190 |
- |
189 |
tableWidget->sortByColumn(0,Qt::AscendingOrder);
|
|
|
190 |
tableWidget->setSortingEnabled(TRUE);
|
|
|
191 |
tableWidget->resizeColumnsToContents();
|
| 178 |
- |
192 |
|
| 272 |
david |
193 |
/*
|
|
|
194 |
** Init the bulk_set checkboxes to tristate
|
|
|
195 |
*/
|
|
|
196 |
cb_disq->setCheckState(Qt::PartiallyChecked);
|
|
|
197 |
cb_enable->setCheckState(Qt::PartiallyChecked);
|
|
|
198 |
cb_ne->setCheckState(Qt::PartiallyChecked);
|
|
|
199 |
cb_vetcheck->setCheckState(Qt::PartiallyChecked);
|
|
|
200 |
|
|
|
201 |
teamNumber->setMaximum(config.max_team);
|
|
|
202 |
teamNumber->setMinimum(config.min_team);
|
|
|
203 |
|
| 134 |
david |
204 |
inPopulate = FALSE;
|
| 191 |
david |
205 |
updateChanged(false);
|
| 134 |
david |
206 |
}
|
|
|
207 |
|
|
|
208 |
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
|
|
|
209 |
{
|
|
|
210 |
if ( !inPopulate )
|
|
|
211 |
{
|
| 136 |
- |
212 |
if ( item->column() )
|
|
|
213 |
{
|
| 314 |
david |
214 |
//qDebug ("DataChanged");
|
| 136 |
- |
215 |
item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
|
|
|
216 |
|
|
|
217 |
// Mark first item in row to help detect changes
|
|
|
218 |
int row = item->row();
|
|
|
219 |
item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
|
| 191 |
david |
220 |
item->tableWidget()->item(row,0)->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
|
| 136 |
- |
221 |
}
|
| 191 |
david |
222 |
|
|
|
223 |
updateChanged(true);
|
| 134 |
david |
224 |
}
|
|
|
225 |
}
|
| 178 |
- |
226 |
|
| 191 |
david |
227 |
void qmDisqualified::updateChanged(bool newDirty)
|
|
|
228 |
{
|
|
|
229 |
if (newDirty != dirty)
|
|
|
230 |
{
|
|
|
231 |
dirty = newDirty;
|
|
|
232 |
if (dirty)
|
|
|
233 |
{
|
|
|
234 |
pb_save->setEnabled(true);
|
|
|
235 |
pb_save->setStyleSheet("background-color: rgb(255, 0, 0);");
|
|
|
236 |
}
|
|
|
237 |
else
|
|
|
238 |
{
|
|
|
239 |
pb_save->setEnabled(false);
|
|
|
240 |
pb_save->setStyleSheet("");
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
}
|
|
|
244 |
|
|
|
245 |
void qmDisqualified::showEvent ( QShowEvent * event )
|
|
|
246 |
{
|
| 314 |
david |
247 |
//qDebug("qmDisqualified::showEvent");
|
| 191 |
david |
248 |
if ( ! event->spontaneous() && !dirty )
|
|
|
249 |
{
|
|
|
250 |
populate();
|
|
|
251 |
}
|
|
|
252 |
}
|
|
|
253 |
|
| 272 |
david |
254 |
/*----------------------------------------------------------------------------
|
|
|
255 |
** FUNCTION : bulk_set
|
|
|
256 |
**
|
|
|
257 |
** DESCRIPTION : Set multiple attributes on the current team
|
|
|
258 |
**
|
|
|
259 |
**
|
|
|
260 |
** INPUTS : Nothing
|
|
|
261 |
**
|
|
|
262 |
** RETURNS : Nothing
|
|
|
263 |
**
|
|
|
264 |
----------------------------------------------------------------------------*/
|
|
|
265 |
|
|
|
266 |
void qmDisqualified::bulk_set(void)
|
|
|
267 |
{
|
|
|
268 |
bool team_found = FALSE;
|
|
|
269 |
bool item_set = FALSE;
|
|
|
270 |
|
|
|
271 |
//qDebug("qmDisqualified::bulk_set:%d", teamNumber->value());
|
|
|
272 |
for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
|
|
|
273 |
{
|
|
|
274 |
QTableWidgetItem *item;
|
|
|
275 |
item = tableWidget->item(ii, 0);
|
|
|
276 |
if ( item )
|
|
|
277 |
{
|
|
|
278 |
int team = item->data(Qt::EditRole).toInt();
|
|
|
279 |
if ( team && team == teamNumber->value() )
|
|
|
280 |
{
|
|
|
281 |
tableWidget->scrollToItem(item,QAbstractItemView::PositionAtCenter);
|
|
|
282 |
//qDebug("Found Entry:%d", team);
|
|
|
283 |
|
|
|
284 |
enum Qt::CheckState state;
|
|
|
285 |
state = cb_disq->checkState();
|
|
|
286 |
if (state != Qt::PartiallyChecked)
|
|
|
287 |
{
|
|
|
288 |
item = tableWidget->item(ii,2);
|
|
|
289 |
item->setCheckState(state);
|
|
|
290 |
item_set = TRUE;
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
state = cb_ne->checkState();
|
|
|
294 |
if (state != Qt::PartiallyChecked)
|
|
|
295 |
{
|
|
|
296 |
item = tableWidget->item(ii,3);
|
|
|
297 |
item->setCheckState(state);
|
|
|
298 |
item_set = TRUE;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
state = cb_enable->checkState();
|
|
|
302 |
if (state != Qt::PartiallyChecked)
|
|
|
303 |
{
|
|
|
304 |
item = tableWidget->item(ii,4);
|
|
|
305 |
item->setCheckState(state);
|
|
|
306 |
item_set = TRUE;
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
state = cb_vetcheck->checkState();
|
|
|
310 |
if (state != Qt::PartiallyChecked)
|
|
|
311 |
{
|
|
|
312 |
item = tableWidget->item(ii,5);
|
|
|
313 |
item->setCheckState(state);
|
|
|
314 |
item_set = TRUE;
|
|
|
315 |
}
|
|
|
316 |
team_found = TRUE;
|
|
|
317 |
break;
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
/*
|
|
|
323 |
** Report to user
|
|
|
324 |
*/
|
|
|
325 |
if ( team_found)
|
|
|
326 |
{
|
|
|
327 |
if (item_set )
|
|
|
328 |
MainWindow::showMessage("Values set");
|
|
|
329 |
else
|
|
|
330 |
MainWindow::showMessage("Nothing selected to set");
|
|
|
331 |
}
|
|
|
332 |
else
|
|
|
333 |
{
|
|
|
334 |
MainWindow::showMessage("Team not found");
|
|
|
335 |
}
|
|
|
336 |
}
|
|
|
337 |
|
| 275 |
david |
338 |
/*----------------------------------------------------------------------------
|
|
|
339 |
** FUNCTION : center_display
|
|
|
340 |
**
|
|
|
341 |
** DESCRIPTION : Place the specified team in the center of the display
|
|
|
342 |
** If not found then place close item in display
|
|
|
343 |
**
|
|
|
344 |
**
|
|
|
345 |
** INPUTS : teamNumber
|
|
|
346 |
**
|
|
|
347 |
** RETURNS : Nothing
|
|
|
348 |
**
|
|
|
349 |
----------------------------------------------------------------------------*/
|
| 272 |
david |
350 |
|
| 275 |
david |
351 |
void qmDisqualified::center_display(int teamNumber)
|
|
|
352 |
{
|
|
|
353 |
QTableWidgetItem *item = NULL;
|
|
|
354 |
for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
|
|
|
355 |
{
|
|
|
356 |
item = tableWidget->item(ii, 0);
|
|
|
357 |
if ( item )
|
|
|
358 |
{
|
|
|
359 |
int team = item->data(Qt::EditRole).toInt();
|
|
|
360 |
if ( team && team >= teamNumber )
|
|
|
361 |
{
|
|
|
362 |
break;
|
|
|
363 |
}
|
|
|
364 |
}
|
|
|
365 |
}
|
|
|
366 |
if ( item )
|
|
|
367 |
{
|
|
|
368 |
tableWidget->scrollToItem(item,QAbstractItemView::PositionAtCenter);
|
|
|
369 |
}
|
|
|
370 |
}
|
|
|
371 |
|
| 178 |
- |
372 |
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
|
|
|
373 |
{
|
|
|
374 |
number = 0;
|
|
|
375 |
}
|
|
|
376 |
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) : QTableWidgetItem(type+QTableWidgetItem::UserType)
|
|
|
377 |
{
|
|
|
378 |
number = value;
|
|
|
379 |
setData(0,value);
|
|
|
380 |
}
|
|
|
381 |
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, bool checked, int num, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
|
|
|
382 |
{
|
|
|
383 |
setCheckState(checked ? Qt::Checked : Qt::Unchecked);
|
|
|
384 |
number = num;
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
// Special sorting, based on type
|
|
|
388 |
// type == 0 : Text
|
|
|
389 |
// type == 1 : Number
|
|
|
390 |
// type == 2 : Checked
|
|
|
391 |
//
|
|
|
392 |
bool qmDisqualifiedItem::operator< ( const QTableWidgetItem & other ) const
|
|
|
393 |
{
|
|
|
394 |
const qmDisqualifiedItem * other_widget = dynamic_cast<const qmDisqualifiedItem*>(&other);
|
|
|
395 |
if (other_widget && other_widget->type() == QTableWidgetItem::UserType + 2 )
|
|
|
396 |
{
|
|
|
397 |
if (other_widget->checkState() == checkState() )
|
|
|
398 |
{
|
|
|
399 |
// qDebug ("Same(%d): %d : %d", other_widget->number < number, other_widget->number, number);
|
|
|
400 |
if (this->tableWidget()->horizontalHeader()->sortIndicatorOrder() != Qt::AscendingOrder )
|
|
|
401 |
{
|
|
|
402 |
return other_widget->number < number;
|
|
|
403 |
}
|
|
|
404 |
else
|
|
|
405 |
{
|
|
|
406 |
return number < other_widget->number;
|
|
|
407 |
}
|
|
|
408 |
}
|
|
|
409 |
return (other_widget->checkState() < checkState() );
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
return ( QTableWidgetItem::operator< (other) );
|
|
|
413 |
}
|
| 272 |
david |
414 |
|
|
|
415 |
|