Subversion Repositories svn1

Rev

Details | Last modification | View Log | RSS feed

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