Subversion Repositories svn1

Rev

Rev 176 | Rev 182 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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