Subversion Repositories svn1-original

Rev

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

Rev 276 Rev 297
Line 6... Line 6...
6
#include <QRegExp>
6
#include <QRegExp>
7
#include <QtGui/QHBoxLayout>
7
#include <QtGui/QHBoxLayout>
8
#include <QtGui/QVBoxLayout>
8
#include <QtGui/QVBoxLayout>
9
#include <QtGui/QWidget>
9
#include <QtGui/QWidget>
10
#include <QHeaderView>
10
#include <QHeaderView>
-
 
11
#include <QtWebKit/QtWebKit>
11
 
12
 
12
#include    "consts.h"
13
#include    "consts.h"
13
#include    "structs.h"
14
#include    "structs.h"
14
#include    "proto.h"
15
#include    "proto.h"
15
 
16
 
16
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile,QWidget *parent) :
17
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile,QWidget *parent) :
17
    QDialog(parent)
18
        QDialog(parent)
18
{
19
{
19
 
20
 
20
    //
21
    //
21
    // Create Windows
22
    // Create Windows
22
    //
23
    //
-
 
24
    createWindow();
-
 
25
    fileName->setText(efile);
-
 
26
 
-
 
27
    // Open the users file
-
 
28
 
-
 
29
    QFile file(efile);
-
 
30
    if ( ! file.open(QIODevice::ReadOnly | QIODevice::Text) )
-
 
31
    {
-
 
32
        MainWindow::showMessage("Cannot open external data file");
-
 
33
        return;
-
 
34
    }
-
 
35
    MainWindow::showMessage("Loading External Data");
-
 
36
 
-
 
37
    // Process Each line of the file
-
 
38
    QTextStream in(&file);
-
 
39
    QRegExp csv_split("\"?,\"?");
-
 
40
    while (!in.atEnd())
-
 
41
    {
-
 
42
        QString line = in.readLine();
-
 
43
        line = line.trimmed();             // Remove leading and training White Space
-
 
44
        line.remove(0xA0);                 // M$ special uglyness
-
 
45
        line.remove(0xC2);                 // M$ special uglyness
-
 
46
 
-
 
47
        bool has_RefError = hasRefError(line);
-
 
48
        QStringList parts = splitCsvData(line);
-
 
49
        insertParts( parts, has_RefError );
-
 
50
        
-
 
51
    }
-
 
52
    tableWidget->resizeColumnsToContents();
-
 
53
 
-
 
54
    // Report errors
-
 
55
    reportErrors( bad_cat, bad_refs);
-
 
56
}
-
 
57
 
-
 
58
 
-
 
59
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile, QByteArray *data ,QWidget *parent) :
-
 
60
        QDialog(parent)
-
 
61
{
-
 
62
    // Create the basic Window
-
 
63
    createWindow();
-
 
64
    fileName->setText(efile);
-
 
65
 
-
 
66
    // Parse the data. It is an html file
-
 
67
    //
-
 
68
    MainWindow::showMessage("Parsing HTML");
-
 
69
    qDebug("Data size: %d", data->length());
-
 
70
 
-
 
71
    QWebPage page;
-
 
72
    QWebFrame * frame = page.mainFrame();
-
 
73
    frame->setContent(*data);
-
 
74
 
-
 
75
    QWebElement document = frame->documentElement();
-
 
76
    QWebElement firstTable = document.findFirst("table");
-
 
77
    QWebElementCollection elements = firstTable.findAll("tr");
-
 
78
 
-
 
79
 
-
 
80
    foreach(QWebElement e, elements){
-
 
81
 
-
 
82
        //qDebug()<< "e element" <<e.tagName() << ":" << e.toPlainText();
-
 
83
        qDebug("-----Row");
-
 
84
        QWebElementCollection td = e.findAll("td");
-
 
85
        QStringList parts;
-
 
86
        
-
 
87
        foreach(QWebElement e, td)
-
 
88
        {
-
 
89
            //qDebug()<< e.tagName() << ":" << e.toPlainText();
-
 
90
            parts.append(e.toPlainText());
-
 
91
        }
-
 
92
        insertParts( parts, false );
-
 
93
    }
-
 
94
 
-
 
95
    tableWidget->resizeColumnsToContents();
-
 
96
    reportErrors( bad_cat, bad_refs);
-
 
97
}
-
 
