| 311 |
david |
1 |
#include <QVBoxLayout>
|
|
|
2 |
#include <QGroupBox>
|
|
|
3 |
#include <QDialogButtonBox>
|
|
|
4 |
#include <QTableWidget>
|
|
|
5 |
#include <QHeaderView>
|
|
|
6 |
#include "qmfulldata.h"
|
|
|
7 |
#include "consts.h"
|
|
|
8 |
#include "structs.h"
|
|
|
9 |
#include "proto.h"
|
|
|
10 |
#include "mainwindow.h"
|
|
|
11 |
#include "qmdialogteameditor.h"
|
|
|
12 |
|
|
|
13 |
|
| 312 |
david |
14 |
/*----------------------------------------------------------------------------
|
|
|
15 |
** FUNCTION : qmFullData
|
|
|
16 |
**
|
|
|
17 |
** DESCRIPTION : Display all the team data in colums that can be sorted
|
|
|
18 |
**
|
|
|
19 |
**
|
|
|
20 |
** INPUTS :
|
|
|
21 |
**
|
|
|
22 |
** RETURNS :
|
|
|
23 |
**
|
|
|
24 |
----------------------------------------------------------------------------*/
|
| 311 |
david |
25 |
|
|
|
26 |
qmFullData::qmFullData(QWidget *parent) :
|
|
|
27 |
QWidget(parent)
|
|
|
28 |
{
|
| 312 |
david |
29 |
|
|
|
30 |
/*
|
|
|
31 |
** Create the main display region
|
|
|
32 |
** A groupbox with a table in it
|
|
|
33 |
** A 'refresh' button
|
|
|
34 |
*/
|
|
|
35 |
|
| 311 |
david |
36 |
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
|
|
|
37 |
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
38 |
|
|
|
39 |
QGroupBox *groupBox = new QGroupBox("Class");
|
|
|
40 |
verticalLayout->addWidget(groupBox);
|
|
|
41 |
QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
|
|
|
42 |
tableWidget = new QTableWidget(groupBox);
|
|
|
43 |
tableWidget->setAlternatingRowColors(true);
|
| 312 |
david |
44 |
//tableWidget->setRowCount(config.num_teams + 1);
|
|
|
45 |
//tableWidget->setColumnCount(config.num_legs + 3);
|
| 311 |
david |
46 |
//tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
47 |
tableWidget->horizontalHeader()->setVisible(true);
|
|
|
48 |
tableWidget->horizontalHeader()->setDefaultSectionSize(70);
|
|
|
49 |
tableWidget->horizontalHeader()->setHighlightSections(true);
|
|
|
50 |
|
|
|
51 |
tableWidget->verticalHeader()->setVisible(true);
|
|
|
52 |
tableWidget->verticalHeader()->setDefaultSectionSize(20);
|
|
|
53 |
|
|
|
54 |
verticalLayout2->addWidget(tableWidget);
|
|
|
55 |
|
|
|
56 |
QHBoxLayout *horizontalLayout;
|
|
|
57 |
horizontalLayout = new QHBoxLayout();
|
|
|
58 |
horizontalLayout->setContentsMargins(0, 0, 5, 5);
|
|
|
59 |
verticalLayout->addLayout(horizontalLayout);
|
|
|
60 |
|
|
|
61 |
QDialogButtonBox *buttonBox = new QDialogButtonBox();
|
|
|
62 |
refreshButton = buttonBox->addButton("Refresh Data",QDialogButtonBox::ActionRole );
|
|
|
63 |
horizontalLayout->addWidget(buttonBox);
|
|
|
64 |
|
|
|
65 |
// Wire in the button
|
|
|
66 |
connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(loadData()) );
|
|
|
67 |
connect(tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(selectTeam(int,int)));
|
|
|
68 |
|
|
|
69 |
// Insert Labels
|
|
|
70 |
QStringList labels;
|
|
|
71 |
labels << "Team" << "Full Name" << "Cat";
|
|
|
72 |
for (int ii = 0; ii < config.num_legs; ii++)
|
|
|
73 |
{
|
|
|
74 |
labels << config.leg_name[ii];
|
|
|
75 |
}
|
|
|
76 |
// loadData();
|
|
|
77 |
|
|
|
78 |
tableWidget->setHorizontalHeaderLabels(labels);
|
|
|
79 |
tableWidget->resizeColumnsToContents();
|
|
|
80 |
}
|
|
|
81 |
|
| 312 |
david |
82 |
/*----------------------------------------------------------------------------
|
|
|
83 |
** FUNCTION : showEvent
|
|
|
84 |
**
|
|
|
85 |
** DESCRIPTION : Slot that is wired into the main windows widget
|
|
|
86 |
** It will be called when the main window widget changes
|
|
|
87 |
** If this display is the current display, then load new data
|
|
|
88 |
**
|
|
|
89 |
** INPUTS : index of the tab that now has focus
|
|
|
90 |
**
|
|
|
91 |
----------------------------------------------------------------------------*/
|
|
|
92 |
|
|
|
93 |
void qmFullData::showEvent ( QShowEvent * event )
|
|
|
94 |
{
|
|
|
95 |
qDebug("qmFullData::showEvent");
|
|
|
96 |
if ( ! event->spontaneous() )
|
|
|
97 |
{
|
|
|
98 |
loadData();
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
/*----------------------------------------------------------------------------
|
|
|
103 |
** FUNCTION : loadData
|
|
|
104 |
**
|
|
|
105 |
** DESCRIPTION : Load Data into the Window
|
|
|
106 |
**
|
|
|
107 |
**
|
|
|
108 |
** INPUTS :
|
|
|
109 |
**
|
|
|
110 |
** RETURNS :
|
|
|
111 |
**
|
|
|
112 |
----------------------------------------------------------------------------*/
|
|
|
113 |
|
| 311 |
david |
114 |
void qmFullData::loadData(void)
|
|
|
115 |
{
|
|
|
116 |
team_type team_buf;
|
|
|
117 |
|
|
|
118 |
/*
|
|
|
119 |
** Delete existing entries in the table
|
|
|
120 |
*/
|
|
|
121 |
tableWidget->clearContents();
|
|
|
122 |
tableWidget->setRowCount(config.max_team+1);
|
|
|
123 |
tableWidget->setColumnCount(config.num_legs + 3 + 5);
|
|
|
124 |
tableWidget->setSortingEnabled(FALSE);
|
|
|
125 |
|
|
|
126 |
/*
|
|
|
127 |
** Scan all the team data
|
|
|
128 |
*/
|
|
|
129 |
for ( int team = config.min_team; team <= config.max_team; team++)
|
|
|
130 |
{
|
|
|
131 |
int leg;
|
|
|
132 |
tableWidget->hideRow ( team );
|
|
|
133 |
if( valid_field( team ) )
|
|
|
134 |
{
|
|
|
135 |
g_record( team, &team_buf );
|
|
|
136 |
if( team_buf.flags.valid )
|
|
|
137 |
{
|
|
|
138 |
tableWidget->showRow( team );
|
|
|
139 |
|
|
|
140 |
tableWidget->setItem(team, 0, new qmTwiNumber(team) );
|
|
|
141 |
tableWidget->setItem(team, 1, new qmTwiString(team_buf.name));
|
|
|
142 |
tableWidget->setItem(team, 2, new qmTwiString(config.team_class[team_buf.teamclass-1].abr));
|
|
|
143 |
|
|
|
144 |
for (leg=0; leg < config.num_legs; leg++)
|
|
|
145 |
{
|
|
|
146 |
tableWidget->setItem(team, 3 + leg, new qmTwiTime(team_buf.leg[leg+1].elapsed));
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Disq", team_buf.flags.disqualified) );
|
|
|
150 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Non Equest",team_buf.flags.non_equestrian) );
|
|
|
151 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Enable", team_buf.flags.valid) );
|
|
|
152 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("VetCheck", team_buf.flags.vet_check) );
|
|
|
153 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Bad Times", team_buf.flags.bad_times) );
|
|
|
154 |
}
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
tableWidget->sortByColumn(0,Qt::AscendingOrder);
|
|
|
158 |
tableWidget->setSortingEnabled(TRUE);
|
|
|
159 |
tableWidget->resizeColumnsToContents();
|
|
|
160 |
}
|
|
|
161 |
|
| 312 |
david |
162 |
/*----------------------------------------------------------------------------
|
|
|
163 |
** FUNCTION : selectTeam
|
|
|
164 |
**
|
|
|
165 |
** DESCRIPTION : Given a table row/col, locate the team and
|
|
|
166 |
** if its valid, then open up a modal dialog to
|
|
|
167 |
** edit the team data.
|
|
|
168 |
**
|
|
|
169 |
** On return, refresh all data in the page.
|
|
|
170 |
**
|
|
|
171 |
** INPUTS :
|
|
|
172 |
**
|
|
|
173 |
** RETURNS :
|
|
|
174 |
**
|
|
|
175 |
----------------------------------------------------------------------------*/
|
|
|
176 |
|
| 311 |
david |
177 |
void qmFullData::selectTeam( int row, int col)
|
|
|
178 |
{
|
|
|
179 |
//qDebug("qmFullData::selectTeam:%d,%d",row,col);
|
|
|
180 |
QTableWidgetItem *item = tableWidget->item(row,0);
|
|
|
181 |
if (item)
|
|
|
182 |
{
|
| 312 |
david |
183 |
//qDebug("qmFullData::selectTeam:%d,%d, %p",row,col, item);
|
| 311 |
david |
184 |
const qmTwiNumber * itemNumber = dynamic_cast<const qmTwiNumber*>(item);
|
|
|
185 |
if ( itemNumber)
|
| 312 |
david |
186 |
{
|
|
|
187 |
//qDebug("qmFullData::selectTeam: Team:%d",itemNumber->number);
|
| 311 |
david |
188 |
qmDialogTeamEditor dialog(itemNumber->number, this);
|
|
|
189 |
dialog.exec();
|
|
|
190 |
loadData();
|
| 312 |
david |
191 |
}
|
| 311 |
david |
192 |
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
|
| 312 |
david |
196 |
/*----------------------------------------------------------------------------
|
|
|
197 |
** FUNCTION : qmTwi...
|
|
|
198 |
**
|
|
|
199 |
** DESCRIPTION : A collection of helper classes to help display team
|
|
|
200 |
** information in a table.
|
|
|
201 |
**
|
|
|
202 |
** All derive from QTableWidgetItem and display read-only
|
|
|
203 |
** data
|
|
|
204 |
**
|
|
|
205 |
** Some of them have associated sorting functions to
|
|
|
206 |
** order data in a pleasing manner.
|
|
|
207 |
**
|
|
|
208 |
**
|
|
|
209 |
** INPUTS :
|
|
|
210 |
**
|
|
|
211 |
** RETURNS :
|
|
|
212 |
**
|
|
|
213 |
----------------------------------------------------------------------------*/
|
|
|
214 |
|
| 311 |
david |
215 |
qmTwiString::qmTwiString ( QString value ) : QTableWidgetItem(0)
|
|
|
216 |
{
|
|
|
217 |
setData(0,value);
|
|
|
218 |
setFlags(flags() & ~Qt::ItemIsEditable);
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
qmTwiNumber::qmTwiNumber ( int value ) : QTableWidgetItem(0)
|
|
|
222 |
{
|
|
|
223 |
number = value;
|
|
|
224 |
setData(0,value);
|
|
|
225 |
setFlags(flags() & ~Qt::ItemIsEditable);
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
bool qmTwiNumber::operator< ( const QTableWidgetItem & other ) const
|
|
|
229 |
{
|
|
|
230 |
const qmTwiNumber * other_widget = dynamic_cast<const qmTwiNumber*>(&other);
|
|
|
231 |
return number < other_widget->number;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
qmTwiTime::qmTwiTime ( int value ) : QTableWidgetItem(0)
|
|
|
235 |
{
|
|
|
236 |
number = value;
|
|
|
237 |
setData(0,time_a(value));
|
|
|
238 |
setFlags(flags() & ~Qt::ItemIsEditable);
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
bool qmTwiTime::operator< ( const QTableWidgetItem & other ) const
|
|
|
242 |
{
|
|
|
243 |
const qmTwiTime * other_widget = dynamic_cast<const qmTwiTime*>(&other);
|
|
|
244 |
if (number >= 0 && other_widget->number >= 0)
|
|
|
245 |
{
|
|
|
246 |
return number < other_widget->number;
|
|
|
247 |
}
|
|
|
248 |
else if (number >= 0 && other_widget->number < 0)
|
|
|
249 |
{
|
|
|
250 |
return true;
|
|
|
251 |
}
|
|
|
252 |
else
|
|
|
253 |
{
|
|
|
254 |
return false;
|
|
|
255 |
}
|
|
|
256 |
}
|
|
|
257 |
|
|
|
258 |
qmTwiFlag::qmTwiFlag ( const QString txt, int checked ) : QTableWidgetItem(txt)
|
|
|
259 |
{
|
|
|
260 |
setCheckState(checked ? Qt::Checked : Qt::Unchecked);
|
|
|
261 |
setFlags(flags() & ~(Qt::ItemIsEditable | Qt::ItemIsUserCheckable));
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
bool qmTwiFlag::operator< ( const QTableWidgetItem & other ) const
|
|
|
265 |
{
|
|
|
266 |
const qmTwiFlag * other_widget = dynamic_cast<const qmTwiFlag*>(&other);
|
|
|
267 |
return (other_widget->checkState() < checkState() );
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
|