From 58fb726ebfc6870884bf64d5075cbca433fbbcc8 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei Date: Fri, 15 Jul 2016 01:09:38 +0300 Subject: [PATCH] Add default field type preference - resolves sqlitebrowser/sqlitebrowser#650 --- src/EditTableDialog.cpp | 9 +++++++++ src/PreferencesDialog.cpp | 11 +++++++++++ src/PreferencesDialog.ui | 20 +++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index d0acc726..ef11223d 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -1,4 +1,5 @@ #include "EditTableDialog.h" +#include "PreferencesDialog.h" #include "ui_EditTableDialog.h" #include "sqlitetablemodel.h" #include "sqlitedb.h" @@ -453,6 +454,14 @@ void EditTableDialog::addField() typeBox->setProperty("column", tbitem->text(kName)); typeBox->setEditable(true); typeBox->addItems(sqlb::Field::Datatypes); + + int defaultFieldTypeIndex = PreferencesDialog::getSettingsValue("db", "defaultfieldtype").toInt(); + + if (defaultFieldTypeIndex < sqlb::Field::Datatypes.count()) + { + typeBox->setCurrentIndex(defaultFieldTypeIndex); + } + ui->treeWidget->setItemWidget(tbitem, kType, typeBox); connect(typeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTypes())); //connect(typeBox, SIGNAL(editTextChanged(QString)), this, SLOT(updateTypes())); diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index ae956e4d..9db63685 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -65,6 +65,15 @@ void PreferencesDialog::loadSettings() ui->spinPrefetchSize->setValue(getSettingsValue("db", "prefetchsize").toInt()); ui->editDatabaseDefaultSqlText->setText(getSettingsValue("db", "defaultsqltext").toString()); + ui->defaultFieldTypeComboBox->addItems(sqlb::Field::Datatypes); + + int defaultFieldTypeIndex = getSettingsValue("db", "defaultfieldtype").toInt(); + + if (defaultFieldTypeIndex < sqlb::Field::Datatypes.count()) + { + ui->defaultFieldTypeComboBox->setCurrentIndex(defaultFieldTypeIndex); + } + ui->comboDataBrowserFont->setCurrentIndex(ui->comboEditorFont->findText(getSettingsValue("databrowser", "font").toString())); ui->spinDataBrowserFontSize->setValue(getSettingsValue("databrowser", "fontsize").toInt()); loadColorSetting(ui->fr_null_fg, "null_fg"); @@ -115,6 +124,8 @@ void PreferencesDialog::saveSettings() setSettingsValue("db", "prefetchsize", ui->spinPrefetchSize->value()); setSettingsValue("db", "defaultsqltext", ui->editDatabaseDefaultSqlText->text()); + setSettingsValue("db", "defaultfieldtype", ui->defaultFieldTypeComboBox->currentIndex()); + setSettingsValue("checkversion", "enabled", ui->checkUpdates->isChecked()); setSettingsValue("databrowser", "font", ui->comboDataBrowserFont->currentText()); diff --git a/src/PreferencesDialog.ui b/src/PreferencesDialog.ui index 35c471a3..f390328e 100644 --- a/src/PreferencesDialog.ui +++ b/src/PreferencesDialog.ui @@ -7,7 +7,7 @@ 0 0 590 - 532 + 555 @@ -232,7 +232,7 @@ - + Advanced @@ -246,7 +246,7 @@ - + @@ -262,7 +262,7 @@ - + SQL to execute after opening database @@ -272,7 +272,7 @@ - + Qt::Horizontal @@ -285,6 +285,16 @@ + + + + + + + Default field type + + +