diff options
Diffstat (limited to 'qt-ui/divelogimportdialog.cpp')
-rw-r--r-- | qt-ui/divelogimportdialog.cpp | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index bb4701ce3..409064833 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -1,5 +1,6 @@ #include "divelogimportdialog.h" #include "mainwindow.h" +#include "color.h" #include "ui_divelogimportdialog.h" #include <QShortcut> #include <QDrag> @@ -23,7 +24,7 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = ColumnNameProvider::ColumnNameProvider(QObject *parent) : QAbstractListModel(parent) { columnNames << tr("Dive #") << tr("Date") << tr("Time") << tr("Duration") << tr("Location") << tr("GPS") << tr("Weight") << tr("Cyl. size") << tr("Start pressure") << - tr("End pressure") << tr("Max. depth") << tr("Avg. depth") << tr("Divemaster") << tr("Buddy") << tr("Notes") << tr("Tags") << tr("Air temp.") << tr("Water temp.") << + tr("End pressure") << tr("Max. depth") << tr("Avg. depth") << tr("Divemaster") << tr("Buddy") << tr("Suit") << tr("Notes") << tr("Tags") << tr("Air temp.") << tr("Water temp.") << tr("O₂") << tr("He") << tr("Sample time") << tr("Sample depth") << tr("Sample temperature") << tr("Sample pO₂") << tr("Sample CNS") << tr("Sample NDL") << tr("Sample TTS") << tr("Sample stopdepth") << tr("Sample pressure"); } @@ -315,6 +316,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia ui->setupUi(this); fileNames = fn; column = 0; + delta = "0"; /* Add indexes of XSLTs requiring special handling to the list */ specialCSV << 3; @@ -374,7 +376,53 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) QString firstLine = f.readLine(); if (firstLine.contains("SEABEAR")) { seabear = true; - firstLine = "Sample time;Sample depth;Sample NDL;Sample TTS;Sample stopdepth;Sample temperature;Sample pressure"; + + /* + * Parse header - currently only interested in sample + * interval, or if we have old format (if interval value + * is missing from the header). + */ + + while ((firstLine = f.readLine()).length() > 3 && !f.atEnd()) { + if (firstLine.contains("//Log interval: ")) + delta = firstLine.remove(QString::fromLatin1("//Log interval: ")).trimmed(); + } + + /* + * Parse CSV fields + * The pO2 values from CCR diving are ignored later on. + */ + + firstLine = f.readLine().trimmed(); + + currColumns = firstLine.split(';'); + Q_FOREACH (QString columnText, currColumns) { + if (columnText == "Time") { + headers.append("Sample time"); + } else if (columnText == "Depth") { + headers.append("Sample depth"); + } else if (columnText == "Temperature") { + headers.append("Sample temperature"); + } else if (columnText == "NDT") { + headers.append("Sample NDL"); + } else if (columnText == "TTS") { + headers.append("Sample TTS"); + } else if (columnText == "pO2_1") { + headers.append("Sample pO2_1"); + } else if (columnText == "pO2_2") { + headers.append("Sample pO2_2"); + } else if (columnText == "pO2_3") { + headers.append("Sample pO2_3"); + } else if (columnText == "Ceiling") { + headers.append("Sample ceiling"); + } else { + // We do not know about this value + qDebug() << "Seabear import found an un-handled field: " << columnText; + headers.append(""); + } + } + + firstLine = headers.join(";"); blockSignals(true); ui->knownImports->setCurrentText("Seabear CSV"); blockSignals(false); @@ -513,7 +561,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) } while (rows < 10 && !f.atEnd()) { - QString currLine = f.readLine(); + QString currLine = f.readLine().trimmed(); currColumns = currLine.split(separator); fileColumns.append(currColumns); rows += 1; @@ -526,6 +574,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) void DiveLogImportDialog::on_buttonBox_accepted() { + imported_via_xslt = true; QStringList r = resultModel->result(); if (ui->knownImports->currentText() != "Manual import") { for (int i = 0; i < fileNames.size(); ++i) { @@ -542,10 +591,12 @@ void DiveLogImportDialog::on_buttonBox_accepted() r.indexOf(tr("Sample pressure")), ui->CSVSeparator->currentIndex(), specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv", - ui->CSVUnits->currentIndex() - ) < 0) + ui->CSVUnits->currentIndex(), + delta.toUtf8().data() + ) < 0) { + imported_via_xslt = false; return; - + } // Seabear CSV stores NDL and TTS in Minutes, not seconds struct dive *dive = dive_table.dives[dive_table.nr - 1]; for(int s_nr = 0 ; s_nr <= dive->dc.samples ; s_nr++) { @@ -585,9 +636,10 @@ void DiveLogImportDialog::on_buttonBox_accepted() r.indexOf(tr("Location")), r.indexOf(tr("GPS")), r.indexOf(tr("Max. depth")), - r.indexOf(tr("Mean depth")), + r.indexOf(tr("Avg. depth")), r.indexOf(tr("Divemaster")), r.indexOf(tr("Buddy")), + r.indexOf(tr("Suit")), r.indexOf(tr("Notes")), r.indexOf(tr("Weight")), r.indexOf(tr("Tags")), @@ -618,6 +670,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() } process_dives(true, false); MainWindow::instance()->refreshDisplay(); + imported_via_xslt = false; } TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent) |