98
 
-
 
99
void QmDialogLoadExternalTeams::createWindow(void)
-
 
100
{
-
 
101
    bad_cat = 0;
-
 
102
    bad_refs = 0;
-
 
103
 
23
    resize(550, 500);
104
    resize(550, 500);
24
    setSizeGripEnabled(true);
105
    setSizeGripEnabled(true);
25
    setWindowTitle("Load External Team Data");
106
    setWindowTitle("Load External Team Data");
26
 
107
 
27
    QVBoxLayout *verticalLayout;
108
    QVBoxLayout *verticalLayout;
28
    verticalLayout = new QVBoxLayout(this);
109
    verticalLayout = new QVBoxLayout(this);
29
    verticalLayout->setContentsMargins(0, 0, 0, 0);
110
    verticalLayout->setContentsMargins(0, 0, 0, 0);
30
 
111
 
31
    QVBoxLayout *verticalLayout2;
112
    QVBoxLayout *verticalLayout2;
32
    verticalLayout2 = new QVBoxLayout(this);
113
    verticalLayout2 = new QVBoxLayout();
33
    verticalLayout2->setContentsMargins(5, 5, 5, 5);
114
    verticalLayout2->setContentsMargins(5, 5, 5, 5);
34
 
115
 
35
    QHBoxLayout *horizontalLayout;
116
    QHBoxLayout *horizontalLayout;
36
    horizontalLayout = new QHBoxLayout();
117
    horizontalLayout = new QHBoxLayout();
37
 
118
 
Line 51... Line 132...
51
 
132
 
52
    fileName = new QLineEdit(this);
133
    fileName = new QLineEdit(this);
53
    fileName->setObjectName(QString::fromUtf8("fileName"));
134
    fileName->setObjectName(QString::fromUtf8("fileName"));
54
    fileName->setGeometry(QRect(20, 470, 331, 20));
135
    fileName->setGeometry(QRect(20, 470, 331, 20));
55
    fileName->setReadOnly(true);
136
    fileName->setReadOnly(true);
56
    fileName->setText(efile);
-
 
57
    horizontalLayout->addWidget(fileName);
137
    horizontalLayout->addWidget(fileName);
58
 
138
 
59
 
139
 
60
 
140
 
61
    load = new QPushButton(this);
141
    load = new QPushButton(this);
Line 71... Line 151...
71
    cancel->setText("Cancel");
151
    cancel->setText("Cancel");
72
    horizontalLayout->addWidget(cancel);
152
    horizontalLayout->addWidget(cancel);
73
 
153
 
74
    verticalLayout->addLayout(horizontalLayout);
154
    verticalLayout->addLayout(horizontalLayout);
75
 
155
 
76
 
-
 
77
    // Open the users file
-
 
78
 
-
 
79
    QFile file(efile);
-
 
80
    if ( ! file.open(QIODevice::ReadOnly | QIODevice::Text) )
-
 
81
    {
-
 
82
        MainWindow::showMessage("Cannot open external data file");
-
 
83
        return;
-
 
84
    }
-
 
85
    MainWindow::showMessage("Loading External Data");
-
 
86
 
-
 
87
    // Insert column headers
156
    // Insert column headers
88
    tableWidget->setColumnCount(3 + ( 2 * config.num_legs) );
157
    tableWidget->setColumnCount(3 + ( 2 * config.num_legs) );
89
    QStringList labels;
158
    QStringList labels;
90
    labels << "Team" << "Team Name" << "Cat";
159
    labels << "Team" << "Team Name" << "Cat";
91
    for (int ii = 1; ii <= config.num_legs; ii++ )
160
    for (int ii = 1; ii <= config.num_legs; ii++ )
92
    {
161
    {
93
        labels += QString("Leg:%1").arg(QString::number(ii));
162
        labels += QString("Leg:%1").arg(QString::number(ii));
94
        labels += QString("Age:%1").arg(QString::number(ii));
163
        labels += QString("Age:%1").arg(QString::number(ii));
95
    }
164
    }
96
    tableWidget->setHorizontalHeaderLabels(labels);
165
    tableWidget->setHorizontalHeaderLabels(labels);
-
 
166
    
97
 
167
 
98
    // Process Each line of the file
168
    // Connect up buttons
-
 
169
 
-
 
170
    connect (load, SIGNAL(clicked()), this, SLOT(loadData()));
-
 
171
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
-
 
172
}
-
 
