Subversion Repositories svn1-original

Rev

Rev 370 | Go to most recent revision | Details | Compare with Previous | 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
 
296 david 73
 
74
    cb_eqNames = new QCheckBox("EQ/Names");
75
    cb_eqNames->setChecked(true);
76
    cb_eqNames->setToolTip("Check that Equestrian teams do have a\nteam member for the equestrian leg");
77
    horizontalLayout1->addWidget(cb_eqNames);
78
 
283 david 79
    cb_neNames = new QCheckBox("NE/Names");
80
    cb_neNames->setChecked(true);
81
    cb_neNames->setToolTip("Check that NE teams do not have a\nteam member for the equestrian leg");
82
    horizontalLayout1->addWidget(cb_neNames);
83
 
84
    cb_checkLegs = new QCheckBox("Leg Times");
85
    cb_checkLegs->setChecked(true);
86
    cb_checkLegs->setToolTip("Check Leg Start and End times");
87
    horizontalLayout1->addWidget(cb_checkLegs);
88
 
282 david 89
    horizontalLayout1->addWidget(new QLabel("Leg"));
90
    leg = new QmTeamSelector();
91
    horizontalLayout1->addWidget(leg);
92
 
322 david 93
    QSpacerItem *horizontalSpacer1;
282 david 94
    horizontalSpacer1 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
283 david 95
    horizontalLayout->addItem(horizontalSpacer1);
282 david 96
 
97
    buttonBox = new QDialogButtonBox();
98
    pb_check = buttonBox->addButton("Check",QDialogButtonBox::ActionRole );
99
    pb_cancel = buttonBox->addButton("Clear",QDialogButtonBox::ActionRole );
296 david 100
    verticalLayout2->addWidget(buttonBox);
282 david 101
 
102
    leg->setMinimum(0);
103
    leg->setMaximum(config.num_legs);
104
    leg->setValue(config.num_legs);
105
 
106
    connect(pb_check, SIGNAL(clicked()), this, SLOT(populate()));
107
    connect(pb_cancel, SIGNAL(clicked()), this, SLOT(cancel()) );
108
    connect(listWidget,SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(selected(QListWidgetItem *)));
283 david 109
    connect(cb_all, SIGNAL(clicked()), this, SLOT(checkAllTests()));
140 - 110
}
111
 
112
qmDataCheck::~qmDataCheck()
113
{
282 david 114
 
140 - 115
}
143 david 116
 
264 - 117
/*----------------------------------------------------------------------------
118
** FUNCTION           : addItem
119
**
120
** DESCRIPTION        : Add an entry to the list of errored items
121
**
122
**
123
** INPUTS             : team            - Team
124
**                      leg             - May be 0
125
**                      msg             - Text error message
126
**
127
** RETURNS            : Nothing
128
**
129
----------------------------------------------------------------------------*/
130
 
131
void qmDataCheck::addItem(int team, int leg, QString msg)
132
{
133
    qmDataCheckItem *item = new qmDataCheckItem(team, leg);
134
    item->setData(Qt::EditRole, msg);
282 david 135
    listWidget->addItem(item);
264 - 136
}
137
 
