# HG changeset patch # User Teemu Piippo # Date 1680980969 -10800 # Node ID 66c75604f5b81f20f5f40c4c48d2f483b2a04fdb # Parent 65b4741b302d75761addf0ea5491cbbd8c74371b Add settings import and export diff -r 65b4741b302d -r 66c75604f5b8 src/settingseditor/settingseditor.cpp --- a/src/settingseditor/settingseditor.cpp Sat Apr 08 21:48:49 2023 +0300 +++ b/src/settingseditor/settingseditor.cpp Sat Apr 08 22:09:29 2023 +0300 @@ -1,5 +1,6 @@ #include #include +#include #include #include "src/settings.h" #include "src/gl/common.h" @@ -87,6 +88,45 @@ } } ); + connect( + this->ui.exportSettingsButton, + &QAbstractButton::clicked, + [&] + { + const QString defaultName = QStringLiteral(CMAKE_PROJECT_NAME ".conf"); + QString filename = QFileDialog::getSaveFileName(this, "", defaultName, "*.conf"); + if (not filename.isEmpty()) + { + QSettings settings; + QSettings exportSettings{filename, QSettings::IniFormat}; + for (const QString& key : settings.allKeys()) + { + exportSettings.setValue(key, settings.value(key)); + } + exportSettings.sync(); + } + } + ); + connect( + this->ui.importSettingsButton, + &QAbstractButton::clicked, + [&] + { + QString filename = QFileDialog::getOpenFileName(this, "", "", "*.ini"); + if (not filename.isEmpty()) + { + QSettings settings; + const QSettings importSettings{filename}; + settings.clear(); + for (const QString& key : importSettings.allKeys()) + { + settings.setValue(key, importSettings.value(key)); + } + settings.sync(); + this->loadSettings(); + } + } + ); for (auto* widget : this->findChildren()) { connect(widget, &QAbstractButton::clicked, this, &SettingsEditor::saveSettings); } @@ -108,30 +148,34 @@ void SettingsEditor::saveSettings() { - setSetting(this->ui.mainColorButton->color()); - setSetting(this->ui.backgroundColorButton->color()); - setSetting(this->ui.selectedColorButton->color()); - setSetting(static_cast(this->ui.lineThickness->value())); - setSetting(this->ui.lineAntiAliasing->isChecked()); - setSetting(this->ui.logOpenGLDebugMessages->isChecked()); - setSetting(this->ui.codeEditorSystemFont->isChecked()); - setSetting(this->ui.codeEditorFontFamily->currentText()); - setSetting(this->ui.codeEditorFontSize->value()); - const int viewMode = this->ui.viewModeButtonGroup->checkedId(); - if (viewMode != -1) { - setSetting(static_cast(viewMode)); + if (not disableSettingsAutoSave) + { + setSetting(this->ui.mainColorButton->color()); + setSetting(this->ui.backgroundColorButton->color()); + setSetting(this->ui.selectedColorButton->color()); + setSetting(static_cast(this->ui.lineThickness->value())); + setSetting(this->ui.lineAntiAliasing->isChecked()); + setSetting(this->ui.logOpenGLDebugMessages->isChecked()); + setSetting(this->ui.codeEditorSystemFont->isChecked()); + setSetting(this->ui.codeEditorFontFamily->currentText()); + setSetting(this->ui.codeEditorFontSize->value()); + const int viewMode = this->ui.viewModeButtonGroup->checkedId(); + if (viewMode != -1) { + setSetting(static_cast(viewMode)); + } + const QVariant toolButtonStyle = this->ui.toolButtonStyle->currentData(); + if (toolButtonStyle.isValid()) { + setSetting( + static_cast(toolButtonStyle.toInt())); + } + this->librariesEditor.saveSettings(); + Q_EMIT this->settingsChanged(); } - const QVariant toolButtonStyle = this->ui.toolButtonStyle->currentData(); - if (toolButtonStyle.isValid()) { - setSetting( - static_cast(toolButtonStyle.toInt())); - } - this->librariesEditor.saveSettings(); - Q_EMIT this->settingsChanged(); } void SettingsEditor::loadSettings() { + this->disableSettingsAutoSave = true; this->libraries.restoreFromSettings(); this->ui.mainColorButton->setColor(setting()); this->ui.backgroundColorButton->setColor(setting()); @@ -151,4 +195,5 @@ if (toolButtonStyleIndex != -1) { this->ui.toolButtonStyle->setCurrentIndex(toolButtonStyleIndex); } + this->disableSettingsAutoSave = false; } diff -r 65b4741b302d -r 66c75604f5b8 src/settingseditor/settingseditor.h --- a/src/settingseditor/settingseditor.h Sat Apr 08 21:48:49 2023 +0300 +++ b/src/settingseditor/settingseditor.h Sat Apr 08 22:09:29 2023 +0300 @@ -17,6 +17,7 @@ Q_SIGNALS: void settingsChanged(); private: + bool disableSettingsAutoSave = false; class Ui_SettingsEditor& ui; LibrariesModel libraries; LibrariesEditor librariesEditor; diff -r 65b4741b302d -r 66c75604f5b8 src/settingseditor/settingseditor.ui --- a/src/settingseditor/settingseditor.ui Sat Apr 08 21:48:49 2023 +0300 +++ b/src/settingseditor/settingseditor.ui Sat Apr 08 22:09:29 2023 +0300 @@ -6,8 +6,8 @@ 0 0 - 718 - 629 + 972 + 817 @@ -30,8 +30,8 @@ 0 0 - 680 - 560 + 948 + 746 @@ -159,6 +159,37 @@ + + + + Export settings + + + + + + Export settings to file… + + + + :/icons/save-as-outline.png:/icons/save-as-outline.png + + + + + + + Import settings from file… + + + + :/icons/folder-open-outline.png:/icons/folder-open-outline.png + + + + + + @@ -316,7 +347,10 @@
widgets/coloredit.h
- + + + +