Subversion Repositories svn1-original

Rev

Go to most recent revision | 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
    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
 
283 david 52
    cb_all = new QCheckBox("All");
53
    cb_all->setChecked(true);
54
    cb_all->setToolTip("Enable all tests");
55
    horizontalLayout1->addWidget(cb_all);
282 david 56
 
283 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);
282 david 63
 
283 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);
282 david 68
 
283 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
 
296 david 74
 
75
    cb_eqNames = new QCheckBox("EQ/Names");
76
    cb_eqNames->setChecked(true);
77
    cb_eqNames->setToolTip("Check that Equestrian teams do have a\nteam member for the equestrian leg");
78
    horizontalLayout1->addWidget(cb_eqNames);
79
 
283 david 80
    cb_neNames = new QCheckBox("NE/Names");
81
    cb_neNames->setChecked(true);
82
    cb_neNames->setToolTip("Check that NE teams do not have a\nteam member for the equestrian leg");
83
    horizontalLayout1->addWidget(cb_neNames);
84
 
85
    cb_checkLegs = new QCheckBox("Leg Times");
86
    cb_checkLegs->setChecked(true);
87
    cb_checkLegs->setToolTip("Check Leg Start and End times");
88
    horizontalLayout1->addWidget(cb_checkLegs);
89
 
282 david 90
    horizontalLayout1->addWidget(new QLabel("Leg"));
91
    leg = new QmTeamSelector();
92
    horizontalLayout1->addWidget(leg);
93
 
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 );
260 - 160
            if ( !team_buf.flags.disqualified && 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
 
280 david 175
                // Test for NE Team with a team name
296 david 176
                if ((cb_neNames->isChecked() || cb_eqNames->isChecked()) && config.equestrian_leg )
280 david 177
                {
178
                    int neindex = config.equestrian_leg - 1;
179
                    char *nptr = team_buf.members[neindex].name;
296 david 180
                    bool validTeamName = ( *nptr && strcmp(nptr, "0") != 0
181
                                        && strcmp(nptr, "-") != 0
182
                                        && stricmp(nptr, "N/A") != 0 );
280 david 183
 
296 david 184
                    if (cb_neNames->isChecked() && team_buf.flags.non_equestrian && validTeamName )
280 david 185
                    {
186
                        addItem(tm, 0, QString("Team %1, NE with named competitor: %2").arg(QString::number(tm)).arg(nptr) );
187
                        badData = 1;
188
                    }
296 david 189
                    if (cb_eqNames->isChecked() && !team_buf.flags.non_equestrian && !validTeamName )
190
                    {
191
                        addItem(tm, 0, QString("Team %1, possible NE team").arg(QString::number(tm)) );
192
                        badData = 1;
193
                    }
280 david 194
                }
195
 
264 - 196
                // Test Leg Data if required
283 david 197
                if (cb_checkLegs->isChecked() && leg_end)
264 - 198
                {
199
                    test_times( &team_buf, leg_end );
200
                    if( check_error.type > 0 )
201
                    {
202
                        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]));
203
                        badData = 1;
204
                    }
205
                }
143 david 206
            }
207
        }
264 - 208
        else
209
        {
210
            //
211
            // Team not within the configured range
212
            // Warn if the team has time data - may be a miss configuration
213
            //
214
            int i;
215
            g_record( tm, &team_buf );
216
            for( i = 0; i <= config.num_legs; i++ )
217
            {
218
                if ( team_buf.leg[i].start > 0 || team_buf.leg[i].end > 0 )
219
                {
220
                    addItem(tm, 0, QString("Team %1, Unconfigured team has time information").arg(QString::number(tm) ) );
221
                    badData = 1;
222
                    break;
223
                }
224
            }
225
 
226
        }
227
 
228
        //
229
        //  Count teams with wonky data
230
        //
231
        if (badData)
232
            count_bad++;
143 david 233
    }
234
    if( count_bad )
235
        MainWindow::showMessage(QString("%1 teams with inconsistent data").arg(count_bad));
236
    else
237
        MainWindow::showMessage("All team data correct");
238
}
239
 
240
void qmDataCheck::cancel(void)
241
{
282 david 242
    listWidget->clear();
143 david 243
}
244
 
245
void qmDataCheck::selected(QListWidgetItem *item)
246
{
264 - 247
    //qDebug("Item selected");
143 david 248
    qmDataCheckItem *myitem = dynamic_cast<qmDataCheckItem *>(item);
249
    if ( myitem )
250
    {
264 - 251
        //qDebug("   Team:%d, Leg: %d", myitem->team, myitem->leg);
143 david 252
        qmDialogTeamEditor dialog(myitem->team, this);
253
        dialog.exec();
254
    }
255
}
256
 
283 david 257
void qmDataCheck::checkAllTests(void)
258
{
259
    bool all_state = cb_all->isChecked();
260
 
261
    cb_checkLegs->setChecked(all_state);
262
    cb_class->setChecked(all_state);
296 david 263
    cb_eqNames->setChecked(all_state);
283 david 264
    cb_neNames->setChecked(all_state);
265
    cb_teamName->setChecked(all_state);
266
}
267