| 98 |
- |
1 |
#include "qmconfigure.h"
|
|
|
2 |
#include "ui_qmconfigure.h"
|
|
|
3 |
#include "consts.h"
|
|
|
4 |
#include "structs.h"
|
|
|
5 |
#include "proto.h"
|
|
|
6 |
|
|
|
7 |
QmConfigure::QmConfigure(QWidget *parent) :
|
|
|
8 |
QWidget(parent),
|
|
|
9 |
ui(new Ui::QmConfigure)
|
|
|
10 |
{
|
|
|
11 |
ui->setupUi(this);
|
| 103 |
david |
12 |
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()) );
|
|
|
13 |
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
|
| 98 |
- |
14 |
|
| 103 |
david |
15 |
populate();
|
| 99 |
david |
16 |
|
|
|
17 |
|
|
|
18 |
}
|
| 103 |
david |
19 |
void QmConfigure::populate(void)
|
| 99 |
david |
20 |
{
|
| 98 |
- |
21 |
ui->eventName->setText( config.event_name);
|
| 103 |
david |
22 |
ui->eventName->setMaxLength(MAX_EVENT_NAME);
|
|
|
23 |
|
|
|
24 |
ui->addendum->setText(config.addendum);
|
| 106 |
- |
25 |
ui->addendum->setMaxLength(sizeof(config.addendum)-1);
|
| 103 |
david |
26 |
|
|
|
27 |
ui->datafilename->setText(config.datafilename);
|
|
|
28 |
ui->datafilename->setMaxLength(sizeof(config.datafilename - 1));
|
|
|
29 |
|
| 98 |
- |
30 |
ui->legName1->setText(config.leg_name[0]);
|
| 103 |
david |
31 |
ui->legName1->setMaxLength(MAX_LEG_NAME);
|
|
|
32 |
|
| 98 |
- |
33 |
ui->legName2->setText(config.leg_name[1]);
|
| 103 |
david |
34 |
ui->legName2->setMaxLength(MAX_LEG_NAME);
|
| 98 |
- |
35 |
ui->legName3->setText(config.leg_name[2]);
|
| 103 |
david |
36 |
ui->legName3->setMaxLength(MAX_LEG_NAME);
|
| 98 |
- |
37 |
ui->legName4->setText(config.leg_name[3]);
|
| 103 |
david |
38 |
ui->legName4->setMaxLength(MAX_LEG_NAME);
|
| 98 |
- |
39 |
ui->legName5->setText(config.leg_name[4]);
|
| 103 |
david |
40 |
ui->legName5->setMaxLength(MAX_LEG_NAME);
|
| 99 |
david |
41 |
|
|
|
42 |
ui->spinBox_1l->setValue( config.t_def[0].start);
|
|
|
43 |
ui->spinBox_1u->setValue( config.t_def[0].end);
|
|
|
44 |
ui->spinBox_2l->setValue( config.t_def[1].start);
|
|
|
45 |
ui->spinBox_2u->setValue( config.t_def[1].end);
|
|
|
46 |
ui->spinBox_3l->setValue( config.t_def[2].start);
|
|
|
47 |
ui->spinBox_3u->setValue( config.t_def[2].end);
|
|
|
48 |
ui->spinBox_4l->setValue( config.t_def[3].start);
|
|
|
49 |
ui->spinBox_4u->setValue( config.t_def[3].end);
|
|
|
50 |
ui->spinBox_5l->setValue( config.t_def[4].start);
|
|
|
51 |
ui->spinBox_5u->setValue( config.t_def[4].end);
|
|
|
52 |
ui->spinBox_6l->setValue( config.t_def[5].start);
|
|
|
53 |
ui->spinBox_6u->setValue( config.t_def[5].end);
|
|
|
54 |
ui->spinBox_7l->setValue( config.t_def[6].start);
|
|
|
55 |
ui->spinBox_7u->setValue( config.t_def[6].end);
|
|
|
56 |
ui->spinBox_8l->setValue( config.t_def[7].start);
|
|
|
57 |
ui->spinBox_8u->setValue( config.t_def[7].end);
|
|
|
58 |
|
| 103 |
david |
59 |
ui->spinBox_NeLeg->setValue(config.equestrian_leg);
|
|
|
60 |
ui->ne_leg_abr->setText(config.nonequestrian_class_abr);
|
|
|
61 |
ui->ne_leg_abr->setMaxLength(sizeof(config.nonequestrian_class_abr)-1);
|
|
|
62 |
|
| 104 |
david |
63 |
ui->spinBox_LinesPerPage->setValue(config.lines_per_page);
|
|
|
64 |
ui->perfSkip->setChecked( config.perf_skip );
|
| 98 |
- |
65 |
|
| 104 |
david |
66 |
}
|
|
|
67 |
|
| 103 |
david |
68 |
void QmConfigure::save(void)
|
| 99 |
david |
69 |
{
|
| 103 |
david |
70 |
int error = 0;
|
|
|
71 |
int num_teams = 0;
|
| 99 |
david |
72 |
|
| 103 |
david |
73 |
/*
|
|
|
74 |
** Copy original data
|
|
|
75 |
*/
|
|
|
76 |
MARA_CFG newcfg = config;
|
|
|
77 |
|
| 110 |
- |
78 |
/*
|
|
|
79 |
** Extract data from Widgets
|
|
|
80 |
*/
|
| 103 |
david |
81 |
strncpy(newcfg.event_name, qPrintable(ui->eventName->text()), sizeof(newcfg.event_name)) ;
|
|
|
82 |
strncpy(newcfg.datafilename, qPrintable(ui->datafilename->text()), sizeof(newcfg.datafilename-1)) ;
|
|
|
83 |
strncpy(newcfg.addendum, qPrintable(ui->addendum->text()), sizeof(newcfg.addendum-1)) ;
|
|
|
84 |
|
|
|
85 |
ui->legName1->setText(config.leg_name[0]);
|
|
|
86 |
ui->legName1->setMaxLength(MAX_LEG_NAME);
|
|
|
87 |
|
|
|
88 |
strncpy(newcfg.leg_name[0], qPrintable(ui->legName1->text()), sizeof(newcfg.leg_name[0])) ;
|
|
|
89 |
strncpy(newcfg.leg_name[1], qPrintable(ui->legName2->text()), sizeof(newcfg.leg_name[1])) ;
|
|
|
90 |
strncpy(newcfg.leg_name[2], qPrintable(ui->legName3->text()), sizeof(newcfg.leg_name[2])) ;
|
|
|
91 |
strncpy(newcfg.leg_name[3], qPrintable(ui->legName4->text()), sizeof(newcfg.leg_name[3])) ;
|
|
|
92 |
strncpy(newcfg.leg_name[4], qPrintable(ui->legName5->text()), sizeof(newcfg.leg_name[4])) ;
|
|
|
93 |
|
|
|
94 |
newcfg.t_def[0].start = ui->spinBox_1l->value();
|
|
|
95 |
newcfg.t_def[0].end = ui->spinBox_1u->value();
|
|
|
96 |
|
|
|
97 |
newcfg.t_def[1].start = ui->spinBox_2l->value();
|
|
|
98 |
newcfg.t_def[1].end = ui->spinBox_2u->value();
|
|
|
99 |
|
|
|
100 |
newcfg.t_def[2].start = ui->spinBox_3l->value();
|
|
|
101 |
newcfg.t_def[2].end = ui->spinBox_3u->value();
|
|
|
102 |
|
|
|
103 |
newcfg.t_def[3].start = ui->spinBox_4l->value();
|
|
|
104 |
newcfg.t_def[3].end = ui->spinBox_4u->value();
|
|
|
105 |
|
|
|
106 |
newcfg.t_def[4].start = ui->spinBox_5l->value();
|
|
|
107 |
newcfg.t_def[4].end = ui->spinBox_5u->value();
|
|
|
108 |
|
|
|
109 |
newcfg.t_def[5].start = ui->spinBox_6l->value();
|
|
|
110 |
newcfg.t_def[5].end = ui->spinBox_6u->value();
|
|
|
111 |
|
|
|
112 |
newcfg.t_def[6].start = ui->spinBox_7l->value();
|
|
|
113 |
newcfg.t_def[6].end = ui->spinBox_7u->value();
|
|
|
114 |
|
|
|
115 |
newcfg.t_def[7].start = ui->spinBox_8l->value();
|
|
|
116 |
newcfg.t_def[7].end = ui->spinBox_8u->value();
|
|
|
117 |
|
|
|
118 |
newcfg.equestrian_leg = ui->spinBox_NeLeg->value();
|
|
|
119 |
strncpy(newcfg.nonequestrian_class_abr, qPrintable(ui->ne_leg_abr->text()), sizeof(newcfg.nonequestrian_class_abr)-1) ;
|
|
|
120 |
|
| 104 |
david |
121 |
newcfg.lines_per_page = ui->spinBox_LinesPerPage->value();
|
|
|
122 |
newcfg.perf_skip = ui->perfSkip->isChecked();
|
|
|
123 |
|
| 110 |
- |
124 |
/*
|
|
|
125 |
** Sanity Test and Clean up
|
|
|
126 |
*/
|
|
|
127 |
compact( newcfg.event_name ); /* Rip of leading white_space */
|
| 103 |
david |
128 |
for( int i = 0; i < MAX_LEGS; i++ )
|
|
|
129 |
compact( newcfg.leg_name[i] );
|
|
|
130 |
compact( newcfg.addendum );
|
|
|
131 |
compact( newcfg.datafilename );
|
|
|
132 |
|
|
|
133 |
/*
|
|
|
134 |
* Do all sorts of consistency tests on the data
|
|
|
135 |
* Firstly - calculate the number of legs. Justify the data in the array
|
|
|
136 |
*/
|
|
|
137 |
|
|
|
138 |
newcfg.num_legs = 0;
|
|
|
139 |
for( int i = 0; i < MAX_LEGS; i++ )
|
|
|
140 |
if( newcfg.leg_name[i][0] )
|
|
|
141 |
newcfg.num_legs++;
|
|
|
142 |
for( int i = newcfg.num_legs; i < MAX_LEGS; i++ )
|
|
|
143 |
if( newcfg.leg_name[i][0] )
|
|
|
144 |
{
|
|
|
145 |
printf( "Configuration error: Missing leg\n" );
|
|
|
146 |
error++;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
/*
|
|
|
151 |
* Now do the team numbering stuff
|
|
|
152 |
*/
|
|
|
153 |
|
|
|
154 |
for( int i = 0; i < MAX_TMS_SPLIT; i++ )
|
|
|
155 |
{
|
|
|
156 |
if( newcfg.t_def[i].start == 0 && newcfg.t_def[i].end == 0 )
|
|
|
157 |
continue;
|
|
|
158 |
if( newcfg.t_def[i].start > newcfg.t_def[i].end )
|
|
|
159 |
{
|
|
|
160 |
printf
|
|
|
161 |
( "Team definition error : End greater than start. %d to %d\n",
|
|
|
162 |
newcfg.t_def[i].start, newcfg.t_def[i].end );
|
|
|
163 |
error++;
|
|
|
164 |
}
|
|
|
165 |
for( int j = 0; j < i; j++ )
|
|
|
166 |
{
|
|
|
167 |
if( ( newcfg.t_def[i].start >= newcfg.t_def[j].start
|
|
|
168 |
&& newcfg.t_def[i].start <= newcfg.t_def[j].end )
|
|
|
169 |
|| ( newcfg.t_def[i].end >= newcfg.t_def[j].start
|
|
|
170 |
&& newcfg.t_def[i].end <= newcfg.t_def[j].end ) )
|
|
|
171 |
{
|
|
|
172 |
printf
|
|
|
173 |
( "Team definition error : Overlapping definition. %d to %d\n",
|
|
|
174 |
newcfg.t_def[i].start, newcfg.t_def[i].end );
|
|
|
175 |
error++;
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
/*
|
|
|
181 |
* Determine the number of team splits
|
|
|
182 |
* There may be blank entries - these will be removed by sorting the array
|
|
|
183 |
*/
|
|
|
184 |
qsort( ( char * ) newcfg.t_def, MAX_TMS_SPLIT, sizeof( *newcfg.t_def ), f_comp_int );
|
|
|
185 |
for( newcfg.num_teams = 0; newcfg.num_teams < MAX_TMS_SPLIT; newcfg.num_teams++ )
|
|
|
186 |
if( !newcfg.t_def[newcfg.num_teams].start )
|
|
|
187 |
break;
|
|
|
188 |
|
|
|
189 |
newcfg.min_team = newcfg.t_def[0].start;
|
|
|
190 |
newcfg.max_team = newcfg.t_def[newcfg.num_teams - 1].end;
|
|
|
191 |
|
|
|
192 |
/*
|
|
|
193 |
** Limit the number of entrants
|
|
|
194 |
*/
|
|
|
195 |
for( int i = 0; i < MAX_TMS_SPLIT; i++ )
|
|
|
196 |
{
|
|
|
197 |
if( newcfg.t_def[i].start )
|
|
|
198 |
{
|
|
|
199 |
num_teams += newcfg.t_def[i].end - newcfg.t_def[i].start + 1;
|
|
|
200 |
}
|
|
|
201 |
}
|
|
|
202 |
#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)
|
|
|
203 |
if( num_teams > LIMIT_TEAMS )
|
|
|
204 |
{
|
|
|
205 |
printf( "Maximum number of teams exceeded - reduce number of teams\n" );
|
|
|
206 |
error++;
|
|
|
207 |
}
|
|
|
208 |
#endif
|
|
|
209 |
|
|
|
210 |
#if defined (HI_TECH_C) || defined (__TURBOC__)
|
|
|
211 |
|
|
|
212 |
/*
|
|
|
213 |
* Ensure that the number of teams allocated can fit within available
|
|
|
214 |
* Memory space. Ie: Can we malloc the report data structures
|
|
|
215 |
*/
|
|
|
216 |
{
|
|
|
217 |
long sz;
|
|
|
218 |
|
|
|
219 |
sz = sizeof( ty_s_data ) > sizeof( ty_s_aux ) ?
|
|
|
220 |
sizeof( ty_s_data ) : sizeof( ty_s_aux );
|
|
|
221 |
if( sz * ( newcfg.max_team - newcfg.min_team + 2 ) > ( 1024L * 64L ) )
|
|
|
222 |
{
|
|
|
223 |
printf( "Too many teams: Reduce team spread.\n" );
|
|
|
224 |
error++;
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
#endif
|
|
|
228 |
|
|
|
229 |
/*
|
|
|
230 |
** Ensure the non-equestrian class and the equestrian leg are valid
|
|
|
231 |
*/
|
|
|
232 |
if( newcfg.equestrian_leg )
|
|
|
233 |
{
|
|
|
234 |
if( newcfg.equestrian_leg > newcfg.num_legs )
|
|
|
235 |
{
|
|
|
236 |
printf( "Invalid non-equestrian leg number.\n" );
|
|
|
237 |
error++;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
/*
|
|
|
241 |
** Ensure that the entered non-equestrian class name does exist
|
|
|
242 |
*/
|
|
|
243 |
newcfg.nonequestrian_class = lookup_class( newcfg.nonequestrian_class_abr, &newcfg );
|
|
|
244 |
if( newcfg.nonequestrian_class == 0 )
|
|
|
245 |
printf( "WARNING: Non-equestrian class not found\n" );
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
if ( error == 0 )
|
|
|
249 |
{
|
|
|
250 |
config = newcfg;
|
|
|
251 |
wt_config();
|
|
|
252 |
}
|
| 99 |
david |
253 |
}
|
|
|
254 |
|
| 103 |
david |
255 |
void QmConfigure::cancel(void)
|
| 99 |
david |
256 |
{
|
| 103 |
david |
257 |
populate();
|
| 99 |
david |
258 |
}
|
|
|
259 |
|
|
|
260 |
|
| 98 |
- |
261 |
QmConfigure::~QmConfigure()
|
|
|
262 |
{
|
|
|
263 |
delete ui;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
void QmConfigure::changeEvent(QEvent *e)
|
|
|
267 |
{
|
|
|
268 |
QWidget::changeEvent(e);
|
|
|
269 |
switch (e->type()) {
|
|
|
270 |
case QEvent::LanguageChange:
|
|
|
271 |
ui->retranslateUi(this);
|
|
|
272 |
break;
|
|
|
273 |
default:
|
|
|
274 |
break;
|
|
|
275 |
}
|
|
|
276 |
}
|