173
 
-
 
174
void QmDialogLoadExternalTeams::insertParts(QStringList &parts, bool has_RefError)
-
 
175
{
-
 
176
    QString first = parts.value(0);
-
 
177
    bool ok;
99
    QTextStream in(&file);
178
    if ( first.isEmpty() )
100
    int ii = 0;
179
        return;
-
 
180
    int team = first.toInt(&ok);
101
    int bad_cat = 0;
181
    if ( ! ok || team <= 0 )
102
    bool has_RefError;
182
        return;
-
 
183
    int ii = tableWidget->rowCount();
-
 
184
    tableWidget->setRowCount(1 + ii );
-
 
185
 
103
    int  bad_refs = 0;
186
    // Insert Team number
-
 
187
    QTableWidgetItem *item = new QTableWidgetItem(first);
104
    QRegExp csv_split("\"?,\"?");
188
    tableWidget->setItem(ii, 0, item );
-
 
189
    parts.removeFirst();
105
    while (!in.atEnd())
190
    if ( has_RefError )
106
    {
191
    {
107
        QString line = in.readLine();
192
        item->setBackgroundColor(QColor(0,0,200,50));
108
        line = line.trimmed();             // Remove leading and training White Space
-
 
109
        line.remove(0xA0);                 // M$ special uglyness
193
        bad_refs++;
110
        line.remove(0xC2);                 // M$ special uglyness
-
 
-
 
194
    }
111
 
195
 
112
        has_RefError = hasRefError(line);
196
    // Extract Team Name
113
        QStringList parts = splitCsvData(line);
197
    item = new QTableWidgetItem( parts.value(0) );
114
        QString first = parts.value(0);
198
    tableWidget->setItem(ii, 1, item );
115
        bool ok;
-
 
116
        if ( first.isEmpty() )
199
    if ( hasRefError(parts.value(0)) )
117
            continue;
200
    {
118
        int team = first.toInt(&ok);
201
        item->setBackgroundColor(QColor(0,0,200,50));
119
        if ( ! ok || team <= 0 )
-
 
120
            continue;
202
    }
121
        tableWidget->setRowCount(1+ii);
203
    parts.removeFirst();
122
 
204
 
123
        // Insert Team number
205
    // Extract Team Cat
124
        QTableWidgetItem *item = new QTableWidgetItem(first);
206
    item = new QTableWidgetItem( parts.value(0)) ;
125
        tableWidget->setItem(ii, 0, item );
207
    tableWidget->setItem(ii, 2, item );
126
        parts.removeFirst();
-
 
127
        if ( has_RefError )
-
 
128
        {
-
 
129
            item->setBackgroundColor(QColor(0,0,200,50));
-
 
130
            bad_refs++;
-
 
131
        }
-
 
132
 
208
 
133
        // Extract Team Name
209
    if (config.lookup_class(qPrintable(parts.value(0)) ) <= 0 )
-
 
210
    {
134
        item = new QTableWidgetItem( parts.value(0) );
211
        item->setBackgroundColor(QColor(200,0,0,50));
135
        tableWidget->setItem(ii, 1, item );
212
        bad_cat++;
-
 
213
    }
136
        if ( hasRefError(parts.value(0)) )
214
    if ( hasRefError(parts.value(0)) )
137
        {
215
    {
138
            item->setBackgroundColor(QColor(0,0,200,50));
216
        item->setBackgroundColor(QColor(0,0,200,50));
139
        }
217
    }
140
        parts.removeFirst();
218
    parts.removeFirst();
141
        
-
 
142
        // Extract Team Cat
-
 
143
        item = new QTableWidgetItem( parts.value(0)) ;
-
 
144
        tableWidget->setItem(ii, 2, item );
-
 
145
 
219
 
-
 
220
    int yy = 0;
146
        if (config.lookup_class(qPrintable(parts.value(0)) ) <= 0 )
221
    while ( parts.count() > 0)
147
        {
222
    {
148
            item->setBackgroundColor(QColor(200,0,0,50));
223
        // Name of competitor
149
            bad_cat++;
224
        item = new QTableWidgetItem( parts.value(0));
150
        }
225
        tableWidget->setItem(ii, 3+yy, item);
151
        if ( hasRefError(parts.value(0)) )
226
        if ( hasRefError(parts.value(0)) )
152
        {
227
        {
153
            item->setBackgroundColor(QColor(0,0,200,50));
228
            item->setBackgroundColor(QColor(0,0,200,50));
154
        }
229
        }
155
        parts.removeFirst();
230
        parts.removeFirst();
156
        
-
 
157
        int yy = 0;
-
 
158
        while ( parts.count() > 0)
-
 
159
        {
-
 
160
            // Name of competitor
-
 
161
            item = new QTableWidgetItem( parts.value(0));
-
 
162
            tableWidget->setItem(ii, 3+yy, item);
-
 
163
            if ( hasRefError(parts.value(0)) )
-
 
164
            {
-
 
165
                item->setBackgroundColor(QColor(0,0,200,50));
-
 
166
            }
-
 
167
            parts.removeFirst();
-
 
168
            
-
 
169
 
231
 
-
 
232
 
170
// Not loading age at the moment
233
        // Not loading age at the moment
171
// Reason: The CSV file is being create with a '0' for the NE teams
234
        // Reason: The CSV file is being create with a '0' for the NE teams
172
#if DO_AGE_LOAD
235
#if DO_AGE_LOAD
173
            // Posible age - if its a number
236
        // Posible age - if its a number
174
            int age = parts.value(0).toInt(&ok);
237
        int age = parts.value(0).toInt(&ok);
175
            if ( ok )
238
        if ( ok )
-
 
239
        {
-
 
240
            if ( age > 0 )
176
            {
241
            {
177
                if ( age > 0 )
-
 
178
                {
-
 
179
                    tableWidget->setItem(ii, 4+yy, new QTableWidgetItem( parts.value(0)));
242
                tableWidget->setItem(ii, 4+yy, new QTableWidgetItem( parts.value(0)));
180
                }
-
 
181
                parts.removeFirst();
-
 
182
            }
243
            }
183
#endif
-
 
184
            yy += 2;
244
            parts.removeFirst();
185
        }
245
        }
-
 
246
#endif
186
        ii++;
247
        yy += 2;
187
    }
248
    }
188
    tableWidget->resizeColumnsToContents();
-
 
189
 
-
 
190
    // Report errors
-
 
191
    reportErrors( bad_cat, bad_refs);
-
 
192
 
-
 
193
    // Connect up buttons
-
 
194
 
249
    
195
    connect (load, SIGNAL(clicked()), this, SLOT(loadData()));
-
 
196
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
-
 
197
}
250
}
198
 
