| 175 |
david |
1 |
#include "qmconfteams.h"
|
| 178 |
- |
2 |
#include "qmconfig.h"
|
| 175 |
david |
3 |
#include "ui_qmconfteams.h"
|
| 187 |
- |
4 |
#include "consts.h"
|
|
|
5 |
#include "structs.h"
|
|
|
6 |
#include "proto.h"
|
|
|
7 |
#include "mainwindow.h"
|
|
|
8 |
#include "twinspinbox.h"
|
| 201 |
- |
9 |
#include "qmeditaddendum.h"
|
| 175 |
david |
10 |
|
|
|
11 |
QmConfTeams::QmConfTeams(QWidget *parent) :
|
|
|
12 |
QWidget(parent),
|
|
|
13 |
ui(new Ui::QmConfigure)
|
|
|
14 |
{
|
|
|
15 |
ui->setupUi(this);
|
| 186 |
- |
16 |
connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(save()) );
|
|
|
17 |
connect(ui->pushButtonRestore, SIGNAL(clicked()), this, SLOT(cancel()) );
|
| 201 |
- |
18 |
connect(ui->editAddendum, SIGNAL(clicked()), this, SLOT(editAddendum()));
|
| 175 |
david |
19 |
|
| 184 |
- |
20 |
ui->spinBox_NeLeg->setMaximum(5);
|
|
|
21 |
ui->spinBox_NeLeg->setMinimum(0);
|
|
|
22 |
connect(ui->spinBox_NeLeg, SIGNAL(valueChanged(int)), this,SLOT(updateNe()));
|
|
|
23 |
connect(ui->legNe1,SIGNAL(clicked()), this,SLOT(calcNe1()));
|
|
|
24 |
connect(ui->legNe2,SIGNAL(clicked()), this,SLOT(calcNe2()));
|
|
|
25 |
connect(ui->legNe3,SIGNAL(clicked()), this,SLOT(calcNe3()));
|
|
|
26 |
connect(ui->legNe4,SIGNAL(clicked()), this,SLOT(calcNe4()));
|
|
|
27 |
connect(ui->legNe5,SIGNAL(clicked()), this,SLOT(calcNe5()));
|
|
|
28 |
|
| 186 |
- |
29 |
connect(ui->eventName, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
30 |
connect(ui->legName1, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
31 |
connect(ui->legName2, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
32 |
connect(ui->legName3, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
33 |
connect(ui->legName4, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
34 |
connect(ui->legName5, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
35 |
|
|
|
36 |
connect(ui->ne_leg_abr, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
37 |
connect(ui->addendum, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
38 |
connect(ui->datafilename, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
|
|
39 |
connect(ui->spinBox_LinesPerPage, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
|
|
40 |
connect(ui->perfSkip, SIGNAL(stateChanged(int)), this, SLOT(changed()));
|
|
|
41 |
|
|
|
42 |
|
| 187 |
- |
43 |
ui->tn1->setLimits( 0, 999);
|
|
|
44 |
ui->tn2->setLimits( 0, 999);
|
|
|
45 |
ui->tn3->setLimits( 0, 999);
|
|
|
46 |
ui->tn4->setLimits( 0, 999);
|
|
|
47 |
ui->tn5->setLimits( 0, 999);
|
|
|
48 |
ui->tn6->setLimits( 0, 999);
|
|
|
49 |
ui->tn7->setLimits( 0, 999);
|
|
|
50 |
ui->tn8->setLimits( 0, 999);
|
| 186 |
- |
51 |
|
| 187 |
- |
52 |
connect(ui->tn1, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
53 |
connect(ui->tn2, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
54 |
connect(ui->tn3, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
55 |
connect(ui->tn4, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
56 |
connect(ui->tn5, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
57 |
connect(ui->tn6, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
58 |
connect(ui->tn7, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
59 |
connect(ui->tn8, SIGNAL(changed()), this, SLOT(changed()));
|
|
|
60 |
|
| 186 |
- |
61 |
populating = false;
|
|
|
62 |
dirty = true;
|
| 175 |
david |
63 |
populate();
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
}
|
|
|
67 |
void QmConfTeams::populate(void)
|
|
|
68 |
{
|
| 186 |
- |
69 |
populating = true;
|
| 175 |
david |
70 |
ui->eventName->setText( config.event_name);
|
|
|
71 |
ui->eventName->setMaxLength(MAX_EVENT_NAME);
|
|
|
72 |
|
|
|
73 |
ui->addendum->setText(config.addendum);
|
|
|
74 |
ui->addendum->setMaxLength(sizeof(config.addendum)-1);
|
|
|
75 |
|
|
|
76 |
ui->datafilename->setText(config.datafilename);
|
| 201 |
- |
77 |
ui->datafilename->setMaxLength(sizeof(config.datafilename) - 1);
|
| 175 |
david |
78 |
|
|
|
79 |
ui->legName1->setText(config.leg_name[0]);
|
|
|
80 |
ui->legName1->setMaxLength(MAX_LEG_NAME);
|
|
|
81 |
ui->legName2->setText(config.leg_name[1]);
|
|
|
82 |
ui->legName2->setMaxLength(MAX_LEG_NAME);
|
|
|
83 |
ui->legName3->setText(config.leg_name[2]);
|
|
|
84 |
ui->legName3->setMaxLength(MAX_LEG_NAME);
|
|
|
85 |
ui->legName4->setText(config.leg_name[3]);
|
|
|
86 |
ui->legName4->setMaxLength(MAX_LEG_NAME);
|
|
|
87 |
ui->legName5->setText(config.leg_name[4]);
|
|
|
88 |
ui->legName5->setMaxLength(MAX_LEG_NAME);
|
|
|
89 |
|
| 187 |
- |
90 |
ui->tn1->setData( config.t_def[0].start, config.t_def[0].end);
|
|
|
91 |
ui->tn2->setData( config.t_def[1].start, config.t_def[1].end);
|
|
|
92 |
ui->tn3->setData( config.t_def[2].start, config.t_def[2].end);
|
|
|
93 |
ui->tn4->setData( config.t_def[3].start, config.t_def[3].end);
|
|
|
94 |
ui->tn5->setData( config.t_def[4].start, config.t_def[4].end);
|
|
|
95 |
ui->tn6->setData( config.t_def[5].start, config.t_def[5].end);
|
|
|
96 |
ui->tn7->setData( config.t_def[6].start, config.t_def[6].end);
|
|
|
97 |
ui->tn8->setData( config.t_def[7].start, config.t_def[7].end);
|
| 175 |
david |
98 |
|
|
|
99 |
ui->spinBox_NeLeg->setValue(config.equestrian_leg);
|
| 184 |
- |
100 |
updateNe();
|
| 175 |
david |
101 |
ui->ne_leg_abr->setText(config.nonequestrian_class_abr);
|
|
|
102 |
ui->ne_leg_abr->setMaxLength(sizeof(config.nonequestrian_class_abr)-1);
|
|
|
103 |
|
|
|
104 |
ui->spinBox_LinesPerPage->setValue(config.lines_per_page);
|
|
|
105 |
ui->perfSkip->setChecked( config.perf_skip );
|
| 186 |
- |
106 |
populating = false;
|
|
|
107 |
updateChanged(false);
|
| 175 |
david |
108 |
}
|
|
|
109 |
|
| 184 |
- |
110 |
void QmConfTeams::updateNe(void)
|
|
|
111 |
{
|
|
|
112 |
int value = ui->spinBox_NeLeg->value();
|
|
|
113 |
ui->legNe1->setChecked(value == 1);
|
|
|
114 |
ui->legNe2->setChecked(value == 2);
|
|
|
115 |
ui->legNe3->setChecked(value == 3);
|
|
|
116 |
ui->legNe4->setChecked(value == 4);
|
|
|
117 |
ui->legNe5->setChecked(value == 5);
|
| 186 |
- |
118 |
updateChanged(true);
|
| 184 |
- |
119 |
}
|
|
|
120 |
|
|
|
121 |
void QmConfTeams::calcNe1(void){ui->spinBox_NeLeg->setValue(1); updateNe(); }
|
|
|
122 |
void QmConfTeams::calcNe2(void){ui->spinBox_NeLeg->setValue(2); updateNe(); }
|
|
|
123 |
void QmConfTeams::calcNe3(void){ui->spinBox_NeLeg->setValue(3); updateNe(); }
|
|
|
124 |
void QmConfTeams::calcNe4(void){ui->spinBox_NeLeg->setValue(4); updateNe(); }
|
|
|
125 |
void QmConfTeams::calcNe5(void){ui->spinBox_NeLeg->setValue(5); updateNe(); }
|
|
|
126 |
|
| 175 |
david |
127 |
void QmConfTeams::save(void)
|
|
|
128 |
{
|
|
|
129 |
int num_teams = 0;
|
|
|
130 |
|
|
|
131 |
/*
|
|
|
132 |
** Copy original data
|
|
|
133 |
*/
|
| 180 |
- |
134 |
QmConfig newcfg(config);
|
| 175 |
david |
135 |
|
|
|
136 |
/*
|
|
|
137 |
** Extract data from Widgets
|
|
|
138 |
*/
|
|
|
139 |
strncpy(newcfg.event_name, qPrintable(ui->eventName->text()), sizeof(newcfg.event_name)) ;
|
| 201 |
- |
140 |
strncpy(newcfg.datafilename, qPrintable(ui->datafilename->text()), sizeof(newcfg.datafilename)) ;
|
|
|
141 |
strncpy(newcfg.addendum, qPrintable(ui->addendum->text()), sizeof(newcfg.addendum)) ;
|
| 175 |
david |
142 |
|
|
|
143 |
strncpy(newcfg.leg_name[0], qPrintable(ui->legName1->text()), sizeof(newcfg.leg_name[0])) ;
|
|
|
144 |
strncpy(newcfg.leg_name[1], qPrintable(ui->legName2->text()), sizeof(newcfg.leg_name[1])) ;
|
|
|
145 |
strncpy(newcfg.leg_name[2], qPrintable(ui->legName3->text()), sizeof(newcfg.leg_name[2])) ;
|
|
|
146 |
strncpy(newcfg.leg_name[3], qPrintable(ui->legName4->text()), sizeof(newcfg.leg_name[3])) ;
|
|
|
147 |
strncpy(newcfg.leg_name[4], qPrintable(ui->legName5->text()), sizeof(newcfg.leg_name[4])) ;
|
|
|
148 |
|
| 187 |
- |
149 |
ui->tn1->getData(&newcfg.t_def[0].start, &newcfg.t_def[0].end);
|
|
|
150 |
ui->tn2->getData(&newcfg.t_def[1].start, &newcfg.t_def[1].end);
|
|
|
151 |
ui->tn3->getData(&newcfg.t_def[2].start, &newcfg.t_def[2].end);
|
|
|
152 |
ui->tn4->getData(&newcfg.t_def[3].start, &newcfg.t_def[3].end);
|
|
|
153 |
ui->tn5->getData(&newcfg.t_def[4].start, &newcfg.t_def[4].end);
|
|
|
154 |
ui->tn6->getData(&newcfg.t_def[5].start, &newcfg.t_def[5].end);
|
|
|
155 |
ui->tn7->getData(&newcfg.t_def[6].start, &newcfg.t_def[6].end);
|
|
|
156 |
ui->tn8->getData(&newcfg.t_def[7].start, &newcfg.t_def[7].end);
|
| 175 |
david |
157 |
|
|
|
158 |
newcfg.equestrian_leg = ui->spinBox_NeLeg->value();
|
|
|
159 |
strncpy(newcfg.nonequestrian_class_abr, qPrintable(ui->ne_leg_abr->text()), sizeof(newcfg.nonequestrian_class_abr)-1) ;
|
|
|
160 |
|
|
|
161 |
newcfg.lines_per_page = ui->spinBox_LinesPerPage->value();
|
|
|
162 |
newcfg.perf_skip = ui->perfSkip->isChecked();
|
|
|
163 |
|
|
|
164 |
/*
|
|
|
165 |
** Sanity Test and Clean up
|
|
|
166 |
*/
|
| 186 |
- |
167 |
try
|
|
|
168 |
{
|
|
|
169 |
MainWindow::showMessage( "Saving Config");
|
| 175 |
david |
170 |
|
| 186 |
- |
171 |
compact( newcfg.event_name ); /* Rip of leading white_space */
|
|
|
172 |
for( int i = 0; i < MAX_LEGS; i++ )
|
|
|
173 |
compact( newcfg.leg_name[i] );
|
|
|
174 |
compact( newcfg.addendum );
|
|
|
175 |
compact( newcfg.datafilename );
|
|
|
176 |
|
|
|
177 |
/*
|
| 175 |
david |
178 |
* Do all sorts of consistency tests on the data
|
|
|
179 |
* Firstly - calculate the number of legs. Justify the data in the array
|
|
|
180 |
*/
|
|
|
181 |
|
| 186 |
- |
182 |
newcfg.num_legs = 0;
|
|
|
183 |
for( int i = 0; i < MAX_LEGS; i++ )
|
|
|
184 |
if( newcfg.leg_name[i][0] )
|
|
|
185 |
newcfg.num_legs++;
|
|
|
186 |
for( int i = newcfg.num_legs; i < MAX_LEGS; i++ )
|
| 175 |
david |
187 |
{
|
| 186 |
- |
188 |
if( newcfg.leg_name[i][0] )
|
|
|
189 |
{
|
|
|
190 |
throw( "Configuration error: Missing leg" );
|
|
|
191 |
}
|
| 175 |
david |
192 |
}
|
|
|
193 |
|
|
|
194 |
|
| 186 |
- |
195 |
/*
|
| 175 |
david |
196 |
* Now do the team numbering stuff
|
|
|
197 |
*/
|
|
|
198 |
|
| 186 |
- |
199 |
for( int i = 0; i < MAX_TMS_SPLIT; i++ )
|
| 175 |
david |
200 |
{
|
| 186 |
- |
201 |
if( newcfg.t_def[i].start == 0 && newcfg.t_def[i].end == 0 )
|
|
|
202 |
continue;
|
|
|
203 |
if( newcfg.t_def[i].start > newcfg.t_def[i].end )
|
| 175 |
david |
204 |
{
|
| 186 |
- |
205 |
throw( tprintf( "Team definition error : End greater than start. %d to %d", newcfg.t_def[i].start, newcfg.t_def[i].end ));
|
|
|
206 |
|
| 175 |
david |
207 |
}
|
| 186 |
- |
208 |
for( int j = 0; j < i; j++ )
|
|
|
209 |
{
|
|
|
210 |
if( ( newcfg.t_def[i].start >= newcfg.t_def[j].start
|
|
|
211 |
&& newcfg.t_def[i].start <= newcfg.t_def[j].end )
|
|
|
212 |
|| ( newcfg.t_def[i].end >= newcfg.t_def[j].start
|
|
|
213 |
&& newcfg.t_def[i].end <= newcfg.t_def[j].end ) )
|
|
|
214 |
{
|
|
|
215 |
throw (tprintf( "Team definition error : Overlapping definition. %d to %d",
|
|
|
216 |
newcfg.t_def[i].start, newcfg.t_def[i].end ));
|
|
|
217 |
}
|
|
|
218 |
}
|
| 175 |
david |
219 |
}
|
|
|
220 |
|
| 186 |
- |
221 |
/*
|
| 175 |
david |
222 |
* Determine the number of team splits
|
|
|
223 |
* There may be blank entries - these will be removed by sorting the array
|
|
|
224 |
*/
|
| 186 |
- |
225 |
qsort( ( char * ) newcfg.t_def, MAX_TMS_SPLIT, sizeof( *newcfg.t_def ), f_comp_int );
|
|
|
226 |
for( newcfg.num_teams = 0; newcfg.num_teams < MAX_TMS_SPLIT; newcfg.num_teams++ )
|
|
|
227 |
if( !newcfg.t_def[newcfg.num_teams].start )
|
|
|
228 |
break;
|
| 175 |
david |
229 |
|
| 186 |
- |
230 |
newcfg.min_team = newcfg.t_def[0].start;
|
|
|
231 |
newcfg.max_team = newcfg.t_def[newcfg.num_teams - 1].end;
|
| 175 |
david |
232 |
|
| 186 |
- |
233 |
/*
|
| 175 |
david |
234 |
** Limit the number of entrants
|
|
|
235 |
*/
|
| 186 |
- |
236 |
for( int i = 0; i < MAX_TMS_SPLIT; i++ )
|
| 175 |
david |
237 |
{
|
| 186 |
- |
238 |
if( newcfg.t_def[i].start )
|
|
|
239 |
{
|
|
|
240 |
num_teams += newcfg.t_def[i].end - newcfg.t_def[i].start + 1;
|
|
|
241 |
}
|
| 175 |
david |
242 |
}
|
|
|
243 |
#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)
|
| 186 |
- |
244 |
if( num_teams > LIMIT_TEAMS )
|
|
|
245 |
{
|
|
|
246 |
throw( "Maximum number of teams exceeded - reduce number of teams" );
|
|
|
247 |
}
|
| 175 |
david |
248 |
#endif
|
|
|
249 |
|
|
|
250 |
#if defined (HI_TECH_C) || defined (__TURBOC__)
|
|
|
251 |
|
| 186 |
- |
252 |
/*
|
| 175 |
david |
253 |
* Ensure that the number of teams allocated can fit within available
|
|
|
254 |
* Memory space. Ie: Can we malloc the report data structures
|
|
|
255 |
*/
|
| 186 |
- |
256 |
{
|
|
|
257 |
long sz;
|
| 175 |
david |
258 |
|
| 186 |
- |
259 |
sz = sizeof( ty_s_data ) > sizeof( ty_s_aux ) ?
|
|
|
260 |
sizeof( ty_s_data ) : sizeof( ty_s_aux );
|
|
|
261 |
if( sz * ( newcfg.max_team - newcfg.min_team + 2 ) > ( 1024L * 64L ) )
|
|
|
262 |
{
|
|
|
263 |
throw( "Too many teams: Reduce team spread." );
|
|
|
264 |
}
|
| 175 |
david |
265 |
}
|
|
|
266 |
#endif
|
|
|
267 |
|
| 186 |
- |
268 |
/*
|
| 175 |
david |
269 |
** Ensure the non-equestrian class and the equestrian leg are valid
|
|
|
270 |
*/
|
| 186 |
- |
271 |
if( newcfg.equestrian_leg )
|
| 175 |
david |
272 |
{
|
| 186 |
- |
273 |
if( newcfg.equestrian_leg > newcfg.num_legs )
|
|
|
274 |
{
|
|
|
275 |
throw( "Invalid non-equestrian leg number" );
|
|
|
276 |
}
|
| 175 |
david |
277 |
|
| 186 |
- |
278 |
/*
|
| 175 |
david |
279 |
** Ensure that the entered non-equestrian class name does exist
|
|
|
280 |
*/
|
| 186 |
- |
281 |
newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
|
|
|
282 |
if( newcfg.nonequestrian_class == 0 )
|
|
|
283 |
MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
|
|
|
284 |
}
|
| 175 |
david |
285 |
|
|
|
286 |
config = newcfg;
|
| 180 |
- |
287 |
config.write_config();
|
| 186 |
- |
288 |
updateChanged(false);
|
|
|
289 |
|
| 175 |
david |
290 |
}
|
| 186 |
- |
291 |
catch ( const char * str )
|
|
|
292 |
{
|
|
|
293 |
MainWindow::showMessage(str);
|
|
|
294 |
}
|
|
|
295 |
catch ( char * str )
|
|
|
296 |
{
|
|
|
297 |
MainWindow::showMessage(str);
|
|
|
298 |
}
|
|
|
299 |
catch ( ... )
|
|
|
300 |
{
|
|
|
301 |
MainWindow::showMessage ("QmConfTeams: Error of some form");
|
|
|
302 |
}
|
| 175 |
david |
303 |
}
|
|
|
304 |
|
|
|
305 |
void QmConfTeams::cancel(void)
|
|
|
306 |
{
|
|
|
307 |
populate();
|
|
|
308 |
}
|
|
|
309 |
|
| 186 |
- |
310 |
void QmConfTeams::changed(void)
|
|
|
311 |
{
|
|
|
312 |
if ( populating )
|
|
|
313 |
return;
|
|
|
314 |
updateChanged(true);
|
|
|
315 |
}
|
| 175 |
david |
316 |
|
| 186 |
- |
317 |
void QmConfTeams::updateChanged(bool newDirty)
|
|
|
318 |
{
|
| 203 |
david |
319 |
ui->editAddendum->setEnabled(!ui->addendum->text().isEmpty());
|
| 186 |
- |
320 |
if (newDirty != dirty)
|
|
|
321 |
{
|
|
|
322 |
dirty = newDirty;
|
|
|
323 |
if (dirty)
|
|
|
324 |
{
|
|
|
325 |
ui->Changed->setVisible(true);
|
|
|
326 |
ui->pushButtonSave->setEnabled(true);
|
| 230 |
- |
327 |
ui->pushButtonSave->setStyleSheet("background-color: rgb(255, 0, 0);");
|
| 186 |
- |
328 |
}
|
|
|
329 |
else
|
|
|
330 |
{
|
|
|
331 |
ui->Changed->setVisible(false);
|
|
|
332 |
ui->pushButtonSave->setEnabled(false);
|
| 230 |
- |
333 |
ui->pushButtonSave->setStyleSheet("");
|
| 186 |
- |
334 |
}
|
|
|
335 |
}
|
|
|
336 |
}
|
|
|
337 |
|
| 201 |
- |
338 |
void QmConfTeams::editAddendum(void)
|
|
|
339 |
{
|
| 202 |
- |
340 |
QString fname = ui->addendum->text();
|
|
|
341 |
if ( !fname.isEmpty() )
|
|
|
342 |
{
|
| 203 |
david |
343 |
QmEditAddendum dialog(QmConfig::getAddendemFile(fname, true));
|
| 202 |
- |
344 |
dialog.exec();
|
|
|
345 |
}
|
| 201 |
- |
346 |
}
|
|
|
347 |
|
| 175 |
david |
348 |
QmConfTeams::~QmConfTeams()
|
|
|
349 |
{
|
|
|
350 |
delete ui;
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
void QmConfTeams::changeEvent(QEvent *e)
|
|
|
354 |
{
|
|
|
355 |
QWidget::changeEvent(e);
|
| 201 |
- |
356 |
//qDebug("QmConfTeams Event:%d", e->type());
|
| 175 |
david |
357 |
switch (e->type()) {
|
|
|
358 |
case QEvent::LanguageChange:
|
|
|
359 |
ui->retranslateUi(this);
|
|
|
360 |
break;
|
|
|
361 |
default:
|
|
|
362 |
break;
|
|
|
363 |
}
|
|
|
364 |
}
|