Skip to content

Commit

Permalink
Update the CSV export dialog to use the PreferencesDialog methods
Browse files Browse the repository at this point in the history
  • Loading branch information
justinclift committed May 25, 2016
1 parent c913909 commit 76aeba0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/ExportCsvDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ ExportCsvDialog::ExportCsvDialog(DBBrowserDB* db, QWidget* parent, const QString
// Create UI
ui->setupUi(this);

QSettings settings(QApplication::organizationName(), QApplication::organizationName());
ui->checkHeader->setChecked(settings.value("exportcsv/firstrowheader", true).toBool());
setSeparatorChar(QChar(settings.value("exportcsv/separator", ',').toInt()));
setQuoteChar(QChar(settings.value("exportcsv/quotecharacter", '"').toInt()));
// Retrieve the saved dialog preferences
bool firstRow = PreferencesDialog::getSettingsValue("exportcsv", "firstrowheader").toBool();
int separatorChar = PreferencesDialog::getSettingsValue("exportcsv", "separator").toInt();
int quoteChar = PreferencesDialog::getSettingsValue("exportcsv", "quotecharacter").toInt();

// Set the widget values using the retrieved preferences
ui->checkHeader->setChecked(firstRow);
setSeparatorChar(separatorChar);
setQuoteChar(quoteChar);

// Update the visible/hidden status of the "Other" line edit fields
showCustomCharEdits();

// If a SQL query was specified hide the table combo box. If not fill it with tables to export
Expand Down Expand Up @@ -223,15 +229,12 @@ void ExportCsvDialog::accept()
}
}

// save settings
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
settings.beginGroup("exportcsv");
settings.setValue("firstrowheader", ui->checkHeader->isChecked());
settings.setValue("separator", currentSeparatorChar());
settings.setValue("quotecharacter", currentQuoteChar());
settings.endGroup();

// Save the dialog preferences for future use
PreferencesDialog::setSettingsValue("exportcsv", "firstrowheader", ui->checkHeader->isChecked(), false);
PreferencesDialog::setSettingsValue("exportcsv", "separator", currentSeparatorChar(), false);
PreferencesDialog::setSettingsValue("exportcsv", "quotecharacter", currentQuoteChar(), false);

// Notify the user the export has completed
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));
QDialog::accept();
}
Expand Down
12 changes: 12 additions & 0 deletions src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
if(group == "db" && name == "defaultsqltext")
return "";

// exportcsv/firstrowheader?
if(group == "exportcsv" && name == "firstrowheader")
return true;

// exportcsv/separator?
if(group == "exportcsv" && name == "separator")
return ',';

// exportcsv/quotecharacter?
if(group == "exportcsv" && name == "quotecharacter")
return '"';

// MainWindow/geometry?
if(group == "MainWindow" && name == "geometry")
return "";
Expand Down

0 comments on commit 76aeba0

Please sign in to comment.