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