Subversion Repositories svn1-original

Rev

Rev 184 | Rev 187 | 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"
186 - 7
#include    "mainwindow.h"
175 david 8
 
9
QmConfTeams::QmConfTeams(QWidget *parent) :
10
    QWidget(parent),
11
    ui(new Ui::QmConfigure)
12
{
13
    ui->setupUi(this);
186 - 14
    connect(ui->pushButtonSave, SIGNAL(clicked()), this, SLOT(save()) );
15
    connect(ui->pushButtonRestore, SIGNAL(clicked()), this, SLOT(cancel()) );
175 david 16
 
184 - 17
    ui->spinBox_NeLeg->setMaximum(5);
18
    ui->spinBox_NeLeg->setMinimum(0);
19
    connect(ui->spinBox_NeLeg, SIGNAL(valueChanged(int)), this,SLOT(updateNe()));
20
    connect(ui->legNe1,SIGNAL(clicked()), this,SLOT(calcNe1()));
21
    connect(ui->legNe2,SIGNAL(clicked()), this,SLOT(calcNe2()));
22
    connect(ui->legNe3,SIGNAL(clicked()), this,SLOT(calcNe3()));
23
    connect(ui->legNe4,SIGNAL(clicked()), this,SLOT(calcNe4()));
24
    connect(ui->legNe5,SIGNAL(clicked()), this,SLOT(calcNe5()));
25
 
186 - 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;
175 david 59
    populate();
60
 
61
 
62
}
63
void QmConfTeams::populate(void)
64
{
186 - 65
    populating = true;
175 david 66
    ui->eventName->setText( config.event_name);
67
    ui->eventName->setMaxLength(MAX_EVENT_NAME);
68
 
69
    ui->addendum->setText(config.addendum);
70
    ui->addendum->setMaxLength(sizeof(config.addendum)-1);
71
 
72
    ui->datafilename->setText(config.datafilename);
73
    ui->datafilename->setMaxLength(sizeof(config.datafilename - 1));
74
 
75
    ui->legName1->setText(config.leg_name[0]);
76
    ui->legName1->setMaxLength(MAX_LEG_NAME);
77
    ui->legName2->setText(config.leg_name[1]);
78
    ui->legName2->setMaxLength(MAX_LEG_NAME);
79
    ui->legName3->setText(config.leg_name[2]);
80
    ui->legName3->setMaxLength(MAX_LEG_NAME);
81
    ui->legName4->setText(config.leg_name[3]);
82
    ui->legName4->setMaxLength(MAX_LEG_NAME);
83
    ui->legName5->setText(config.leg_name[4]);
84
    ui->legName5->setMaxLength(MAX_LEG_NAME);
85
 
86
    ui->spinBox_1l->setValue( config.t_def[0].start);
87
    ui->spinBox_1u->setValue( config.t_def[0].end);
88
    ui->spinBox_2l->setValue( config.t_def[1].start);
89
    ui->spinBox_2u->setValue( config.t_def[1].end);
90
    ui->spinBox_3l->setValue( config.t_def[2].start);
91
    ui->spinBox_3u->setValue( config.t_def[2].end);
92
    ui->spinBox_4l->setValue( config.t_def[3].start);
93
    ui->spinBox_4u->setValue( config.t_def[3].end);
94
    ui->spinBox_5l->setValue( config.t_def[4].start);
95
    ui->spinBox_5u->setValue( config.t_def[4].end);
96
    ui->spinBox_6l->setValue( config.t_def[5].start);
97
    ui->spinBox_6u->setValue( config.t_def[5].end);
98
    ui->spinBox_7l->setValue( config.t_def[6].start);
99
    ui->spinBox_7u->setValue( config.t_def[6].end);
100
    ui->spinBox_8l->setValue( config.t_def[7].start);
101
    ui->spinBox_8u->setValue( config.t_def[7].end);
102
 
103
    ui->spinBox_NeLeg->setValue(config.equestrian_leg);
184 - 104
    updateNe();
175 david 105
    ui->ne_leg_abr->setText(config.nonequestrian_class_abr);
106
    ui->ne_leg_abr->setMaxLength(sizeof(config.nonequestrian_class_abr)-1);
107
 
108
     ui->spinBox_LinesPerPage->setValue(config.lines_per_page);
109
     ui->perfSkip->setChecked( config.perf_skip );
186 - 110
    populating = false;
111
    updateChanged(false);
175 david 112
   }
113
 
184 - 114
void QmConfTeams::updateNe(void)
115
{
116
    int value = ui->spinBox_NeLeg->value();
117
    ui->legNe1->setChecked(value == 1);
118
    ui->legNe2->setChecked(value == 2);
119
    ui->legNe3->setChecked(value == 3);
120
    ui->legNe4->setChecked(value == 4);
121
    ui->legNe5->setChecked(value == 5);
186 - 122
    updateChanged(true);
184 - 123
}
124
 
