Subversion Repositories svn1

Rev

Rev 139 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 139 Rev 380
Line 1... Line 1...
1
#include "qmdatacheck.h"
1
#include "qmdatacheck.h"
-
 
2
#include <QtCore/QVariant>
-
 
3
#include <QAction>
-
 
4
#include <QApplication>
-
 
5
#include <QButtonGroup>
-
 
6
#include <QDialogButtonBox>
-
 
7
#include <QGroupBox>
-
 
8
#include <QHBoxLayout>
2
#include "ui_qmdatacheck.h"
9
#include <QHeaderView>
-
 
10
#include <QLabel>
-
 
11
#include <QListWidget>
-
 
12
#include <QSpacerItem>
-
 
13
#include <QSpinBox>
-
 
14
#include <QWidget>
3
#include    "consts.h"
15
#include    "consts.h"
4
#include    "structs.h"
16
#include    "structs.h"
5
#include    "proto.h"
17
#include    "proto.h"
6
#include "QString"
18
#include "QString"
7
#include "mainwindow.h"
19
#include "mainwindow.h"
Line 10... Line 22...
10
const char       *qck_err_mess[] = {
22
const char       *qck_err_mess[] = {
11
    "No error",
23
    "No error",
12
    "Invalid start time",
24
    "Invalid start time",
13
    "Invalid end time",
25
    "Invalid end time",
14
    "End before start",
26
    "End before start",
15
    "Team data not entered"
27
    "Team data not entered",
-
 
28
    "NE with named competitor"      // No longer used
16
};
29
};
17
 
30
 
18
qmDataCheck::qmDataCheck(QWidget *parent) :
31
qmDataCheck::qmDataCheck(QWidget *parent) :
19
    QWidget(parent),
32
    QWidget(parent)
20
    ui(new Ui::qmDataCheck)
-
 
21
{
33
{
22
    ui->setupUi(this);
-
 
23
 
34
 
-
 
35
    resize ( 600,400);
-
 
36
 
-
 
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
 
24
    ui->leg->setMinimum(1);
118
    leg->setMinimum(0);
25
    ui->leg->setMaximum(config.num_legs);
119
    leg->setMaximum(config.num_legs);
26
    ui->leg->setValue(config.num_legs);
120
    leg->setValue(config.num_legs);
27
 
121
 
28
    connect( ui->buttonBox, SIGNAL(accepted()), this, SLOT(populate()));
122
    connect(pb_check, SIGNAL(clicked()), this, SLOT(populate()));
29
    connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(cancel()) );
123
    connect(pb_cancel, SIGNAL(clicked()), this, SLOT(cancel()) );
30
    connect(ui->listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
124
    connect(listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
-
 
125
    connect(cb_all, SIGNAL(clicked()), this, SLOT(checkAllTests()));
31
}
126
}
32
 
127
 
33
qmDataCheck::~qmDataCheck()
128
qmDataCheck::~qmDataCheck()
34
{
129
{
-
 
130
 
-
 
131
}
-
 
132
 
-
 
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);
35
    delete ui;
151
    listWidget->addItem(item);
36
}
152
}
37
 
153
 
38
void qmDataCheck::populate(void)
154
void qmDataCheck::populate(void)
39
{
155
{
40
    int leg_end = ui->leg->value();
156
    int leg_end = leg->value();
41
    if ( leg_end <= 0 || leg_end > config.num_legs)
157
    if ( leg_end < 0 || leg_end > config.num_legs)
42
    {
158
    {
43
        MainWindow::showMessage("Bad Leg Number selected");
159
        MainWindow::showMessage("Bad Leg Number selected");
44
        return;
160
        return;
45
    }
161
    }
46
    ui->listWidget->clear();
162
    listWidget->clear();
47
 
163
 
48
    /*
164
    /*
49
     * Start the testing
165
     * Start the testing
50
     * Read each team into memory and start the testing
166
     * Read each team into memory and start the testing
51
     */
167
     */
52
    int count_bad = 0;
168
    int count_bad = 0;
-
 
169
    int neindex = config.equestrian_leg - 1;
-
 
170
 
53
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
171
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
54
    {
172
    {
-
 
173
        int badData = 0;
55
        team_type team_buf;
174
        team_type team_buf;
56
        if( valid_field( tm ) )
175
        if( valid_field( tm ) )
57
        {
176
        {
58
            g_record( tm, &team_buf );
177
            g_record( tm, &team_buf );
59
            if( team_buf.flags.disqualified == FALSE
178
            if (team_buf.flags.valid)
60
                && test_times( &team_buf, leg_end ) )
-
 
61
            {
179
            {
-
 
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;
62
                count_bad++;
198
                        }
-
 
199
 
-
 
200
                        char *nptr = team_buf.members[leg].name;
-
 
201
                        bool validTeamName = ( *nptr && strcmp(nptr, "0") != 0
-
 
202
                                            && strcmp(nptr, "-") != 0
63
                qmDataCheckItem *item = new qmDataCheckItem( tm, check_error.leg);
203
                                            && stricmp(nptr, "N/A") != 0 );
-
 
204
 
-
 
205
                       if (!validTeamName) {
64
                QString msg = QString("Team %1, Leg %2: %3").arg(QString::number(tm)).arg(QString::number(check_error.leg)).arg(qck_err_mess[check_error.type]);
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
                            }
65
                item->setData(Qt::EditRole, msg);
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
 
66
                ui->listWidget->addItem(item);
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
                }
67
            }
256
            }
68
        }
257
        }
-
 
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++;
69
    }
283
    }
70
    if( count_bad )
284
    if( count_bad )
71
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
285
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
72
    else
286
    else
73
        MainWindow::showMessage("All team data correct");
287
        MainWindow::showMessage("All team data correct");
74
}
288
}
75
 
289
 
76
void qmDataCheck::cancel(void)
290
void qmDataCheck::cancel(void)
77
{
291
{
78
    ui->listWidget->clear();
292
    listWidget->clear();
79
}
293
}
80
 
294
 
81
void qmDataCheck::selected(QListWidgetItem *item)
295
void qmDataCheck::selected(QListWidgetItem *item)
82
{
296
{
83
    qDebug("Item selected");
297
    //qDebug("Item selected");
84
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
298
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
85
    if ( myitem )
299
    if ( myitem )
86
    {
300
    {
87
        qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
301
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
88
        qmDialogTeamEditor dialog(myitem->team, this);
302
        qmDialogTeamEditor dialog(myitem->team, this);
89
        dialog.exec();
303
        dialog.exec();
90
    }
304
    }
-
 
305
}
-
 
306
 
-
 
307
void qmDataCheck::checkAllTests(void)
-
 
308
{
-
 
309
    bool all_state = cb_all->isChecked();
91
 
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);
92
}
317
}
93
 
318