Skip to content

Commit e2f3186

Browse files
committed
Fix saving/restoring of settings in Import CSV dialog
Saving and restoring of quote and separator characters did not work as expected in the Import CSV dialog since the last commits. A missing "else" made us try to save the string "Other" as the quote character when a custom quote character was selected. Also the translation from and to the saved format on disk had its problems. See issue #1860.
1 parent 2d12330 commit e2f3186

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/ImportCsvDialog.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ ImportCsvDialog::ImportCsvDialog(const QStringList &filenames, DBBrowserDB* db,
5858
ui->checkboxHeader->setChecked(Settings::getValue("importcsv", "firstrowheader").toBool());
5959
ui->checkBoxTrimFields->setChecked(Settings::getValue("importcsv", "trimfields").toBool());
6060
ui->checkBoxSeparateTables->setChecked(Settings::getValue("importcsv", "separatetables").toBool());
61-
setSeparatorChar(static_cast<char32_t>(Settings::getValue("importcsv", "separator").toInt()));
62-
setQuoteChar(static_cast<char32_t>(Settings::getValue("importcsv", "quotecharacter").toInt()));
61+
setSeparatorChar(Settings::getValue("importcsv", "separator").toChar());
62+
setQuoteChar(Settings::getValue("importcsv", "quotecharacter").toChar());
6363
setEncoding(Settings::getValue("importcsv", "encoding").toString());
6464

6565
ui->checkboxHeader->blockSignals(false);
@@ -375,7 +375,7 @@ CSVParser::ParserResult ImportCsvDialog::parseCSV(const QString &fileName, std::
375375
QFile file(fileName);
376376
file.open(QIODevice::ReadOnly);
377377

378-
CSVParser csv(ui->checkBoxTrimFields->isChecked(), currentSeparatorChar(), currentQuoteChar());
378+
CSVParser csv(ui->checkBoxTrimFields->isChecked(), toUtf8(currentSeparatorChar()), toUtf8(currentQuoteChar()));
379379

380380
// Only show progress dialog if we parse all rows. The assumption here is that if a row count limit has been set, it won't be a very high one.
381381
if(count == 0)
@@ -704,7 +704,7 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name)
704704
return true;
705705
}
706706

707-
void ImportCsvDialog::setQuoteChar(char32_t c)
707+
void ImportCsvDialog::setQuoteChar(QChar c)
708708
{
709709
QComboBox* combo = ui->comboQuote;
710710
int index = combo->findText(QString(c));
@@ -719,21 +719,20 @@ void ImportCsvDialog::setQuoteChar(char32_t c)
719719
}
720720
}
721721

722-
char32_t ImportCsvDialog::currentQuoteChar() const
722+
QChar ImportCsvDialog::currentQuoteChar() const
723723
{
724724
QString value;
725725

726726
// The last item in the combobox is the 'Other' item; if it is selected return the text of the line edit field instead
727727
if(ui->comboQuote->currentIndex() == ui->comboQuote->count()-1)
728728
value = ui->editCustomQuote->text().length() ? ui->editCustomQuote->text() : "";
729-
730-
if(ui->comboQuote->currentText().length())
729+
else if(ui->comboQuote->currentText().length())
731730
value = ui->comboQuote->currentText();
732731

733-
return toUtf8(value);
732+
return value.size() ? value.front() : QChar();
734733
}
735734

736-
void ImportCsvDialog::setSeparatorChar(char32_t c)
735+
void ImportCsvDialog::setSeparatorChar(QChar c)
737736
{
738737
QComboBox* combo = ui->comboSeparator;
739738
QString sText = c == '\t' ? QString("Tab") : QString(c);
@@ -749,7 +748,7 @@ void ImportCsvDialog::setSeparatorChar(char32_t c)
749748
}
750749
}
751750

752-
char32_t ImportCsvDialog::currentSeparatorChar() const
751+
QChar ImportCsvDialog::currentSeparatorChar() const
753752
{
754753
QString value;
755754

@@ -759,7 +758,7 @@ char32_t ImportCsvDialog::currentSeparatorChar() const
759758
else
760759
value = ui->comboSeparator->currentText() == tr("Tab") ? "\t" : ui->comboSeparator->currentText();
761760

762-
return toUtf8(value);
761+
return value.size() ? value.front() : QChar();
763762
}
764763

765764
void ImportCsvDialog::setEncoding(const QString& sEnc)

src/ImportCsvDialog.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ private slots:
4545

4646
bool importCsv(const QString& f, const QString& n = QString());
4747

48-
void setQuoteChar(char32_t c);
49-
char32_t currentQuoteChar() const;
48+
void setQuoteChar(QChar c);
49+
QChar currentQuoteChar() const;
5050

51-
void setSeparatorChar(char32_t c);
52-
char32_t currentSeparatorChar() const;
51+
void setSeparatorChar(QChar c);
52+
QChar currentSeparatorChar() const;
5353

5454
void setEncoding(const QString& sEnc);
5555
QString currentEncoding() const;

0 commit comments

Comments
 (0)