125
void QmConfTeams::calcNe1(void){ui->spinBox_NeLeg->setValue(1); updateNe(); }
126
void QmConfTeams::calcNe2(void){ui->spinBox_NeLeg->setValue(2); updateNe(); }
127
void QmConfTeams::calcNe3(void){ui->spinBox_NeLeg->setValue(3); updateNe(); }
128
void QmConfTeams::calcNe4(void){ui->spinBox_NeLeg->setValue(4); updateNe(); }
129
void QmConfTeams::calcNe5(void){ui->spinBox_NeLeg->setValue(5); updateNe(); }
130
 
175 david 131
void QmConfTeams::save(void)
132
{
133
    int num_teams = 0;
134
 
135
    /*
136
    **    Copy original data
137
    */
180 - 138
    QmConfig    newcfg(config);
175 david 139
 
140
    /*
141
    **  Extract data from Widgets
142
    */
143
    strncpy(newcfg.event_name, qPrintable(ui->eventName->text()), sizeof(newcfg.event_name)) ;
144
    strncpy(newcfg.datafilename, qPrintable(ui->datafilename->text()), sizeof(newcfg.datafilename-1)) ;
145
    strncpy(newcfg.addendum, qPrintable(ui->addendum->text()), sizeof(newcfg.addendum-1)) ;
146
 
147
    strncpy(newcfg.leg_name[0], qPrintable(ui->legName1->text()), sizeof(newcfg.leg_name[0])) ;
148
    strncpy(newcfg.leg_name[1], qPrintable(ui->legName2->text()), sizeof(newcfg.leg_name[1])) ;
149
    strncpy(newcfg.leg_name[2], qPrintable(ui->legName3->text()), sizeof(newcfg.leg_name[2])) ;
150
    strncpy(newcfg.leg_name[3], qPrintable(ui->legName4->text()), sizeof(newcfg.leg_name[3])) ;
151
    strncpy(newcfg.leg_name[4], qPrintable(ui->legName5->text()), sizeof(newcfg.leg_name[4])) ;
152
 
153
    newcfg.t_def[0].start = ui->spinBox_1l->value();
154
    newcfg.t_def[0].end = ui->spinBox_1u->value();
155
 
156
    newcfg.t_def[1].start = ui->spinBox_2l->value();
157
    newcfg.t_def[1].end   = ui->spinBox_2u->value();
158
 
159
    newcfg.t_def[2].start = ui->spinBox_3l->value();
160
    newcfg.t_def[2].end   = ui->spinBox_3u->value();
161
 
162
    newcfg.t_def[3].start = ui->spinBox_4l->value();
163
    newcfg.t_def[3].end   = ui->spinBox_4u->value();
164
 
165
    newcfg.t_def[4].start = ui->spinBox_5l->value();
166
    newcfg.t_def[4].end   = ui->spinBox_5u->value();
167
 
168
    newcfg.t_def[5].start = ui->spinBox_6l->value();
169
    newcfg.t_def[5].end   = ui->spinBox_6u->value();
170
 
171
    newcfg.t_def[6].start = ui->spinBox_7l->value();
172
    newcfg.t_def[6].end   = ui->spinBox_7u->value();
173
 
174
    newcfg.t_def[7].start = ui->spinBox_8l->value();
175
    newcfg.t_def[7].end   = ui->spinBox_8u->value();
176
 
177
    newcfg.equestrian_leg = ui->spinBox_NeLeg->value();
178
    strncpy(newcfg.nonequestrian_class_abr, qPrintable(ui->ne_leg_abr->text()), sizeof(newcfg.nonequestrian_class_abr)-1) ;
179
 
180
    newcfg.lines_per_page = ui->spinBox_LinesPerPage->value();
181
    newcfg.perf_skip = ui->perfSkip->isChecked();
182
 
183
    /*
184
    **  Sanity Test and Clean up
185
    */
186 - 186
    try
187
    {
188
        MainWindow::showMessage( "Saving Config");
175 david 189
 
186 - 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
 
196
        /*
175 david 197
     * Do all sorts of consistency tests on the data
198
     * Firstly - calculate the number of legs. Justify the data in the array
199
     */
200
 
186 - 201
        newcfg.num_legs = 0;
202
        for( int i = 0; i < MAX_LEGS; i++ )
203
            if( newcfg.leg_name[i][0] )
204
                newcfg.num_legs++;
205
        for( int i = newcfg.num_legs; i < MAX_LEGS; i++ )
175 david 206
        {
186 - 207
            if( newcfg.leg_name[i][0] )
208
            {
209
                throw( "Configuration error: Missing leg" );
210
            }
175 david 211
        }
212
 
213
 
186 - 214
        /*
175 david 215
     * Now do the team numbering stuff
216
     */
217
 
186 - 218
        for( int i = 0; i < MAX_TMS_SPLIT; i++ )
175 david 219
        {
186 - 220
            if( newcfg.t_def[i].start == 0 && newcfg.t_def[i].end == 0 )
221
                continue;
222
            if( newcfg.t_def[i].start > newcfg.t_def[i].end )
175 david 223
            {
186 - 224
                throw( tprintf( "Team definition error : End greater than start. %d to %d", newcfg.t_def[i].start, newcfg.t_def[i].end ));
225
 
175 david 226
            }
186 - 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 ) )
233
                    {
234
                    throw (tprintf( "Team definition error : Overlapping definition. %d to %d",
235
                              newcfg.t_def[i].start, newcfg.t_def[i].end ));
236
                    }
237
            }
175 david 238
        }
239
 
186 - 240
        /*
175 david 241
     * Determine the number of team splits
242
     * There may be blank entries - these will be removed by sorting the array
243
     */
186 - 244
        qsort( ( char * ) newcfg.t_def, MAX_TMS_SPLIT, sizeof( *newcfg.t_def ), f_comp_int );
245
        for( newcfg.num_teams = 0; newcfg.num_teams < MAX_TMS_SPLIT; newcfg.num_teams++ )
246
            if( !newcfg.t_def[newcfg.num_teams].start )
247
                break;
175 david 248
 
186 - 249
        newcfg.min_team = newcfg.t_def[0].start;
250
        newcfg.max_team = newcfg.t_def[newcfg.num_teams - 1].end;
175 david 251
 
186 - 252
        /*
175 david 253
     **  Limit the number of entrants
254
     */
186 - 255
        for( int i = 0; i < MAX_TMS_SPLIT; i++ )
175 david 256
        {
186 - 257
            if( newcfg.t_def[i].start )
258
            {
259
                num_teams += newcfg.t_def[i].end - newcfg.t_def[i].start + 1;
260
            }
175 david 261
        }
262
#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)
186 - 263
        if( num_teams > LIMIT_TEAMS )
264
        {
265
            throw( "Maximum number of teams exceeded - reduce number of teams" );
266
        }
175 david 267
#endif
268
 
269
#if defined (HI_TECH_C) || defined (__TURBOC__)
270
 
186 - 271
        /*
175 david 272
     * Ensure that the number of teams allocated can fit within available
273
     * Memory space. Ie: Can we malloc the report data structures
274
     */
186 - 275
        {
276
            long        sz;
175 david 277
 
186 - 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
            {
282
                throw( "Too many teams: Reduce team spread." );
283
            }
175 david 284
        }
285
#endif
286
 
186 - 287
        /*
175 david 288
     **  Ensure the non-equestrian class and the equestrian leg are valid
289
     */
186 - 290
        if( newcfg.equestrian_leg )
175 david 291
        {
186 - 292
            if( newcfg.equestrian_leg > newcfg.num_legs )
293
            {
294
                throw( "Invalid non-equestrian leg number" );
295
            }
175 david 296
 
186 - 297
            /*
175 david 298
         **  Ensure that the entered non-equestrian class name does exist
299
         */
186 - 300
            newcfg.nonequestrian_class = newcfg.lookup_class( newcfg.nonequestrian_class_abr );
301
            if( newcfg.nonequestrian_class == 0 )
302
                MainWindow::showMessage( "WARNING: Non-equestrian class not found" );
303
        }
175 david 304
 
305
        config = newcfg;
180 - 306
        config.write_config();
186 - 307
        updateChanged(false);
308
 
175 david 309
    }
186 - 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");
321
    }
175 david 322
}
323
 
324
void QmConfTeams::cancel(void)
325
{
326
    populate();
327
}
328
 
186 - 329
void QmConfTeams::changed(void)
330
{
331
    if ( populating )
332
        return;
333
    updateChanged(true);
334
}
175 david 335
 
186 - 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
}
353
 
175 david 354
QmConfTeams::~QmConfTeams()
355
{
356
    delete ui;
357
}
358
 
359
void QmConfTeams::changeEvent(QEvent *e)
360
{
361
    QWidget::changeEvent(e);
186 - 362
    qDebug("QmConfTeams Event:%d", e->type());
175 david 363
    switch (e->type()) {
364
    case QEvent::LanguageChange:
365
        ui->retranslateUi(this);
366
        break;
367
    default:
368
        break;
369
    }
370
}