add a foreign key setting

to open database with foreign keys enabled
This commit is contained in:
Peinthor Rene
2013-01-29 18:26:29 +01:00
parent 9c9e1a61f3
commit f8e51cc07a
4 changed files with 58 additions and 3 deletions

View File

@@ -52,6 +52,11 @@ void PreferencesDialog::encodingChanged( int which )
}
}
void PreferencesDialog::foreignkeysStateChanged(int state)
{
foreignkeys = state > 0;
}
void PreferencesDialog::chooseLocation()
{
QString s = QFileDialog::getExistingDirectory(
@@ -76,6 +81,7 @@ void PreferencesDialog::loadSettings()
defaultnewdata = settings.value( "/db/defaultnewdata", "NULL" ).toString();
defaultlocation = settings.value( "/db/defaultlocation", QDir::homePath() ).toString();
defaulttext = settings.value( "/db/defaulttext", "Plain" ).toString();
foreignkeys = settings.value( "/db/foreignkeys", true ).toBool();
if (defaultencoding=="Latin1")
{
@@ -103,6 +109,8 @@ void PreferencesDialog::loadSettings()
ui->defaultTextComboBox->setCurrentIndex(0) ;
defaulttext = QString("Plain");
}
ui->foreignKeysCheckBox->setChecked(foreignkeys);
ui->locationEdit->setText(defaultlocation);
}
@@ -115,6 +123,7 @@ void PreferencesDialog::saveSettings()
settings.setValue( "/db/defaultnewdata", defaultnewdata );
settings.setValue( "/db/defaultlocation", defaultlocation );
settings.setValue( "/db/defaulttext", defaulttext );
settings.setValue( "/db/foreignkeys", foreignkeys );
settings.sync();
accept();
}

View File

@@ -19,11 +19,13 @@ public:
QString defaultlocation;
QString defaultnewdata;
QString defaultencoding;
bool foreignkeys;
private slots:
virtual void defaultDataChanged( int which );
virtual void defaultTextChanged( int which );
virtual void encodingChanged( int which );
virtual void foreignkeysStateChanged( int state );
virtual void chooseLocation();
virtual void loadSettings();
virtual void saveSettings();

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>492</width>
<height>145</height>
<height>219</height>
</rect>
</property>
<property name="windowTitle">
@@ -85,7 +85,7 @@
</item>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Default location</string>
@@ -95,7 +95,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="locationEdit">
@@ -127,6 +127,26 @@
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>Open databases with foreign keys enabled.</string>
</property>
<property name="text">
<string>Foreign keys</string>
</property>
<property name="buddy">
<cstring>foreignKeysCheckBox</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="foreignKeysCheckBox">
<property name="text">
<string>enabled</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@@ -247,6 +267,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>foreignKeysCheckBox</sender>
<signal>stateChanged(int)</signal>
<receiver>PreferencesDialog</receiver>
<slot>foreignkeysStateChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>213</x>
<y>113</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
<y>109</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>saveSettings()</slot>
@@ -254,5 +290,6 @@
<slot>encodingChanged(int)</slot>
<slot>chooseLocation()</slot>
<slot>defaultTextChanged(int)</slot>
<slot>foreignkeysStateChanged(int)</slot>
</slots>
</ui>

View File

@@ -6,6 +6,7 @@
#include <QProgressDialog>
#include <QApplication>
#include <QTextStream>
#include <QSettings>
void DBBrowserObject::addField(int order, const QString& wfield,const QString& wtype)
{
@@ -97,6 +98,12 @@ bool DBBrowserDB::open ( const QString & db)
}
if (_db){
// set preference defaults
QSettings settings(QApplication::organizationName(), QApplication::organizationName());
settings.sync();
bool foreignkeys = settings.value( "/db/foreignkeys", false ).toBool();
setPragma("foreign_keys", foreignkeys ? "1" : "0");
if (SQLITE_OK==sqlite3_exec(_db,"PRAGMA empty_result_callbacks = ON;",
NULL,NULL,NULL)){
if (SQLITE_OK==sqlite3_exec(_db,"PRAGMA show_datatypes = ON;",