Skip to content

Commit 3a06395

Browse files
committed
Divide PreferencesDialog in two classes
This forces PreferencesDialog to serve only for UI needs. Plus, this opens the door for adding another class for shortcut management without pain.
1 parent 11bff0d commit 3a06395

16 files changed

Lines changed: 414 additions & 389 deletions

src/Application.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "Application.h"
1010
#include "MainWindow.h"
11-
#include "PreferencesDialog.h"
11+
#include "Settings.h"
1212

1313
Application::Application(int& argc, char** argv) :
1414
QApplication(argc, argv)
@@ -26,7 +26,7 @@ Application::Application(int& argc, char** argv) :
2626

2727
// Load translations
2828
bool ok;
29-
QString name = PreferencesDialog::getSettingsValue("General", "language").toString();
29+
QString name = Settings::getSettingsValue("General", "language").toString();
3030

3131
// First of all try to load the application translation file.
3232
m_translatorApp = new QTranslator(this);
@@ -38,7 +38,7 @@ Application::Application(int& argc, char** argv) :
3838
}
3939

4040
if (ok == true) {
41-
PreferencesDialog::setSettingsValue("General", "language", name);
41+
Settings::setSettingsValue("General", "language", name);
4242
installTranslator(m_translatorApp);
4343

4444
// The application translation file has been found and loaded.
@@ -58,7 +58,7 @@ Application::Application(int& argc, char** argv) :
5858
// Set the correct locale so that the program won't erroneously detect
5959
// a language change when the user toggles settings for the first time.
6060
// (it also prevents the program from always looking for a translation on launch)
61-
PreferencesDialog::setSettingsValue("General", "language", "en_US");
61+
Settings::setSettingsValue("General", "language", "en_US");
6262
}
6363

6464
// Parse command line

src/DbStructureModel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "DbStructureModel.h"
22
#include "sqlitedb.h"
33
#include "sqlitetablemodel.h"
4-
#include "PreferencesDialog.h"
4+
#include "Settings.h"
55

66
#include <QTreeWidgetItem>
77
#include <QMimeData>
@@ -38,7 +38,7 @@ QVariant DbStructureModel::data(const QModelIndex& index, int role) const
3838

3939
// Depending on the role either return the text or the icon
4040
if(role == Qt::DisplayRole)
41-
return PreferencesDialog::getSettingsValue("db", "hideschemalinebreaks").toBool() ? item->text(index.column()).replace("\n", " ").simplified() : item->text(index.column());
41+
return Settings::getSettingsValue("db", "hideschemalinebreaks").toBool() ? item->text(index.column()).replace("\n", " ").simplified() : item->text(index.column());
4242
else if(role == Qt::ToolTipRole)
4343
return item->text(index.column()); // Don't modify the text when it's supposed to be shown in a tooltip
4444
else if(role == Qt::DecorationRole)

src/EditDialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "EditDialog.h"
22
#include "ui_EditDialog.h"
33
#include "sqlitedb.h"
4-
#include "PreferencesDialog.h"
4+
#include "Settings.h"
55
#include "src/qhexedit.h"
66
#include "FileDialog.h"
77

@@ -34,8 +34,8 @@ EditDialog::EditDialog(QWidget* parent)
3434
connect(ins, SIGNAL(activated()), this, SLOT(toggleOverwriteMode()));
3535

3636
// Set the font for the text and hex editors
37-
QFont editorFont(PreferencesDialog::getSettingsValue("databrowser", "font").toString());
38-
editorFont.setPointSize(PreferencesDialog::getSettingsValue("databrowser", "fontsize").toInt());
37+
QFont editorFont(Settings::getSettingsValue("databrowser", "font").toString());
38+
editorFont.setPointSize(Settings::getSettingsValue("databrowser", "fontsize").toInt());
3939
ui->editorText->setFont(editorFont);
4040
hexEdit->setFont(editorFont);
4141

src/EditTableDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "EditTableDialog.h"
2-
#include "PreferencesDialog.h"
2+
#include "Settings.h"
33
#include "ui_EditTableDialog.h"
44
#include "sqlitetablemodel.h"
55
#include "sqlitedb.h"
@@ -463,7 +463,7 @@ void EditTableDialog::addField()
463463
typeBox->setEditable(true);
464464
typeBox->addItems(sqlb::Field::Datatypes);
465465

466-
int defaultFieldTypeIndex = PreferencesDialog::getSettingsValue("db", "defaultfieldtype").toInt();
466+
int defaultFieldTypeIndex = Settings::getSettingsValue("db", "defaultfieldtype").toInt();
467467

468468
if (defaultFieldTypeIndex < sqlb::Field::Datatypes.count())
469469
{

src/ExportDataDialog.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "ExportDataDialog.h"
22
#include "ui_ExportDataDialog.h"
33
#include "sqlitedb.h"
4-
#include "PreferencesDialog.h"
4+
#include "Settings.h"
55
#include "sqlitetablemodel.h"
66
#include "sqlite.h"
77
#include "FileDialog.h"
@@ -29,11 +29,11 @@ ExportDataDialog::ExportDataDialog(DBBrowserDB* db, ExportFormats format, QWidge
2929
ui->stackFormat->setCurrentIndex(format);
3030

3131
// Retrieve the saved dialog preferences
32-
ui->checkHeader->setChecked(PreferencesDialog::getSettingsValue("exportcsv", "firstrowheader").toBool());
33-
setSeparatorChar(PreferencesDialog::getSettingsValue("exportcsv", "separator").toInt());
34-
setQuoteChar(PreferencesDialog::getSettingsValue("exportcsv", "quotecharacter").toInt());
35-
setNewLineString(PreferencesDialog::getSettingsValue("exportcsv", "newlinecharacters").toString());
36-
ui->checkPrettyPrint->setChecked(PreferencesDialog::getSettingsValue("exportjson", "prettyprint").toBool());
32+
ui->checkHeader->setChecked(Settings::getSettingsValue("exportcsv", "firstrowheader").toBool());
33+
setSeparatorChar(Settings::getSettingsValue("exportcsv", "separator").toInt());
34+
setQuoteChar(Settings::getSettingsValue("exportcsv", "quotecharacter").toInt());
35+
setNewLineString(Settings::getSettingsValue("exportcsv", "newlinecharacters").toString());
36+
ui->checkPrettyPrint->setChecked(Settings::getSettingsValue("exportjson", "prettyprint").toBool());
3737

3838
// Update the visible/hidden status of the "Other" line edit fields
3939
showCustomCharEdits();
@@ -325,11 +325,11 @@ void ExportDataDialog::accept()
325325
}
326326

327327
// Save the dialog preferences for future use
328-
PreferencesDialog::setSettingsValue("exportcsv", "firstrowheader", ui->checkHeader->isChecked());
329-
PreferencesDialog::setSettingsValue("exportjson", "prettyprint", ui->checkPrettyPrint->isChecked());
330-
PreferencesDialog::setSettingsValue("exportcsv", "separator", currentSeparatorChar());
331-
PreferencesDialog::setSettingsValue("exportcsv", "quotecharacter", currentQuoteChar());
332-
PreferencesDialog::setSettingsValue("exportcsv", "newlinecharacters", currentNewLineString());
328+
Settings::setSettingsValue("exportcsv", "firstrowheader", ui->checkHeader->isChecked());
329+
Settings::setSettingsValue("exportjson", "prettyprint", ui->checkPrettyPrint->isChecked());
330+
Settings::setSettingsValue("exportcsv", "separator", currentSeparatorChar());
331+
Settings::setSettingsValue("exportcsv", "quotecharacter", currentQuoteChar());
332+
Settings::setSettingsValue("exportcsv", "newlinecharacters", currentNewLineString());
333333

334334
// Notify the user the export has completed
335335
QMessageBox::information(this, QApplication::applicationName(), tr("Export completed."));

src/FileDialog.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "FileDialog.h"
2-
#include "PreferencesDialog.h"
2+
#include "Settings.h"
33

44
QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, const QString &filter, QString *selectedFilter, Options options)
55
{
@@ -31,13 +31,13 @@ QString FileDialog::getExistingDirectory(QWidget* parent, const QString& caption
3131

3232
QString FileDialog::getFileDialogPath()
3333
{
34-
switch(PreferencesDialog::getSettingsValue("db", "savedefaultlocation").toInt())
34+
switch(Settings::getSettingsValue("db", "savedefaultlocation").toInt())
3535
{
3636
case 0: // Remember last location
3737
case 2: // Remember last location for current session only
38-
return PreferencesDialog::getSettingsValue("db", "lastlocation").toString();
38+
return Settings::getSettingsValue("db", "lastlocation").toString();
3939
case 1: // Always use this locations
40-
return PreferencesDialog::getSettingsValue("db", "defaultlocation").toString();
40+
return Settings::getSettingsValue("db", "defaultlocation").toString();
4141
default:
4242
return "";
4343
}
@@ -47,13 +47,13 @@ void FileDialog::setFileDialogPath(const QString& new_path)
4747
{
4848
QString dir = QFileInfo(new_path).absolutePath();
4949

50-
switch(PreferencesDialog::getSettingsValue("db", "savedefaultlocation").toInt())
50+
switch(Settings::getSettingsValue("db", "savedefaultlocation").toInt())
5151
{
5252
case 0: // Remember last location
53-
PreferencesDialog::setSettingsValue("db", "lastlocation", dir);
53+
Settings::setSettingsValue("db", "lastlocation", dir);
5454
break;
5555
case 2: // Remember last location for current session only
56-
PreferencesDialog::setSettingsValue("db", "lastlocation", dir, true);
56+
Settings::setSettingsValue("db", "lastlocation", dir, true);
5757
break;
5858
case 1: // Always use this locations
5959
break; // Do nothing

src/FilterLineEdit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "FilterLineEdit.h"
2-
#include "PreferencesDialog.h"
2+
#include "Settings.h"
33

44
#include <QTimer>
55
#include <QKeyEvent>
@@ -18,7 +18,7 @@ FilterLineEdit::FilterLineEdit(QWidget* parent, QList<FilterLineEdit*>* filters,
1818
// is (re)started. As soon as the user stops typing the timer has a chance to trigger and call the
1919
// delayedSignalTimerTriggered() method which then stops the timer and emits the delayed signal.
2020
delaySignalTimer = new QTimer(this);
21-
delaySignalTimer->setInterval(PreferencesDialog::getSettingsValue("databrowser", "filter_delay").toInt()); // This is the milliseconds of not-typing we want to wait before triggering
21+
delaySignalTimer->setInterval(Settings::getSettingsValue("databrowser", "filter_delay").toInt()); // This is the milliseconds of not-typing we want to wait before triggering
2222
connect(this, SIGNAL(textChanged(QString)), delaySignalTimer, SLOT(start()));
2323
connect(delaySignalTimer, SIGNAL(timeout()), this, SLOT(delayedSignalTimerTriggered()));
2424

src/MainWindow.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "EditTableDialog.h"
77
#include "ImportCsvDialog.h"
88
#include "ExportDataDialog.h"
9+
#include "Settings.h"
910
#include "PreferencesDialog.h"
1011
#include "EditDialog.h"
1112
#include "sqlitetablemodel.h"
@@ -51,7 +52,7 @@
5152
MainWindow::MainWindow(QWidget* parent)
5253
: QMainWindow(parent),
5354
ui(new Ui::MainWindow),
54-
m_browseTableModel(new SqliteTableModel(this, &db, PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt())),
55+
m_browseTableModel(new SqliteTableModel(this, &db, Settings::getSettingsValue("db", "prefetchsize").toInt())),
5556
m_currentTabTableModel(m_browseTableModel),
5657
editDock(new EditDialog(this)),
5758
gotoValidator(new QIntValidator(0, 0, this))
@@ -105,14 +106,14 @@ void MainWindow::init()
105106
ui->dockEdit->setWidget(editDock);
106107

107108
// Restore window geometry
108-
restoreGeometry(PreferencesDialog::getSettingsValue("MainWindow", "geometry").toByteArray());
109-
restoreState(PreferencesDialog::getSettingsValue("MainWindow", "windowState").toByteArray());
109+
restoreGeometry(Settings::getSettingsValue("MainWindow", "geometry").toByteArray());
110+
restoreState(Settings::getSettingsValue("MainWindow", "windowState").toByteArray());
110111

111112
// Restore various dock state settings
112-
ui->comboLogSubmittedBy->setCurrentIndex(ui->comboLogSubmittedBy->findText(PreferencesDialog::getSettingsValue("SQLLogDock", "Log").toString()));
113-
ui->splitterForPlot->restoreState(PreferencesDialog::getSettingsValue("PlotDock", "splitterSize").toByteArray());
114-
ui->comboLineType->setCurrentIndex(PreferencesDialog::getSettingsValue("PlotDock", "lineType").toInt());
115-
ui->comboPointShape->setCurrentIndex(PreferencesDialog::getSettingsValue("PlotDock", "pointShape").toInt());
113+
ui->comboLogSubmittedBy->setCurrentIndex(ui->comboLogSubmittedBy->findText(Settings::getSettingsValue("SQLLogDock", "Log").toString()));
114+
ui->splitterForPlot->restoreState(Settings::getSettingsValue("PlotDock", "splitterSize").toByteArray());
115+
ui->comboLineType->setCurrentIndex(Settings::getSettingsValue("PlotDock", "lineType").toInt());
116+
ui->comboPointShape->setCurrentIndex(Settings::getSettingsValue("PlotDock", "pointShape").toInt());
116117

117118
// Add keyboard shortcuts
118119
QList<QKeySequence> shortcuts = ui->actionExecuteSql->shortcuts();
@@ -231,7 +232,7 @@ void MainWindow::init()
231232

232233
#ifdef CHECKNEWVERSION
233234
// Check for a new version if automatic update check aren't disabled in the settings dialog
234-
if(PreferencesDialog::getSettingsValue("checkversion", "enabled").toBool())
235+
if(Settings::getSettingsValue("checkversion", "enabled").toBool())
235236
{
236237
// Check for a new release version, usually only enabled on windows
237238
m_NetworkManager = new QNetworkAccessManager(this);
@@ -544,12 +545,12 @@ void MainWindow::closeEvent( QCloseEvent* event )
544545
{
545546
if(db.close())
546547
{
547-
PreferencesDialog::setSettingsValue("MainWindow", "geometry", saveGeometry());
548-
PreferencesDialog::setSettingsValue("MainWindow", "windowState", saveState());
549-
PreferencesDialog::setSettingsValue("SQLLogDock", "Log", ui->comboLogSubmittedBy->currentText());
550-
PreferencesDialog::setSettingsValue("PlotDock", "splitterSize", ui->splitterForPlot->saveState());
551-
PreferencesDialog::setSettingsValue("PlotDock", "lineType", ui->comboLineType->currentIndex());
552-
PreferencesDialog::setSettingsValue("PlotDock", "pointShape", ui->comboPointShape->currentIndex());
548+
Settings::setSettingsValue("MainWindow", "geometry", saveGeometry());
549+
Settings::setSettingsValue("MainWindow", "windowState", saveState());
550+
Settings::setSettingsValue("SQLLogDock", "Log", ui->comboLogSubmittedBy->currentText());
551+
Settings::setSettingsValue("PlotDock", "splitterSize", ui->splitterForPlot->saveState());
552+
Settings::setSettingsValue("PlotDock", "lineType", ui->comboLineType->currentIndex());
553+
Settings::setSettingsValue("PlotDock", "pointShape", ui->comboPointShape->currentIndex());
553554
QMainWindow::closeEvent(event);
554555
} else {
555556
event->ignore();
@@ -1258,7 +1259,7 @@ void MainWindow::openRecentFile()
12581259
void MainWindow::updateRecentFileActions()
12591260
{
12601261
// Get recent files list from settings
1261-
QStringList files = PreferencesDialog::getSettingsValue("General", "recentFileList").toStringList();
1262+
QStringList files = Settings::getSettingsValue("General", "recentFileList").toStringList();
12621263

12631264
// Check if files still exist and remove any non-existant file
12641265
for(int i=0;i<files.size();i++)
@@ -1272,7 +1273,7 @@ void MainWindow::updateRecentFileActions()
12721273
}
12731274

12741275
// Store updated list
1275-
PreferencesDialog::setSettingsValue("General", "recentFileList", files);
1276+
Settings::setSettingsValue("General", "recentFileList", files);
12761277

12771278
int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
12781279

@@ -1302,13 +1303,13 @@ void MainWindow::setCurrentFile(const QString &fileName)
13021303

13031304
void MainWindow::addToRecentFilesMenu(const QString& filename)
13041305
{
1305-
QStringList files = PreferencesDialog::getSettingsValue("General", "recentFileList").toStringList();
1306+
QStringList files = Settings::getSettingsValue("General", "recentFileList").toStringList();
13061307
files.removeAll(filename);
13071308
files.prepend(filename);
13081309
while (files.size() > MaxRecentFiles)
13091310
files.removeLast();
13101311

1311-
PreferencesDialog::setSettingsValue("General", "recentFileList", files);
1312+
Settings::setSettingsValue("General", "recentFileList", files);
13121313

13131314
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
13141315
MainWindow *mainWin = qobject_cast<MainWindow *>(widget);
@@ -1591,7 +1592,7 @@ void MainWindow::loadExtensionsFromSettings()
15911592
if(!db.isOpen())
15921593
return;
15931594

1594-
QStringList list = PreferencesDialog::getSettingsValue("extensions", "list").toStringList();
1595+
QStringList list = Settings::getSettingsValue("extensions", "list").toStringList();
15951596
foreach(QString ext, list)
15961597
{
15971598
if(db.loadExtension(ext) == false)
@@ -1602,16 +1603,16 @@ void MainWindow::loadExtensionsFromSettings()
16021603
void MainWindow::reloadSettings()
16031604
{
16041605
// Read settings
1605-
int prefetch_size = PreferencesDialog::getSettingsValue("db", "prefetchsize").toInt();
1606-
int log_fontsize = PreferencesDialog::getSettingsValue("log", "fontsize").toInt();
1606+
int prefetch_size = Settings::getSettingsValue("db", "prefetchsize").toInt();
1607+
int log_fontsize = Settings::getSettingsValue("log", "fontsize").toInt();
16071608

16081609
QFont logfont("Monospace");
16091610
logfont.setStyleHint(QFont::TypeWriter);
16101611
logfont.setPointSize(log_fontsize);
16111612

16121613
// Set data browser font
1613-
QFont dataBrowserFont(PreferencesDialog::getSettingsValue("databrowser", "font").toString());
1614-
dataBrowserFont.setPointSize(PreferencesDialog::getSettingsValue("databrowser", "fontsize").toInt());
1614+
QFont dataBrowserFont(Settings::getSettingsValue("databrowser", "font").toString());
1615+
dataBrowserFont.setPointSize(Settings::getSettingsValue("databrowser", "fontsize").toInt());
16151616
ui->dataTable->setFont(dataBrowserFont);
16161617

16171618
// Set prefetch sizes for lazy population of table models

0 commit comments

Comments
 (0)