Subversion Repositories svn1-original

Rev

Rev 253 | Rev 276 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 253 Rev 275
Line 97... Line 97...
97
 
97
 
98
    // Process Each line of the file
98
    // Process Each line of the file
99
    QTextStream in(&file);
99
    QTextStream in(&file);
100
    int ii = 0;
100
    int ii = 0;
101
    int bad_cat = 0;
101
    int bad_cat = 0;
-
 
102
    bool has_RefError;
-
 
103
    int  bad_refs = 0;
102
    QRegExp csv_split("\"?,\"?");
104
    QRegExp csv_split("\"?,\"?");
103
    while (!in.atEnd())
105
    while (!in.atEnd())
104
    {
106
    {
105
        QString line = in.readLine();
107
        QString line = in.readLine();
106
        line = line.trimmed();             // Remove leading and training White Space
108
        line = line.trimmed();             // Remove leading and training White Space
107
        line.remove(0xA0);                 // M$ special uglyness
109
        line.remove(0xA0);                 // M$ special uglyness
108
 
110
 
-
 
111
        has_RefError = hasRefError(line);
109
        QStringList parts = splitCsvData(line);
112
        QStringList parts = splitCsvData(line);
110
        QString first = parts.value(0);
113
        QString first = parts.value(0);
111
        bool ok;
114
        bool ok;
112
        if ( first.isEmpty() )
115
        if ( first.isEmpty() )
113
            continue;
116
            continue;
Line 115... Line 118...
115
        if ( ! ok || team <= 0 )
118
        if ( ! ok || team <= 0 )
116
            continue;
119
            continue;
117
        tableWidget->setRowCount(1+ii);
120
        tableWidget->setRowCount(1+ii);
118
 
121
 
119
        // Insert Team number
122
        // Insert Team number
120
        tableWidget->setItem(ii, 0, new QTableWidgetItem(first));
123
        QTableWidgetItem *item = new QTableWidgetItem(first);
-
 
124
        tableWidget->setItem(ii, 0, item );
121
        parts.removeFirst();
125
        parts.removeFirst();
-
 
126
        if ( has_RefError )
-
 
127
        {
-
 
128
            item->setBackgroundColor(QColor(0,0,200,50));
-
 
129
            bad_refs++;
-
 
130
        }
122
 
131
 
123
        // Extract Team Name
132
        // Extract Team Name
124
        tableWidget->setItem(ii, 1, new QTableWidgetItem( parts.value(0) ) );
133
        item = new QTableWidgetItem( parts.value(0) );
-
 
134
        tableWidget->setItem(ii, 1, item );
-
 
135
        if ( hasRefError(parts.value(0)) )
-
 
136
        {
-
 
137
            item->setBackgroundColor(QColor(0,0,200,50));
-
 
138
        }
125
        parts.removeFirst();
139
        parts.removeFirst();
126
 
140
        
127
        // Extract Team Cat
141
        // Extract Team Cat
128
        QTableWidgetItem *item = new QTableWidgetItem( parts.value(0)) ;
142
        item = new QTableWidgetItem( parts.value(0)) ;
129
        tableWidget->setItem(ii, 2, item );
143
        tableWidget->setItem(ii, 2, item );
130
 
144
 
131
        if (config.lookup_class(qPrintable(parts.value(0)) ) <= 0 )
145
        if (config.lookup_class(qPrintable(parts.value(0)) ) <= 0 )
132
        {
146
        {
133
            item->setBackgroundColor(QColor(200,0,0,50));
147
            item->setBackgroundColor(QColor(200,0,0,50));
134
            bad_cat++;
148
            bad_cat++;
135
        }
149
        }
-
 
150
        if ( hasRefError(parts.value(0)) )
-
 
151
        {
-
 
152
            item->setBackgroundColor(QColor(0,0,200,50));
-
 
153
        }
136
        parts.removeFirst();
154
        parts.removeFirst();
137
 
155
        
138
        int yy = 0;
156
        int yy = 0;
139
        while ( parts.count() > 0)
157
        while ( parts.count() > 0)
140
        {
158
        {
141
            // Name of competitor
159
            // Name of competitor
142
            tableWidget->setItem(ii, 3+yy, new QTableWidgetItem( parts.value(0)));
160
            item = new QTableWidgetItem( parts.value(0));
-
 
161
            tableWidget->setItem(ii, 3+yy, item);
-
 
162
            if ( hasRefError(parts.value(0)) )
-
 
163
            {
-
 
164
                item->setBackgroundColor(QColor(0,0,200,50));
-
 
165
            }
143
            parts.removeFirst();
166
            parts.removeFirst();
-
 
167
            
144
 
168
 
145
// Not loading age at the moment
169
// Not loading age at the moment
146
// Reason: The CSV file is being create with a '0' for the NE teams
170
// Reason: The CSV file is being create with a '0' for the NE teams
147
#if DO_AGE_LOAD
171
#if DO_AGE_LOAD
148
            // Posible age - if its a number
172
            // Posible age - if its a number
Line 161... Line 185...
161
        ii++;
185
        ii++;
162
    }
186
    }
163
    tableWidget->resizeColumnsToContents();
187
    tableWidget->resizeColumnsToContents();
164
 
188
 
165
    // Report errors
189
    // Report errors
166
    if (bad_cat)
190
    reportErrors( bad_cat, bad_refs);
167
    {
191
    
168
        MainWindow::showMessage("Invalid Categories in data");
-
 
169
    }
-
 
170
 
-
 
171
    // Connect up buttons
192
    // Connect up buttons
172
 
193
 
173
    connect (load, SIGNAL(clicked()), this, SLOT(loadData()));
194
    connect (load, SIGNAL(clicked()), this, SLOT(loadData()));
174
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
195
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
175
}
196
}
Line 182... Line 203...
182
void QmDialogLoadExternalTeams::loadData(void)
203
void QmDialogLoadExternalTeams::loadData(void)
183
{
204
{
184
    qDebug ("LoadData");
205
    qDebug ("LoadData");
185
    team_type team_buf;
206
    team_type team_buf;
186
    int bad_cat = 0;
207
    int bad_cat = 0;
-
 
208
    int bad_refs = 0;
187
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
209
    for ( int ii = 0; ii < tableWidget->rowCount(); ii++)
188
    {
210
    {
189
        if ( tableWidget->isRowHidden(ii))
211
        if ( tableWidget->isRowHidden(ii))
190
        {
212
        {
191
            continue;
213
            continue;
Line 233... Line 255...
233
                    }
255
                    }
234
                    item = tableWidget->item(ii,yy);
256
                    item = tableWidget->item(ii,yy);
235
                    if (item)
257
                    if (item)
236
                    {
258
                    {
237
                        strncpy(team_buf.members[member].name , qPrintable(item->data(Qt::EditRole).toString()), sizeof(team_buf.members[member].name));
259
                        strncpy(team_buf.members[member].name , qPrintable(item->data(Qt::EditRole).toString()), sizeof(team_buf.members[member].name));
-
 
260
                        if ( hasRefError(item->data(Qt::EditRole).toString()) )
-
 
261
                        {
-
 
262
                            bad = true;
-
 
263
                            bad_refs++;
-
 
264
                        }
238
                    }
265
                    }
239
                    item = tableWidget->item(ii,1+yy);
266
                    item = tableWidget->item(ii,1+yy);
240
                    if (item)
267
                    if (item)
241
                    {
268
                    {
242
                        int age = item->data(Qt::EditRole).toInt();
269
                        int age = item->data(Qt::EditRole).toInt();
Line 264... Line 291...
264
            tableWidget->hideRow(ii);
291
            tableWidget->hideRow(ii);
265
        }
292
        }
266
    }
293
    }
267
 
294
 
268
    // Report errors
295
    // Report errors
-
 
296
    reportErrors( bad_cat, bad_refs);
-
 
297
}
-
 
298
 
-
 
299
/*----------------------------------------------------------------------------
-
 
300
** FUNCTION           : reportErrors
-
 
301
**
-
 
302
** DESCRIPTION        : Report errors on the main window
-
 
303
**
-
 
304
**
-
 
305
** INPUTS             : bad_cat - count of category erors
-
 
306
**                      bad_refs - count of Reference errors
-
 
307
**
-
 
308
** RETURNS            :
-
 
309
**
-
 
310
----------------------------------------------------------------------------*/
-
 
311
 
-
 
312
void QmDialogLoadExternalTeams::reportErrors( int bad_cat, int bad_refs )
-
 
313
{
-
 
314
    if ( bad_cat && bad_refs )
-
 
315
    {
-
 
316
        MainWindow::showMessage("Invalid Categories in data and bad REFs");
-
 
317
    }
269
    if (bad_cat)
318
    else if (bad_cat)
270
    {
319
    {
271
        MainWindow::showMessage("Invalid Categories in data");
320
        MainWindow::showMessage("Invalid Categories in data");
272
    }
321
    }
-
 
322
    else if (bad_refs)
-
 
323
    {
-
 
324
        MainWindow::showMessage("Imported data has bad REFs");
-
 
325
    }
-
 
326
    
273
}
327
}
274
 
328
 
275
/*========================================================================
329
/*========================================================================
276
 *
330
 *
277
 *  Generate team name file
331
 *  Generate team name file
Line 413... Line 467...
413
        */
467
        */
414
        results += result.trimmed();
468
        results += result.trimmed();
415
     }
469
     }
416
    return results;
470
    return results;
417
}
471
}
-
 
472
/*----------------------------------------------------------------------------
-
 
473
** FUNCTION           : hasRefError
-
 
474
**
-
 
475
** DESCRIPTION        : Determine if a string contains an Excel Reference
-
 
476
**                      error: #REF!
-
 
477
**
-
 
478
**
-
 
479
** INPUTS             : data - String to test
-
 
480
**
-
 
481
** RETURNS            : True: Is an error
-
 
482
**
-
 
483
----------------------------------------------------------------------------*/
-
 
484
 
-
 
485
bool QmDialogLoadExternalTeams::hasRefError( const QString data)
-
 
486
{
-
 
487
    return data.contains("#REF!");
-
 
488
}
418
 
489
 
419
/*========================================================================
490
/*========================================================================
420
 *
491
 *
421
 *  Generate team name file
492
 *  Generate team name file
422
 *
493
 *