summaryrefslogtreecommitdiffstats
path: root/qt-ui/csvimportdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/csvimportdialog.cpp')
-rw-r--r--qt-ui/csvimportdialog.cpp102
1 files changed, 102 insertions, 0 deletions
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 <QtDebug>
+#include <QFileDialog>
+#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);
+}