mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-27 04:25:12 +00:00
initial save classes for gui save file
This commit is contained in:
parent
d124f40503
commit
93d4fe1031
@ -1047,6 +1047,10 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
|
|||||||
src/qt_gui/settings_dialog.h
|
src/qt_gui/settings_dialog.h
|
||||||
src/qt_gui/settings_dialog.ui
|
src/qt_gui/settings_dialog.ui
|
||||||
src/qt_gui/main.cpp
|
src/qt_gui/main.cpp
|
||||||
|
src/qt_gui/gui_settings.cpp
|
||||||
|
src/qt_gui/gui_settings.h
|
||||||
|
src/qt_gui/settings.cpp
|
||||||
|
src/qt_gui/settings.h
|
||||||
${EMULATOR}
|
${EMULATOR}
|
||||||
${RESOURCE_FILES}
|
${RESOURCE_FILES}
|
||||||
${TRANSLATIONS}
|
${TRANSLATIONS}
|
||||||
|
@ -85,18 +85,12 @@ static std::vector<GameInstallDir> settings_install_dirs = {};
|
|||||||
std::vector<bool> install_dirs_enabled = {};
|
std::vector<bool> install_dirs_enabled = {};
|
||||||
std::filesystem::path settings_addon_install_dir = {};
|
std::filesystem::path settings_addon_install_dir = {};
|
||||||
std::filesystem::path save_data_path = {};
|
std::filesystem::path save_data_path = {};
|
||||||
u32 main_window_geometry_x = 400;
|
|
||||||
u32 main_window_geometry_y = 400;
|
|
||||||
u32 main_window_geometry_w = 1280;
|
|
||||||
u32 main_window_geometry_h = 720;
|
|
||||||
u32 mw_themes = 0;
|
u32 mw_themes = 0;
|
||||||
u32 m_icon_size = 36;
|
u32 m_icon_size = 36;
|
||||||
u32 m_icon_size_grid = 69;
|
u32 m_icon_size_grid = 69;
|
||||||
u32 m_slider_pos = 0;
|
u32 m_slider_pos = 0;
|
||||||
u32 m_slider_pos_grid = 0;
|
u32 m_slider_pos_grid = 0;
|
||||||
u32 m_table_mode = 0;
|
u32 m_table_mode = 0;
|
||||||
u32 m_window_size_W = 1280;
|
|
||||||
u32 m_window_size_H = 720;
|
|
||||||
std::vector<std::string> m_elf_viewer;
|
std::vector<std::string> m_elf_viewer;
|
||||||
std::vector<std::string> m_recent_files;
|
std::vector<std::string> m_recent_files;
|
||||||
std::string emulator_language = "en_US";
|
std::string emulator_language = "en_US";
|
||||||
@ -520,13 +514,6 @@ void setCheckCompatibilityOnStartup(bool use) {
|
|||||||
checkCompatibilityOnStartup = use;
|
checkCompatibilityOnStartup = use;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
|
|
||||||
main_window_geometry_x = x;
|
|
||||||
main_window_geometry_y = y;
|
|
||||||
main_window_geometry_w = w;
|
|
||||||
main_window_geometry_h = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled) {
|
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled) {
|
||||||
for (const auto& install_dir : settings_install_dirs) {
|
for (const auto& install_dir : settings_install_dirs) {
|
||||||
if (install_dir.path == dir) {
|
if (install_dir.path == dir) {
|
||||||
@ -583,14 +570,6 @@ void setTableMode(u32 mode) {
|
|||||||
m_table_mode = mode;
|
m_table_mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMainWindowWidth(u32 width) {
|
|
||||||
m_window_size_W = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMainWindowHeight(u32 height) {
|
|
||||||
m_window_size_H = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setElfViewer(const std::vector<std::string>& elfList) {
|
void setElfViewer(const std::vector<std::string>& elfList) {
|
||||||
m_elf_viewer.resize(elfList.size());
|
m_elf_viewer.resize(elfList.size());
|
||||||
m_elf_viewer = elfList;
|
m_elf_viewer = elfList;
|
||||||
@ -620,22 +599,6 @@ void setSaveDataPath(const std::filesystem::path& path) {
|
|||||||
save_data_path = path;
|
save_data_path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 getMainWindowGeometryX() {
|
|
||||||
return main_window_geometry_x;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 getMainWindowGeometryY() {
|
|
||||||
return main_window_geometry_y;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 getMainWindowGeometryW() {
|
|
||||||
return main_window_geometry_w;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 getMainWindowGeometryH() {
|
|
||||||
return main_window_geometry_h;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::filesystem::path> getGameInstallDirs() {
|
const std::vector<std::filesystem::path> getGameInstallDirs() {
|
||||||
std::vector<std::filesystem::path> enabled_dirs;
|
std::vector<std::filesystem::path> enabled_dirs;
|
||||||
for (const auto& dir : settings_install_dirs) {
|
for (const auto& dir : settings_install_dirs) {
|
||||||
@ -686,14 +649,6 @@ u32 getTableMode() {
|
|||||||
return m_table_mode;
|
return m_table_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 getMainWindowWidth() {
|
|
||||||
return m_window_size_W;
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 getMainWindowHeight() {
|
|
||||||
return m_window_size_H;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::string> getElfViewer() {
|
std::vector<std::string> getElfViewer() {
|
||||||
return m_elf_viewer;
|
return m_elf_viewer;
|
||||||
}
|
}
|
||||||
@ -836,8 +791,6 @@ void load(const std::filesystem::path& path) {
|
|||||||
m_slider_pos = toml::find_or<int>(gui, "sliderPos", 0);
|
m_slider_pos = toml::find_or<int>(gui, "sliderPos", 0);
|
||||||
m_slider_pos_grid = toml::find_or<int>(gui, "sliderPosGrid", 0);
|
m_slider_pos_grid = toml::find_or<int>(gui, "sliderPosGrid", 0);
|
||||||
mw_themes = toml::find_or<int>(gui, "theme", 0);
|
mw_themes = toml::find_or<int>(gui, "theme", 0);
|
||||||
m_window_size_W = toml::find_or<int>(gui, "mw_width", 0);
|
|
||||||
m_window_size_H = toml::find_or<int>(gui, "mw_height", 0);
|
|
||||||
|
|
||||||
const auto install_dir_array =
|
const auto install_dir_array =
|
||||||
toml::find_or<std::vector<std::u8string>>(gui, "installDirs", {});
|
toml::find_or<std::vector<std::u8string>>(gui, "installDirs", {});
|
||||||
@ -862,10 +815,6 @@ void load(const std::filesystem::path& path) {
|
|||||||
save_data_path = toml::find_fs_path_or(gui, "saveDataPath", {});
|
save_data_path = toml::find_fs_path_or(gui, "saveDataPath", {});
|
||||||
|
|
||||||
settings_addon_install_dir = toml::find_fs_path_or(gui, "addonInstallDir", {});
|
settings_addon_install_dir = toml::find_fs_path_or(gui, "addonInstallDir", {});
|
||||||
main_window_geometry_x = toml::find_or<int>(gui, "geometry_x", 0);
|
|
||||||
main_window_geometry_y = toml::find_or<int>(gui, "geometry_y", 0);
|
|
||||||
main_window_geometry_w = toml::find_or<int>(gui, "geometry_w", 0);
|
|
||||||
main_window_geometry_h = toml::find_or<int>(gui, "geometry_h", 0);
|
|
||||||
m_elf_viewer = toml::find_or<std::vector<std::string>>(gui, "elfDirs", {});
|
m_elf_viewer = toml::find_or<std::vector<std::string>>(gui, "elfDirs", {});
|
||||||
m_recent_files = toml::find_or<std::vector<std::string>>(gui, "recentFiles", {});
|
m_recent_files = toml::find_or<std::vector<std::string>>(gui, "recentFiles", {});
|
||||||
m_table_mode = toml::find_or<int>(gui, "gameTableMode", 0);
|
m_table_mode = toml::find_or<int>(gui, "gameTableMode", 0);
|
||||||
@ -1071,18 +1020,12 @@ void saveMainWindow(const std::filesystem::path& path) {
|
|||||||
fmt::print("Saving new configuration file {}\n", fmt::UTF(path.u8string()));
|
fmt::print("Saving new configuration file {}\n", fmt::UTF(path.u8string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
data["GUI"]["mw_width"] = m_window_size_W;
|
|
||||||
data["GUI"]["mw_height"] = m_window_size_H;
|
|
||||||
data["GUI"]["theme"] = mw_themes;
|
data["GUI"]["theme"] = mw_themes;
|
||||||
data["GUI"]["iconSize"] = m_icon_size;
|
data["GUI"]["iconSize"] = m_icon_size;
|
||||||
data["GUI"]["sliderPos"] = m_slider_pos;
|
data["GUI"]["sliderPos"] = m_slider_pos;
|
||||||
data["GUI"]["iconSizeGrid"] = m_icon_size_grid;
|
data["GUI"]["iconSizeGrid"] = m_icon_size_grid;
|
||||||
data["GUI"]["sliderPosGrid"] = m_slider_pos_grid;
|
data["GUI"]["sliderPosGrid"] = m_slider_pos_grid;
|
||||||
data["GUI"]["gameTableMode"] = m_table_mode;
|
data["GUI"]["gameTableMode"] = m_table_mode;
|
||||||
data["GUI"]["geometry_x"] = main_window_geometry_x;
|
|
||||||
data["GUI"]["geometry_y"] = main_window_geometry_y;
|
|
||||||
data["GUI"]["geometry_w"] = main_window_geometry_w;
|
|
||||||
data["GUI"]["geometry_h"] = main_window_geometry_h;
|
|
||||||
data["GUI"]["elfDirs"] = m_elf_viewer;
|
data["GUI"]["elfDirs"] = m_elf_viewer;
|
||||||
data["GUI"]["recentFiles"] = m_recent_files;
|
data["GUI"]["recentFiles"] = m_recent_files;
|
||||||
|
|
||||||
|
@ -139,7 +139,6 @@ void setVkHostMarkersEnabled(bool enable);
|
|||||||
void setVkGuestMarkersEnabled(bool enable);
|
void setVkGuestMarkersEnabled(bool enable);
|
||||||
|
|
||||||
// Gui
|
// Gui
|
||||||
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h);
|
|
||||||
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled = true);
|
bool addGameInstallDir(const std::filesystem::path& dir, bool enabled = true);
|
||||||
void removeGameInstallDir(const std::filesystem::path& dir);
|
void removeGameInstallDir(const std::filesystem::path& dir);
|
||||||
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled);
|
void setGameInstallDirEnabled(const std::filesystem::path& dir, bool enabled);
|
||||||
@ -150,16 +149,10 @@ void setIconSizeGrid(u32 size);
|
|||||||
void setSliderPosition(u32 pos);
|
void setSliderPosition(u32 pos);
|
||||||
void setSliderPositionGrid(u32 pos);
|
void setSliderPositionGrid(u32 pos);
|
||||||
void setTableMode(u32 mode);
|
void setTableMode(u32 mode);
|
||||||
void setMainWindowWidth(u32 width);
|
|
||||||
void setMainWindowHeight(u32 height);
|
|
||||||
void setElfViewer(const std::vector<std::string>& elfList);
|
void setElfViewer(const std::vector<std::string>& elfList);
|
||||||
void setRecentFiles(const std::vector<std::string>& recentFiles);
|
void setRecentFiles(const std::vector<std::string>& recentFiles);
|
||||||
void setEmulatorLanguage(std::string language);
|
void setEmulatorLanguage(std::string language);
|
||||||
|
|
||||||
u32 getMainWindowGeometryX();
|
|
||||||
u32 getMainWindowGeometryY();
|
|
||||||
u32 getMainWindowGeometryW();
|
|
||||||
u32 getMainWindowGeometryH();
|
|
||||||
const std::vector<std::filesystem::path> getGameInstallDirs();
|
const std::vector<std::filesystem::path> getGameInstallDirs();
|
||||||
const std::vector<bool> getGameInstallDirsEnabled();
|
const std::vector<bool> getGameInstallDirsEnabled();
|
||||||
std::filesystem::path getAddonInstallDir();
|
std::filesystem::path getAddonInstallDir();
|
||||||
@ -169,8 +162,6 @@ u32 getIconSizeGrid();
|
|||||||
u32 getSliderPosition();
|
u32 getSliderPosition();
|
||||||
u32 getSliderPositionGrid();
|
u32 getSliderPositionGrid();
|
||||||
u32 getTableMode();
|
u32 getTableMode();
|
||||||
u32 getMainWindowWidth();
|
|
||||||
u32 getMainWindowHeight();
|
|
||||||
std::vector<std::string> getElfViewer();
|
std::vector<std::string> getElfViewer();
|
||||||
std::vector<std::string> getRecentFiles();
|
std::vector<std::string> getRecentFiles();
|
||||||
std::string getEmulatorLanguage();
|
std::string getEmulatorLanguage();
|
||||||
|
9
src/qt_gui/gui_settings.cpp
Normal file
9
src/qt_gui/gui_settings.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "gui_settings.h"
|
||||||
|
|
||||||
|
gui_settings::gui_settings(QObject* parent) : settings(parent) {
|
||||||
|
m_settings = std::make_unique<QSettings>(ComputeSettingsDir() + "qt_ui.ini",
|
||||||
|
QSettings::Format::IniFormat, parent);
|
||||||
|
}
|
23
src/qt_gui/gui_settings.h
Normal file
23
src/qt_gui/gui_settings.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QWindow>
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
namespace gui {
|
||||||
|
// categories
|
||||||
|
const QString main_window = "main_window";
|
||||||
|
|
||||||
|
// main window settions
|
||||||
|
const gui_value mw_geometry = gui_value(main_window, "geometry", QByteArray());
|
||||||
|
|
||||||
|
} // namespace gui
|
||||||
|
|
||||||
|
class gui_settings : public settings {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit gui_settings(QObject* parent = nullptr);
|
||||||
|
};
|
@ -32,6 +32,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
m_gui_settings = std::make_shared<gui_settings>();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {
|
MainWindow::~MainWindow() {
|
||||||
@ -934,9 +935,10 @@ void MainWindow::RefreshGameTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::ConfigureGuiFromSettings() {
|
void MainWindow::ConfigureGuiFromSettings() {
|
||||||
setGeometry(Config::getMainWindowGeometryX(), Config::getMainWindowGeometryY(),
|
if (!restoreGeometry(m_gui_settings->GetValue(gui::mw_geometry).toByteArray())) {
|
||||||
Config::getMainWindowGeometryW(), Config::getMainWindowGeometryH());
|
// By default, set the window to 70% of the screen
|
||||||
|
resize(QGuiApplication::primaryScreen()->availableSize() * 0.7);
|
||||||
|
}
|
||||||
ui->showGameListAct->setChecked(true);
|
ui->showGameListAct->setChecked(true);
|
||||||
if (Config::getTableMode() == 0) {
|
if (Config::getTableMode() == 0) {
|
||||||
ui->setlistModeListAct->setChecked(true);
|
ui->setlistModeListAct->setChecked(true);
|
||||||
@ -948,11 +950,8 @@ void MainWindow::ConfigureGuiFromSettings() {
|
|||||||
BackgroundMusicPlayer::getInstance().setVolume(Config::getBGMvolume());
|
BackgroundMusicPlayer::getInstance().setVolume(Config::getBGMvolume());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::SaveWindowState() const {
|
void MainWindow::SaveWindowState() {
|
||||||
Config::setMainWindowWidth(this->width());
|
m_gui_settings->SetValue(gui::mw_geometry, saveGeometry(), false);
|
||||||
Config::setMainWindowHeight(this->height());
|
|
||||||
Config::setMainWindowGeometry(this->geometry().x(), this->geometry().y(),
|
|
||||||
this->geometry().width(), this->geometry().height());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::BootGame() {
|
void MainWindow::BootGame() {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "game_info.h"
|
#include "game_info.h"
|
||||||
#include "game_list_frame.h"
|
#include "game_list_frame.h"
|
||||||
#include "game_list_utils.h"
|
#include "game_list_utils.h"
|
||||||
|
#include "gui_settings.h"
|
||||||
#include "main_window_themes.h"
|
#include "main_window_themes.h"
|
||||||
#include "main_window_ui.h"
|
#include "main_window_ui.h"
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ public:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void ConfigureGuiFromSettings();
|
void ConfigureGuiFromSettings();
|
||||||
void SaveWindowState() const;
|
void SaveWindowState();
|
||||||
void SearchGameTable(const QString& text);
|
void SearchGameTable(const QString& text);
|
||||||
void ShowGameList();
|
void ShowGameList();
|
||||||
void RefreshGameTable();
|
void RefreshGameTable();
|
||||||
@ -103,6 +104,7 @@ private:
|
|||||||
std::make_shared<CompatibilityInfoClass>();
|
std::make_shared<CompatibilityInfoClass>();
|
||||||
|
|
||||||
QTranslator* translator;
|
QTranslator* translator;
|
||||||
|
std::shared_ptr<gui_settings> m_gui_settings;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
bool eventFilter(QObject* obj, QEvent* event) override;
|
||||||
|
77
src/qt_gui/settings.cpp
Normal file
77
src/qt_gui/settings.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <common/path_util.h>
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
settings::settings(QObject* parent) : QObject(parent), m_settings_dir(ComputeSettingsDir()) {}
|
||||||
|
|
||||||
|
settings::~settings() {
|
||||||
|
sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
void settings::sync() {
|
||||||
|
if (m_settings) {
|
||||||
|
m_settings->sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString settings::GetSettingsDir() const {
|
||||||
|
return m_settings_dir.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString settings::ComputeSettingsDir() {
|
||||||
|
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||||
|
return QString::fromStdString(config_dir.string() + "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
void settings::RemoveValue(const QString& key, const QString& name, bool sync) const {
|
||||||
|
if (m_settings) {
|
||||||
|
m_settings->beginGroup(key);
|
||||||
|
m_settings->remove(name);
|
||||||
|
m_settings->endGroup();
|
||||||
|
|
||||||
|
if (sync) {
|
||||||
|
m_settings->sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void settings::RemoveValue(const gui_value& entry, bool sync) const {
|
||||||
|
RemoveValue(entry.key, entry.name, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant settings::GetValue(const QString& key, const QString& name, const QVariant& def) const {
|
||||||
|
return m_settings ? m_settings->value(key + "/" + name, def) : def;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant settings::GetValue(const gui_value& entry) const {
|
||||||
|
return GetValue(entry.key, entry.name, entry.def);
|
||||||
|
}
|
||||||
|
|
||||||
|
void settings::SetValue(const gui_value& entry, const QVariant& value, bool sync) const {
|
||||||
|
SetValue(entry.key, entry.name, value, sync);
|
||||||
|
}
|
||||||
|
|
||||||
|
void settings::SetValue(const QString& key, const QVariant& value, bool sync) const {
|
||||||
|
if (m_settings) {
|
||||||
|
m_settings->setValue(key, value);
|
||||||
|
|
||||||
|
if (sync) {
|
||||||
|
m_settings->sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void settings::SetValue(const QString& key, const QString& name, const QVariant& value,
|
||||||
|
bool sync) const {
|
||||||
|
if (m_settings) {
|
||||||
|
m_settings->beginGroup(key);
|
||||||
|
m_settings->setValue(name, value);
|
||||||
|
m_settings->endGroup();
|
||||||
|
|
||||||
|
if (sync) {
|
||||||
|
m_settings->sync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
56
src/qt_gui/settings.h
Normal file
56
src/qt_gui/settings.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2025 shadPS4 Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVariant>
|
||||||
|
#include "gui_save.h"
|
||||||
|
|
||||||
|
struct gui_value {
|
||||||
|
QString key;
|
||||||
|
QString name;
|
||||||
|
QVariant def;
|
||||||
|
|
||||||
|
gui_value() {}
|
||||||
|
|
||||||
|
gui_value(const QString& k, const QString& n, const QVariant& d) : key(k), name(n), def(d) {}
|
||||||
|
|
||||||
|
bool operator==(const gui_value& rhs) const noexcept {
|
||||||
|
return key == rhs.key && name == rhs.name && def == rhs.def;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class settings : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit settings(QObject* parent = nullptr);
|
||||||
|
~settings();
|
||||||
|
|
||||||
|
void sync();
|
||||||
|
|
||||||
|
QString GetSettingsDir() const;
|
||||||
|
|
||||||
|
QVariant GetValue(const QString& key, const QString& name, const QVariant& def) const;
|
||||||
|
QVariant GetValue(const gui_value& entry) const;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
/** Remove entry */
|
||||||
|
void RemoveValue(const QString& key, const QString& name, bool sync = true) const;
|
||||||
|
void RemoveValue(const gui_value& entry, bool sync = true) const;
|
||||||
|
|
||||||
|
/** Write value to entry */
|
||||||
|
void SetValue(const gui_value& entry, const QVariant& value, bool sync = true) const;
|
||||||
|
void SetValue(const QString& key, const QVariant& value, bool sync = true) const;
|
||||||
|
void SetValue(const QString& key, const QString& name, const QVariant& value,
|
||||||
|
bool sync = true) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static QString ComputeSettingsDir();
|
||||||
|
|
||||||
|
std::unique_ptr<QSettings> m_settings;
|
||||||
|
QDir m_settings_dir;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user