143 david 138
void qmDataCheck::populate(void)
139
{
282 david 140
    int leg_end = leg->value();
264 - 141
    if ( leg_end < 0 || leg_end > config.num_legs)
143 david 142
    {
143
        MainWindow::showMessage("Bad Leg Number selected");
144
        return;
145
    }
282 david 146
    listWidget->clear();
143 david 147
 
148
    /*
149
     * Start the testing
150
     * Read each team into memory and start the testing
151
     */
152
    int count_bad = 0;
153
    for( int tm = config.min_team; tm <= config.max_team; tm++ )
154
    {
264 - 155
        int badData = 0;
143 david 156
        team_type team_buf;
157
        if( valid_field( tm ) )
158
        {
159
            g_record( tm, &team_buf );
371 david 160
            if (team_buf.flags.valid)
143 david 161
            {
264 - 162
                // Test for class not defined
283 david 163
                if ( cb_class->isChecked() && (team_buf.teamclass <= 0))
244 - 164
                {
264 - 165
                    addItem(tm, 0, QString("Team %1, No Class specified").arg(QString::number(tm) ) );
166
                    badData = 1;
244 - 167
                }
264 - 168
 
283 david 169
                if ( cb_teamName->isChecked() && (strlen (team_buf.name) <= 0))
264 - 170
                {
171
                    addItem(tm, 0, QString("Team %1, No Team Name specified").arg(QString::number(tm) ) );
172
                    badData = 1;
173
                }
174
 
371 david 175
                if ( !team_buf.flags.disqualified )
280 david 176
                    {
371 david 177
                    // Test for NE Team with a team name
178
                    if ((cb_neNames->isChecked() || cb_eqNames->isChecked()) && config.equestrian_leg )
296 david 179
                    {
371 david 180
                        int neindex = config.equestrian_leg - 1;
181
                        char *nptr = team_buf.members[neindex].name;
182
                        bool validTeamName = ( *nptr && strcmp(nptr, "0") != 0
183
                                            && strcmp(nptr, "-") != 0
184
                                            && stricmp(nptr, "N/A") != 0 );
185
 
186
                        if (cb_neNames->isChecked() && team_buf.flags.non_equestrian && validTeamName && stricmp(nptr, "NE") != 0 )
187
                        {
188
                            addItem(tm, 0, QString("Team %1, NE with named competitor: %2").arg(QString::number(tm)).arg(nptr) );
189
                            badData = 1;
190
                        }
191
                        if (cb_eqNames->isChecked() && !team_buf.flags.non_equestrian && !validTeamName )
192
                        {
193
                            addItem(tm, 0, QString("Team %1, possible NE team").arg(QString::number(tm)) );
194
                            badData = 1;
195
                        }
296 david 196
                    }
280 david 197
 
371 david 198
                    // Test Leg Data if required
199
                    if (cb_checkLegs->isChecked() && leg_end)
264 - 200
                    {
371 david 201
                        test_times( &team_buf, leg_end );
202
                        if( check_error.type > 0 )
203
                        {
204
                            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]));
205
                            badData = 1;
206
                        }
264 - 207
                    }
208
                }
143 david 209
            }
210
        }
264 - 211
        else
212
        {
213
            //
214
            // Team not within the configured range
215
            // Warn if the team has time data - may be a miss configuration
216
            //
217
            int i;
218
            g_record( tm, &team_buf );
219
            for( i = 0; i <= config.num_legs; i++ )
220
            {
221
                if ( team_buf.leg[i].start > 0 || team_buf.leg[i].end > 0 )
222
                {
223
                    addItem(tm, 0, QString("Team %1, Unconfigured team has time information").arg(QString::number(tm) ) );
224
                    badData = 1;
225
                    break;
226
                }
227
            }
228
 
229
        }
230
 
231
        //
232
        //  Count teams with wonky data
233
        //
234
        if (badData)
235
            count_bad++;
143 david 236
    }
237
    if( count_bad )
238
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
239
    else
240
        MainWindow::showMessage("All team data correct");
241
}
242
 
243
void qmDataCheck::cancel(void)
244
{
282 david 245
    listWidget->clear();
143 david 246
}
247
 
248
void qmDataCheck::selected(QListWidgetItem *item)
249
{
264 - 250
    //qDebug("Item selected");
143 david 251
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
252
    if ( myitem )
253
    {
264 - 254
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
143 david 255
        qmDialogTeamEditor dialog(myitem->team, this);
256
        dialog.exec();
257
    }
258
}
259
 
283 david 260
void qmDataCheck::checkAllTests(void)
261
{
262
    bool all_state = cb_all->isChecked();
263
 
264
    cb_checkLegs->setChecked(all_state);
265
    cb_class->setChecked(all_state);
296 david 266
    cb_eqNames->setChecked(all_state);
283 david 267
    cb_neNames->setChecked(all_state);
268
    cb_teamName->setChecked(all_state);
269
}
270