| 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"
|
| 314 |
david |
11 |
#include "qmTableWidgetItem.h"
|
|
|
12 |
#include "qmDialogTeamEditor.h"
|
| 311 |
david |
13 |
|
|
|
14 |
|
| 312 |
david |
15 |
/*----------------------------------------------------------------------------
|
|
|
16 |
** FUNCTION : qmFullData
|
|
|
17 |
**
|
|
|
18 |
** DESCRIPTION : Display all the team data in colums that can be sorted
|
|
|
19 |
**
|
|
|
20 |
**
|
|
|
21 |
** INPUTS :
|
|
|
22 |
**
|
|
|
23 |
** RETURNS :
|
|
|
24 |
**
|
|
|
25 |
----------------------------------------------------------------------------*/
|
| 311 |
david |
26 |
|
|
|
27 |
qmFullData::qmFullData(QWidget *parent) :
|
|
|
28 |
QWidget(parent)
|
|
|
29 |
{
|
| 312 |
david |
30 |
|
|
|
31 |
/*
|
|
|
32 |
** Create the main display region
|
|
|
33 |
** A groupbox with a table in it
|
|
|
34 |
** A 'refresh' button
|
|
|
35 |
*/
|
|
|
36 |
|
| 311 |
david |
37 |
QVBoxLayout *verticalLayout = new QVBoxLayout(this);
|
|
|
38 |
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
39 |
|
|
|
40 |
QGroupBox *groupBox = new QGroupBox("Class");
|
|
|
41 |
verticalLayout->addWidget(groupBox);
|
|
|
42 |
QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
|
|
|
43 |
tableWidget = new QTableWidget(groupBox);
|
|
|
44 |
tableWidget->setAlternatingRowColors(true);
|
| 312 |
david |
45 |
//tableWidget->setRowCount(config.num_teams + 1);
|
|
|
46 |
//tableWidget->setColumnCount(config.num_legs + 3);
|
| 311 |
david |
47 |
//tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
48 |
tableWidget->horizontalHeader()->setVisible(true);
|
|
|
49 |
tableWidget->horizontalHeader()->setDefaultSectionSize(70);
|
|
|
50 |
tableWidget->horizontalHeader()->setHighlightSections(true);
|
|
|
51 |
|
|
|
52 |
tableWidget->verticalHeader()->setVisible(true);
|
|
|
53 |
tableWidget->verticalHeader()->setDefaultSectionSize(20);
|
|
|
54 |
|
|
|
55 |
verticalLayout2->addWidget(tableWidget);
|
|
|
56 |
|
|
|
57 |
QHBoxLayout *horizontalLayout;
|
|
|
58 |
horizontalLayout = new QHBoxLayout();
|
|
|
59 |
horizontalLayout->setContentsMargins(0, 0, 5, 5);
|
|
|
60 |
verticalLayout->addLayout(horizontalLayout);
|
|
|
61 |
|
|
|
62 |
QDialogButtonBox *buttonBox = new QDialogButtonBox();
|
|
|
63 |
refreshButton = buttonBox->addButton("Refresh Data",QDialogButtonBox::ActionRole );
|
|
|
64 |
horizontalLayout->addWidget(buttonBox);
|
|
|
65 |
|
|
|
66 |
// Wire in the button
|
|
|
67 |
connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(loadData()) );
|
|
|
68 |
connect(tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(selectTeam(int,int)));
|
|
|
69 |
|
|
|
70 |
// Insert Labels
|
|
|
71 |
QStringList labels;
|
|
|
72 |
labels << "Team" << "Full Name" << "Cat";
|
|
|
73 |
for (int ii = 0; ii < config.num_legs; ii++)
|
|
|
74 |
{
|
|
|
75 |
labels << config.leg_name[ii];
|
|
|
76 |
}
|
|
|
77 |
// loadData();
|
|
|
78 |
|
|
|
79 |
tableWidget->setHorizontalHeaderLabels(labels);
|
|
|
80 |
tableWidget->resizeColumnsToContents();
|
|
|
81 |
}
|
|
|
82 |
|
| 312 |
david |
83 |
/*----------------------------------------------------------------------------
|
|
|
84 |
** FUNCTION : showEvent
|
|
|
85 |
**
|
|
|
86 |
** DESCRIPTION : Slot that is wired into the main windows widget
|
|
|
87 |
** It will be called when the main window widget changes
|
|
|
88 |
** If this display is the current display, then load new data
|
|
|
89 |
**
|
|
|
90 |
** INPUTS : index of the tab that now has focus
|
|
|
91 |
**
|
|
|
92 |
----------------------------------------------------------------------------*/
|
|
|
93 |
|
|
|
94 |
void qmFullData::showEvent ( QShowEvent * event )
|
|
|
95 |
{
|
|
|
96 |
qDebug("qmFullData::showEvent");
|
|
|
97 |
if ( ! event->spontaneous() )
|
|
|
98 |
{
|
|
|
99 |
loadData();
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/*----------------------------------------------------------------------------
|
|
|
104 |
** FUNCTION : loadData
|
|
|
105 |
**
|
|
|
106 |
** DESCRIPTION : Load Data into the Window
|
|
|
107 |
**
|
|
|
108 |
**
|
|
|
109 |
** INPUTS :
|
|
|
110 |
**
|
|
|
111 |
** RETURNS :
|
|
|
112 |
**
|
|
|
113 |
----------------------------------------------------------------------------*/
|
|
|
114 |
|
| 311 |
david |
115 |
void qmFullData::loadData(void)
|
|
|
116 |
{
|
|
|
117 |
team_type team_buf;
|
|
|
118 |
|
|
|
119 |
/*
|
|
|
120 |
** Delete existing entries in the table
|
|
|
121 |
*/
|
|
|
122 |
tableWidget->clearContents();
|
|
|
123 |
tableWidget->setRowCount(config.max_team+1);
|
|
|
124 |
tableWidget->setColumnCount(config.num_legs + 3 + 5);
|
|
|
125 |
tableWidget->setSortingEnabled(FALSE);
|
|
|
126 |
|
|
|
127 |
/*
|
|
|
128 |
** Scan all the team data
|
|
|
129 |
*/
|
|
|
130 |
for ( int team = config.min_team; team <= config.max_team; team++)
|
|
|
131 |
{
|
|
|
132 |
int leg;
|
|
|
133 |
tableWidget->hideRow ( team );
|
|
|
134 |
if( valid_field( team ) )
|
|
|
135 |
{
|
|
|
136 |
g_record( team, &team_buf );
|
|
|
137 |
if( team_buf.flags.valid )
|
|
|
138 |
{
|
|
|
139 |
tableWidget->showRow( team );
|
|
|
140 |
|
|
|
141 |
tableWidget->setItem(team, 0, new qmTwiNumber(team) );
|
|
|
142 |
tableWidget->setItem(team, 1, new qmTwiString(team_buf.name));
|
|
|
143 |
tableWidget->setItem(team, 2, new qmTwiString(config.team_class[team_buf.teamclass-1].abr));
|
|
|
144 |
|
|
|
145 |
for (leg=0; leg < config.num_legs; leg++)
|
|
|
146 |
{
|
|
|
147 |
tableWidget->setItem(team, 3 + leg, new qmTwiTime(team_buf.leg[leg+1].elapsed));
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Disq", team_buf.flags.disqualified) );
|
|
|
151 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Non Equest",team_buf.flags.non_equestrian) );
|
|
|
152 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Enable", team_buf.flags.valid) );
|
|
|
153 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("VetCheck", team_buf.flags.vet_check) );
|
|
|
154 |
tableWidget->setItem(team, 3+leg++, new qmTwiFlag("Bad Times", team_buf.flags.bad_times) );
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
tableWidget->sortByColumn(0,Qt::AscendingOrder);
|
|
|
159 |
tableWidget->setSortingEnabled(TRUE);
|
|
|
160 |
tableWidget->resizeColumnsToContents();
|
|
|
161 |
}
|
|
|
162 |
|
| 312 |
david |
163 |
/*----------------------------------------------------------------------------
|
|
|
164 |
** FUNCTION : selectTeam
|
|
|
165 |
**
|
|
|
166 |
** DESCRIPTION : Given a table row/col, locate the team and
|
|
|
167 |
** if its valid, then open up a modal dialog to
|
|
|
168 |
** edit the team data.
|
|
|
169 |
**
|
|
|
170 |
** On return, refresh all data in the page.
|
|
|
171 |
**
|
|
|
172 |
** INPUTS :
|
|
|
173 |
**
|
|
|
174 |
** RETURNS :
|
|
|
175 |
**
|
|
|
176 |
----------------------------------------------------------------------------*/
|
|
|
177 |
|
| 311 |
david |
178 |
void qmFullData::selectTeam( int row, int col)
|
|
|
179 |
{
|
|
|
180 |
//qDebug("qmFullData::selectTeam:%d,%d",row,col);
|
|
|
181 |
QTableWidgetItem *item = tableWidget->item(row,0);
|
|
|
182 |
if (item)
|
|
|
183 |
{
|
| 312 |
david |
184 |
//qDebug("qmFullData::selectTeam:%d,%d, %p",row,col, item);
|
| 311 |
david |
185 |
const qmTwiNumber * itemNumber = dynamic_cast<const qmTwiNumber*>(item);
|
|
|
186 |
if ( itemNumber)
|
| 312 |
david |
187 |
{
|
|
|
188 |
//qDebug("qmFullData::selectTeam: Team:%d",itemNumber->number);
|
| 311 |
david |
189 |
qmDialogTeamEditor dialog(itemNumber->number, this);
|
|
|
190 |
dialog.exec();
|
|
|
191 |
loadData();
|
| 312 |
david |
192 |
}
|
| 311 |
david |
193 |
|
|
|
194 |
}
|
|
|
195 |
}
|
|
|
196 |
|