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
 
280 david 97
                // Test for NE Team with a team name
98
                if ( team_buf.flags.non_equestrian && config.equestrian_leg )
99
                {
100
                    int neindex = config.equestrian_leg - 1;
101
                    char *nptr = team_buf.members[neindex].name;
102
 
281 david 103
                    // Ignore allowed NE names
104
                    if ( *nptr && strcmp(nptr, "0") != 0
105
                               && strcmp(nptr, "-") != 0
106
                               && stricmp(nptr, "N/A") != 0 )
280 david 107
                    {
108
                        addItem(tm, 0, QString("Team %1, NE with named competitor: %2").arg(QString::number(tm)).arg(nptr) );
109
                        badData = 1;
110
                    }
111
                }
112
 
264 - 113
                // Test Leg Data if required
114
                if (leg_end)
115
                {
116
                    test_times( &team_buf, leg_end );
117
                    if( check_error.type > 0 )
118
                    {
119
                        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]));
120
                        badData = 1;
121
                    }
122
                }
143 david 123
            }
124
        }
264 - 125
        else
126
        {
127
            //
128
            // Team not within the configured range
129
            // Warn if the team has time data - may be a miss configuration
130
            //
131
            int i;
132
            g_record( tm, &team_buf );
133
            for( i = 0; i <= config.num_legs; i++ )
134
            {
135
                if ( team_buf.leg[i].start > 0 || team_buf.leg[i].end > 0 )
136
                {
137
                    addItem(tm, 0, QString("Team %1, Unconfigured team has time information").arg(QString::number(tm) ) );
138
                    badData = 1;
139
                    break;
140
                }
141
            }
142
 
143
        }
144
 
145
        //
146
        //  Count teams with wonky data
147
        //
148
        if (badData)
149
            count_bad++;
143 david 150
    }
151
    if( count_bad )
152
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
153
    else
154
        MainWindow::showMessage("All team data correct");
155
}
156
 
157
void qmDataCheck::cancel(void)
158
{
159
    ui->listWidget->clear();
160
}
161
 
162
void qmDataCheck::selected(QListWidgetItem *item)
163
{
264 - 164
    //qDebug("Item selected");
143 david 165
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
166
    if ( myitem )
167
    {
264 - 168
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
143 david 169
        qmDialogTeamEditor dialog(myitem->team, this);
170
        dialog.exec();
171
    }
172
}
173