Detect pipe as field separator in CSV import

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2016-04-24 21:11:15 +03:00 committed by Dirk Hohndel
parent 7a4fa510e9
commit 375f698c78

View file

@ -347,7 +347,7 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList fn, QWidget *parent) : QDia
for (int i = 0; !CSVApps[i].name.isNull(); ++i)
ui->knownImports->addItem(CSVApps[i].name);
ui->CSVSeparator->addItems( QStringList() << tr("Tab") << "," << ";");
ui->CSVSeparator->addItems( QStringList() << tr("Tab") << "," << ";" << "|");
loadFileContents(-1, INITIAL);
@ -487,11 +487,14 @@ void DiveLogImportDialog::loadFileContents(int value, whatChanged triggeredBy)
int tabs = firstLine.count('\t');
int commas = firstLine.count(',');
int semis = firstLine.count(';');
if (tabs > commas && tabs > semis)
int pipes = firstLine.count('|');
if (tabs > commas && tabs > semis && tabs > pipes)
separator = "\t";
else if (commas > tabs && commas > semis)
else if (commas > tabs && commas > semis && commas > pipes)
separator = ",";
else if (semis > tabs && semis > commas)
else if (pipes > tabs && pipes > commas && pipes > semis)
separator = "|";
else if (semis > tabs && semis > commas && semis > pipes)
separator = ";";
if (ui->CSVSeparator->currentText() != separator) {
blockSignals(true);