Subversion Repositories svn1-original

Rev

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

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