Subversion Repositories svn1-original

Rev

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