From 4c49670cdba403090067d8b92940b577d16ba550 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Wed, 16 Oct 2013 22:05:19 +0300 Subject: GUI for CSV import This patch implements GUI for importing CSV log files. One is able to configure what columns contain time, depth and temperature fields. Pre-configured log applications currently included are ADP log viewer and XP5. (Both of these use actually tab as separator, so the field separator currently hard-coded.) [Dirk Hohndel: minor fixes] Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- qt-ui/csvimportdialog.cpp | 102 ++++++++++++++++ qt-ui/csvimportdialog.h | 48 ++++++++ qt-ui/csvimportdialog.ui | 253 ++++++++++++++++++++++++++++++++++++++++ qt-ui/mainwindow.cpp | 15 +++ qt-ui/mainwindow.h | 2 + qt-ui/mainwindow.ui | 8 ++ qt-ui/subsurfacewebservices.cpp | 2 +- 7 files changed, 429 insertions(+), 1 deletion(-) create mode 100644 qt-ui/csvimportdialog.cpp create mode 100644 qt-ui/csvimportdialog.h create mode 100644 qt-ui/csvimportdialog.ui (limited to 'qt-ui') diff --git a/qt-ui/csvimportdialog.cpp b/qt-ui/csvimportdialog.cpp new file mode 100644 index 000000000..5ae4036f5 --- /dev/null +++ b/qt-ui/csvimportdialog.cpp @@ -0,0 +1,102 @@ +#include +#include +#include "csvimportdialog.h" +#include "mainwindow.h" +#include "ui_csvimportdialog.h" + +const CSVImportDialog::CSVAppConfig CSVImportDialog::CSVApps[CSVAPPS] = { + {"", }, + {"APD Log Viewer", 0, 1, 15, "Tab"}, + {"XP5", 0, 1, 9, "Tab"}, + {NULL,} +}; + +CSVImportDialog::CSVImportDialog(QWidget *parent) : + QDialog(parent), + selector(true), + ui(new Ui::CSVImportDialog) +{ + ui->setupUi(this); + + for (int i = 0; !CSVApps[i].name.isNull(); ++i) + ui->knownImports->addItem(CSVApps[i].name); + + ui->CSVSeparator->addItem("Tab"); + ui->knownImports->setCurrentIndex(1); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); +} + +CSVImportDialog::~CSVImportDialog() +{ + delete ui; +} + +void CSVImportDialog::on_buttonBox_accepted() +{ + char *error = NULL; + + parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value(), ui->CSVDepth->value(), ui->CSVTemperature->value(), &error); + if (error != NULL) { + + mainWindow()->showError(error); + free(error); + error = NULL; + } + process_dives(TRUE, FALSE); + + mainWindow()->refreshDisplay(); +} + +void CSVImportDialog::on_CSVFileSelector_clicked() +{ + QString filename = QFileDialog::getOpenFileName(this, tr("Open CSV Log File"), ".", tr("CSV Files (*.csv)")); + ui->CSVFile->setText(filename); + if (filename.isEmpty()) + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + else + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +} + +void CSVImportDialog::on_knownImports_currentIndexChanged(int index) +{ + if (index == 0) + return; + + ui->CSVTime->blockSignals(true); + ui->CSVDepth->blockSignals(true); + ui->CSVTemperature->blockSignals(true); + ui->CSVTime->setValue(CSVApps[index].time); + ui->CSVDepth->setValue(CSVApps[index].depth); + ui->CSVTemperature->setValue(CSVApps[index].temperature); + ui->CSVTime->blockSignals(false); + ui->CSVDepth->blockSignals(false); + ui->CSVTemperature->blockSignals(false); +} + +void CSVImportDialog::on_CSVTime_valueChanged(int arg1) +{ + unknownImports(); +} + +void CSVImportDialog::on_CSVDepth_valueChanged(int arg1) +{ + unknownImports(); +} + +void CSVImportDialog::on_CSVTemperature_valueChanged(int arg1) +{ + unknownImports(); +} + +void CSVImportDialog::unknownImports() +{ + ui->knownImports->setCurrentIndex(0); +} + +void CSVImportDialog::on_CSVFile_textEdited() +{ + if (ui->CSVFile->text().isEmpty()) + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + else + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +} diff --git a/qt-ui/csvimportdialog.h b/qt-ui/csvimportdialog.h new file mode 100644 index 000000000..057533018 --- /dev/null +++ b/qt-ui/csvimportdialog.h @@ -0,0 +1,48 @@ +#ifndef CSVIMPORTDIALOG_H +#define CSVIMPORTDIALOG_H + +#include +#include +#include "../dive.h" +#include "../divelist.h" + +namespace Ui { +class CSVImportDialog; +} + +class CSVImportDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CSVImportDialog(QWidget *parent = 0); + ~CSVImportDialog(); + +private slots: + void on_buttonBox_accepted(); + void on_CSVFileSelector_clicked(); + void on_knownImports_currentIndexChanged(int index); + void on_CSVTime_valueChanged(int arg1); + void on_CSVDepth_valueChanged(int arg1); + void on_CSVTemperature_valueChanged(int arg1); + void on_CSVFile_textEdited(); + +private: + void unknownImports(); + + bool selector; + Ui::CSVImportDialog *ui; + + struct CSVAppConfig { + QString name; + int time; + int depth; + int temperature; + QString separator; + }; + +#define CSVAPPS 4 + static const CSVAppConfig CSVApps[CSVAPPS]; +}; + +#endif // CSVIMPORTDIALOG_H diff --git a/qt-ui/csvimportdialog.ui b/qt-ui/csvimportdialog.ui new file mode 100644 index 000000000..ec5002baf --- /dev/null +++ b/qt-ui/csvimportdialog.ui @@ -0,0 +1,253 @@ + + + CSVImportDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 40 + 10 + 331 + 71 + + + + Import File (CSV) + + + + + 0 + 30 + 291 + 29 + + + + + + + 300 + 30 + 25 + 27 + + + + ... + + + + + + + 200 + 80 + 121 + 61 + + + + Field Separator + + + + + 0 + 30 + 111 + 29 + + + + + + + + 40 + 80 + 151 + 151 + + + + Field Configuration + + + + + 60 + 30 + 56 + 29 + + + + 0 + + + 0 + + + + + + 60 + 70 + 56 + 29 + + + + 0 + + + 1 + + + + + + 60 + 110 + 56 + 29 + + + + 0 + + + 15 + + + + + + 0 + 30 + 41 + 19 + + + + Time + + + + + + 0 + 70 + 51 + 19 + + + + Depth + + + + + + 0 + 110 + 41 + 19 + + + + Temp + + + + + + + 200 + 159 + 181 + 61 + + + + Pre-configured imports + + + + + 0 + 30 + 161 + 29 + + + + -1 + + + + + + + + buttonBox + accepted() + CSVImportDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CSVImportDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 247cfdf2f..3b56134c1 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -34,6 +34,7 @@ #include "diveplanner.h" #include "about.h" #include "printdialog.h" +#include "csvimportdialog.h" static MainWindow* instance = 0; @@ -801,3 +802,17 @@ void MainWindow::loadFiles(const QStringList fileNames) WSInfoModel *wsim = WSInfoModel::instance(); wsim->updateInfo(); } + +void MainWindow::on_actionImportCSV_triggered() +{ + CSVImportDialog *csvImport = new(CSVImportDialog); + csvImport->show(); + process_dives(TRUE, FALSE); + + ui.InfoWidget->reload(); + ui.globe->reload(); + ui.ListWidget->reload(DiveTripModel::TREE); + ui.ListWidget->setFocus(); + WSInfoModel *wsim = WSInfoModel::instance(); + wsim->updateInfo(); +} diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 0319c7b28..5dfae3e98 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -99,6 +99,8 @@ private slots: void current_dive_changed(int divenr); void initialUiSetup(); + void on_actionImportCSV_triggered(); + protected: void closeEvent(QCloseEvent *); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 63dded7f8..8a108118e 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -183,6 +183,7 @@ + @@ -441,6 +442,13 @@ Dive Planner + + + Import CSV + + + + diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 2a560efdd..f2b1b88cc 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -47,7 +47,7 @@ void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) case QDialogButtonBox::ApplyRole:{ clear_table(&gps_location_table); QByteArray url = tr("Webservice").toLocal8Bit(); - parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL); + parse_xml_buffer(url.data(), downloadedData.data(), downloadedData.length(), &gps_location_table, NULL, NULL); /* now merge the data in the gps_location table into the dive_table */ if (merge_locations_into_dives()) { -- cgit v1.2.3-70-g09d2