From e2f3186d194c800011996ef1a04c9c3aa728c65e Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Sat, 11 May 2019 16:10:31 +0200 Subject: [PATCH] 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. --- src/ImportCsvDialog.cpp | 21 ++++++++++----------- src/ImportCsvDialog.h | 8 ++++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ImportCsvDialog.cpp b/src/ImportCsvDialog.cpp index 876427b6..407fa4a4 100644 --- a/src/ImportCsvDialog.cpp +++ b/src/ImportCsvDialog.cpp @@ -58,8 +58,8 @@ ImportCsvDialog::ImportCsvDialog(const QStringList &filenames, DBBrowserDB* db, ui->checkboxHeader->setChecked(Settings::getValue("importcsv", "firstrowheader").toBool()); ui->checkBoxTrimFields->setChecked(Settings::getValue("importcsv", "trimfields").toBool()); ui->checkBoxSeparateTables->setChecked(Settings::getValue("importcsv", "separatetables").toBool()); - setSeparatorChar(static_cast(Settings::getValue("importcsv", "separator").toInt())); - setQuoteChar(static_cast(Settings::getValue("importcsv", "quotecharacter").toInt())); + setSeparatorChar(Settings::getValue("importcsv", "separator").toChar()); + setQuoteChar(Settings::getValue("importcsv", "quotecharacter").toChar()); setEncoding(Settings::getValue("importcsv", "encoding").toString()); ui->checkboxHeader->blockSignals(false); @@ -375,7 +375,7 @@ CSVParser::ParserResult ImportCsvDialog::parseCSV(const QString &fileName, std:: QFile file(fileName); file.open(QIODevice::ReadOnly); - CSVParser csv(ui->checkBoxTrimFields->isChecked(), currentSeparatorChar(), currentQuoteChar()); + CSVParser csv(ui->checkBoxTrimFields->isChecked(), toUtf8(currentSeparatorChar()), toUtf8(currentQuoteChar())); // 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. if(count == 0) @@ -704,7 +704,7 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name) return true; } -void ImportCsvDialog::setQuoteChar(char32_t c) +void ImportCsvDialog::setQuoteChar(QChar c) { QComboBox* combo = ui->comboQuote; int index = combo->findText(QString(c)); @@ -719,21 +719,20 @@ void ImportCsvDialog::setQuoteChar(char32_t c) } } -char32_t ImportCsvDialog::currentQuoteChar() const +QChar ImportCsvDialog::currentQuoteChar() const { QString value; // The last item in the combobox is the 'Other' item; if it is selected return the text of the line edit field instead if(ui->comboQuote->currentIndex() == ui->comboQuote->count()-1) value = ui->editCustomQuote->text().length() ? ui->editCustomQuote->text() : ""; - - if(ui->comboQuote->currentText().length()) + else if(ui->comboQuote->currentText().length()) value = ui->comboQuote->currentText(); - return toUtf8(value); + return value.size() ? value.front() : QChar(); } -void ImportCsvDialog::setSeparatorChar(char32_t c) +void ImportCsvDialog::setSeparatorChar(QChar c) { QComboBox* combo = ui->comboSeparator; QString sText = c == '\t' ? QString("Tab") : QString(c); @@ -749,7 +748,7 @@ void ImportCsvDialog::setSeparatorChar(char32_t c) } } -char32_t ImportCsvDialog::currentSeparatorChar() const +QChar ImportCsvDialog::currentSeparatorChar() const { QString value; @@ -759,7 +758,7 @@ char32_t ImportCsvDialog::currentSeparatorChar() const else value = ui->comboSeparator->currentText() == tr("Tab") ? "\t" : ui->comboSeparator->currentText(); - return toUtf8(value); + return value.size() ? value.front() : QChar(); } void ImportCsvDialog::setEncoding(const QString& sEnc) diff --git a/src/ImportCsvDialog.h b/src/ImportCsvDialog.h index d243ea00..6fe68f9a 100644 --- a/src/ImportCsvDialog.h +++ b/src/ImportCsvDialog.h @@ -45,11 +45,11 @@ private: bool importCsv(const QString& f, const QString& n = QString()); - void setQuoteChar(char32_t c); - char32_t currentQuoteChar() const; + void setQuoteChar(QChar c); + QChar currentQuoteChar() const; - void setSeparatorChar(char32_t c); - char32_t currentSeparatorChar() const; + void setSeparatorChar(QChar c); + QChar currentSeparatorChar() const; void setEncoding(const QString& sEnc); QString currentEncoding() const;