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

View File

@@ -19,6 +19,7 @@ public:
private slots:
virtual void accept();
void showCustomCharEdits();
private:
Ui::ExportCsvDialog* ui;

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>331</width>
<height>141</height>
<height>145</height>
</rect>
</property>
<property name="windowTitle">
@@ -60,28 +60,57 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboFieldSeparator">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<property name="text">
<string>,</string>
</property>
<widget class="QComboBox" name="comboFieldSeparator">
<item>
<property name="text">
<string>,</string>
</property>
</item>
<item>
<property name="text">
<string>;</string>
</property>
</item>
<item>
<property name="text">
<string>Tab</string>
</property>
</item>
<item>
<property name="text">
<string>|</string>
</property>
</item>
<item>
<property name="text">
<string>Other</string>
</property>
</item>
</widget>
</item>
<item>
<property name="text">
<string>;</string>
</property>
<widget class="QLineEdit" name="editCustomSeparator">
<property name="maxLength">
<number>1</number>
</property>
</widget>
</item>
<item>
<property name="text">
<string>Tab</string>
</property>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<property name="text">
<string>|</string>
</property>
</item>
</widget>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelQuoteCharacter">
@@ -94,23 +123,52 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="comboQuoteCharacter">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<property name="text">
<string>&quot;</string>
</property>
<widget class="QComboBox" name="comboQuoteCharacter">
<item>
<property name="text">
<string>&quot;</string>
</property>
</item>
<item>
<property name="text">
<string>'</string>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
</item>
<item>
<property name="text">
<string>Other</string>
</property>
</item>
</widget>
</item>
<item>
<property name="text">
<string>'</string>
</property>
<widget class="QLineEdit" name="editCustomQuote">
<property name="maxLength">
<number>1</number>
</property>
</widget>
</item>
<item>
<property name="text">
<string/>
</property>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</widget>
</layout>
</item>
</layout>
</item>
@@ -130,7 +188,9 @@
<tabstop>comboTable</tabstop>
<tabstop>checkHeader</tabstop>
<tabstop>comboFieldSeparator</tabstop>
<tabstop>editCustomSeparator</tabstop>
<tabstop>comboQuoteCharacter</tabstop>
<tabstop>editCustomQuote</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
@@ -167,5 +227,40 @@
</hint>
</hints>
</connection>
<connection>
<sender>comboFieldSeparator</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>ExportCsvDialog</receiver>
<slot>showCustomCharEdits()</slot>
<hints>
<hint type="sourcelabel">
<x>210</x>
<y>64</y>
</hint>
<hint type="destinationlabel">
<x>264</x>
<y>45</y>
</hint>
</hints>
</connection>
<connection>
<sender>comboQuoteCharacter</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>ExportCsvDialog</receiver>
<slot>showCustomCharEdits()</slot>
<hints>
<hint type="sourcelabel">
<x>197</x>
<y>93</y>
</hint>
<hint type="destinationlabel">
<x>270</x>
<y>85</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>showCustomCharEdits()</slot>
</slots>
</ui>