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.
This commit is contained in:
Martin Kleusberg
2014-05-30 18:11:49 +02:00
parent 55435e2703
commit f8b2dd0ee3
3 changed files with 141 additions and 31 deletions

View File

@@ -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);
}