Subversion Repositories svn1

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
136 - 1
#include "qmdatacheck.h"
2
#include "ui_qmdatacheck.h"
139 david 3
#include    "consts.h"
4
#include    "structs.h"
5
#include    "proto.h"
6
#include "QString"
7
#include "mainwindow.h"
8
#include "qmdialogteameditor.h"
136 - 9
 
139 david 10
const char       *qck_err_mess[] = {
11
    "No error",
12
    "Invalid start time",
13
    "Invalid end time",
14
    "End before start",
15
    "Team data not entered"
16
};
17
 
136 - 18
qmDataCheck::qmDataCheck(QWidget *parent) :
19
    QWidget(parent),
20
    ui(new Ui::qmDataCheck)
21
{
22
    ui->setupUi(this);
139 david 23
 
24
    ui->leg->setMinimum(1);
25
    ui->leg->setMaximum(config.num_legs);
26
    ui->leg->setValue(config.num_legs);
27
 
28
    connect( ui->buttonBox, SIGNAL(accepted()), this, SLOT(populate()));
29
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
30
    connect(ui->listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
136 - 31
}
32
 
33
qmDataCheck::~qmDataCheck()
34
{
35
    delete ui;
36
}
139 david 37
 
38
void qmDataCheck::populate(void)
39
{
40
    int leg_end = ui->leg->value();
41
    if ( leg_end <= 0 || leg_end > config.num_legs)
42
    {
43
        MainWindow::showMessage("Bad Leg Number selected");
44
        return;
45
    }
46
    ui->listWidget->clear();
47
 
48
    /*
49
     * Start the testing
50
     * Read each team into memory and start the testing
51
     */
52
    int count_bad = 0;
53
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
54
    {
55
        team_type team_buf;
56
        if( valid_field( tm ) )
57
        {
58
            g_record( tm, &team_buf );
59
            if( team_buf.flags.disqualified == FALSE
60
                && test_times( &team_buf, leg_end ) )
61
            {
62
                count_bad++;
63
                qmDataCheckItem *item = new qmDataCheckItem( tm, check_error.leg);
64
                QString msg = QString("Team %1, Leg %2: %3").arg(QString::number(tm)).arg(QString::number(check_error.leg)).arg(qck_err_mess[check_error.type]);
65
                item->setData(Qt::EditRole, msg);
66
                ui->listWidget->addItem(item);
67
            }
68
        }
69
    }
70
    if( count_bad )
71
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
72
    else
73
        MainWindow::showMessage("All team data correct");
74
}
75
 
76
void qmDataCheck::cancel(void)
77
{
78
    ui->listWidget->clear();
79
}
80
 
81
void qmDataCheck::selected(QListWidgetItem *item)
82
{
83
    qDebug("Item selected");
84
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
85
    if ( myitem )
86
    {
87
        qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
88
        qmDialogTeamEditor dialog(myitem->team, this);
89
        dialog.exec();
90
    }
91
 
92
}
93