src/settingseditor/settingseditor.cpp

changeset 282
f2dc3bbecbfa
parent 264
76a025db4948
child 285
99af8bf63d10
--- a/src/settingseditor/settingseditor.cpp	Tue Jun 28 11:51:17 2022 +0300
+++ b/src/settingseditor/settingseditor.cpp	Tue Jun 28 12:18:00 2022 +0300
@@ -21,16 +21,19 @@
 	this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView});
 	this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView});
 	this->loadLocales();
-	this->setDefaults();
+	this->loadSettings();
+	this->setWindowTitle(tr("Settings"));
 	this->librariesEditor.setModel(&libraries);
 	QVBoxLayout* layout = new QVBoxLayout{this};
 	layout->addWidget(&librariesEditor);
 	this->ui.tabLdrawLibraries->setLayout(layout);
-	connect(
-		this,
-		&SettingsEditor::accepted,
-		this,
-		&SettingsEditor::handleAccepted);
+	connect(this->ui.buttonBox, &QDialogButtonBox::clicked,
+		[&](QAbstractButton* button) {
+			const auto role = this->ui.buttonBox->buttonRole(button);
+			if (role == QDialogButtonBox::ApplyRole) {
+				this->saveSettings();
+			}
+		});
 }
 
 SettingsEditor::~SettingsEditor()
@@ -38,7 +41,7 @@
 	delete &this->ui;
 }
 
-void SettingsEditor::handleAccepted()
+void SettingsEditor::saveSettings()
 {
 	setSetting<Setting::Locale>(this->ui.language->currentData().toString());
 	setSetting<Setting::MainColor>(this->ui.mainColorButton->color());
@@ -52,6 +55,7 @@
 		setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode));
 	}
 	this->librariesEditor.saveSettings();
+	Q_EMIT this->settingsChanged();
 }
 
 void SettingsEditor::loadLocales()
@@ -76,7 +80,7 @@
 	}
 }
 
-void SettingsEditor::setDefaults()
+void SettingsEditor::loadSettings()
 {
 	this->libraries.restoreFromSettings();
 	this->setCurrentLanguage(setting<Setting::Locale>());

mercurial