Subversion Repositories svn1-original

Rev

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

Rev Author Line No. Line
140 - 1
#include "qmdatacheck.h"
2
#include "ui_qmdatacheck.h"
143 david 3
#include    "consts.h"
4
#include    "structs.h"
5
#include    "proto.h"
6
#include "QString"
7
#include "mainwindow.h"
8
#include "qmdialogteameditor.h"
140 - 9
 
143 david 10
const char       *qck_err_mess[] = {
11
    "No error",
12
    "Invalid start time",
13
    "Invalid end time",
14
    "End before start",
244 - 15
    "Team data not entered",
16
    "NE with named competitor"
143 david 17
};
18
 
140 - 19
qmDataCheck::qmDataCheck(QWidget *parent) :
20
    QWidget(parent),
21
    ui(new Ui::qmDataCheck)
22
{
23
    ui->setupUi(this);
143 david 24
 
264 - 25
    ui->leg->setMinimum(0);
143 david 26
    ui->leg->setMaximum(config.num_legs);
27
    ui->leg->setValue(config.num_legs);
28
 
29
    connect( ui->buttonBox, SIGNAL(accepted()), this, SLOT(populate()));
30
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
31
    connect(ui->listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
140 - 32
}
33
 
34
qmDataCheck::~qmDataCheck()
35
{
36
    delete ui;
37
}
143 david 38
 
264 - 39
/*----------------------------------------------------------------------------
40
** FUNCTION           : addItem
41
**
42
** DESCRIPTION        : Add an entry to the list of errored items
43
**
44
**
45
** INPUTS             : team            - Team
46
**                      leg             - May be 0
47
**                      msg             - Text error message
48
**
49
** RETURNS            : Nothing
50
**
51
----------------------------------------------------------------------------*/
52
 
53
void qmDataCheck::addItem(int team, int leg, QString msg)
54
{
55
    qmDataCheckItem *item = new qmDataCheckItem(team, leg);
56
    item->setData(Qt::EditRole, msg);
57
    ui->listWidget->addItem(item);
58
}
59
 
143 david 60
void qmDataCheck::populate(void)
61
{
62
    int leg_end = ui->leg->value();
264 - 63
    if ( leg_end < 0 || leg_end > config.num_legs)
143 david 64
    {
65
        MainWindow::showMessage("Bad Leg Number selected");
66
        return;
67
    }
68
    ui->listWidget->clear();
69
 
70
    /*
71
     * Start the testing
72
     * Read each team into memory and start the testing
73
     */
74
    int count_bad = 0;
75
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
76
    {
264 - 77
        int badData = 0;
143 david 78
        team_type team_buf;
79
        if( valid_field( tm ) )
80
        {
81
            g_record( tm, &team_buf );
260 - 82
            if ( !team_buf.flags.disqualified && team_buf.flags.valid)
143 david 83
            {
264 - 84
                // Test for class not defined
85
                if ( team_buf.teamclass <= 0)
244 - 86
                {
264 - 87
                    addItem(tm, 0, QString("Team %1, No Class specified").arg(QString::number(tm) ) );
88
                    badData = 1;
244 - 89
                }
264 - 90
 
91
                if ( strlen (team_buf.name) <= 0)
92
                {
93
                    addItem(tm, 0, QString("Team %1, No Team Name specified").arg(QString::number(tm) ) );
94
                    badData = 1;
95
                }
96
 
97
                // Test Leg Data if required
98
                if (leg_end)
99
                {
100
                    test_times( &team_buf, leg_end );
101
                    if( check_error.type > 0 )
102
                    {
103
                        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]));
104
                        badData = 1;
105
                    }
106
                }
143 david 107
            }
108
        }
264 - 109
        else
110
        {
111
            //
112
            // Team not within the configured range
113
            // Warn if the team has time data - may be a miss configuration
114
            //
115
            int i;
116
            g_record( tm, &team_buf );
117
            for( i = 0; i <= config.num_legs; i++ )
118
            {
119
                if ( team_buf.leg[i].start > 0 || team_buf.leg[i].end > 0 )
120
                {
121
                    addItem(tm, 0, QString("Team %1, Unconfigured team has time information").arg(QString::number(tm) ) );
122
                    badData = 1;
123
                    break;
124
                }
125
            }
126
 
127
        }
128
 
129
        //
130
        //  Count teams with wonky data
131
        //
132
        if (badData)
133
            count_bad++;
143 david 134
    }
135
    if( count_bad )
136
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
137
    else
138
        MainWindow::showMessage("All team data correct");
139
}
140
 
141
void qmDataCheck::cancel(void)
142
{
143
    ui->listWidget->clear();
144
}
145
 
146
void qmDataCheck::selected(QListWidgetItem *item)
147
{
264 - 148
    //qDebug("Item selected");
143 david 149
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
150
    if ( myitem )
151
    {
264 - 152
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
143 david 153
        qmDialogTeamEditor dialog(myitem->team, this);
154
        dialog.exec();
155
    }
156
}
157