Show warning when closing unsaved. (#16)
This commit is contained in:
parent
9a057bb7b2
commit
0201c7c647
@ -45,6 +45,7 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_panels(QList<Se
|
|||||||
|
|
||||||
// Establish needed connections.
|
// Establish needed connections.
|
||||||
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormSettings::saveSettings);
|
connect(m_ui->m_buttonBox, &QDialogButtonBox::accepted, this, &FormSettings::saveSettings);
|
||||||
|
connect(m_ui->m_buttonBox, &QDialogButtonBox::rejected, this, &FormSettings::cancelSettings);
|
||||||
connect(m_btnApply, &QPushButton::clicked, this, &FormSettings::applySettings);
|
connect(m_btnApply, &QPushButton::clicked, this, &FormSettings::applySettings);
|
||||||
|
|
||||||
addSettingsPanel(new SettingsGeneral(m_settings, this));
|
addSettingsPanel(new SettingsGeneral(m_settings, this));
|
||||||
@ -104,7 +105,7 @@ void FormSettings::applySettings() {
|
|||||||
MessageBox::show(this,
|
MessageBox::show(this,
|
||||||
QMessageBox::Question,
|
QMessageBox::Question,
|
||||||
tr("Critical settings were changed"),
|
tr("Critical settings were changed"),
|
||||||
tr("Some critical settings were changed and will be applied after the application gets restarted. "
|
tr("Some critical settings were changed and will be applied after the application gets restarted."
|
||||||
"\n\nYou have to restart manually."),
|
"\n\nYou have to restart manually."),
|
||||||
QString(),
|
QString(),
|
||||||
tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))),
|
tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))),
|
||||||
@ -114,6 +115,35 @@ void FormSettings::applySettings() {
|
|||||||
m_btnApply->setEnabled(false);
|
m_btnApply->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormSettings::cancelSettings() {
|
||||||
|
QStringList changed_panels;
|
||||||
|
|
||||||
|
foreach (SettingsPanel *panel, m_panels) {
|
||||||
|
if (panel->isDirty()) {
|
||||||
|
changed_panels.append(panel->title().toLower());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed_panels.isEmpty()) {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const QStringList changed_settings_description = changed_panels.replaceInStrings(QRegExp(QSL("^")), QString::fromUtf8(" • "));
|
||||||
|
|
||||||
|
if (MessageBox::show(this,
|
||||||
|
QMessageBox::Critical,
|
||||||
|
tr("Some settings are changed and will be lost"),
|
||||||
|
tr("Some settings were changed and by cancelling this dialog, you would lose these changes."
|
||||||
|
"\n\nYou have to restart manually."),
|
||||||
|
tr("Do you really want to close this dialog without saving settings?"),
|
||||||
|
tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))),
|
||||||
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ==
|
||||||
|
QMessageBox::Yes) {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FormSettings::addSettingsPanel(SettingsPanel *panel) {
|
void FormSettings::addSettingsPanel(SettingsPanel *panel) {
|
||||||
m_ui->m_listSettings->addItem(panel->title());
|
m_ui->m_listSettings->addItem(panel->title());
|
||||||
m_panels.append(panel);
|
m_panels.append(panel);
|
||||||
|
@ -41,6 +41,7 @@ class FormSettings : public QDialog {
|
|||||||
// Saves settings into global configuration.
|
// Saves settings into global configuration.
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void applySettings();
|
void applySettings();
|
||||||
|
void cancelSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addSettingsPanel(SettingsPanel *panel);
|
void addSettingsPanel(SettingsPanel *panel);
|
||||||
|
@ -69,22 +69,6 @@
|
|||||||
</tabstops>
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
|
||||||
<sender>m_buttonBox</sender>
|
|
||||||
<signal>rejected()</signal>
|
|
||||||
<receiver>FormSettings</receiver>
|
|
||||||
<slot>reject()</slot>
|
|
||||||
<hints>
|
|
||||||
<hint type="sourcelabel">
|
|
||||||
<x>334</x>
|
|
||||||
<y>400</y>
|
|
||||||
</hint>
|
|
||||||
<hint type="destinationlabel">
|
|
||||||
<x>286</x>
|
|
||||||
<y>274</y>
|
|
||||||
</hint>
|
|
||||||
</hints>
|
|
||||||
</connection>
|
|
||||||
<connection>
|
<connection>
|
||||||
<sender>m_listSettings</sender>
|
<sender>m_listSettings</sender>
|
||||||
<signal>currentRowChanged(int)</signal>
|
<signal>currentRowChanged(int)</signal>
|
||||||
|
@ -42,6 +42,8 @@ SettingsDatabase::SettingsDatabase(Settings *settings, QWidget *parent)
|
|||||||
connect(m_ui->m_txtMysqlPassword->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlPasswordChanged);
|
connect(m_ui->m_txtMysqlPassword->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlPasswordChanged);
|
||||||
connect(m_ui->m_txtMysqlDatabase->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlDatabaseChanged);
|
connect(m_ui->m_txtMysqlDatabase->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlDatabaseChanged);
|
||||||
connect(m_ui->m_btnMysqlTestSetup, &QPushButton::clicked, this, &SettingsDatabase::mysqlTestConnection);
|
connect(m_ui->m_btnMysqlTestSetup, &QPushButton::clicked, this, &SettingsDatabase::mysqlTestConnection);
|
||||||
|
|
||||||
|
connect(m_ui->m_checkSqliteUseInMemoryDatabase, &QCheckBox::toggled, this, &SettingsDatabase::requireRestart);
|
||||||
connect(m_ui->m_spinMysqlPort, &QSpinBox::editingFinished, this, &SettingsDatabase::requireRestart);
|
connect(m_ui->m_spinMysqlPort, &QSpinBox::editingFinished, this, &SettingsDatabase::requireRestart);
|
||||||
connect(m_ui->m_txtMysqlHostname->lineEdit(), &BaseLineEdit::textEdited, this, &SettingsDatabase::requireRestart);
|
connect(m_ui->m_txtMysqlHostname->lineEdit(), &BaseLineEdit::textEdited, this, &SettingsDatabase::requireRestart);
|
||||||
connect(m_ui->m_txtMysqlPassword->lineEdit(), &BaseLineEdit::textEdited, this, &SettingsDatabase::requireRestart);
|
connect(m_ui->m_txtMysqlPassword->lineEdit(), &BaseLineEdit::textEdited, this, &SettingsDatabase::requireRestart);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user