Subversion Repositories svn1

Rev

Rev 256 | Rev 277 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "qmdatacheck.h"
#include "ui_qmdatacheck.h"
#include    "consts.h"
#include    "structs.h"
#include    "proto.h"
#include "QString"
#include "mainwindow.h"
#include "qmdialogteameditor.h"

const char       *qck_err_mess[] = {
    "No error",
    "Invalid start time",
    "Invalid end time",
    "End before start",
    "Team data not entered",
    "NE with named competitor"
};

qmDataCheck::qmDataCheck(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::qmDataCheck)
{
    ui->setupUi(this);

    ui->leg->setMinimum(0);
    ui->leg->setMaximum(config.num_legs);
    ui->leg->setValue(config.num_legs);

    connect( ui->buttonBox, SIGNAL(accepted()), this, SLOT(populate()));
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
    connect(ui->listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
}

qmDataCheck::~qmDataCheck()
{
    delete ui;
}

/*----------------------------------------------------------------------------
** FUNCTION           : addItem
**
** DESCRIPTION        : Add an entry to the list of errored items
**
**
** INPUTS             : team            - Team
**                      leg             - May be 0
**                      msg             - Text error message
**
** RETURNS            : Nothing
**
----------------------------------------------------------------------------*/

void qmDataCheck::addItem(int team, int leg, QString msg)
{
    qmDataCheckItem *item = new qmDataCheckItem(team, leg);
    item->setData(Qt::EditRole, msg);
    ui->listWidget->addItem(item);
}

void qmDataCheck::populate(void)
{
    int leg_end = ui->leg->value();
    if ( leg_end < 0 || leg_end > config.num_legs)
    {
        MainWindow::showMessage("Bad Leg Number selected");
        return;
    }
    ui->listWidget->clear();

    /*
     * Start the testing
     * Read each team into memory and start the testing
     */
    int count_bad = 0;
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
    {
        int badData = 0;
        team_type team_buf;
        if( valid_field( tm ) )
        {
            g_record( tm, &team_buf );
            if ( !team_buf.flags.disqualified && team_buf.flags.valid)
            {
                // Test for class not defined
                if ( team_buf.teamclass <= 0)
                {
                    addItem(tm, 0, QString("Team %1, No Class specified").arg(QString::number(tm) ) );
                    badData = 1;
                }

                if ( strlen (team_buf.name) <= 0)
                {
                    addItem(tm, 0, QString("Team %1, No Team Name specified").arg(QString::number(tm) ) );
                    badData = 1;
                }

                // Test Leg Data if required
                if (leg_end)
                {
                    test_times( &team_buf, leg_end );
                    if( check_error.type > 0 )
                    {
                        addItem(tm, check_error.leg, QString("Team %1, Leg %2: %3").arg(QString::number(tm)).arg(QString::number(check_error.leg)).arg(qck_err_mess[check_error.type]));
                        badData = 1;
                    }
                }
            }
        }
        else
        {
            //
            // Team not within the configured range
            // Warn if the team has time data - may be a miss configuration
            //
            int i;
            g_record( tm, &team_buf );
            for( i = 0; i <= config.num_legs; i++ )
            {
                if ( team_buf.leg[i].start > 0 || team_buf.leg[i].end > 0 )
                {
                    addItem(tm, 0, QString("Team %1, Unconfigured team has time information").arg(QString::number(tm) ) );
                    badData = 1;
                    break;
                }
            }

        }

        //
        //  Count teams with wonky data
        //
        if (badData)
            count_bad++;
    }
    if( count_bad )
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
    else
        MainWindow::showMessage("All team data correct");
}

void qmDataCheck::cancel(void)
{
    ui->listWidget->clear();
}

void qmDataCheck::selected(QListWidgetItem *item)
{
    //qDebug("Item selected");
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
    if ( myitem )
    {
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
        qmDialogTeamEditor dialog(myitem->team, this);
        dialog.exec();
    }
}