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);
102 - 25
    ui->addendum->setMaxLength(sizeof(config.addendum)-1);
99 david 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
 
100 david 63
     ui->spinBox_LinesPerPage->setValue(config.lines_per_page);
64
     ui->perfSkip->setChecked( config.perf_skip );
94 - 65
 
100 david 66
   }
67
 
99 david 68
void QmConfigure::save(void)
95 david 69
{
99 david 70
    int error = 0;
71
    int num_teams = 0;
95 david 72
 
99 david 73
    /*
74
    **    Copy original data
75
    */
76
    MARA_CFG    newcfg = config;
77
 
78
    strncpy(newcfg.event_name, qPrintable(ui->eventName->text()), sizeof(newcfg.event_name)) ;
79
    strncpy(newcfg.datafilename, qPrintable(ui->datafilename->text()), sizeof(newcfg.datafilename-1)) ;
80
    strncpy(newcfg.addendum, qPrintable(ui->addendum->text()), sizeof(newcfg.addendum-1)) ;
81
 
82
    ui->legName1->setText(config.leg_name[0]);
83
    ui->legName1->setMaxLength(MAX_LEG_NAME);
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
 
100 david 118
    newcfg.lines_per_page = ui->spinBox_LinesPerPage->value();
119
    newcfg.perf_skip = ui->perfSkip->isChecked();
120
 
99 david 121
       compact( newcfg.event_name );               /* Rip of leading white_space */
122
    for( int i = 0; i < MAX_LEGS; i++ )
123
        compact( newcfg.leg_name[i] );
124
    compact( newcfg.addendum );
125
    compact( newcfg.datafilename );
126
 
127
    /*
128
     * Do all sorts of consistency tests on the data
129
     * Firstly - calculate the number of legs. Justify the data in the array
130
     */
131
 
132
    newcfg.num_legs = 0;
133
    for( int i = 0; i < MAX_LEGS; i++ )
134
        if( newcfg.leg_name[i][0] )
135
            newcfg.num_legs++;
136
    for( int i = newcfg.num_legs; i < MAX_LEGS; i++ )
137
        if( newcfg.leg_name[i][0] )
138
        {
139
            printf( "Configuration error: Missing leg\n" );
140
            error++;
141
        }
142
 
143
 
144
    /*
145
     * Now do the team numbering stuff
146
     */
147
 
148
    for( int i = 0; i < MAX_TMS_SPLIT; i++ )
149
    {
150
        if( newcfg.t_def[i].start == 0 && newcfg.t_def[i].end == 0 )
151
            continue;
152
        if( newcfg.t_def[i].start > newcfg.t_def[i].end )
153
        {
154
            printf
155
                ( "Team definition error : End greater than start. %d to %d\n",
156
                  newcfg.t_def[i].start, newcfg.t_def[i].end );
157
            error++;
158
        }
159
        for( int j = 0; j < i; j++ )
160
        {
161
            if( ( newcfg.t_def[i].start >= newcfg.t_def[j].start
162
                  && newcfg.t_def[i].start <= newcfg.t_def[j].end )
163
                || ( newcfg.t_def[i].end >= newcfg.t_def[j].start
164
                     && newcfg.t_def[i].end <= newcfg.t_def[j].end ) )
165
            {
166
                printf
167
                    ( "Team definition error : Overlapping definition. %d to %d\n",
168
                      newcfg.t_def[i].start, newcfg.t_def[i].end );
169
                error++;
170
            }
171
        }
172
    }
173
 
174
    /*
175
     * Determine the number of team splits
176
     * There may be blank entries - these will be removed by sorting the array
177
     */
178
    qsort( ( char * ) newcfg.t_def, MAX_TMS_SPLIT, sizeof( *newcfg.t_def ), f_comp_int );
179
    for( newcfg.num_teams = 0; newcfg.num_teams < MAX_TMS_SPLIT; newcfg.num_teams++ )
180
        if( !newcfg.t_def[newcfg.num_teams].start )
181
            break;
182
 
183
    newcfg.min_team = newcfg.t_def[0].start;
184
    newcfg.max_team = newcfg.t_def[newcfg.num_teams - 1].end;
185
 
186
    /*
187
     **  Limit the number of entrants
188
     */
189
    for( int i = 0; i < MAX_TMS_SPLIT; i++ )
190
    {
191
        if( newcfg.t_def[i].start )
192
        {
193
            num_teams += newcfg.t_def[i].end - newcfg.t_def[i].start + 1;
194
        }
195
    }
196
#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)
197
    if( num_teams > LIMIT_TEAMS )
198
    {
199
        printf( "Maximum number of teams exceeded - reduce number of teams\n" );
200
        error++;
201
    }
202
#endif
203
 
204
#if defined (HI_TECH_C) || defined (__TURBOC__)
205
 
206
    /*
207
     * Ensure that the number of teams allocated can fit within available
208
     * Memory space. Ie: Can we malloc the report data structures
209
     */
210
    {
211
        long        sz;
212
 
213
        sz = sizeof( ty_s_data ) > sizeof( ty_s_aux ) ?
214
            sizeof( ty_s_data ) : sizeof( ty_s_aux );
215
        if( sz * ( newcfg.max_team - newcfg.min_team + 2 ) > ( 1024L * 64L ) )
216
        {
217
            printf( "Too many teams: Reduce team spread.\n" );
218
            error++;
219
        }
220
    }
221
#endif
222
 
223
    /*
224
     **  Ensure the non-equestrian class and the equestrian leg are valid
225
     */
226
    if( newcfg.equestrian_leg )
227
    {
228
        if( newcfg.equestrian_leg > newcfg.num_legs )
229
        {
230
            printf( "Invalid non-equestrian leg number.\n" );
231
            error++;
232
        }
233
 
234
        /*
235
         **  Ensure that the entered non-equestrian class name does exist
236
         */
237
        newcfg.nonequestrian_class = lookup_class( newcfg.nonequestrian_class_abr, &newcfg );
238
        if( newcfg.nonequestrian_class == 0 )
239
            printf( "WARNING: Non-equestrian class not found\n" );
240
    }
241
 
242
    if ( error == 0 )
243
    {
244
        config = newcfg;
245
        wt_config();
246
    }
95 david 247
}
248
 
99 david 249
void QmConfigure::cancel(void)
95 david 250
{
99 david 251
    populate();
95 david 252
}
253
 
254
 
94 - 255
QmConfigure::~QmConfigure()
256
{
257
    delete ui;
258
}
259
 
260
void QmConfigure::changeEvent(QEvent *e)
261
{
262
    QWidget::changeEvent(e);
263
    switch (e->type()) {
264
    case QEvent::LanguageChange:
265
        ui->retranslateUi(this);
266
        break;
267
    default:
268
        break;
269
    }
270
}