Subversion Repositories svn1-original

Rev

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

Rev 297 Rev 298
Line 12... Line 12...
12
 
12
 
13
#include    "consts.h"
13
#include    "consts.h"
14
#include    "structs.h"
14
#include    "structs.h"
15
#include    "proto.h"
15
#include    "proto.h"
16
 
16
 
-
 
17
/*----------------------------------------------------------------------------
-
 
18
** FUNCTION           : QmDialogLoadExternalTeams
-
 
19
**
-
 
20
** DESCRIPTION        : Load team data from a CSV file
-
 
21
**
-
 
22
**
-
 
23
** INPUTS             : efile       - name of file
-
 
24
**                      parent      - parent widget
-
 
25
**
-
 
26
** RETURNS            :
-
 
27
**
-
 
28
----------------------------------------------------------------------------*/
-
 
29
 
17
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile,QWidget *parent) :
30
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile,QWidget *parent) :
18
        QDialog(parent)
31
        QDialog(parent)
19
{
32
{
20
 
33
 
21
    //
34
    //
Line 47... Line 60...
47
        bool has_RefError = hasRefError(line);
60
        bool has_RefError = hasRefError(line);
48
        QStringList parts = splitCsvData(line);
61
        QStringList parts = splitCsvData(line);
49
        insertParts( parts, has_RefError );
62
        insertParts( parts, has_RefError );
50
        
63
        
51
    }
64
    }
52
    tableWidget->resizeColumnsToContents();
-
 
53
 
65
 
54
    // Report errors
66
    // Post Load fix up
-
 
67
    tableWidget->resizeColumnsToContents();
55
    reportErrors( bad_cat, bad_refs);
68
    reportErrors( bad_cat, bad_refs);
56
}
69
}
57
 
70
 
-
 
71
/*----------------------------------------------------------------------------
-
 
72
** FUNCTION           : QmDialogLoadExternalTeams
-
 
73
**
-
 
74
** DESCRIPTION        : Load team data from a Web Page
-
 
75
**
-
 
76
**
-
 
77
** INPUTS             : efile       - name of file (display only)
-
 
78
**                      data        - Address of the webpage data loaded in memory
-
 
79
**                      parent      - parent widget
-
 
80
**
-
 
81
** RETURNS            :
-
 
82
**
-
 
83
----------------------------------------------------------------------------*/
58
 
84
 
59
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile, QByteArray *data ,QWidget *parent) :
85
QmDialogLoadExternalTeams::QmDialogLoadExternalTeams(const QString &efile, QByteArray *data ,QWidget *parent) :
60
        QDialog(parent)
86
        QDialog(parent)
61
{
87
{
62
    // Create the basic Window
88
    // Create the basic Window
Line 70... Line 96...
70
 
96
 
71
    QWebPage page;
97
    QWebPage page;
72
    QWebFrame * frame = page.mainFrame();
98
    QWebFrame * frame = page.mainFrame();
73
    frame->setContent(*data);
99
    frame->setContent(*data);
74
 
100
 
-
 
101
    /*
-
 
102
    **  Get the first table
-
 
103
    **      Get all rows
-
 
104
    **      Get all data items in each row
-
 
105
    */
75
    QWebElement document = frame->documentElement();
106
    QWebElement document = frame->documentElement();
76
    QWebElement firstTable = document.findFirst("table");
107
    QWebElement firstTable = document.findFirst("table");
77
    QWebElementCollection elements = firstTable.findAll("tr");
108
    QWebElementCollection elements = firstTable.findAll("tr");
78
 
109
 
79
 
-
 
80
    foreach(QWebElement e, elements){
110
    foreach(QWebElement e, elements){
81
 
111
 
82
        //qDebug()<< "e element" <<e.tagName() << ":" << e.toPlainText();
112
        //qDebug()<< "e element" <<e.tagName() << ":" << e.toPlainText();
83
        qDebug("-----Row");
113
        //qDebug("-----Row");
84
        QWebElementCollection td = e.findAll("td");
114
        QWebElementCollection td = e.findAll("td");
85
        QStringList parts;
115
        QStringList parts;
86
        
116
        
87
        foreach(QWebElement e, td)
117
        foreach(QWebElement e, td)
88
        {
118
        {
Line 90... Line 120...
90
            parts.append(e.toPlainText());
120
            parts.append(e.toPlainText());
91
        }
121
        }
92
        insertParts( parts, false );
122
        insertParts( parts, false );
93
    }
123
    }
94
 
124
 
-
 
125
    // Post Load fix up
95
    tableWidget->resizeColumnsToContents();
126
    tableWidget->resizeColumnsToContents();
96
    reportErrors( bad_cat, bad_refs);
127
    reportErrors( bad_cat, bad_refs);
97
}
128
}
98
 
129
 
-
 
130
/*----------------------------------------------------------------------------
-
 
131
** FUNCTION           : createWindow
-
 
132
**
-
 
133
** DESCRIPTION        : Create the basic window
-
 
134
**                      Used in multiple places
-
 
135
**
-
 
136
**
-
 
137
** INPUTS             :
-
 
138
**
-
 
139
** RETURNS            :
-
 
140
**
-
 
141
----------------------------------------------------------------------------*/
-
 
