mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user