Subversion Repositories svn1-original

Rev

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