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