From 6ab87a7420c5897740d4adfa06aa109fbdaa4280 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Wed, 22 Jul 2015 18:06:27 +0300 Subject: Clean hard coded values on divelog CSV import Hard coding the values of known imports is quite awkward if we add these. Thus switching to use enum and names instead. Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- qt-ui/divelogimportdialog.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp index ea783b093..561fb077b 100644 --- a/qt-ui/divelogimportdialog.cpp +++ b/qt-ui/divelogimportdialog.cpp @@ -21,6 +21,15 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = { NULL, } }; +static enum { + MANUAL, + APD, + XP5, + SENSUS, + SEABEAR, + SUBSURFACE +} known; + 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") << @@ -437,7 +446,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) } // Special handling for APD Log Viewer - if ((triggeredBy == KNOWNTYPES && value == 1) || (triggeredBy == INITIAL && fileNames.first().endsWith(".apd", Qt::CaseInsensitive))) { + if ((triggeredBy == KNOWNTYPES && value == APD) || (triggeredBy == INITIAL && fileNames.first().endsWith(".apd", Qt::CaseInsensitive))) { apd=true; firstLine = "Sample time\tSample depth\tSample setpoint\t\t\t\tSample pO₂\t\t\t\t\t\t\t\t\tSample temperature\t\tSample CNS\tSample stopdepth"; blockSignals(true); @@ -467,7 +476,7 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) currColumns = firstLine.split(separator); } } - if (triggeredBy == INITIAL || (triggeredBy == KNOWNTYPES && value == 0) || triggeredBy == SEPARATOR) { + if (triggeredBy == INITIAL || (triggeredBy == KNOWNTYPES && value == MANUAL) || triggeredBy == SEPARATOR) { // now try and guess the columns Q_FOREACH (QString columnText, currColumns) { columnText.replace("\"", ""); @@ -493,9 +502,9 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy) } } } - if (triggeredBy == KNOWNTYPES && value != 0) { + if (triggeredBy == KNOWNTYPES && value != MANUAL) { // an actual known type - if (value == 5) { + if (value == SUBSURFACE) { /* * Subsurface CSV file needs separator detection * as we used to default to comma but switched -- cgit v1.2.3-70-g09d2