2013-10-16 19:05:19 +00:00
|
|
|
#include <QtDebug>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include "csvimportdialog.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_csvimportdialog.h"
|
|
|
|
|
|
|
|
const CSVImportDialog::CSVAppConfig CSVImportDialog::CSVApps[CSVAPPS] = {
|
|
|
|
{"", },
|
2013-11-21 22:48:42 +00:00
|
|
|
{"APD Log Viewer", 0, 1, 15, 6, 17, 18, "Tab"},
|
|
|
|
{"XP5", 0, 1, 9, -1, -1, -1, "Tab"},
|
2013-10-16 19:05:19 +00:00
|
|
|
{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");
|
2013-12-04 23:19:28 +00:00
|
|
|
ui->CSVSeparator->addItem(",");
|
2013-10-16 19:05:19 +00:00
|
|
|
ui->knownImports->setCurrentIndex(1);
|
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
CSVImportDialog::~CSVImportDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2013-11-21 22:48:37 +00:00
|
|
|
#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() : -1)
|
2013-10-16 19:05:19 +00:00
|
|
|
void CSVImportDialog::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
char *error = NULL;
|
|
|
|
|
2013-11-21 22:48:40 +00:00
|
|
|
parse_csv_file(ui->CSVFile->text().toUtf8().data(), ui->CSVTime->value(),
|
|
|
|
ui->CSVDepth->value(), VALUE_IF_CHECKED(CSVTemperature),
|
|
|
|
VALUE_IF_CHECKED(CSVpo2),
|
2013-11-21 22:48:41 +00:00
|
|
|
VALUE_IF_CHECKED(CSVcns),
|
2013-11-21 22:48:42 +00:00
|
|
|
VALUE_IF_CHECKED(CSVstopdepth),
|
2013-12-04 23:19:28 +00:00
|
|
|
ui->CSVSeparator->currentIndex(),
|
2013-11-21 22:48:40 +00:00
|
|
|
&error);
|
2013-10-16 19:05:19 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
mainWindow()->showError(error);
|
|
|
|
free(error);
|
|
|
|
error = NULL;
|
|
|
|
}
|
|
|
|
process_dives(TRUE, FALSE);
|
|
|
|
|
|
|
|
mainWindow()->refreshDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVImportDialog::on_CSVFileSelector_clicked()
|
|
|
|
{
|
2013-12-24 08:27:14 +00:00
|
|
|
QString filename = QFileDialog::getOpenFileName(this, tr("Open CSV Log File"), ".", tr("CSV Files (*.csv);;All Files(*)"));
|
2013-10-16 19:05:19 +00:00
|
|
|
ui->CSVFile->setText(filename);
|
2013-12-24 11:59:48 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!filename.isEmpty());
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
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-10-16 19:05:19 +00:00
|
|
|
void CSVImportDialog::on_knownImports_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void CSVImportDialog::unknownImports(bool arg1)
|
|
|
|
{
|
|
|
|
unknownImports();
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-21 22:48:36 +00:00
|
|
|
void CSVImportDialog::unknownImports(int arg1)
|
2013-10-16 19:05:19 +00:00
|
|
|
{
|
|
|
|
unknownImports();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVImportDialog::unknownImports()
|
|
|
|
{
|
|
|
|
ui->knownImports->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVImportDialog::on_CSVFile_textEdited()
|
|
|
|
{
|
2013-12-24 11:59:48 +00:00
|
|
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui->CSVFile->text().isEmpty());
|
2013-10-16 19:05:19 +00:00
|
|
|
}
|