aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-01-06 18:12:48 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-06 19:38:19 -0800
commit555fd979cb164c1405b82ef9cdecdfa284052f3b (patch)
tree0621213dcbbbb486f0b1da93f93cdfafc54d4044
parentd0a62e452b7327b4fa91f5e05e5edaca46d9a87a (diff)
downloadsubsurface-555fd979cb164c1405b82ef9cdecdfa284052f3b.tar.gz
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>
-rw-r--r--qt-ui/divelogimportdialog.cpp129
-rw-r--r--qt-ui/divelogimportdialog.h3
2 files changed, 65 insertions, 67 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 16c713989..570e86286 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -15,7 +15,7 @@ static QString subsurface_mimedata = "subsurface/csvcolumns";
const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
// time, depth, temperature, po2, cns, ndl, tts, stopdepth, pressure
- { "", },
+ { "Manual Import", },
{ "APD Log Viewer", 1, 2, 16, 7, 18, -1, -1, 19, -1, "Tab" },
{ "XP5", 1, 2, 10, -1, -1, -1, -1, -1, -1, "Tab" },
{ "SensusCSV", 10, 11, -1, -1, -1, -1, -1, -1, -1, "," },
@@ -204,6 +204,11 @@ int ColumnNameResult::columnCount(const QModelIndex &parent) const
return columnNames.count();
}
+QStringList ColumnNameResult::result() const
+{
+ return columnNames;
+}
+
void ColumnNameResult::setColumnValues(QList<QStringList> columns)
{
if (rowCount() != 1) {
@@ -287,23 +292,26 @@ void DiveLogImportDialog::loadFileContents() {
resultModel->setColumnValues(fileColumns);
}
-#define VALUE_IF_CHECKED(x) (ui->x->isEnabled() ? ui->x->value() - 1 : -1)
void DiveLogImportDialog::on_buttonBox_accepted()
{
- /*
- for (int i = 0; i < fileNames.size(); ++i) {
- if (ui->knownImports->currentText() == QString("Seabear CSV")) {
- parse_seabear_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1,
- ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
- VALUE_IF_CHECKED(CSVpo2),
- VALUE_IF_CHECKED(CSVcns),
- VALUE_IF_CHECKED(CSVndl),
- VALUE_IF_CHECKED(CSVtts),
- VALUE_IF_CHECKED(CSVstopdepth),
- VALUE_IF_CHECKED(CSVpressure),
- ui->CSVSeparator->currentIndex(),
- specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
- ui->CSVUnits->currentIndex());
+ QStringList r = resultModel->result();
+ if (ui->knownImports->currentText() != "Manual Import") {
+ for (int i = 0; i < fileNames.size(); ++i) {
+ if (ui->knownImports->currentText() == "Seabear CSV") {
+ parse_seabear_csv_file(fileNames[i].toUtf8().data(),
+ r.indexOf(tr("Time")),
+ r.indexOf(tr("Max Depth")),
+ r.indexOf(tr("Water temp")),
+ r.indexOf(tr("PO₂")),
+ r.indexOf(tr("CNS")),
+ r.indexOf(tr("NDL")),
+ r.indexOf(tr("TTS")),
+ r.indexOf(tr("Stopped Depth")),
+ 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
struct dive *dive = dive_table.dives[dive_table.nr - 1];
@@ -312,61 +320,52 @@ void DiveLogImportDialog::on_buttonBox_accepted()
sample->ndl.seconds *= 60;
sample->tts.seconds *= 60;
}
- } else
- parse_csv_file(fileNames[i].toUtf8().data(), ui->CSVTime->value() - 1,
- ui->CSVDepth->value() - 1, VALUE_IF_CHECKED(CSVTemperature),
- VALUE_IF_CHECKED(CSVpo2),
- VALUE_IF_CHECKED(CSVcns),
- VALUE_IF_CHECKED(CSVndl),
- VALUE_IF_CHECKED(CSVtts),
- VALUE_IF_CHECKED(CSVstopdepth),
- VALUE_IF_CHECKED(CSVpressure),
- ui->CSVSeparator->currentIndex(),
- specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
- ui->CSVUnits->currentIndex());
+ } else {
+ parse_csv_file(fileNames[i].toUtf8().data(),
+ r.indexOf(tr("Time")),
+ r.indexOf(tr("Max Depth")),
+ r.indexOf(tr("Water temp")),
+ r.indexOf(tr("PO₂")),
+ r.indexOf(tr("CNS")),
+ r.indexOf(tr("NDL")),
+ r.indexOf(tr("TTS")),
+ r.indexOf(tr("Stopped Depth")),
+ r.indexOf(tr("Pressure")),
+ ui->CSVSeparator->currentIndex(),
+ specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
+ ui->CSVUnits->currentIndex()
+ );
+ }
}
} else {
for (int i = 0; i < fileNames.size(); ++i) {
parse_manual_file(fileNames[i].toUtf8().data(),
- ui->ManualSeparator->currentIndex(),
- ui->Units->currentIndex(),
- ui->DateFormat->currentIndex(),
- ui->DurationFormat->currentIndex(),
- VALUE_IF_CHECKED(DiveNumber),
- VALUE_IF_CHECKED(Date), VALUE_IF_CHECKED(Time),
- VALUE_IF_CHECKED(Duration), VALUE_IF_CHECKED(Location),
- VALUE_IF_CHECKED(Gps), VALUE_IF_CHECKED(MaxDepth),
- VALUE_IF_CHECKED(MeanDepth), VALUE_IF_CHECKED(Buddy),
- VALUE_IF_CHECKED(Notes), VALUE_IF_CHECKED(Weight),
- VALUE_IF_CHECKED(Tags),
- VALUE_IF_CHECKED(CylinderSize), VALUE_IF_CHECKED(StartPressure),
- VALUE_IF_CHECKED(EndPressure), VALUE_IF_CHECKED(O2),
- VALUE_IF_CHECKED(He), VALUE_IF_CHECKED(AirTemp),
- VALUE_IF_CHECKED(WaterTemp));
+ ui->CSVSeparator->currentIndex(),
+ ui->CSVUnits->currentIndex(),
+ ui->DateFormat->currentIndex(),
+ ui->DurationFormat->currentIndex(),
+ r.indexOf(tr("Dive #")),
+ r.indexOf(tr("Date")),
+ r.indexOf(tr("Time")),
+ r.indexOf(tr("Duration")),
+ r.indexOf(tr("Location")),
+ r.indexOf(tr("GPS")),
+ r.indexOf(tr("Max depth")),
+ r.indexOf(tr("Mean depth")),
+ r.indexOf(tr("Buddy")),
+ r.indexOf(tr("Notes")),
+ 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);
-
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);
-}
diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h
index a2283906f..77990451f 100644
--- a/qt-ui/divelogimportdialog.h
+++ b/qt-ui/divelogimportdialog.h
@@ -37,6 +37,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
void setColumnValues(QList<QStringList> columns);
+ QStringList result() const;
private:
QList<QStringList> columnValues;
QStringList columnNames;
@@ -79,8 +80,6 @@ public:
private
slots:
void on_buttonBox_accepted();
- void on_knownImports_currentIndexChanged(int index);
- void unknownImports();
void loadFileContents();
private:
bool selector;