7 { |
7 { |
8 ui->setupUi(this); |
8 ui->setupUi(this); |
9 connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); |
9 connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); |
10 connect(ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit())); |
10 connect(ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit())); |
11 connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open())); |
11 connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open())); |
|
12 |
|
13 |
12 } |
14 } |
13 |
15 |
14 MainWindow::~MainWindow() |
16 MainWindow::~MainWindow() |
15 { |
17 { |
16 delete ui; |
18 delete ui; |
17 } |
19 } |
18 |
20 |
19 void MainWindow::open() |
21 void MainWindow::open(const QString &s) |
20 { |
22 { |
21 QString fileName = QFileDialog::getOpenFileName( |
23 QString fileName; |
22 this, |
24 if (s.isEmpty()) { |
23 tr("Open IGC file"), |
25 fileName = QFileDialog::getOpenFileName( |
24 "flights", tr("IGC files (*.igc);; All files (*)")); |
26 this, |
25 if (fileName.isEmpty()) return; |
27 tr("Open IGC file"), |
|
28 "flights", tr("IGC files (*.igc);; All files (*)")); |
|
29 if (fileName.isEmpty()) return; |
|
30 } |
|
31 else fileName = s; |
26 |
32 |
27 if(currentFile.isOpen()) |
|
28 currentFile.close(); |
|
29 |
33 |
30 currentFile.setFileName(fileName); |
34 if(currentFile_.isOpen()) |
|
35 currentFile_.close(); |
31 |
36 |
32 if (!currentFile.open(QFile::ReadOnly)) { |
37 currentFile_.setFileName(fileName); |
|
38 |
|
39 if (!currentFile_.open(QFile::ReadOnly)) { |
33 QMessageBox::critical(this, |
40 QMessageBox::critical(this, |
34 tr("Ooops!"), |
41 tr("Ooops!"), |
35 tr("The file %1 cannot be opened: %2!").arg(fileName).arg(currentFile.errorString())); |
42 tr("The file %1 cannot be opened: %2!").arg(fileName).arg(currentFile_.errorString())); |
36 return; |
43 return; |
37 } |
44 } |
38 |
45 |
39 input.setDevice(¤tFile); |
46 input_.setDevice(¤tFile_); |
40 setWindowTitle(QFileInfo(fileName).baseName()); |
47 setWindowTitle(QFileInfo(fileName).baseName()); |
41 statusBar()->showMessage(tr("opening %1").arg(fileName), 5000); |
48 statusBar()->showMessage(tr("opening %1").arg(fileName), 5000); |
42 |
49 |
43 igc.read(input); |
50 igc_.read(input_); |
44 |
51 |
45 qDebug() << igc.device(); |
52 |
46 qDebug() << igc.pilot(); |
53 // now let's fill the table |
47 qDebug() << igc.date(); |
54 QTableWidget *t = ui->table; |
|
55 int r = 0; |
|
56 const int K = 0; |
|
57 const int V = 1; |
|
58 |
|
59 // cleanup |
|
60 t->clearContents(); |
|
61 t->setRowCount(0); |
|
62 |
|
63 // fill |
|
64 t->setRowCount(t->rowCount() + 1); |
|
65 t->setItem(r, K, new QTableWidgetItem(tr("Pilot"))); |
|
66 t->setItem(r, V, new QTableWidgetItem(igc_.pilot())); |
|
67 ++r; |
|
68 |
|
69 t->setRowCount(t->rowCount() + 1); |
|
70 t->setItem(r, K, new QTableWidgetItem(tr("Date"))); |
|
71 t->setItem(r, V, new QTableWidgetItem(igc_ |
|
72 .date() |
|
73 .toString(tr("yyyy-MMM-dd (dddd)")))); |
|
74 ++r; |
|
75 |
|
76 t->setRowCount(t->rowCount() + 1); |
|
77 t->setItem(r, K, new QTableWidgetItem(tr("Glider"))); |
|
78 t->setItem(r, V, new QTableWidgetItem(igc_.glider())); |
|
79 ++r; |
|
80 |
|
81 |
|
82 // ui->table->setItem(0, 1, new QTableWidgetItem(igc_.pilot())); |
|
83 |
|
84 qDebug() << igc_.device(); |
|
85 qDebug() << igc_.pilot(); |
|
86 qDebug() << igc_.date(); |
48 |
87 |
49 } |
88 } |