142
 
99
void QmDialogLoadExternalTeams::createWindow(void)
143
void QmDialogLoadExternalTeams::createWindow(void)
100
{
144
{
101
    bad_cat = 0;
145
    bad_cat = 0;
102
    bad_refs = 0;
146
    bad_refs = 0;
103
 
147
 
Line 134... Line 178...
134
    fileName->setObjectName(QString::fromUtf8("fileName"));
178
    fileName->setObjectName(QString::fromUtf8("fileName"));
135
    fileName->setGeometry(QRect(20, 470, 331, 20));
179
    fileName->setGeometry(QRect(20, 470, 331, 20));
136
    fileName->setReadOnly(true);
180
    fileName->setReadOnly(true);
137
    horizontalLayout->addWidget(fileName);
181
    horizontalLayout->addWidget(fileName);
138
 
182
 
139
 
-
 
140
 
-
 
141
    load = new QPushButton(this);
183
    load = new QPushButton(this);
142
    load->setObjectName(QString::fromUtf8("load"));
184
    load->setObjectName(QString::fromUtf8("load"));
143
    load->setGeometry(QRect(370, 470, 75, 23));
185
    load->setGeometry(QRect(370, 470, 75, 23));
144
    load->setText("Load");
186
    load->setText("Load");
145
    horizontalLayout->addWidget(load);
187
    horizontalLayout->addWidget(load);
Line 164... Line 206...
164
    }
206
    }
165
    tableWidget->setHorizontalHeaderLabels(labels);
207
    tableWidget->setHorizontalHeaderLabels(labels);
166
    
208
    
167
 
209
 
168
    // Connect up buttons
210
    // Connect up buttons
169
 
-
 
170
    connect (load, SIGNAL(clicked()), this, SLOT(loadData()));
211
    connect (load, SIGNAL(clicked()), this, SLOT(loadData()));
171
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
212
    connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
172
}
213
}
173
 
214
 
-
 
215
/*----------------------------------------------------------------------------
-
 
216
** FUNCTION           : insertParts
-
 
217
**
-
 
218
** DESCRIPTION        : Insert raw data into the display table
-
 
219
**
-
 
220
**
-
 
221
** INPUTS             : parts           - Ref to a list of parts
-
 
222
**                      has_RefError    - Data ras Ref Error
-
 
223
**
-
 
224
** RETURNS            :
-
 
225
**
-
 
226
----------------------------------------------------------------------------*/
-
 
227
 
174
void QmDialogLoadExternalTeams::insertParts(QStringList &parts, bool has_RefError)
228
void QmDialogLoadExternalTeams::insertParts(QStringList &parts, bool has_RefError)
175
{
229
{
176
    QString first = parts.value(0);
230
    QString first = parts.value(0);
177
    bool ok;
231
    bool ok;
178
    if ( first.isEmpty() )
232
    if ( first.isEmpty() )
179
        return;
233
        return;
-
 
234
 
180
    int team = first.toInt(&ok);
235
    int team = first.toInt(&ok);
181
    if ( ! ok || team <= 0 )
236
    if ( ! ok || team <= 0 )
182
        return;
237
        return;
-
 
238
 
183
    int ii = tableWidget->rowCount();
239
    int ii = tableWidget->rowCount();
184
    tableWidget->setRowCount(1 + ii );
240
    tableWidget->setRowCount(1 + ii );
185
 
241
 
186
    // Insert Team number
242
    // Insert Team number
187
    QTableWidgetItem *item = new QTableWidgetItem(first);
243
    QTableWidgetItem *item = new QTableWidgetItem(first);
Line 246... Line 302...
246
#endif
302
#endif
247
        yy += 2;
303
        yy += 2;
248
    }
304
    }
249
    
305
    
250
}
306
}
-
 
307
/*----------------------------------------------------------------------------
-
 
308
** FUNCTION           : ~QmDialogLoadExternalTeams
-
 
309
**
-
 
310
** DESCRIPTION        : Class destructor
251
 
311
**
-
 
312
**
-
 
313
** INPUTS             :
-
 
314
**
-
 
315
** RETURNS            :
-
 
316
**
-
 
317
----------------------------------------------------------------------------*/
252
 
318
 
253
QmDialogLoadExternalTeams::~QmDialogLoadExternalTeams()
319
QmDialogLoadExternalTeams::~QmDialogLoadExternalTeams()
254
{
320
{
255
 
321
 
256
}
322
}
257
 
323
 
-
 
324
/*----------------------------------------------------------------------------
-
 
325
** FUNCTION           : loadData
-
 
326
**
-
 
327
** DESCRIPTION        : Store the data from the table into the database
-
 
328
**
-
 
329
**
-
 
330
** INPUTS             :
-
 
331
**
-
 
332
** RETURNS            :
-
 
333
**
-
 
334
----------------------------------------------------------------------------*/
-
 
335
 
258
void QmDialogLoadExternalTeams::loadData(void)
336
void QmDialogLoadExternalTeams::loadData(void)
259
{
337
{
260
    qDebug ("LoadData");
338
    qDebug ("LoadData");
261
    team_type team_buf;
339
    team_type team_buf;
262
    int bad_cat = 0;
340
    int bad_cat = 0;