From f8b2dd0ee3c63a3fdf1845e43b1e4280fa2c78a3 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Fri, 30 May 2014 18:11:49 +0200 Subject: [PATCH] ExportCsvDialog: Add option to define custom quote/separator chars Make it possible to use other quote and separator characters than those predefined in the respective combo boxes when exporting a CSV file. See issue #23. --- src/ExportCsvDialog.cpp | 20 +++++- src/ExportCsvDialog.h | 1 + src/ExportCsvDialog.ui | 151 ++++++++++++++++++++++++++++++++-------- 3 files changed, 141 insertions(+), 31 deletions(-) diff --git a/src/ExportCsvDialog.cpp b/src/ExportCsvDialog.cpp index de80a54e..ec27b804 100644 --- a/src/ExportCsvDialog.cpp +++ b/src/ExportCsvDialog.cpp @@ -17,6 +17,7 @@ ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString { // Create UI ui->setupUi(this); + showCustomCharEdits(); // If a SQL query was specified hide the table combo box. If not fill it with tables to export if(query.isEmpty()) @@ -72,10 +73,16 @@ void ExportCsvDialog::accept() tableModel.fetchMore(); // Prepare the quote and separating characters - QString quoteChar = ui->comboQuoteCharacter->currentText(); + QString quoteChar = ui->comboQuoteCharacter->currentIndex() == ui->comboQuoteCharacter->count()-1 ? ui->editCustomQuote->text() : ui->comboQuoteCharacter->currentText(); QString quotequoteChar = quoteChar + quoteChar; - QString sepChar = ui->comboFieldSeparator->currentText(); - if(sepChar == tr("Tab")) sepChar = "\t"; + QString sepChar; + if(ui->comboFieldSeparator->currentIndex() == ui->comboFieldSeparator->count()-1) + { + sepChar = ui->editCustomSeparator->text(); + } else { + sepChar = ui->comboFieldSeparator->currentText(); + if(sepChar == tr("Tab")) sepChar = "\t"; + } QString newlineChar = "\n"; // Open file @@ -121,3 +128,10 @@ void ExportCsvDialog::accept() } } } + +void ExportCsvDialog::showCustomCharEdits() +{ + // Show/hide custom quote/separator input fields + ui->editCustomQuote->setVisible(ui->comboQuoteCharacter->currentIndex() == ui->comboQuoteCharacter->count()-1); + ui->editCustomSeparator->setVisible(ui->comboFieldSeparator->currentIndex() == ui->comboFieldSeparator->count()-1); +} diff --git a/src/ExportCsvDialog.h b/src/ExportCsvDialog.h index b4934515..f69d669c 100644 --- a/src/ExportCsvDialog.h +++ b/src/ExportCsvDialog.h @@ -19,6 +19,7 @@ public: private slots: virtual void accept(); + void showCustomCharEdits(); private: Ui::ExportCsvDialog* ui; diff --git a/src/ExportCsvDialog.ui b/src/ExportCsvDialog.ui index dc968e29..ff917492 100644 --- a/src/ExportCsvDialog.ui +++ b/src/ExportCsvDialog.ui @@ -7,7 +7,7 @@ 0 0 331 - 141 + 145 @@ -60,28 +60,57 @@ - + - - , - + + + + , + + + + + ; + + + + + Tab + + + + + | + + + + + Other + + + - - ; - + + + 1 + + - - Tab - + + + Qt::Horizontal + + + + 40 + 20 + + + - - - | - - - + @@ -94,23 +123,52 @@ - + - - " - + + + + " + + + + + ' + + + + + + + + + + Other + + + - - ' - + + + 1 + + - - - + + + Qt::Horizontal + + + + 40 + 20 + + + - + @@ -130,7 +188,9 @@ comboTable checkHeader comboFieldSeparator + editCustomSeparator comboQuoteCharacter + editCustomQuote buttonBox @@ -167,5 +227,40 @@ + + comboFieldSeparator + currentIndexChanged(int) + ExportCsvDialog + showCustomCharEdits() + + + 210 + 64 + + + 264 + 45 + + + + + comboQuoteCharacter + currentIndexChanged(int) + ExportCsvDialog + showCustomCharEdits() + + + 197 + 93 + + + 270 + 85 + + + + + showCustomCharEdits() +