Rev 102 | Blame | Last modification | View Log | RSS feed
#include "qmconfigure.h"#include "ui_qmconfigure.h"#include "consts.h"#include "structs.h"#include "proto.h"QmConfigure::QmConfigure(QWidget *parent) :QWidget(parent),ui(new Ui::QmConfigure){ui->setupUi(this);connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(save()) );connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );populate();}void QmConfigure::populate(void){ui->eventName->setText( config.event_name);ui->eventName->setMaxLength(MAX_EVENT_NAME);ui->addendum->setText(config.addendum);ui->addendum->setMaxLength(sizeof(config.addendum)-1);ui->datafilename->setText(config.datafilename);ui->datafilename->setMaxLength(sizeof(config.datafilename - 1));ui->legName1->setText(config.leg_name[0]);ui->legName1->setMaxLength(MAX_LEG_NAME);ui->legName2->setText(config.leg_name[1]);ui->legName2->setMaxLength(MAX_LEG_NAME);ui->legName3->setText(config.leg_name[2]);ui->legName3->setMaxLength(MAX_LEG_NAME);ui->legName4->setText(config.leg_name[3]);ui->legName4->setMaxLength(MAX_LEG_NAME);ui->legName5->setText(config.leg_name[4]);ui->legName5->setMaxLength(MAX_LEG_NAME);ui->spinBox_1l->setValue( config.t_def[0].start);ui->spinBox_1u->setValue( config.t_def[0].end);ui->spinBox_2l->setValue( config.t_def[1].start);ui->spinBox_2u->setValue( config.t_def[1].end);ui->spinBox_3l->setValue( config.t_def[2].start);ui->spinBox_3u->setValue( config.t_def[2].end);ui->spinBox_4l->setValue( config.t_def[3].start);ui->spinBox_4u->setValue( config.t_def[3].end);ui->spinBox_5l->setValue( config.t_def[4].start);ui->spinBox_5u->setValue( config.t_def[4].end);ui->spinBox_6l->setValue( config.t_def[5].start);ui->spinBox_6u->setValue( config.t_def[5].end);ui->spinBox_7l->setValue( config.t_def[6].start);ui->spinBox_7u->setValue( config.t_def[6].end);ui->spinBox_8l->setValue( config.t_def[7].start);ui->spinBox_8u->setValue( config.t_def[7].end);ui->spinBox_NeLeg->setValue(config.equestrian_leg);ui->ne_leg_abr->setText(config.nonequestrian_class_abr);ui->ne_leg_abr->setMaxLength(sizeof(config.nonequestrian_class_abr)-1);ui->spinBox_LinesPerPage->setValue(config.lines_per_page);ui->perfSkip->setChecked( config.perf_skip );}void QmConfigure::save(void){int error = 0;int num_teams = 0;/*** Copy original data*/MARA_CFG newcfg = config;/*** Extract data from Widgets*/strncpy(newcfg.event_name, qPrintable(ui->eventName->text()), sizeof(newcfg.event_name)) ;strncpy(newcfg.datafilename, qPrintable(ui->datafilename->text()), sizeof(newcfg.datafilename-1)) ;strncpy(newcfg.addendum, qPrintable(ui->addendum->text()), sizeof(newcfg.addendum-1)) ;ui->legName1->setText(config.leg_name[0]);ui->legName1->setMaxLength(MAX_LEG_NAME);strncpy(newcfg.leg_name[0], qPrintable(ui->legName1->text()), sizeof(newcfg.leg_name[0])) ;strncpy(newcfg.leg_name[1], qPrintable(ui->legName2->text()), sizeof(newcfg.leg_name[1])) ;strncpy(newcfg.leg_name[2], qPrintable(ui->legName3->text()), sizeof(newcfg.leg_name[2])) ;strncpy(newcfg.leg_name[3], qPrintable(ui->legName4->text()), sizeof(newcfg.leg_name[3])) ;strncpy(newcfg.leg_name[4], qPrintable(ui->legName5->text()), sizeof(newcfg.leg_name[4])) ;newcfg.t_def[0].start = ui->spinBox_1l->value();newcfg.t_def[0].end = ui->spinBox_1u->value();newcfg.t_def[1].start = ui->spinBox_2l->value();newcfg.t_def[1].end = ui->spinBox_2u->value();newcfg.t_def[2].start = ui->spinBox_3l->value();newcfg.t_def[2].end = ui->spinBox_3u->value();newcfg.t_def[3].start = ui->spinBox_4l->value();newcfg.t_def[3].end = ui->spinBox_4u->value();newcfg.t_def[4].start = ui->spinBox_5l->value();newcfg.t_def[4].end = ui->spinBox_5u->value();newcfg.t_def[5].start = ui->spinBox_6l->value();newcfg.t_def[5].end = ui->spinBox_6u->value();newcfg.t_def[6].start = ui->spinBox_7l->value();newcfg.t_def[6].end = ui->spinBox_7u->value();newcfg.t_def[7].start = ui->spinBox_8l->value();newcfg.t_def[7].end = ui->spinBox_8u->value();newcfg.equestrian_leg = ui->spinBox_NeLeg->value();strncpy(newcfg.nonequestrian_class_abr, qPrintable(ui->ne_leg_abr->text()), sizeof(newcfg.nonequestrian_class_abr)-1) ;newcfg.lines_per_page = ui->spinBox_LinesPerPage->value();newcfg.perf_skip = ui->perfSkip->isChecked();/*** Sanity Test and Clean up*/compact( newcfg.event_name ); /* Rip of leading white_space */for( int i = 0; i < MAX_LEGS; i++ )compact( newcfg.leg_name[i] );compact( newcfg.addendum );compact( newcfg.datafilename );/** Do all sorts of consistency tests on the data* Firstly - calculate the number of legs. Justify the data in the array*/newcfg.num_legs = 0;for( int i = 0; i < MAX_LEGS; i++ )if( newcfg.leg_name[i][0] )newcfg.num_legs++;for( int i = newcfg.num_legs; i < MAX_LEGS; i++ )if( newcfg.leg_name[i][0] ){printf( "Configuration error: Missing leg\n" );error++;}/** Now do the team numbering stuff*/for( int i = 0; i < MAX_TMS_SPLIT; i++ ){if( newcfg.t_def[i].start == 0 && newcfg.t_def[i].end == 0 )continue;if( newcfg.t_def[i].start > newcfg.t_def[i].end ){printf( "Team definition error : End greater than start. %d to %d\n",newcfg.t_def[i].start, newcfg.t_def[i].end );error++;}for( int j = 0; j < i; j++ ){if( ( newcfg.t_def[i].start >= newcfg.t_def[j].start&& newcfg.t_def[i].start <= newcfg.t_def[j].end )|| ( newcfg.t_def[i].end >= newcfg.t_def[j].start&& newcfg.t_def[i].end <= newcfg.t_def[j].end ) ){printf( "Team definition error : Overlapping definition. %d to %d\n",newcfg.t_def[i].start, newcfg.t_def[i].end );error++;}}}/** Determine the number of team splits* There may be blank entries - these will be removed by sorting the array*/qsort( ( char * ) newcfg.t_def, MAX_TMS_SPLIT, sizeof( *newcfg.t_def ), f_comp_int );for( newcfg.num_teams = 0; newcfg.num_teams < MAX_TMS_SPLIT; newcfg.num_teams++ )if( !newcfg.t_def[newcfg.num_teams].start )break;newcfg.min_team = newcfg.t_def[0].start;newcfg.max_team = newcfg.t_def[newcfg.num_teams - 1].end;/*** Limit the number of entrants*/for( int i = 0; i < MAX_TMS_SPLIT; i++ ){if( newcfg.t_def[i].start ){num_teams += newcfg.t_def[i].end - newcfg.t_def[i].start + 1;}}#if defined(LIMIT_TEAMS) && (LIMIT_TEAMS > 0)if( num_teams > LIMIT_TEAMS ){printf( "Maximum number of teams exceeded - reduce number of teams\n" );error++;}#endif#if defined (HI_TECH_C) || defined (__TURBOC__)/** Ensure that the number of teams allocated can fit within available* Memory space. Ie: Can we malloc the report data structures*/{long sz;sz = sizeof( ty_s_data ) > sizeof( ty_s_aux ) ?sizeof( ty_s_data ) : sizeof( ty_s_aux );if( sz * ( newcfg.max_team - newcfg.min_team + 2 ) > ( 1024L * 64L ) ){printf( "Too many teams: Reduce team spread.\n" );error++;}}#endif/*** Ensure the non-equestrian class and the equestrian leg are valid*/if( newcfg.equestrian_leg ){if( newcfg.equestrian_leg > newcfg.num_legs ){printf( "Invalid non-equestrian leg number.\n" );error++;}/*** Ensure that the entered non-equestrian class name does exist*/newcfg.nonequestrian_class = lookup_class( newcfg.nonequestrian_class_abr, &newcfg );if( newcfg.nonequestrian_class == 0 )printf( "WARNING: Non-equestrian class not found\n" );}if ( error == 0 ){config = newcfg;wt_config();}}void QmConfigure::cancel(void){populate();}QmConfigure::~QmConfigure(){delete ui;}void QmConfigure::changeEvent(QEvent *e){QWidget::changeEvent(e);switch (e->type()) {case QEvent::LanguageChange:ui->retranslateUi(this);break;default:break;}}