| 138 |
david |
1 |
#include "qmdisqualified.h"
|
|
|
2 |
#include "ui_qmdisqualified.h"
|
|
|
3 |
|
|
|
4 |
#include "consts.h"
|
|
|
5 |
#include "structs.h"
|
|
|
6 |
#include "proto.h"
|
|
|
7 |
|
|
|
8 |
qmDisqualified::qmDisqualified(QWidget *parent) :
|
|
|
9 |
QWidget(parent),
|
|
|
10 |
ui(new Ui::qmDisqualified)
|
|
|
11 |
{
|
|
|
12 |
inPopulate = FALSE;
|
|
|
13 |
ui->setupUi(this);
|
|
|
14 |
|
|
|
15 |
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()) );
|
|
|
16 |
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
|
|
|
17 |
connect(ui->loadButton, SIGNAL(released()), this, SLOT(populate()) );
|
|
|
18 |
connect(ui->tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(tableItemChanged(QTableWidgetItem *)));
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
qmDisqualified::~qmDisqualified()
|
|
|
22 |
{
|
|
|
23 |
delete ui;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
void qmDisqualified::save(void)
|
|
|
27 |
{
|
| 140 |
- |
28 |
team_type team_buf;
|
|
|
29 |
for ( int ii = 0; ii < ui->tableWidget->rowCount(); ii++)
|
|
|
30 |
{
|
|
|
31 |
QTableWidgetItem *item;
|
|
|
32 |
item = ui->tableWidget->item(ii, 0);
|
|
|
33 |
if ( item )
|
|
|
34 |
{
|
|
|
35 |
if ( item->data(Qt::UserRole + 1).toBool() )
|
|
|
36 |
{
|
|
|
37 |
int team = item->data(Qt::EditRole).toInt();
|
|
|
38 |
if ( team )
|
|
|
39 |
{
|
|
|
40 |
qDebug("Detected change:%d", team);
|
|
|
41 |
g_record( team, &team_buf );
|
|
|
42 |
|
|
|
43 |
item = ui->tableWidget->item(ii,2);
|
|
|
44 |
team_buf.flags.disqualified = ( item->checkState () == Qt::Checked);
|
|
|
45 |
|
|
|
46 |
item = ui->tableWidget->item(ii,3);
|
|
|
47 |
team_buf.flags.non_equestrian = ( item->checkState () == Qt::Checked);
|
|
|
48 |
//TODO: If nonEquestrian, then also disqualified ?? Original is.
|
|
|
49 |
|
|
|
50 |
item = ui->tableWidget->item(ii,4);
|
|
|
51 |
team_buf.flags.valid = ( item->checkState () == Qt::Checked);
|
|
|
52 |
|
|
|
53 |
put_team_record( team, &team_buf );
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
populate();
|
|
|
59 |
|
| 138 |
david |
60 |
}
|
|
|
61 |
|
|
|
62 |
void qmDisqualified::cancel(void)
|
|
|
63 |
{
|
|
|
64 |
populate();
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
void qmDisqualified::populate(void)
|
|
|
68 |
{
|
|
|
69 |
team_type team_buf;
|
|
|
70 |
inPopulate = TRUE;
|
|
|
71 |
|
|
|
72 |
/*
|
|
|
73 |
** Delete existing entries in the table
|
|
|
74 |
*/
|
|
|
75 |
ui->tableWidget->clearContents();
|
|
|
76 |
ui->tableWidget->setRowCount(config.max_team);
|
| 140 |
- |
77 |
ui->tableWidget->setColumnCount(5);
|
| 138 |
david |
78 |
ui->tableWidget->setSortingEnabled(FALSE);
|
|
|
79 |
|
|
|
80 |
/*
|
|
|
81 |
** Scan all the team data
|
|
|
82 |
*/
|
|
|
83 |
for ( int team = config.min_team; team <= config.max_team; team++)
|
|
|
84 |
{
|
|
|
85 |
ui->tableWidget->hideRow ( team );
|
|
|
86 |
if( valid_field( team ) )
|
|
|
87 |
{
|
|
|
88 |
g_record( team, &team_buf );
|
| 140 |
- |
89 |
if( team_buf.flags.valid || true )
|
| 138 |
david |
90 |
{
|
| 182 |
- |
91 |
qmDisqualifiedItem *item;
|
| 138 |
david |
92 |
|
|
|
93 |
ui->tableWidget->showRow( team );
|
|
|
94 |
|
| 182 |
- |
95 |
item = new qmDisqualifiedItem(team);
|
| 140 |
- |
96 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 138 |
david |
97 |
ui->tableWidget->setItem(team, 0, item );
|
|
|
98 |
|
| 182 |
- |
99 |
item = new qmDisqualifiedItem(team_buf.name);
|
| 140 |
- |
100 |
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
| 138 |
david |
101 |
ui->tableWidget->setItem(team, 1, item );
|
|
|
102 |
|
| 182 |
- |
103 |
ui->tableWidget->setItem(team, 2, new qmDisqualifiedItem("Disq", team_buf.flags.disqualified, team) );
|
|
|
104 |
ui->tableWidget->setItem(team, 3, new qmDisqualifiedItem("Non Equest",team_buf.flags.non_equestrian,team) );
|
|
|
105 |
ui->tableWidget->setItem(team, 4, new qmDisqualifiedItem("Enable", team_buf.flags.valid,team) );
|
| 138 |
david |
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
| 182 |
- |
109 |
ui->tableWidget->sortByColumn(0,Qt::AscendingOrder);
|
| 140 |
- |
110 |
ui->tableWidget->setSortingEnabled(TRUE);
|
|
|
111 |
ui->tableWidget->resizeColumnsToContents();
|
| 182 |
- |
112 |
|
| 138 |
david |
113 |
inPopulate = FALSE;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
void qmDisqualified::tableItemChanged(QTableWidgetItem *item)
|
|
|
117 |
{
|
|
|
118 |
if ( !inPopulate )
|
|
|
119 |
{
|
| 140 |
- |
120 |
if ( item->column() )
|
|
|
121 |
{
|
|
|
122 |
qDebug ("DataChanged");
|
|
|
123 |
item->setData(Qt::BackgroundRole, QBrush(QColor(255,0,0,50)));
|
|
|
124 |
|
|
|
125 |
// Mark first item in row to help detect changes
|
|
|
126 |
int row = item->row();
|
|
|
127 |
item->tableWidget()->item(row,0)->setData(Qt::UserRole + 1, true );
|
|
|
128 |
}
|
| 138 |
david |
129 |
}
|
|
|
130 |
}
|
| 182 |
- |
131 |
|
|
|
132 |
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
|
|
|
133 |
{
|
|
|
134 |
number = 0;
|
|
|
135 |
}
|
|
|
136 |
qmDisqualifiedItem::qmDisqualifiedItem ( int value, int type ) : QTableWidgetItem(type+QTableWidgetItem::UserType)
|
|
|
137 |
{
|
|
|
138 |
number = value;
|
|
|
139 |
setData(0,value);
|
|
|
140 |
}
|
|
|
141 |
qmDisqualifiedItem::qmDisqualifiedItem ( const QString & text, bool checked, int num, int type ) : QTableWidgetItem(text, type+QTableWidgetItem::UserType)
|
|
|
142 |
{
|
|
|
143 |
setCheckState(checked ? Qt::Checked : Qt::Unchecked);
|
|
|
144 |
number = num;
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
// Special sorting, based on type
|
|
|
148 |
// type == 0 : Text
|
|
|
149 |
// type == 1 : Number
|
|
|
150 |
// type == 2 : Checked
|
|
|
151 |
//
|
|
|
152 |
bool qmDisqualifiedItem::operator< ( const QTableWidgetItem & other ) const
|
|
|
153 |
{
|
|
|
154 |
const qmDisqualifiedItem * other_widget = dynamic_cast<const qmDisqualifiedItem*>(&other);
|
|
|
155 |
if (other_widget && other_widget->type() == QTableWidgetItem::UserType + 2 )
|
|
|
156 |
{
|
|
|
157 |
if (other_widget->checkState() == checkState() )
|
|
|
158 |
{
|
|
|
159 |
// qDebug ("Same(%d): %d : %d", other_widget->number < number, other_widget->number, number);
|
|
|
160 |
if (this->tableWidget()->horizontalHeader()->sortIndicatorOrder() != Qt::AscendingOrder )
|
|
|
161 |
{
|
|
|
162 |
return other_widget->number < number;
|
|
|
163 |
}
|
|
|
164 |
else
|
|
|
165 |
{
|
|
|
166 |
return number < other_widget->number;
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
return (other_widget->checkState() < checkState() );
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
return ( QTableWidgetItem::operator< (other) );
|
|
|
173 |
}
|