Subversion Repositories svn1-original

Rev

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

Rev 154 Rev 155
Line 32... Line 32...
32
    QStringList labels;
32
    QStringList labels;
33
    labels << "Team" << "Team Name" << "Cat";
33
    labels << "Team" << "Team Name" << "Cat";
34
    for (int ii = 1; ii <= config.num_legs; ii++ )
34
    for (int ii = 1; ii <= config.num_legs; ii++ )
35
    {
35
    {
36
        labels += QString("Leg:%1").arg(QString::number(ii));
36
        labels += QString("Leg:%1").arg(QString::number(ii));
37
        labels += QString("Sex:%1").arg(QString::number(ii));
37
        labels += QString("Age:%1").arg(QString::number(ii));
38
    }
38
    }
39
    ui->tableWidget->setHorizontalHeaderLabels(labels);
39
    ui->tableWidget->setHorizontalHeaderLabels(labels);
40
 
40
 
41
    // Process Each line of the file
41
    // Process Each line of the file
42
    QTextStream in(&file);
42
    QTextStream in(&file);
Line 47... Line 47...
47
    {
47
    {
48
         QString line = in.readLine();
48
         QString line = in.readLine();
49
         line = line.trimmed();             // Remove leading and training White Space
49
         line = line.trimmed();             // Remove leading and training White Space
50
         line.remove(0xA0);                 // M$ special uglyness
50
         line.remove(0xA0);                 // M$ special uglyness
51
 
51
 
52
         QStringList parts = line.split(csv_split);
52
         QStringList parts = splitCsvData(line);
53
         QString first = parts.value(0);
53
         QString first = parts.value(0);
54
         bool ok;
54
         bool ok;
55
         if ( first.isEmpty() )
55
         if ( first.isEmpty() )
56
             continue;
56
             continue;
57
         int team = first.toInt(&ok);
57
         int team = first.toInt(&ok);
Line 85... Line 85...
85
             ui->tableWidget->setItem(ii, 3+yy, new QTableWidgetItem( parts.value(0)));
85
             ui->tableWidget->setItem(ii, 3+yy, new QTableWidgetItem( parts.value(0)));
86
             parts.removeFirst();
86
             parts.removeFirst();
87
 
87
 
88
             // Posible age - if its a number
88
             // Posible age - if its a number
89
             int age = parts.value(0).toInt(&ok);
89
             int age = parts.value(0).toInt(&ok);
90
             if ( ok && age > 0 )
90
             if ( ok )
91
             {
91
             {
-
 
92
                 if ( age > 0 )
-
 
93
                 {
92
                 ui->tableWidget->setItem(ii, 4+yy, new QTableWidgetItem( parts.value(0)));
94
                     ui->tableWidget->setItem(ii, 4+yy, new QTableWidgetItem( parts.value(0)));
-
 
95
                 }
93
                 parts.removeFirst();
96
                 parts.removeFirst();
94
             }
97
             }
95
             yy += 2;
98
             yy += 2;
96
         }
99
         }
97
         ii++;
100
         ii++;
Line 233... Line 236...
233
        return;
236
        return;
234
    }
237
    }
235
    QTextStream out(&file);
238
    QTextStream out(&file);
236
 
239
 
237
    // Print headings
240
    // Print headings
-
 
241
    out << toCsv("Team Number");
-
 
242
    out << "," << toCsv("Team Name");
238
    out << "\"Team Number\"," << "\"Team Name\"," << "\"Class Abr\"";
243
    out << "," <<  toCsv("Class Abr");
239
 
244
 
240
    for( int j = 1; j <= config.num_legs; j++ )
245
    for( int j = 1; j <= config.num_legs; j++ )
241
    {
246
    {
242
        out << ",\"Competitor Name\"";
247
        out << "," << toCsv("Competitor Name");
243
        out << ",\"Age\"";
248
        out << "," << toCsv("Age");
244
    }
249
    }
245
    out << endl;
250
    out << endl;
246
 
251
 
247
    /*
252
    /*
248
     * Put the data into the file
253
     * Put the data into the file
Line 255... Line 260...
255
            /*
260
            /*
256
            **  Basic information
261
            **  Basic information
257
            **      - Team number
262
            **      - Team number
258
            **      - Full team name
263
            **      - Full team name
259
            */