251
 
-
 
252
 
199
QmDialogLoadExternalTeams::~QmDialogLoadExternalTeams()
253
QmDialogLoadExternalTeams::~QmDialogLoadExternalTeams()
200
{
254
{
201
 
255
 
202
}
256
}
203
 
257
 
Line 466... Line 520...
466
 
520
 
467
        /*
521
        /*
468
        **  Clean up the extracted string
522
        **  Clean up the extracted string
469
        */
523
        */
470
        results += result.trimmed();
524
        results += result.trimmed();
471
     }
525
    }
472
    return results;
526
    return results;
473
}
527
}
474
/*----------------------------------------------------------------------------
528
/*----------------------------------------------------------------------------
475
** FUNCTION           : hasRefError
529
** FUNCTION           : hasRefError
476
**
530
**
Line 515... Line 569...
515
        MainWindow::showMessage("Cannot open external team info file");
569
        MainWindow::showMessage("Cannot open external team info file");
516
        return;
570
        return;
517
    }
571
    }
518
    QTextStream out(&file);
572
    QTextStream out(&file);
519
 
573
 
520
     /*
574
    /*
521
     * Put the data into the file
575
     * Put the data into the file
522
     */
576
     */
523
    team_type   team_buf;
577
    team_type   team_buf;
524
    for(int i = config.min_team; i <= config.max_team; i++ )
578
    for(int i = config.min_team; i <= config.max_team; i++ )
525
    {
579
    {