Skip to content

Commit 36c5b1b

Browse files
committed
Import: allow CSV separator and quote to be passed from command line
Support these settings from the command line: --option importcsv/separator=\, --option importcsv/quotecharacter=\' Since they are stored as string, they cannot convert to QChar unless manually converted. See issue #2589
1 parent d4d0c23 commit 36c5b1b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/ImportCsvDialog.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
#include <QElapsedTimer>
2727
#endif
2828

29+
QChar ImportCsvDialog::getSettingsChar(const std::string& group, const std::string& name)
30+
{
31+
QVariant value = Settings::getValue(group, name);
32+
// QVariant is not able to return the character as a QChar when QString is stored.
33+
// We do it manually, since it is versatile, when the option is passed from the command line,
34+
// for example.
35+
if(value.userType() == QMetaType::QString)
36+
return value.toString().at(0);
37+
else
38+
return value.toChar();
39+
}
40+
2941
ImportCsvDialog::ImportCsvDialog(const std::vector<QString>& filenames, DBBrowserDB* db, QWidget* parent)
3042
: QDialog(parent),
3143
ui(new Ui::ImportCsvDialog),
@@ -60,8 +72,8 @@ ImportCsvDialog::ImportCsvDialog(const std::vector<QString>& filenames, DBBrowse
6072
ui->checkBoxTrimFields->setChecked(Settings::getValue("importcsv", "trimfields").toBool());
6173
ui->checkBoxSeparateTables->setChecked(Settings::getValue("importcsv", "separatetables").toBool());
6274
ui->checkLocalConventions->setChecked(Settings::getValue("importcsv", "localconventions").toBool());
63-
setSeparatorChar(Settings::getValue("importcsv", "separator").toChar());
64-
setQuoteChar(Settings::getValue("importcsv", "quotecharacter").toChar());
75+
setSeparatorChar(getSettingsChar("importcsv", "separator"));
76+
setQuoteChar(getSettingsChar("importcsv", "quotecharacter"));
6577
setEncoding(Settings::getValue("importcsv", "encoding").toString());
6678

6779
ui->checkboxHeader->blockSignals(false);

src/ImportCsvDialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ private slots:
6262
std::string currentOnConflictStrategy() const;
6363

6464
char32_t toUtf8(const QString& s) const;
65+
66+
static QChar getSettingsChar(const std::string& group, const std::string& name);
6567
};
6668

6769
#endif

0 commit comments

Comments
 (0)