264
            */
260
            out << "\"" << team_buf.numb << "\"";
265
            out << toCsv(team_buf.numb);
261
            out << ",\"" << team_buf.name << "\"";
266
            out << "," << toCsv(team_buf.name);
262
            out << ",\"" <<(team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr)  << "\"";
267
            out << "," << toCsv(team_buf.teamclass == 0 ? "" : config.team_class[team_buf.teamclass - 1].abr);
263
 
268
 
264
            for(int j = 1; j <= config.num_legs; j++ )
269
            for(int j = 1; j <= config.num_legs; j++ )
265
            {
270
            {
266
                out << ",\"" << team_buf.members[j-1].name << "\"";
271
                out << "," << toCsv(team_buf.members[j-1].name);
267
                out << ",\"" << team_buf.members[j-1].age << "\"";
272
                out << "," << toCsv(team_buf.members[j-1].age);
268
            }
273
            }
269
            out <<endl;
274
            out <<endl;
270
        }
275
        }
271
    }
276
    }
272
}
277
}
-
 
278
 
-
 
279
QStringList QmDialogLoadExternalTeams::splitCsvData( const QString str)
-
 
280
{
-
 
281
    QStringList results;
-
 
282
 
-
 
283
    const QChar *data = str.constData();
-
 
284
    while (!data->isNull())
-
 
285
    {
-
 
286
        QString result;
-
 
287
        bool quoted = false;
-
 
288
        /*
-
 
289
        **  Extract the next record
-
 
290
        */
-
 
291
        while ( TRUE )
-
 
292
        {
-
 
293
            QChar uch = *data;
-
 
294
 
-
 
295
            /*
-
 
296
            **  End of the field
-
 
297
            */
-
 
298
            if ( uch == '\n' || uch == '\r' || uch == '\0' )
-
 
299
                break;
-
 
300
 
-
 
301
            data++;
-
 
302
 
-
 
303
            /*
-
 
304
            ** Ugly character from MS CSV files
-
 
305
            */
-
 
306
            if ( uch == (char) 0xA0 )
-
 
307
            {
-
 
308
                continue;
-
 
309
            }
-
 
310
 
-
 
311
            if ( !quoted && uch == ',' )
-
 
312
            {
-
 
313
                break;
-
 
314
            }
-
 
315
 
-
 
316
            /*
-
 
317
            **  An unquoted " will start scanning for a matching quote
-
 
318
            */
-
 
319
            if ( !quoted && uch == '"' )
-
 
320
            {
-
 
321
                quoted = true;
-
 
322
                continue;
-
 
323
            }
-
 
324
 
-
 
325
            /*
-
 
326
            **  A quoted " may be an embedded quote or the end of a quote
-
 
327
            */
-
 
328
            if ( quoted && uch == '"' )
-
 
329
            {
-
 
330
                if ( *data != '"' )
-
 
331
                {
-
 
332
                    quoted = FALSE;
-
 
333
                    continue;
-
 
334
                }
-
 
335
 
-
 
336
                /*
-
 
337
                **  Skip one " and pick up the next
-
 
338
                */
-
 
339
                ++data;
-
 
340
            }
-
 
341
 
-
 
342
            /*
-
 
343
            **  Save this character
-
 
344
            */
-
 
345
            result += uch;
-
 
346
        }
-
 
347
 
-
 
348
        /*
-
 
349
        **  Clean up the extracted string
-
 
350
        */
-
 
351
        results += result.trimmed();
-
 
352
     }
-
 
353
    return results;
-
 
354
}
-
 
355
 
-
 
356
QString QmDialogLoadExternalTeams::toCsv(const QString &str)
-
 
357
{
-
 
358
    QString result = QString(str);
-
 
359
    if ( result.contains("\"") || result.contains(",") )
-
 
360
    {
-
 
361
        result.replace("\"", "\"\"");
-
 
362
        result.prepend("\"");
-
 
363
        result.append("\"");
-
 
364
    }
-
 
365
    return result;
-
 
366
}
-
 
367
 
-
 
368
QString QmDialogLoadExternalTeams::toCsv(const int data)
-
 
369
{
-
 
370
    return QString::number(data);
-
 
371
}