mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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:
parent
d0a62e452b
commit
555fd979cb
2 changed files with 65 additions and 67 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue