Browse Source

Use QSignalBlocker in launcher where applicable

Ivan Savenko 1 year ago
parent
commit
0acf65af17
2 changed files with 6 additions and 11 deletions
  1. 2 5
      launcher/languages.cpp
  2. 4 6
      launcher/settingsView/csettingsview_moc.cpp

+ 2 - 5
launcher/languages.cpp

@@ -86,7 +86,7 @@ QString Languages::generateLanguageName(const Languages::Options & language)
 
 void Languages::fillLanguages(QComboBox * widget, bool includeAll)
 {
-	widget->blockSignals(true); // we do not want calls caused by initialization
+	QSignalBlocker guard(widget); // we do not want calls caused by initialization
 	widget->clear();
 
 	std::string activeLanguage = includeAll ?
@@ -115,13 +115,11 @@ void Languages::fillLanguages(QComboBox * widget, bool includeAll)
 		if(activeLanguage == language.identifier)
 			widget->setCurrentIndex(widget->count() - 1);
 	}
-
-	widget->blockSignals(false);
 }
 
 void Languages::fillLanguages(QListWidget * widget, bool includeAll)
 {
-	widget->blockSignals(true); // we do not want calls caused by initialization
+	QSignalBlocker guard(widget); // we do not want calls caused by initialization
 	widget->clear();
 
 	std::string activeLanguage = includeAll ?
@@ -154,5 +152,4 @@ void Languages::fillLanguages(QListWidget * widget, bool includeAll)
 		if(activeLanguage == language.identifier)
 			widget->setCurrentRow(widget->count() - 1);
 	}
-	widget->blockSignals(false);
 }

+ 4 - 6
launcher/settingsView/csettingsview_moc.cpp

@@ -216,7 +216,8 @@ static QVector<QSize> findAvailableResolutions(int displayIndex)
 
 void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
 {
-	ui->comboBoxResolution->blockSignals(true); // avoid saving wrong resolution after adding first item from the list
+	QSignalBlocker guard(ui->comboBoxResolution); // avoid saving wrong resolution after adding first item from the list
+
 	ui->comboBoxResolution->clear();
 
 	bool fullscreen = settings["video"]["fullscreen"].Bool();
@@ -243,13 +244,12 @@ void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
 	// if selected resolution no longer exists, force update value to the largest (last) resolution
 	if(resIndex == -1)
 		ui->comboBoxResolution->setCurrentIndex(ui->comboBoxResolution->count() - 1);
-
-	ui->comboBoxResolution->blockSignals(false);
 }
 
 void CSettingsView::fillValidRenderers()
 {
-	ui->comboBoxRendererType->blockSignals(true); // avoid saving wrong resolution after adding first item from the list
+	QSignalBlocker guard(ui->comboBoxRendererType); // avoid saving wrong renderer after adding first item from the list
+
 	ui->comboBoxRendererType->clear();
 
 	auto driversList = getAvailableRenderingDrivers();
@@ -259,8 +259,6 @@ void CSettingsView::fillValidRenderers()
 
 	int index = ui->comboBoxRendererType->findText(QString::fromStdString(rendererName));
 	ui->comboBoxRendererType->setCurrentIndex(index);
-
-	ui->comboBoxRendererType->blockSignals(false);
 }
 #else
 void CSettingsView::fillValidResolutionsForScreen(int screenIndex)