Subversion Repositories svn1

Rev

Rev 95 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 95 Rev 99
Line 7... Line 7...
7
QmConfigure::QmConfigure(QWidget *parent) :
7
QmConfigure::QmConfigure(QWidget *parent) :
8
    QWidget(parent),
8
    QWidget(parent),
9
    ui(new Ui::QmConfigure)
9
    ui(new Ui::QmConfigure)
10
{
10
{
11
    ui->setupUi(this);
11
    ui->setupUi(this);
12
    connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(QmConfigureSave()) );
12
    connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()) );
13
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(QmConfigureCancel()) );
13
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
14
 
14
 
15
    QmConfigurePopulate();
15
    populate();
16
 
16
 
17
 
17
 
18
}
18
}
19
void QmConfigure::QmConfigurePopulate(void)
19
void QmConfigure::populate(void)
20
{
20
{
21
    ui->eventName->setText( config.event_name);
21
    ui->eventName->setText( config.event_name);
-
 
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
 
22
    ui->legName1->setText(config.leg_name[0]);
30
    ui->legName1->setText(config.leg_name[0]);
-
 
31
    ui->legName1->setMaxLength(MAX_LEG_NAME);
-
 
32
 
23
    ui->legName2->setText(config.leg_name[1]);
33
    ui->legName2->setText(config.leg_name[1]);
-
 
34
    ui->legName2->setMaxLength(MAX_LEG_NAME);
24
    ui->legName3->setText(config.leg_name[2]);
35
    ui->legName3->setText(config.leg_name[2]);
-
 
36
    ui->legName3->setMaxLength(MAX_LEG_NAME);
25
    ui->legName4->setText(config.leg_name[3]);
37
    ui->legName4->setText(config.leg_name[3]);
-
 
38
    ui->legName4->setMaxLength(MAX_LEG_NAME);
26
    ui->legName5->setText(config.leg_name[4]);
39
    ui->legName5->setText(config.leg_name[4]);
-
 
40
    ui->legName5->setMaxLength(MAX_LEG_NAME);
27
 
41
 
28
    ui->spinBox_1l->setValue( config.t_def[0].start);
42
    ui->spinBox_1l->setValue( config.t_def[0].start);
29
    ui->spinBox_1u->setValue( config.t_def[0].end);
43
    ui->spinBox_1u->setValue( config.t_def[0].end);
30
    ui->spinBox_2l->setValue( config.t_def[1].start);
44
    ui->spinBox_2l->setValue( config.t_def[1].start);
31
    ui->spinBox_2u->setValue( config.t_def[1].end);
45
    ui->spinBox_2u->setValue( config.t_def[1].end);
Line 40... Line 54...
40
    ui->spinBox_7l->setValue( config.t_def[6].start);
54
    ui->spinBox_7l->setValue( config.t_def[6].start);
41
    ui->spinBox_7u->setValue( config.t_def[6].end);
55
    ui->spinBox_7u->setValue( config.t_def[6].end);
42
    ui->spinBox_8l->setValue( config.t_def[7].start);
56
    ui->spinBox_8l->setValue( config.t_def[7].start);
43
    ui->spinBox_8u->setValue( config.t_def[7].end);
57
    ui->spinBox_8u->setValue( config.t_def[7].end);
44
 
58
 
-
 
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
 
45
}
63
}
46
 
64
 
47
void QmConfigure::QmConfigureSave(void)
65
void QmConfigure::save(void)
48
{
66
{
-
 
67
    int error = 0;
-
 
68
    int num_teams = 0;
-
 
69
 
-
 
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);
49
 
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
    }
50
}
241
}
51
 
242
 
52
void QmConfigure::QmConfigureCancel(void)
243
void QmConfigure::cancel(void)
53
{
244
{
54
    QmConfigurePopulate();
245
    populate();
55
}
246
}
56
 
247
 
57
 
248
 
58
QmConfigure::~QmConfigure()
249
QmConfigure::~QmConfigure()
59
{
250
{