Subversion Repositories svn1-original

Rev

Rev 184 | Rev 187 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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