Qt: Add option to reset to defaults

This commit is contained in:
Connor McLaughlin 2021-07-09 13:05:52 +10:00
parent cf51557b7f
commit 7caa5c09dd
9 changed files with 80 additions and 11 deletions

View File

@ -1084,6 +1084,7 @@ void MainWindow::connectSignals()
connect(m_ui.actionGridViewRefreshCovers, &QAction::triggered, m_game_list_widget,
&GameListWidget::refreshGridCovers);
connect(m_host_interface, &QtHostInterface::settingsResetToDefault, this, &MainWindow::onSettingsResetToDefault);
connect(m_host_interface, &QtHostInterface::errorReported, this, &MainWindow::reportError,
Qt::BlockingQueuedConnection);
connect(m_host_interface, &QtHostInterface::messageReported, this, &MainWindow::reportMessage);
@ -1297,6 +1298,28 @@ void MainWindow::updateTheme()
}
}
void MainWindow::onSettingsResetToDefault()
{
if (m_settings_dialog)
{
const bool shown = m_settings_dialog->isVisible();
m_settings_dialog->hide();
m_settings_dialog->deleteLater();
m_settings_dialog = new SettingsDialog(m_host_interface, this);
if (shown)
{
m_settings_dialog->setModal(false);
m_settings_dialog->show();
}
}
updateDebugMenuCPUExecutionMode();
updateDebugMenuGPURenderer();
updateDebugMenuCropMode();
updateDebugMenuVisibility();
}
void MainWindow::saveStateToConfig()
{
{

View File

@ -65,6 +65,7 @@ private Q_SLOTS:
void setTheme(const QString& theme);
void updateTheme();
void onSettingsResetToDefault();
void onEmulationStarting();
void onEmulationStarted();
void onEmulationStopped();

View File

@ -290,18 +290,15 @@ void QtHostInterface::setDefaultSettings()
return;
}
Settings old_settings(std::move(g_settings));
{
std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
SetDefaultSettings(*m_settings_interface.get());
m_settings_interface->Save();
SetDefaultSettings();
}
CommonHostInterface::LoadSettings(*m_settings_interface.get());
CommonHostInterface::ApplyGameSettings(false);
CommonHostInterface::FixIncompatibleSettings(false);
}
CheckForSettingsChanges(old_settings);
void QtHostInterface::SetDefaultSettings()
{
CommonHostInterface::SetDefaultSettings();
checkRenderToMainState();
queueSettingsSave();
emit settingsResetToDefault();
}
void QtHostInterface::applySettings(bool display_osd_messages /* = false */)
@ -318,7 +315,11 @@ void QtHostInterface::applySettings(bool display_osd_messages /* = false */)
void QtHostInterface::ApplySettings(bool display_osd_messages)
{
CommonHostInterface::ApplySettings(display_osd_messages);
checkRenderToMainState();
}
void QtHostInterface::checkRenderToMainState()
{
// detect when render-to-main flag changes
if (!System::IsShutdown())
{

View File

@ -127,6 +127,7 @@ Q_SIGNALS:
void messageReported(const QString& message);
void debuggerMessageReported(const QString& message);
bool messageConfirmed(const QString& message);
void settingsResetToDefault();
void emulationStarting();
void emulationStarted();
void emulationStopped();
@ -213,6 +214,7 @@ protected:
const std::string& game_title) override;
void SetDefaultSettings(SettingsInterface& si) override;
void SetDefaultSettings() override;
void ApplySettings(bool display_osd_messages) override;
void SetMouseMode(bool relative, bool hide_cursor) override;
@ -267,6 +269,7 @@ private:
void installTranslator();
void renderDisplay();
void connectDisplaySignals(QtDisplayWidget* widget);
void checkRenderToMainState();
void updateDisplayState();
void queueSettingsSave();
void wakeThread();

View File

@ -14,6 +14,7 @@
#include "postprocessingsettingswidget.h"
#include "qthostinterface.h"
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QMessageBox>
#ifdef WITH_CHEEVOS
#include "achievementsettingswidget.h"
@ -76,6 +77,7 @@ SettingsDialog::SettingsDialog(QtHostInterface* host_interface, QWidget* parent
m_ui.helpText->setText(m_category_help_text[0]);
connect(m_ui.settingsCategory, &QListWidget::currentRowChanged, this, &SettingsDialog::onCategoryCurrentRowChanged);
connect(m_ui.closeButton, &QPushButton::clicked, this, &SettingsDialog::accept);
connect(m_ui.restoreDefaultsButton, &QPushButton::clicked, this, &SettingsDialog::onRestoreDefaultsClicked);
connect(m_console_settings, &ConsoleSettingsWidget::multitapModeChanged, m_controller_settings,
&ControllerSettingsWidget::updateMultitapControllerTitles);
@ -143,6 +145,16 @@ void SettingsDialog::onCategoryCurrentRowChanged(int row)
m_ui.helpText->setText(m_category_help_text[row]);
}
void SettingsDialog::onRestoreDefaultsClicked()
{
if (!QMessageBox::question(this, tr("Confirm Restore Defaults"), tr("Are you sure you want to restore the default settings? Any preferences will be lost.")))
{
return;
}
m_host_interface->setDefaultSettings();
}
void SettingsDialog::registerWidgetHelp(QObject* object, QString title, QString recommended_value, QString text)
{
// construct rich text with formatted description

View File

@ -67,11 +67,15 @@ public:
void registerWidgetHelp(QObject* object, QString title, QString recommended_value, QString text);
bool eventFilter(QObject* object, QEvent* event) override;
Q_SIGNALS:
void settingsResetToDefaults();
public Q_SLOTS:
void setCategory(Category category);
private Q_SLOTS:
void onCategoryCurrentRowChanged(int row);
void onRestoreDefaultsClicked();
private:
void setCategoryHelpTexts();

View File

@ -217,6 +217,13 @@
</item>
<item row="2" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="restoreDefaultsButton">
<property name="text">
<string>Restore Defaults</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View File

@ -3104,6 +3104,21 @@ void CommonHostInterface::ApplySettings(bool display_osd_messages)
CheckForSettingsChanges(old_settings);
}
void CommonHostInterface::SetDefaultSettings()
{
Settings old_settings(std::move(g_settings));
{
std::lock_guard<std::recursive_mutex> guard(m_settings_mutex);
SetDefaultSettings(*m_settings_interface.get());
LoadSettings(*m_settings_interface.get());
ApplyGameSettings(true);
FixIncompatibleSettings(true);
}
CheckForSettingsChanges(old_settings);
}
void CommonHostInterface::UpdateInputMap()
{
std::lock_guard<std::recursive_mutex> lock(m_settings_mutex);

View File

@ -426,6 +426,9 @@ protected:
/// Restores all settings to defaults.
virtual void SetDefaultSettings(SettingsInterface& si) override;
/// Resets known settings to default.
virtual void SetDefaultSettings();
/// Loads settings to m_settings and any frontend-specific parameters.
virtual void LoadSettings(SettingsInterface& si) override;