2013-10-16 19:05:19 +00:00
|
|
|
#include <QtDebug>
|
|
|
|
#include <QFileDialog>
|
2013-12-29 16:11:20 +00:00
|
|
|
#include "divelogimportdialog.h"
|
2013-10-16 19:05:19 +00:00
|
|
|
#include "mainwindow.h"
|
2013-12-29 16:11:20 +00:00
|
|
|
#include "ui_divelogimportdialog.h"
|
2013-10-16 19:05:19 +00:00
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
|
2013-10-16 19:05:19 +00:00
|
|
|
{"", },
|
2013-12-29 05:52:44 +00:00
|
|
|
{"APD Log Viewer", 1, 2, 16, 7, 18, 19, "Tab"},
|
|
|
|
{"XP5", 1, 2, 10, -1, -1, -1, "Tab"},
|
2013-10-16 19:05:19 +00:00
|
|
|
{NULL,}
|
|
|
|
};
|
|
|
|
|
2014-01-07 20:01:28 +00:00
|
|
|
DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) :
|
2013-10-16 19:05:19 +00:00
|
|
|
QDialog(parent),
|
|
|
|
selector(true),
|
2013-12-29 16:11:20 +00:00
|
|
|
ui(new Ui::DiveLogImportDialog)
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-01-07 20:01:28 +00:00
|
|
|
fileNames = *fn;
|
2013-10-16 19:05:19 +00:00
|
|
|
|
|
|
|
for (int i = 0; !CSVApps[i].name.isNull(); ++i)
|
|
|
|
ui->knownImports->addItem(CSVApps[i].name);
|
|
|
|
|
|
|
|
ui->CSVSeparator->addItem("Tab");
|
2013-12-04 23:19:28 +00:00
|
|
|
ui->CSVSeparator->addItem(",");
|
2013-10-16 19:05:19 +00:00
|
|
|
ui->knownImports->setCurrentIndex(1);
|
2013-11-21 22:48:36 +00:00
|
|
|
|
|
|
|
connect(ui->CSVDepth, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
|
|
|
|
connect(ui->CSVTime, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
|
|
|
|
connect(ui->CSVTemperature, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
|
2013-11-21 22:48:37 +00:00
|
|
|
connect(ui->temperatureCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports(bool)));
|
2013-11-21 22:48:40 +00:00
|
|
|
connect(ui->CSVpo2, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
|
|
|
|
connect(ui->po2CheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports(bool)));
|
2013-11-21 22:48:41 +00:00
|
|
|
connect(ui->CSVcns, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
|
|
|
|
connect(ui->cnsCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports(bool)));
|
2013-11-21 22:48:42 +00:00
|
|
|
connect(ui->CSVstopdepth, SIGNAL(valueChanged(int)), this, SLOT(unknownImports(int)));
|
|
|
|
connect(ui->stopdepthCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports(bool)));
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
DiveLogImportDialog::~DiveLogImportDialog()
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2013-12-29 05:52:44 +00:00
|
|
|
#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() - 1: -1)
|
2013-12-29 16:11:20 +00:00
|
|
|
void DiveLogImportDialog::on_buttonBox_accepted()
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
char *error = NULL;
|
|
|
|
|
2014-01-07 20:01:28 +00:00
|
|
|
for (int i = 0; i < fileNames.size(); ++i) {
|
|
|
|
parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1,
|
2013-12-29 16:11:19 +00:00
|
|
|
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
|
|
|
|
VALUE_IF_CHECKED(CSVpo2),
|
|
|
|
VALUE_IF_CHECKED(CSVcns),
|
|
|
|
VALUE_IF_CHECKED(CSVstopdepth),
|
|
|
|
ui->CSVSeparator->currentIndex(),
|
|
|
|
&error);
|
|
|
|
if (error != NULL) {
|
|
|
|
mainWindow()->showError(error);
|
|
|
|
free(error);
|
|
|
|
error = NULL;
|
|
|
|
}
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|
|
|
|
process_dives(TRUE, FALSE);
|
|
|
|
|
|
|
|
mainWindow()->refreshDisplay();
|
|
|
|
}
|
|
|
|
|
2013-11-21 22:48:37 +00:00
|
|
|
#define SET_VALUE_AND_CHECKBOX(CSV, BOX, VAL) ({\
|
|
|
|
ui->CSV->blockSignals(true);\
|
|
|
|
ui->CSV->setValue(VAL);\
|
|
|
|
ui->CSV->setEnabled(VAL >= 0);\
|
|
|
|
ui->BOX->setChecked(VAL >= 0);\
|
|
|
|
ui->CSV->blockSignals(false);\
|
|
|
|
})
|
2013-12-29 16:11:20 +00:00
|
|
|
void DiveLogImportDialog::on_knownImports_currentIndexChanged(int index)
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
if (index == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ui->CSVTime->blockSignals(true);
|
|
|
|
ui->CSVDepth->blockSignals(true);
|
|
|
|
ui->CSVTime->setValue(CSVApps[index].time);
|
|
|
|
ui->CSVDepth->setValue(CSVApps[index].depth);
|
|
|
|
ui->CSVTime->blockSignals(false);
|
|
|
|
ui->CSVDepth->blockSignals(false);
|
2013-11-21 22:48:37 +00:00
|
|
|
SET_VALUE_AND_CHECKBOX(CSVTemperature, temperatureCheckBox, CSVApps[index].temperature);
|
2013-11-21 22:48:40 +00:00
|
|
|
SET_VALUE_AND_CHECKBOX(CSVpo2, po2CheckBox, CSVApps[index].po2);
|
2013-11-21 22:48:41 +00:00
|
|
|
SET_VALUE_AND_CHECKBOX(CSVcns, cnsCheckBox, CSVApps[index].cns);
|
2013-11-21 22:48:42 +00:00
|
|
|
SET_VALUE_AND_CHECKBOX(CSVstopdepth, stopdepthCheckBox, CSVApps[index].stopdepth);
|
2013-11-21 22:48:37 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
void DiveLogImportDialog::unknownImports(bool arg1)
|
2013-11-21 22:48:37 +00:00
|
|
|
{
|
|
|
|
unknownImports();
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
void DiveLogImportDialog::unknownImports(int arg1)
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
unknownImports();
|
|
|
|
}
|
|
|
|
|
2013-12-29 16:11:20 +00:00
|
|
|
void DiveLogImportDialog::unknownImports()
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
ui->knownImports->setCurrentIndex(0);
|
|
|
|
}
|