| 134 |
david |
1 |
#include "qmdisqualified.h"
|
|
|
2 |
#include "consts.h"
|
|
|
3 |
#include "structs.h"
|
|
|
4 |
#include "proto.h"
|
| 190 |
- |
5 |
#include <QHeaderView>
|
| 191 |
david |
6 |
#include <QPushButton>
|
| 134 |
david |
7 |
|
|
|
8 |
qmDisqualified::qmDisqualified(QWidget *parent) :
|
| 190 |
- |
9 |
QWidget(parent)
|
|
|
10 |
|
| 134 |
david |
11 |
{
|
| 191 |
david |
12 |
inPopulate = false;
|
|
|
13 |
dirty = true;
|
| 190 |
- |
14 |
resize ( 600,400);
|
| 134 |
david |
15 |
|
| 190 |
- |
16 |
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
|
|
|
17 |
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
18 |
|
|
|
19 |
QGroupBox *groupBox = new QGroupBox("Disqualified and Non Equestrian");
|
|
|
20 |
verticalLayout->addWidget(groupBox);
|
|
|
21 |
|
|
|
22 |
QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
|
|
|
23 |
|
|
|
24 |
tableWidget = new QTableWidget(groupBox);
|
|
|
25 |
tableWidget->setObjectName(QString::fromUtf8("tableWidget"));
|
|
|
26 |
//tableWidget->setGeometry(QRect(10, 20, 501, 421));
|
|
|
27 |
tableWidget->setAlternatingRowColors(true);
|
|
|
28 |
tableWidget->horizontalHeader()->setProperty("showSortIndicator", QVariant(true));
|
|
|
29 |
tableWidget->verticalHeader()->setDefaultSectionSize(20);
|
|
|
30 |
tableWidget->verticalHeader()->setProperty("showSortIndicator", QVariant(false));
|
|
|
31 |
verticalLayout2->addWidget(tableWidget);
|
|
|
32 |
|
|
|
33 |
buttonBox = new QDialogButtonBox();
|
| 191 |
david |
34 |
pb_restore = buttonBox->addButton("Restore",QDialogButtonBox::ActionRole );
|
|
|
35 |
pb_save = buttonBox->addButton("Save",QDialogButtonBox::ActionRole );
|
| 190 |
- |
36 |
verticalLayout->addWidget(buttonBox);
|
|
|
37 |
|
| 191 |
david |
38 |
connect(pb_save, SIGNAL(clicked()), this, SLOT(save()) );
|
|
|
39 |
connect(pb_restore, SIGNAL(clicked()), this, SLOT(cancel()) );
|
| 190 |
- |
40 |
connect(tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
|
| 191 |
david |
41 |
updateChanged (false);
|
| 134 |
david |
42 |
}
|
|
|
43 |
|
|
|
44 |
qmDisqualified::~qmDisqualified()
|
|
|
45 |
{
|
| 190 |
- |
46 |
|
| 134 |
david |
47 |
}
|
|
|
48 |
|
|
|
49 |
void qmDisqualified::save(void)
|
|
|
50 |
{
|
| 136 |
- |
51 |
team_type team_buf;
|
| 190 |
- |
52 |
for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
|
| 136 |
- |
53 |
{
|
|
|
54 |
QTableWidgetItem *item;
|
| 190 |
- |
55 |
item = tableWidget->item(ii, 0);
|
| 136 |
- |
56 |
if ( item )
|
|
|
57 |
{
|
|
|
58 |
if ( item->data(Qt::UserRole + 1).toBool() )
|
|
|
59 |
{
|
|
|
60 |
int team = item->data(Qt::EditRole).toInt();
|
|
|
61 |
if ( team )
|
|
|
62 |
{
|
|
|
63 |
qDebug("Detected change:%d", team);
|
|
|
64 |
g_record( team, &team_buf );
|
|
|
65 |
|
| 190 |
- |
66 |
item = tableWidget->item(ii,2);
|
| 136 |
- |
67 |
team_buf.flags.disqualified = ( item->checkState () == Qt::Checked);
|
|
|
68 |
|
| 190 |
- |
69 |
item = tableWidget->item(ii,3);
|
| 136 |
- |
70 |
team_buf.flags.non_equestrian = ( item->checkState () == Qt::Checked);
|
|
|
71 |
|
| 190 |
- |
72 |
item = tableWidget->item(ii,4);
|
| 136 |
- |
73 |
team_buf.flags.valid = ( item->checkState () == Qt::Checked);
|
|
|
74 |
|
| 225 |
- |
75 |
item = tableWidget->item(ii,5);
|
|
|
76 |
team_buf.flags.vet_check = ( item->checkState () == Qt::Checked);
|
|
|
77 |
|
| 136 |
- |
78 |
put_team_record( team, &team_buf );
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
populate();
|
|
|
84 |
|
| 134 |
david |
85 |
}
|
|
|
86 |
|
|
|
87 |
void qmDisqualified::cancel(void)
|
|
|
88 |
{
|
|
|
89 |
populate();
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
void qmDisqualified::populate(void)
|
|
|
93 |
{
|
|
|
94 |
team_type team_buf;
|
|
|
95 |
inPopulate = TRUE;
|
|
|
96 |
|
|
|
97 |
/*
|
|
|
98 |
** Delete existing entries in the table
|
|
|
99 |
*/
|
| 190 |
- |
100 |
tableWidget->clearContents();
|
| 224 |
- |
101 |
tableWidget->setRowCount(config.max_team+1);
|
| 225 |
- |
102 |
tableWidget->setColumnCount(7);
|
| 190 |
- |
103 |
tableWidget->setSortingEnabled(FALSE);
|
| 134 |
david |
104 |
|
|
|
105 |
/*
|
|
|
106 |
** Scan all the team data
|
|
|
107 |
*/
|
|
|
108 |
for ( int team = config.min_team; team <= config.max_team; team++)
|
|
|
109 |
{
|
| 190 |
- |
110 |
tableWidget->hideRow ( team );
|
| 134 |
david |
111 |
if( valid_field( team ) )
|
|
|
112 |
{
|
|
|
113 |
g_record( team, &team_buf );
|
| 136 |
- |
114 |
if( team_buf.flags.valid || true )
|
| 134 |
david |
115 |
{
|
| 178 |
- |
116 |
qmDisqualifiedItem *item;
|
| 134 |
david |
117 |
|
| 190 |
- |
118 |
tableWidget->showRow( team );
|
| 134 |
david |
119 |
|
| 178 |
- |
120 |
item = new qmDisqualifiedItem(team);
|
| 136 |
- |
121 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 190 |
- |
122 |
tableWidget->setItem(team, 0, item );
|
| 134 |
david |
123 |
|
| 178 |
- |
124 |
item = new qmDisqualifiedItem(team_buf.name);
|
| 136 |
- |
125 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 190 |
- |
126 |
tableWidget->setItem(team, 1, item );
|
| 134 |
david |
127 |
|
| 190 |
- |
128 |
tableWidget->setItem(team, 2, new qmDisqualifiedItem("Disq", team_buf.flags.disqualified, team) );
|
|
|
129 |
tableWidget->setItem(team, 3, new qmDisqualifiedItem("Non Equest",team_buf.flags.non_equestrian,team) );
|
|
|
130 |
tableWidget->setItem(team, 4, new qmDisqualifiedItem("Enable", team_buf.flags.valid,team) );
|
| 225 |
- |
131 |
tableWidget->setItem(team, 5, new qmDisqualifiedItem("VetCheck", team_buf.flags.vet_check,team) );
|
| 189 |
- |
132 |
|
|
|
133 |
item = new qmDisqualifiedItem("Bad Times", team_buf.flags.bad_times);
|
|
|
134 |
item->setFlags(Qt::ItemIsSelectable/* | Qt::ItemIsEnabled*/);
|
| 225 |
- |
135 |
tableWidget->setItem(team, 6, item );
|
| 134 |
david |
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
| 190 |
- |
139 |
tableWidget->sortByColumn(0,Qt::AscendingOrder);
|
|
|
140 |
tableWidget->setSortingEnabled(TRUE);
|
|
|
141 |
tableWidget->resizeColumnsToContents();
|
| 178 |
- |
142 |
|
| 134 |
david |
143 |
inPopulate = FALSE;
|
| 191 |
david |
144 |
updateChanged(false);
|
| 134 |
david |
145 |
}
|
|
|
146 |
|
|
|
147 |
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
|
|
|
148 |
{
|
|
|
149 |
if ( !inPopulate )
|
|
|
150 |
{
|
| 136 |
- |
151 |
if ( item->column() )
|
|
|
152 |
{
|
|
|
153 |
qDebug ("DataChanged");
|
|
|
154 |
item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
|
|
|
155 |
|
|
|
156 |
// Mark first item in row to help detect changes
|
|
|
157 |
int row = item->row();
|
|
|
158 |
item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
|
| 191 |
david |
159 |
item->tableWidget()->item(row,0)->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
|
| 136 |
- |
160 |
}
|
| 191 |
david |
161 |
|
|
|
162 |
updateChanged(true);
|
| 134 |
david |
163 |
}
|
|
|
164 |
}
|
| 178 |
- |
165 |
|
| 191 |
david |
166 |
void qmDisqualified::updateChanged(bool newDirty)
|
|
|
167 |
{
|
|
|
168 |
if (newDirty != dirty)
|
|
|
169 |
{
|
|
|
170 |
dirty = newDirty;
|
|
|
171 |
if (dirty)
|
|
|
172 |
{
|
|
|
173 |
pb_save->setEnabled(true);
|
|
|
174 |
pb_save->setStyleSheet("background-color: rgb(255, 0, 0);");
|
|
|
175 |
}
|
|
|
176 |
else
|
|
|
177 |
{
|
|
|
178 |
pb_save->setEnabled(false);
|
|
|
179 |
pb_save->setStyleSheet("");
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
void qmDisqualified::showEvent ( QShowEvent * event )
|
|
|
185 |
{
|
|
|
186 |
qDebug("qmDisqualified::showEvent");
|
|
|
187 |
if ( ! event->spontaneous() && !dirty )
|
|
|
188 |
{
|
|
|
189 |
populate();
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|
| 178 |
- |
193 |
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
|
|
|
194 |
{
|
|
|
195 |
number = 0;
|
|
|
196 |
}
|
|
|
197 |
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) : QTableWidgetItem(type+QTableWidgetItem::UserType)
|
|
|
198 |
{
|
|
|
199 |
number = value;
|
|
|
200 |
setData(0,value);
|
|
|
201 |
}
|
|
|
202 |
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, bool checked, int num, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
|
|
|
203 |
{
|
|
|
204 |
setCheckState(checked ? Qt::Checked : Qt::Unchecked);
|
|
|
205 |
number = num;
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
// Special sorting, based on type
|
|
|
209 |
// type == 0 : Text
|
|
|
210 |
// type == 1 : Number
|
|
|
211 |
// type == 2 : Checked
|
|
|
212 |
//
|
|
|
213 |
bool qmDisqualifiedItem::operator< ( const QTableWidgetItem & other ) const
|
|
|
214 |
{
|
|
|
215 |
const qmDisqualifiedItem * other_widget = dynamic_cast<const qmDisqualifiedItem*>(&other);
|
|
|
216 |
if (other_widget && other_widget->type() == QTableWidgetItem::UserType + 2 )
|
|
|
217 |
{
|
|
|
218 |
if (other_widget->checkState() == checkState() )
|
|
|
219 |
{
|
|
|
220 |
// qDebug ("Same(%d): %d : %d", other_widget->number < number, other_widget->number, number);
|
|
|
221 |
if (this->tableWidget()->horizontalHeader()->sortIndicatorOrder() != Qt::AscendingOrder )
|
|
|
222 |
{
|
|
|
223 |
return other_widget->number < number;
|
|
|
224 |
}
|
|
|
225 |
else
|
|
|
226 |
{
|
|
|
227 |
return number < other_widget->number;
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
return (other_widget->checkState() < checkState() );
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
return ( QTableWidgetItem::operator< (other) );
|
|
|
234 |
}
|