| 95 |
david |
1 |
#include "qmconfclass.h"
|
| 174 |
- |
2 |
#include "qmconfig.h"
|
| 95 |
david |
3 |
#include "ui_qmconfclass.h"
|
| 99 |
david |
4 |
#include "consts.h"
|
|
|
5 |
#include "structs.h"
|
|
|
6 |
#include "proto.h"
|
| 180 |
- |
7 |
#include "mainwindow.h"
|
| 95 |
david |
8 |
|
| 99 |
david |
9 |
#include "QTableWidgetItem"
|
| 107 |
david |
10 |
#include "spinboxdelegate.h"
|
|
|
11 |
#include "timedelegate.h"
|
| 111 |
david |
12 |
#include "textdelegate.h"
|
| 180 |
- |
13 |
#include <QMenu>
|
| 99 |
david |
14 |
|
| 104 |
- |
15 |
QmConfClass::QmConfClass(QWidget *parent) :
|
| 95 |
david |
16 |
QWidget(parent),
|
| 104 |
- |
17 |
ui(new Ui::QmConfClass)
|
| 95 |
david |
18 |
{
|
|
|
19 |
ui->setupUi(this);
|
| 99 |
david |
20 |
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()) );
|
|
|
21 |
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
|
|
|
22 |
|
| 109 |
david |
23 |
QStringList labels;
|
|
|
24 |
labels << "Abr" << "Full Name" << "Start Time" << "Winners";
|
|
|
25 |
|
| 107 |
david |
26 |
|
| 180 |
- |
27 |
ui->tableWidget->setRowCount(config.num_class + 1);
|
|
|
28 |
ui->tableWidget->setColumnCount(8);
|
|
|
29 |
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
30 |
connect(ui->tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
|
|
|
31 |
|
|
|
32 |
|
| 107 |
david |
33 |
/*
|
|
|
34 |
** Setup delegated for specialised editing
|
|
|
35 |
*/
|
| 111 |
david |
36 |
ui->tableWidget->setItemDelegateForColumn(0, new textDelegate(2));
|
|
|
37 |
ui->tableWidget->setItemDelegateForColumn(1, new textDelegate(LEN_CLASS_NAME));
|
| 107 |
david |
38 |
ui->tableWidget->setItemDelegateForColumn(2, new timeDelegate());
|
| 110 |
- |
39 |
ui->tableWidget->setItemDelegateForColumn(3, new SpinBoxDelegate(0,50));
|
| 107 |
david |
40 |
|
| 99 |
david |
41 |
populate();
|
| 180 |
- |
42 |
|
|
|
43 |
|
|
|
44 |
// Wire in the status button
|
|
|
45 |
connect(ui->statusButton, SIGNAL(clicked()), this, SLOT(updateStatus()));
|
|
|
46 |
statusShown = false;
|
|
|
47 |
ui->tableWidget->setColumnHidden(5, true);
|
|
|
48 |
ui->tableWidget->setColumnHidden(6, true);
|
|
|
49 |
ui->tableWidget->setColumnHidden(7, true);
|
|
|
50 |
|
|
|
51 |
labels << "" << "Total" <<"Disqual" << "NonEq";
|
|
|
52 |
|
|
|
53 |
ui->tableWidget->setHorizontalHeaderLabels(labels);
|
| 111 |
david |
54 |
ui->tableWidget->resizeColumnsToContents();
|
| 180 |
- |
55 |
|
| 95 |
david |
56 |
}
|
|
|
57 |
|
| 104 |
- |
58 |
void QmConfClass::populate(void)
|
| 99 |
david |
59 |
{
|
| 180 |
- |
60 |
ui->tableWidget->setRowCount(config.num_class + 1);
|
| 99 |
david |
61 |
for ( int ii = 0; ii < MAX_CLASS; ii++)
|
|
|
62 |
{
|
| 111 |
david |
63 |
ui->tableWidget->setItem(ii, 0, new QTableWidgetItem(config.team_class[ii].abr) );
|
|
|
64 |
ui->tableWidget->setItem(ii, 1, new QTableWidgetItem(config.team_class[ii].full_name ));
|
| 105 |
- |
65 |
|
| 111 |
david |
66 |
if ( *config.team_class[ii].abr )
|
|
|
67 |
{
|
|
|
68 |
QTableWidgetItem *item;
|
|
|
69 |
item = new QTableWidgetItem();
|
|
|
70 |
item->setData(Qt::EditRole,QTime().addSecs(config.team_class[ii].start) );
|
|
|
71 |
ui->tableWidget->setItem(ii, 2, item);
|
| 107 |
david |
72 |
|
| 111 |
david |
73 |
item = new QTableWidgetItem();
|
|
|
74 |
item->setData(Qt::EditRole,config.class_winners[ii] );
|
|
|
75 |
ui->tableWidget->setItem(ii, 3, item);
|
|
|
76 |
}
|
| 99 |
david |
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
| 104 |
- |
80 |
void QmConfClass::save(void)
|
| 99 |
david |
81 |
{
|
| 104 |
- |
82 |
int error = 0;
|
| 99 |
david |
83 |
|
| 104 |
- |
84 |
/*
|
|
|
85 |
** Copy original data
|
|
|
86 |
*/
|
| 176 |
- |
87 |
QmConfig newcfg(config);
|
| 104 |
- |
88 |
|
|
|
89 |
/*
|
|
|
90 |
** Extract the data from the Widgets
|
|
|
91 |
*/
|
|
|
92 |
for ( int ii = 0; ii < MAX_CLASS; ii++)
|
|
|
93 |
{
|
|
|
94 |
QTableWidgetItem *item = ui->tableWidget->item ( ii, 0 );
|
| 111 |
david |
95 |
if ( item )
|
|
|
96 |
{
|
|
|
97 |
strncpy(newcfg.team_class[ii].abr, qPrintable(item->text()), sizeof(newcfg.team_class[ii].abr)-1);
|
|
|
98 |
}
|
|
|
99 |
else
|
|
|
100 |
{
|
|
|
101 |
*newcfg.team_class[ii].abr = 0;
|
|
|
102 |
}
|
| 104 |
- |
103 |
|
|
|
104 |
item = ui->tableWidget->item ( ii, 1 );
|
| 111 |
david |
105 |
if ( item )
|
|
|
106 |
{
|
|
|
107 |
strncpy(newcfg.team_class[ii].full_name, qPrintable(item->text()), sizeof(newcfg.team_class[ii].full_name)-1);
|
|
|
108 |
}
|
|
|
109 |
else
|
|
|
110 |
{
|
|
|
111 |
*newcfg.team_class[ii].full_name = 0;
|
|
|
112 |
}
|
| 108 |
david |
113 |
|
|
|
114 |
item = ui->tableWidget->item( ii, 2 );
|
| 111 |
david |
115 |
if ( item )
|
|
|
116 |
{
|
|
|
117 |
newcfg.team_class[ii].start = QTime(0,0,0).secsTo(item->data(Qt::EditRole).toTime());
|
|
|
118 |
}
|
|
|
119 |
else
|
|
|
120 |
{
|
|
|
121 |
newcfg.team_class[ii].start = 0;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
item = ui->tableWidget->item( ii, 3 );
|
|
|
125 |
if ( item )
|
|
|
126 |
{
|
|
|
127 |
newcfg.class_winners[ii] = item->data(Qt::EditRole).toInt();
|
|
|
128 |
}
|
|
|
129 |
else
|
|
|
130 |
{
|
|
|
131 |
newcfg.class_winners[ii] = 0;
|
|
|
132 |
}
|
| 104 |
- |
133 |
}
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
/*
|
|
|
137 |
** Now do the Class definitions
|
|
|
138 |
*/
|
|
|
139 |
for( int i = 0; i < MAX_CLASS; i++ )
|
|
|
140 |
{
|
|
|
141 |
compact( newcfg.team_class[i].abr );
|
|
|
142 |
compact( newcfg.team_class[i].full_name );
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
for( int i = 0; i < MAX_CLASS; i++ )
|
|
|
146 |
{
|
|
|
147 |
if( ( newcfg.team_class[i].abr[0] == '\0' ) != ( newcfg.team_class[i].full_name[0] == '\0' ) )
|
|
|
148 |
{
|
| 180 |
- |
149 |
MainWindow::showMessage( "Configuration error. Class without description" );
|
| 104 |
- |
150 |
error++;
|
|
|
151 |
}
|
|
|
152 |
if( newcfg.team_class[i].abr[0] != '\0' && newcfg.team_class[i].start < 0L )
|
|
|
153 |
{
|
| 180 |
- |
154 |
MainWindow::showMessage( "Configuration error. Bad start time on class" );
|
| 104 |
- |
155 |
error++;
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
newcfg.num_class = 0;
|
|
|
160 |
for( int i = 0; i < MAX_CLASS; i++ )
|
|
|
161 |
if( newcfg.team_class[i].full_name[0] )
|
|
|
162 |
newcfg.num_class++;
|
|
|
163 |
|
|
|
164 |
for( int i = newcfg.num_class; i < MAX_CLASS; i++ )
|
|
|
165 |
if( newcfg.team_class[i].full_name[0] )
|
|
|
166 |
{
|
| 180 |
- |
167 |
MainWindow::showMessage( "Configuration error: Missing Class name. Gaps not allowed" );
|
| 104 |
- |
168 |
error++;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
if( newcfg.num_class == 0 )
|
|
|
172 |
{
|
| 180 |
- |
173 |
MainWindow::showMessage( "Error: No categories defined" );
|
| 104 |
- |
174 |
error++;
|
|
|
175 |
}
|
|
|
176 |
|
| 176 |
- |
177 |
newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
|
| 104 |
- |
178 |
if( newcfg.equestrian_leg && newcfg.nonequestrian_class == 0 )
|
| 180 |
- |
179 |
MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
|
| 104 |
- |
180 |
|
| 111 |
david |
181 |
/*
|
|
|
182 |
** Sanity test of the data
|
|
|
183 |
*/
|
|
|
184 |
for( int i = 0; i < MAX_CLASS; i++ )
|
|
|
185 |
{
|
|
|
186 |
if( newcfg.team_class[i].abr[0] != '\0' && newcfg.class_winners[i] == 0 )
|
|
|
187 |
{
|
| 180 |
- |
188 |
//MainWindow::showMessage( " Warning: Class without winners: %s", newcfg.team_class[i].abr );
|
|
|
189 |
MainWindow::showMessage( QString("Warning: Class without winners:") + newcfg.team_class[i].abr );
|
| 111 |
david |
190 |
}
|
|
|
191 |
|
|
|
192 |
// if ( newcfg.class_winners[i] > class_summary.teamclass[i+1].total )
|
|
|
193 |
// {
|
|
|
194 |
// printf( " Warning: Num winners greater than those in class: %s\n", newcfg.team_class[i].abr );
|
|
|
195 |
// }
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
|
| 104 |
- |
199 |
if ( error == 0 )
|
|
|
200 |
{
|
|
|
201 |
config = newcfg;
|
| 176 |
- |
202 |
config.write_config();
|
| 180 |
- |
203 |
MainWindow::showMessage( "Config Saved");
|
| 104 |
- |
204 |
}
|
|
|
205 |
|
| 99 |
david |
206 |
}
|
|
|
207 |
|
| 104 |
- |
208 |
void QmConfClass::cancel(void)
|
| 99 |
david |
209 |
{
|
|
|
210 |
populate();
|
|
|
211 |
}
|
|
|
212 |
|
| 104 |
- |
213 |
QmConfClass::~QmConfClass()
|
| 95 |
david |
214 |
{
|
|
|
215 |
delete ui;
|
|
|
216 |
}
|
|
|
217 |
|
| 180 |
- |
218 |
void QmConfClass::ctxMenu(const QPoint & pos)
|
|
|
219 |
{
|
|
|
220 |
qDebug("Context Menu");
|
|
|
221 |
QMenu *menu = new QMenu;
|
|
|
222 |
int trow = 0;
|
|
|
223 |
menu->setTitle("Add/Remove Category");
|
|
|
224 |
|
|
|
225 |
QTableWidgetItem *item;
|
|
|
226 |
item = ui->tableWidget->itemAt(pos);
|
|
|
227 |
menu->addAction(tr("New Category"), this, SLOT(ctxMenuAddRow()));
|
|
|
228 |
if (item)
|
|
|
229 |
{
|
|
|
230 |
menu->addAction(tr("Delete Category"), this, SLOT(ctxMenuDeleteRow()));
|
|
|
231 |
}
|
|
|
232 |
menu->exec(ui->tableWidget->mapToGlobal(pos));
|
|
|
233 |
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
void QmConfClass::ctxMenuDeleteRow(void)
|
|
|
237 |
{
|
|
|
238 |
//qDebug ("DELETE ROW: %d", ui->tableWidget->currentRow () );
|
|
|
239 |
ui->tableWidget->removeRow(ui->tableWidget->currentRow ());
|
|
|
240 |
}
|
|
|
241 |
|
|
|
242 |
void QmConfClass::ctxMenuAddRow(void)
|
|
|
243 |
{
|
|
|
244 |
ui->tableWidget->setRowCount( 1+ ui->tableWidget->rowCount());
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
void QmConfClass::updateStatus(void)
|
|
|
248 |
{
|
|
|
249 |
if (!statusShown)
|
|
|
250 |
{
|
|
|
251 |
ui->tableWidget->setColumnHidden(5, false);
|
|
|
252 |
ui->tableWidget->setColumnHidden(6, false);
|
|
|
253 |
ui->tableWidget->setColumnHidden(7, false);
|
|
|
254 |
statusShown = true;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
if( load_report_data() )
|
|
|
258 |
{
|
|
|
259 |
t_class_summary data;
|
|
|
260 |
calc_class_summary( & data );
|
|
|
261 |
|
|
|
262 |
// Insert summary data
|
|
|
263 |
int ii;
|
|
|
264 |
for (ii = 0; ii < config.num_class; ii++)
|
|
|
265 |
{
|
|
|
266 |
QTableWidgetItem *item;
|
|
|
267 |
item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].total));
|
|
|
268 |
item->setFlags(Qt::NoItemFlags);
|
|
|
269 |
ui->tableWidget->setItem(ii,5, item );
|
|
|
270 |
|
|
|
271 |
item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].disqualified)) ;
|
|
|
272 |
item->setFlags(Qt::NoItemFlags);
|
|
|
273 |
ui->tableWidget->setItem(ii,6, item);
|
|
|
274 |
|
|
|
275 |
item = new QTableWidgetItem(QString::number(data.teamclass[ii+1].non_equestrian));
|
|
|
276 |
item->setFlags(Qt::NoItemFlags);
|
|
|
277 |
ui->tableWidget->setItem(ii,7, item);
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
ui->tableWidget->resizeColumnsToContents();
|
|
|
281 |
ui->tableWidget->resizeRowsToContents();
|
|
|
282 |
}
|
|
|
283 |
}
|
|
|
284 |
|
| 104 |
- |
285 |
void QmConfClass::changeEvent(QEvent *e)
|
| 95 |
david |
286 |
{
|
|
|
287 |
QWidget::changeEvent(e);
|
|
|
288 |
switch (e->type()) {
|
|
|
289 |
case QEvent::LanguageChange:
|
|
|
290 |
ui->retranslateUi(this);
|
|
|
291 |
break;
|
|
|
292 |
default:
|
|
|
293 |
break;
|
|
|
294 |
}
|
|
|
295 |
}
|