| 153 |
david |
1 |
#include "qmdialoguploadlegtimes.h"
|
|
|
2 |
#include "ui_qmdialoguploadlegtimes.h"
|
|
|
3 |
#include "QTableWidgetItem"
|
|
|
4 |
#include "QFile"
|
|
|
5 |
#include "QString"
|
|
|
6 |
#include "QFileDialog"
|
|
|
7 |
#include "mainwindow.h"
|
|
|
8 |
#include "QTextStream"
|
|
|
9 |
#include "timedelegate.h"
|
|
|
10 |
|
|
|
11 |
#include "consts.h"
|
|
|
12 |
#include "structs.h"
|
|
|
13 |
#include "proto.h"
|
|
|
14 |
|
|
|
15 |
QmDialogUploadLegTimes::QmDialogUploadLegTimes(QWidget *parent) :
|
|
|
16 |
QDialog(parent),
|
|
|
17 |
ui(new Ui::QmDialogUploadLegTimes)
|
|
|
18 |
{
|
|
|
19 |
ui->setupUi(this);
|
|
|
20 |
ui->legNumber->setMaximum(config.num_legs);
|
|
|
21 |
|
|
|
22 |
// Connect up buttons
|
|
|
23 |
connect(ui->load, SIGNAL(clicked()), this, SLOT(load()));
|
|
|
24 |
connect(ui->cancel,SIGNAL(clicked()), this, SLOT(close()));
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
// Set up the table
|
|
|
28 |
ui->tableWidget->setColumnCount(5);
|
|
|
29 |
|
|
|
30 |
QStringList labels;
|
|
|
31 |
labels << "Team" << "Time" << "Time" << "Time" << "Time";
|
|
|
32 |
ui->tableWidget->setHorizontalHeaderLabels(labels);
|
|
|
33 |
|
|
|
34 |
ui->tableWidget->setItemDelegateForColumn(1, new timeDelegate());
|
|
|
35 |
ui->tableWidget->setItemDelegateForColumn(2, new timeDelegate());
|
|
|
36 |
ui->tableWidget->setItemDelegateForColumn(3, new timeDelegate());
|
|
|
37 |
ui->tableWidget->setItemDelegateForColumn(4, new timeDelegate());
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
QmDialogUploadLegTimes::~QmDialogUploadLegTimes()
|
|
|
41 |
{
|
|
|
42 |
delete ui;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
void QmDialogUploadLegTimes::load(void)
|
|
|
46 |
{
|
|
|
47 |
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"),
|
|
|
48 |
QDir::currentPath(),
|
|
|
49 |
tr("Data (*.leg);;All (*.*)"),
|
|
|
50 |
0,
|
|
|
51 |
QFileDialog::ReadOnly);
|
|
|
52 |
if ( fileName.isEmpty() )
|
|
|
53 |
{
|
|
|
54 |
MainWindow::showMessage("No File Specified");
|
|
|
55 |
return;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
// Open the file
|
|
|
59 |
|
|
|
60 |
QFile file(fileName);
|
|
|
61 |
if ( ! file.open(QIODevice::ReadOnly | QIODevice::Text) )
|
|
|
62 |
{
|
|
|
63 |
MainWindow::showMessage("Cannot open Leg Data file");
|
|
|
64 |
return;
|
|
|
65 |
}
|
|
|
66 |
MainWindow::showMessage("Loading Leg Data");
|
|
|
67 |
// Insert column headers
|
|
|
68 |
ui->tableWidget->clearContents();
|
|
|
69 |
ui->tableWidget->setRowCount(0);
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
// Process Each line of the file
|
|
|
73 |
// Format is TeamNumber Time
|
|
|
74 |
QTextStream in(&file);
|
|
|
75 |
while (!in.atEnd())
|
|
|
76 |
{
|
|
|
77 |
QString line = in.readLine();
|
|
|
78 |
line = line.trimmed(); // Remove leading and training White Space
|
|
|
79 |
QStringList parts = line.split(" ");
|
|
|
80 |
QString first = parts.value(0);
|
|
|
81 |
|
|
|
82 |
bool ok;
|
|
|
83 |
int team = first.toInt(&ok);
|
|
|
84 |
if ( ! ok || team <= 0 )
|
|
|
85 |
continue;
|
|
|
86 |
if (team > ui->tableWidget->rowCount())
|
|
|
87 |
{
|
|
|
88 |
ui->tableWidget->setRowCount(team);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
QTableWidgetItem *item = ui->tableWidget->item(team-1,0);
|
|
|
92 |
if (!item)
|
|
|
93 |
{
|
|
|
94 |
item = new QTableWidgetItem(QString::number(team));
|
|
|
95 |
item->setFlags(item->flags() & ~(Qt::ItemIsEditable|Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled));
|
|
|
96 |
ui->tableWidget->setItem(team-1,0,item);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
// Insert the time at the first available slot
|
|
|
100 |
int ii;
|
|
|
101 |
QTableWidgetItem *titem = NULL;
|
|
|
102 |
for (ii=1 ; ii < ui->tableWidget->columnCount(); ii++)
|
|
|
103 |
{
|
|
|
104 |
titem = ui->tableWidget->item(team-1,ii);
|
|
|
105 |
if (! titem)
|
|
|
106 |
{
|
|
|
107 |
break;
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
titem = new QTableWidgetItem(parts.value(1));
|
|
|
111 |
ui->tableWidget->setItem(team-1,ii,titem);
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|