Subversion Repositories svn1

Rev

Rev 278 | Rev 292 | Go to most recent revision | Details | Compare with Previous | 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",
240 - 15
    "Team data not entered",
278 david 16
    "NE with named competitor"      // No longer used
139 david 17
};
18
 
136 - 19
qmDataCheck::qmDataCheck(QWidget *parent) :
278 david 20
    QWidget(parent)
136 - 21
{
139 david 22
 
278 david 23
    resize ( 600,400);
139 david 24
 
278 david 25
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
26
    verticalLayout->setContentsMargins(0, 0, 0, 0);
27
 
28
    QGroupBox *groupBox = new QGroupBox("Data Check");
29
    verticalLayout->addWidget(groupBox);
30
 
31
    QVBoxLayout *verticalLayout2 = new QVBoxLayout(groupBox);
32
 
33
    listWidget = new QListWidget(groupBox);
34
    verticalLayout2->addWidget(listWidget);
35
 
36
    QHBoxLayout *horizontalLayout;
37
    horizontalLayout = new QHBoxLayout();
38
    horizontalLayout->setContentsMargins(0, 0, 0, 5);
39
 
40
    QGroupBox *groupBox2 = new QGroupBox("Tests");
41
    verticalLayout2->addLayout(horizontalLayout);
42
    horizontalLayout->addWidget(groupBox2);
43
 
44
    QHBoxLayout *horizontalLayout1;
45
    QSpacerItem *horizontalSpacer1;
46
 
47
    horizontalLayout1 = new QHBoxLayout();
48
    horizontalLayout1->setContentsMargins(5, 5, 5, 5);
49
    groupBox2->setLayout(horizontalLayout1);
50
    groupBox2->setToolTip("Enable Tests to be performed");
51
 
279 david 52
    cb_all = new QCheckBox("All");
53
    cb_all->setChecked(true);
54
    cb_all->setToolTip("Enable all tests");
55
    horizontalLayout1->addWidget(cb_all);
278 david 56
 
279 david 57
    QFrame *line = new QFrame();
58
    line->setObjectName(QString::fromUtf8("line"));
59
    line->setGeometry(QRect(320, 150, 118, 3));
60
    line->setFrameShape(QFrame::VLine);
61
    line->setFrameShadow(QFrame::Sunken);
62
    horizontalLayout1->addWidget(line);
278 david 63
 
279 david 64
    cb_teamName = new QCheckBox("Team Names");
65
    cb_teamName->setChecked(true);
66
    cb_teamName->setToolTip("Check that teams have a name");
67
    horizontalLayout1->addWidget(cb_teamName);
278 david 68
 
279 david 69
    cb_class = new QCheckBox("Class");
70
    cb_class->setChecked(true);
71
    cb_class->setToolTip("Check that teams have a valid class");
72
    horizontalLayout1->addWidget(cb_class);
73
 
74
    cb_neNames = new QCheckBox("NE/Names");
75
    cb_neNames->setChecked(true);
76
    cb_neNames->setToolTip("Check that NE teams do not have a\nteam member for the equestrian leg");
77
    horizontalLayout1->addWidget(cb_neNames);
78
 
79
    cb_checkLegs = new QCheckBox("Leg Times");
80
    cb_checkLegs->setChecked(true);
81
    cb_checkLegs->setToolTip("Check Leg Start and End times");
82
    horizontalLayout1->addWidget(cb_checkLegs);
83
 
278 david 84
    horizontalLayout1->addWidget(new QLabel("Leg"));
85
    leg = new QmTeamSelector();
86
    horizontalLayout1->addWidget(leg);
87
 
88
    horizontalSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
279 david 89
    horizontalLayout->addItem(horizontalSpacer1);
278 david 90
 
91
    buttonBox = new QDialogButtonBox();
92
    pb_check = buttonBox->addButton("Check",QDialogButtonBox::ActionRole );
93
    pb_cancel = buttonBox->addButton("Clear",QDialogButtonBox::ActionRole );
94
    horizontalLayout->addWidget(buttonBox);
95
 
96
    leg->setMinimum(0);
97
    leg->setMaximum(config.num_legs);
98
    leg->setValue(config.num_legs);
99
 
100
    connect(pb_check, SIGNAL(clicked()), this, SLOT(populate()));
101
    connect(pb_cancel, SIGNAL(clicked()), this, SLOT(cancel()) );
102
    connect(listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
279 david 103
    connect(cb_all, SIGNAL(clicked()), this, SLOT(checkAllTests()));
136 - 104
}
105
 
106
qmDataCheck::~qmDataCheck()
107
{
278 david 108
 
136 - 109
}
139 david 110
 
260 - 111
/*----------------------------------------------------------------------------
112
** FUNCTION           : addItem
113
**
114
** DESCRIPTION        : Add an entry to the list of errored items
115
**
116
**
117
** INPUTS             : team            - Team
118
**                      leg             - May be 0
119
**                      msg             - Text error message
120
**
121
** RETURNS            : Nothing
122
**
123
----------------------------------------------------------------------------*/
124
 
125
void qmDataCheck::addItem(int team, int leg, QString msg)
126
{
127
    qmDataCheckItem *item = new qmDataCheckItem(team, leg);
128
    item->setData(Qt::EditRole, msg);
278 david 129
    listWidget->addItem(item);
260 - 130
}
131
 
139 david 132
void qmDataCheck::populate(void)
133
{
278 david 134
    int leg_end = leg->value();
260 - 135
    if ( leg_end < 0 || leg_end > config.num_legs)
139 david 136
    {
137
        MainWindow::showMessage("Bad Leg Number selected");
138
        return;
139
    }
278 david 140
    listWidget->clear();
139 david 141
 
142
    /*
143
     * Start the testing
144
     * Read each team into memory and start the testing
145
     */
146
    int count_bad = 0;
147
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
148
    {
260 - 149
        int badData = 0;
139 david 150
        team_type team_buf;
151
        if( valid_field( tm ) )
152
        {
153
            g_record( tm, &team_buf );
256 - 154
            if ( !team_buf.flags.disqualified && team_buf.flags.valid)
139 david 155
            {
260 - 156
                // Test for class not defined
279 david 157
                if ( cb_class->isChecked() && (team_buf.teamclass <= 0))
240 - 158
                {
260 - 159
                    addItem(tm, 0, QString("Team %1, No Class specified").arg(QString::number(tm) ) );
160
                    badData = 1;
240 - 161
                }
260 - 162
 
279 david 163
                if ( cb_teamName->isChecked() && (strlen (team_buf.name) <= 0))
260 - 164
                {
165
                    addItem(tm, 0, QString("Team %1, No Team Name specified").arg(QString::number(tm) ) );
166
                    badData = 1;
167
                }
168
 
276 david 169
                // Test for NE Team with a team name
279 david 170
                if (cb_neNames->isChecked() && team_buf.flags.non_equestrian && config.equestrian_leg )
276 david 171
                {
172
                    int neindex = config.equestrian_leg - 1;
173
                    char *nptr = team_buf.members[neindex].name;
174
 
277 david 175
                    // Ignore allowed NE names
176
                    if ( *nptr && strcmp(nptr, "0") != 0
177
                               && strcmp(nptr, "-") != 0
178
                               && stricmp(nptr, "N/A") != 0 )
276 david 179
                    {
180
                        addItem(tm, 0, QString("Team %1, NE with named competitor: %2").arg(QString::number(tm)).arg(nptr) );
181
                        badData = 1;
182
                    }
183
                }
184
 
260 - 185
                // Test Leg Data if required
279 david 186
                if (cb_checkLegs->isChecked() && leg_end)
260 - 187
                {
188
                    test_times( &team_buf, leg_end );
189
                    if( check_error.type > 0 )
190
                    {
191
                        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]));
192
                        badData = 1;
193
                    }
194
                }
139 david 195
            }
196
        }
