Port the code that actually parses the CSV to the new system

Change the QWidget based approach to the Model based approach, using the
result QStringList for finding if we have the depth or the time of some
specific column.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-01-06 18:12:48 -02:00 committed by Dirk Hohndel
parent d0a62e452b
commit 555fd979cb
2 changed files with 65 additions and 67 deletions

View file

@ -15,7 +15,7 @@ static QString subsurface_mimedata = "subsurface/csvcolumns";
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = { const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
// time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure // time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure
{ "", }, { "Manual Import", },
{ "APD Log Viewer", 1, 2, 16, 7, 18, -1, -1, 19, -1, "Tab" }, { "APD Log Viewer", 1, 2, 16, 7, 18, -1, -1, 19, -1, "Tab" },
{ "XP5", 1, 2, 10, -1, -1, -1, -1, -1, -1, "Tab" }, { "XP5", 1, 2, 10, -1, -1, -1, -1, -1, -1, "Tab" },
{ "SensusCSV", 10, 11, -1, -1, -1, -1, -1, -1, -1, "," }, { "SensusCSV", 10, 11, -1, -1, -1, -1, -1, -1, -1, "," },
@ -204,6 +204,11 @@ int ColumnNameResult::columnCount(const QModelIndex &parent) const
return columnNames.count(); return columnNames.count();
} }
QStringList ColumnNameResult::result() const
{
return columnNames;
}
void ColumnNameResult::setColumnValues(QList<QStringList> columns) void ColumnNameResult::setColumnValues(QList<QStringList> columns)
{ {
if (rowCount() != 1) { if (rowCount() != 1) {
@ -287,23 +292,26 @@ void DiveLogImportDialog::loadFileContents() {
resultModel->setColumnValues(fileColumns); resultModel->setColumnValues(fileColumns);
} }
#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() - 1 : -1)
void DiveLogImportDialog::on_buttonBox_accepted() void DiveLogImportDialog::on_buttonBox_accepted()
{ {
/* QStringList r = resultModel->result();
for (int i = 0; i < fileNames.size(); ++i) { if (ui->knownImports->currentText() != "Manual Import") {
if (ui->knownImports->currentText() == QString("Seabear CSV")) { for (int i = 0; i < fileNames.size(); ++i) {
parse_seabear_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1, if (ui->knownImports->currentText() == "Seabear CSV") {
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature), parse_seabear_csv_file(fileNames[i].toUtf8().data(),
VALUE_IF_CHECKED(CSVpo2), r.indexOf(tr("Time")),
VALUE_IF_CHECKED(CSVcns), r.indexOf(tr("Max Depth")),
VALUE_IF_CHECKED(CSVndl), r.indexOf(tr("Water temp")),
VALUE_IF_CHECKED(CSVtts), r.indexOf(tr("PO₂")),
VALUE_IF_CHECKED(CSVstopdepth), r.indexOf(tr("CNS")),
VALUE_IF_CHECKED(CSVpressure), r.indexOf(tr("NDL")),
ui->CSVSeparator->currentIndex(), r.indexOf(tr("TTS")),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", r.indexOf(tr("Stopped Depth")),
ui->CSVUnits->currentIndex()); r.indexOf(tr("Pressure")),
ui->CSVSeparator->currentIndex(),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
ui->CSVUnits->currentIndex()
);
// Seabear CSV stores NDL and TTS in Minutes, not seconds // Seabear CSV stores NDL and TTS in Minutes, not seconds
struct dive *dive = dive_table.dives[dive_table.nr - 1]; struct dive *dive = dive_table.dives[dive_table.nr - 1];
@ -312,61 +320,52 @@ void DiveLogImportDialog::on_buttonBox_accepted()
sample->ndl.seconds *= 60; sample->ndl.seconds *= 60;
sample->tts.seconds *= 60; sample->tts.seconds *= 60;
} }
} else } else {
parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1, parse_csv_file(fileNames[i].toUtf8().data(),
ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature), r.indexOf(tr("Time")),
VALUE_IF_CHECKED(CSVpo2), r.indexOf(tr("Max Depth")),
VALUE_IF_CHECKED(CSVcns), r.indexOf(tr("Water temp")),
VALUE_IF_CHECKED(CSVndl), r.indexOf(tr("PO₂")),
VALUE_IF_CHECKED(CSVtts), r.indexOf(tr("CNS")),
VALUE_IF_CHECKED(CSVstopdepth), r.indexOf(tr("NDL")),
VALUE_IF_CHECKED(CSVpressure), r.indexOf(tr("TTS")),
ui->CSVSeparator->currentIndex(), r.indexOf(tr("Stopped Depth")),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", r.indexOf(tr("Pressure")),
ui->CSVUnits->currentIndex()); ui->CSVSeparator->currentIndex(),
specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
ui->CSVUnits->currentIndex()
);
}
} }
} else { } else {
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
parse_manual_file(fileNames[i].toUtf8().data(), parse_manual_file(fileNames[i].toUtf8().data(),
ui->ManualSeparator->currentIndex(), ui->CSVSeparator->currentIndex(),
ui->Units->currentIndex(), ui->CSVUnits->currentIndex(),
ui->DateFormat->currentIndex(), ui->DateFormat->currentIndex(),
ui->DurationFormat->currentIndex(), ui->DurationFormat->currentIndex(),
VALUE_IF_CHECKED(DiveNumber), r.indexOf(tr("Dive #")),
VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time), r.indexOf(tr("Date")),
VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location), r.indexOf(tr("Time")),
VALUE_IF_CHECKED(Gps), VALUE_IF_CHECKED(MaxDepth), r.indexOf(tr("Duration")),
VALUE_IF_CHECKED(MeanDepth), VALUE_IF_CHECKED(Buddy), r.indexOf(tr("Location")),
VALUE_IF_CHECKED(Notes), VALUE_IF_CHECKED(Weight), r.indexOf(tr("GPS")),
VALUE_IF_CHECKED(Tags), r.indexOf(tr("Max depth")),
VALUE_IF_CHECKED(CylinderSize), VALUE_IF_CHECKED(StartPressure), r.indexOf(tr("Mean depth")),
VALUE_IF_CHECKED(EndPressure), VALUE_IF_CHECKED(O2), r.indexOf(tr("Buddy")),
VALUE_IF_CHECKED(He), VALUE_IF_CHECKED(AirTemp), r.indexOf(tr("Notes")),
VALUE_IF_CHECKED(WaterTemp)); r.indexOf(tr("Weight")),
r.indexOf(tr("Tags")),
r.indexOf(tr("Cyl size")),
r.indexOf(tr("Start Pressure")),
r.indexOf(tr("End Pressure")),
r.indexOf(tr("O₂")),
r.indexOf(tr("He")),
r.indexOf(tr("Air Temp")),
r.indexOf(tr("Water Temp"))
);
} }
} }
*/
process_dives(true, false); process_dives(true, false);
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();
} }
#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); })
void DiveLogImportDialog::on_knownImports_currentIndexChanged(int index)
{
if (index == 0)
return;
}
void DiveLogImportDialog::unknownImports()
{
if (!specialCSV.contains(ui->knownImports->currentIndex()))
ui->knownImports->setCurrentIndex(0);
}

View file

@ -37,6 +37,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
void setColumnValues(QList<QStringList> columns); void setColumnValues(QList<QStringList> columns);
QStringList result() const;
private: private:
QList<QStringList> columnValues; QList<QStringList> columnValues;
QStringList columnNames; QStringList columnNames;
@ -79,8 +80,6 @@ public:
private private
slots: slots:
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void on_knownImports_currentIndexChanged(int index);
void unknownImports();
void loadFileContents(); void loadFileContents();
private: private:
bool selector; bool selector;