260 - 197
        else
198
        {
199
            //
200
            // Team not within the configured range
201
            // Warn if the team has time data - may be a miss configuration
202
            //
203
            int i;
204
            g_record( tm, &team_buf );
205
            for( i = 0; i <= config.num_legs; i++ )
206
            {
207
                if ( team_buf.leg[i].start > 0 || team_buf.leg[i].end > 0 )
208
                {
209
                    addItem(tm, 0, QString("Team %1, Unconfigured team has time information").arg(QString::number(tm) ) );
210
                    badData = 1;
211
                    break;
212
                }
213
            }
214
 
215
        }
216
 
217
        //
218
        //  Count teams with wonky data
219
        //
220
        if (badData)
221
            count_bad++;
139 david 222
    }
223
    if( count_bad )
224
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
225
    else
226
        MainWindow::showMessage("All team data correct");
227
}
228
 
229
void qmDataCheck::cancel(void)
230
{
278 david 231
    listWidget->clear();
139 david 232
}
233
 
234
void qmDataCheck::selected(QListWidgetItem *item)
235
{
260 - 236
    //qDebug("Item selected");
139 david 237
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
238
    if ( myitem )
239
    {
260 - 240
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
139 david 241
        qmDialogTeamEditor dialog(myitem->team, this);
242
        dialog.exec();
243
    }
244
}
245
 
279 david 246
void qmDataCheck::checkAllTests(void)
247
{
248
    bool all_state = cb_all->isChecked();
249
 
250
    cb_checkLegs->setChecked(all_state);
251
    cb_class->setChecked(all_state);
252
    cb_neNames->setChecked(all_state);
253
    cb_teamName->setChecked(all_state);
254
}
255