Give settings managers default groups instead of manually specifying them everywhere. (#6273)

* Give settings managers default groups instead of manually specifying them everywhere.

Took 1 hour 2 minutes


Took 41 seconds

Took 32 seconds

Took 5 minutes

* Fix dbconverter mock.

Took 2 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-11-15 15:58:25 +01:00 committed by GitHub
parent 5df00de246
commit f62e29f5d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 161 additions and 83 deletions

View file

@ -5,7 +5,7 @@
#include <QtMath> #include <QtMath>
CardCounterSettings::CardCounterSettings(const QString &settingsPath, QObject *parent) CardCounterSettings::CardCounterSettings(const QString &settingsPath, QObject *parent)
: SettingsManager(settingsPath + "global.ini", parent) : SettingsManager(settingsPath + "global.ini", "cards", "counters", parent)
{ {
} }

View file

@ -2,7 +2,7 @@
#include "mocks.h" #include "mocks.h"
CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject *parent) CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "cardDatabase.ini", parent) : SettingsManager(settingPath + "cardDatabase.ini", QString(), QString(), parent)
{ {
} }
void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */) void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */)

View file

@ -1,7 +1,7 @@
#include "card_database_settings.h" #include "card_database_settings.h"
CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject *parent) CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "cardDatabase.ini", parent) : SettingsManager(settingPath + "cardDatabase.ini", QString(), QString(), parent)
{ {
} }

View file

@ -1,21 +1,21 @@
#include "card_override_settings.h" #include "card_override_settings.h"
CardOverrideSettings::CardOverrideSettings(const QString &settingPath, QObject *parent) CardOverrideSettings::CardOverrideSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "cardPreferenceOverrides.ini", parent) : SettingsManager(settingPath + "cardPreferenceOverrides.ini", "cards", QString(), parent)
{ {
} }
void CardOverrideSettings::setCardPreferenceOverride(const CardRef &cardRef) void CardOverrideSettings::setCardPreferenceOverride(const CardRef &cardRef)
{ {
setValue(cardRef.providerId, cardRef.name, "cards"); setValue(cardRef.providerId, cardRef.name);
} }
void CardOverrideSettings::deleteCardPreferenceOverride(const QString &cardName) void CardOverrideSettings::deleteCardPreferenceOverride(const QString &cardName)
{ {
deleteValue(cardName, "cards"); deleteValue(cardName);
} }
QString CardOverrideSettings::getCardPreferenceOverride(const QString &cardName) QString CardOverrideSettings::getCardPreferenceOverride(const QString &cardName)
{ {
return getValue(cardName, "cards").toString(); return getValue(cardName).toString();
} }

View file

@ -3,7 +3,7 @@
#include <QtCore/QFile> #include <QtCore/QFile>
DebugSettings::DebugSettings(const QString &settingPath, QObject *parent) DebugSettings::DebugSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "debug.ini", parent) : SettingsManager(settingPath + "debug.ini", "debug", QString(), parent)
{ {
// Create the default debug.ini if it doesn't exist yet // Create the default debug.ini if it doesn't exist yet
if (!QFile(settingPath + "debug.ini").exists()) { if (!QFile(settingPath + "debug.ini").exists()) {
@ -13,7 +13,7 @@ DebugSettings::DebugSettings(const QString &settingPath, QObject *parent)
bool DebugSettings::getShowCardId() bool DebugSettings::getShowCardId()
{ {
return getValue("showCardId", "debug").toBool(); return getValue("showCardId").toBool();
} }
bool DebugSettings::getLocalGameOnStartup() bool DebugSettings::getLocalGameOnStartup()

View file

@ -9,21 +9,21 @@ const QStringList DownloadSettings::DEFAULT_DOWNLOAD_URLS = {
"https://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card"}; "https://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card"};
DownloadSettings::DownloadSettings(const QString &settingPath, QObject *parent = nullptr) DownloadSettings::DownloadSettings(const QString &settingPath, QObject *parent = nullptr)
: SettingsManager(settingPath + "downloads.ini", parent) : SettingsManager(settingPath + "downloads.ini", "downloads", QString(), parent)
{ {
} }
void DownloadSettings::setDownloadUrls(const QStringList &downloadURLs) void DownloadSettings::setDownloadUrls(const QStringList &downloadURLs)
{ {
setValue(QVariant::fromValue(downloadURLs), "urls", "downloads"); setValue(QVariant::fromValue(downloadURLs), "urls");
} }
QStringList DownloadSettings::getAllURLs() QStringList DownloadSettings::getAllURLs()
{ {
return getValue("urls", "downloads").toStringList(); return getValue("urls").toStringList();
} }
void DownloadSettings::resetToDefaultURLs() void DownloadSettings::resetToDefaultURLs()
{ {
setValue(QVariant::fromValue(DEFAULT_DOWNLOAD_URLS), "urls", "downloads"); setValue(QVariant::fromValue(DEFAULT_DOWNLOAD_URLS), "urls");
} }

View file

@ -4,7 +4,7 @@
#include <QTime> #include <QTime>
GameFiltersSettings::GameFiltersSettings(const QString &settingPath, QObject *parent) GameFiltersSettings::GameFiltersSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "gamefilters.ini", parent) : SettingsManager(settingPath + "gamefilters.ini", "filter_games", QString(), parent)
{ {
} }
@ -19,190 +19,190 @@ QString GameFiltersSettings::hashGameType(const QString &gameType) const
void GameFiltersSettings::setHideBuddiesOnlyGames(bool hide) void GameFiltersSettings::setHideBuddiesOnlyGames(bool hide)
{ {
setValue(hide, "hide_buddies_only_games", "filter_games"); setValue(hide, "hide_buddies_only_games");
} }
bool GameFiltersSettings::isHideBuddiesOnlyGames() bool GameFiltersSettings::isHideBuddiesOnlyGames()
{ {
QVariant previous = getValue("hide_buddies_only_games", "filter_games"); QVariant previous = getValue("hide_buddies_only_games");
return previous == QVariant() || previous.toBool(); return previous == QVariant() || previous.toBool();
} }
void GameFiltersSettings::setHideFullGames(bool hide) void GameFiltersSettings::setHideFullGames(bool hide)
{ {
setValue(hide, "hide_full_games", "filter_games"); setValue(hide, "hide_full_games");
} }
bool GameFiltersSettings::isHideFullGames() bool GameFiltersSettings::isHideFullGames()
{ {
QVariant previous = getValue("hide_full_games", "filter_games"); QVariant previous = getValue("hide_full_games");
return !(previous == QVariant()) && previous.toBool(); return !(previous == QVariant()) && previous.toBool();
} }
void GameFiltersSettings::setHideGamesThatStarted(bool hide) void GameFiltersSettings::setHideGamesThatStarted(bool hide)
{ {
setValue(hide, "hide_games_that_started", "filter_games"); setValue(hide, "hide_games_that_started");
} }
bool GameFiltersSettings::isHideGamesThatStarted() bool GameFiltersSettings::isHideGamesThatStarted()
{ {
QVariant previous = getValue("hide_games_that_started", "filter_games"); QVariant previous = getValue("hide_games_that_started");
return !(previous == QVariant()) && previous.toBool(); return !(previous == QVariant()) && previous.toBool();
} }
void GameFiltersSettings::setHidePasswordProtectedGames(bool hide) void GameFiltersSettings::setHidePasswordProtectedGames(bool hide)
{ {
setValue(hide, "hide_password_protected_games", "filter_games"); setValue(hide, "hide_password_protected_games");
} }
bool GameFiltersSettings::isHidePasswordProtectedGames() bool GameFiltersSettings::isHidePasswordProtectedGames()
{ {
QVariant previous = getValue("hide_password_protected_games", "filter_games"); QVariant previous = getValue("hide_password_protected_games");
return previous == QVariant() || previous.toBool(); return previous == QVariant() || previous.toBool();
} }
void GameFiltersSettings::setHideIgnoredUserGames(bool hide) void GameFiltersSettings::setHideIgnoredUserGames(bool hide)
{ {
setValue(hide, "hide_ignored_user_games", "filter_games"); setValue(hide, "hide_ignored_user_games");
} }
bool GameFiltersSettings::isHideIgnoredUserGames() bool GameFiltersSettings::isHideIgnoredUserGames()
{ {
QVariant previous = getValue("hide_ignored_user_games", "filter_games"); QVariant previous = getValue("hide_ignored_user_games");
return !(previous == QVariant()) && previous.toBool(); return !(previous == QVariant()) && previous.toBool();
} }
void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide) void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide)
{ {
setValue(hide, "hide_not_buddy_created_games", "filter_games"); setValue(hide, "hide_not_buddy_created_games");
} }
bool GameFiltersSettings::isHideNotBuddyCreatedGames() bool GameFiltersSettings::isHideNotBuddyCreatedGames()
{ {
QVariant previous = getValue("hide_not_buddy_created_games", "filter_games"); QVariant previous = getValue("hide_not_buddy_created_games");
return !(previous == QVariant()) && previous.toBool(); return !(previous == QVariant()) && previous.toBool();
} }
void GameFiltersSettings::setHideOpenDecklistGames(bool hide) void GameFiltersSettings::setHideOpenDecklistGames(bool hide)
{ {
setValue(hide, "hide_open_decklist_games", "filter_games"); setValue(hide, "hide_open_decklist_games");
} }
bool GameFiltersSettings::isHideOpenDecklistGames() bool GameFiltersSettings::isHideOpenDecklistGames()
{ {
QVariant previous = getValue("hide_open_decklist_games", "filter_games"); QVariant previous = getValue("hide_open_decklist_games");
return !(previous == QVariant()) && previous.toBool(); return !(previous == QVariant()) && previous.toBool();
} }
void GameFiltersSettings::setGameNameFilter(QString gameName) void GameFiltersSettings::setGameNameFilter(QString gameName)
{ {
setValue(gameName, "game_name_filter", "filter_games"); setValue(gameName, "game_name_filter");
} }
QString GameFiltersSettings::getGameNameFilter() QString GameFiltersSettings::getGameNameFilter()
{ {
return getValue("game_name_filter", "filter_games").toString(); return getValue("game_name_filter").toString();
} }
void GameFiltersSettings::setCreatorNameFilter(QString creatorName) void GameFiltersSettings::setCreatorNameFilter(QString creatorName)
{ {
setValue(creatorName, "creator_name_filter", "filter_games"); setValue(creatorName, "creator_name_filter");
} }
QString GameFiltersSettings::getCreatorNameFilter() QString GameFiltersSettings::getCreatorNameFilter()
{ {
return getValue("creator_name_filter", "filter_games").toString(); return getValue("creator_name_filter").toString();
} }
void GameFiltersSettings::setMinPlayers(int min) void GameFiltersSettings::setMinPlayers(int min)
{ {
setValue(min, "min_players", "filter_games"); setValue(min, "min_players");
} }
int GameFiltersSettings::getMinPlayers() int GameFiltersSettings::getMinPlayers()
{ {
QVariant previous = getValue("min_players", "filter_games"); QVariant previous = getValue("min_players");
return previous == QVariant() ? 1 : previous.toInt(); return previous == QVariant() ? 1 : previous.toInt();
} }
void GameFiltersSettings::setMaxPlayers(int max) void GameFiltersSettings::setMaxPlayers(int max)
{ {
setValue(max, "max_players", "filter_games"); setValue(max, "max_players");
} }
int GameFiltersSettings::getMaxPlayers() int GameFiltersSettings::getMaxPlayers()
{ {
QVariant previous = getValue("max_players", "filter_games"); QVariant previous = getValue("max_players");
return previous == QVariant() ? 99 : previous.toInt(); return previous == QVariant() ? 99 : previous.toInt();
} }
void GameFiltersSettings::setMaxGameAge(const QTime &maxGameAge) void GameFiltersSettings::setMaxGameAge(const QTime &maxGameAge)
{ {
setValue(maxGameAge, "max_game_age_time", "filter_games"); setValue(maxGameAge, "max_game_age_time");
} }
QTime GameFiltersSettings::getMaxGameAge() QTime GameFiltersSettings::getMaxGameAge()
{ {
QVariant previous = getValue("max_game_age_time", "filter_games"); QVariant previous = getValue("max_game_age_time");
return previous.toTime(); return previous.toTime();
} }
void GameFiltersSettings::setGameTypeEnabled(QString gametype, bool enabled) void GameFiltersSettings::setGameTypeEnabled(QString gametype, bool enabled)
{ {
setValue(enabled, "game_type/" + hashGameType(gametype), "filter_games"); setValue(enabled, "game_type/" + hashGameType(gametype));
} }
void GameFiltersSettings::setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled) void GameFiltersSettings::setGameHashedTypeEnabled(QString gametypeHASHED, bool enabled)
{ {
setValue(enabled, gametypeHASHED, "filter_games"); setValue(enabled, gametypeHASHED);
} }
bool GameFiltersSettings::isGameTypeEnabled(QString gametype) bool GameFiltersSettings::isGameTypeEnabled(QString gametype)
{ {
QVariant previous = getValue("game_type/" + hashGameType(gametype), "filter_games"); QVariant previous = getValue("game_type/" + hashGameType(gametype));
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
} }
void GameFiltersSettings::setShowOnlyIfSpectatorsCanWatch(bool show) void GameFiltersSettings::setShowOnlyIfSpectatorsCanWatch(bool show)
{ {
setValue(show, "show_only_if_spectators_can_watch", "filter_games"); setValue(show, "show_only_if_spectators_can_watch");
} }
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch() bool GameFiltersSettings::isShowOnlyIfSpectatorsCanWatch()
{ {
QVariant previous = getValue("show_only_if_spectators_can_watch", "filter_games"); QVariant previous = getValue("show_only_if_spectators_can_watch");
return previous == QVariant() ? false : previous.toBool(); return previous == QVariant() ? false : previous.toBool();
} }
void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show) void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show)
{ {
setValue(show, "show_spectator_password_protected", "filter_games"); setValue(show, "show_spectator_password_protected");
} }
bool GameFiltersSettings::isShowSpectatorPasswordProtected() bool GameFiltersSettings::isShowSpectatorPasswordProtected()
{ {
QVariant previous = getValue("show_spectator_password_protected", "filter_games"); QVariant previous = getValue("show_spectator_password_protected");
return previous == QVariant() ? true : previous.toBool(); return previous == QVariant() ? true : previous.toBool();
} }
void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show) void GameFiltersSettings::setShowOnlyIfSpectatorsCanChat(bool show)
{ {
setValue(show, "show_only_if_spectators_can_chat", "filter_games"); setValue(show, "show_only_if_spectators_can_chat");
} }
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat() bool GameFiltersSettings::isShowOnlyIfSpectatorsCanChat()
{ {
QVariant previous = getValue("show_only_if_spectators_can_chat", "filter_games"); QVariant previous = getValue("show_only_if_spectators_can_chat");
return previous == QVariant() ? true : previous.toBool(); return previous == QVariant() ? true : previous.toBool();
} }
void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show) void GameFiltersSettings::setShowOnlyIfSpectatorsCanSeeHands(bool show)
{ {
setValue(show, "show_only_if_spectators_can_see_hands", "filter_games"); setValue(show, "show_only_if_spectators_can_see_hands");
} }
bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands() bool GameFiltersSettings::isShowOnlyIfSpectatorsCanSeeHands()
{ {
QVariant previous = getValue("show_only_if_spectators_can_see_hands", "filter_games"); QVariant previous = getValue("show_only_if_spectators_can_see_hands");
return previous == QVariant() ? true : previous.toBool(); return previous == QVariant() ? true : previous.toBool();
} }

View file

@ -1,7 +1,7 @@
#include "layouts_settings.h" #include "layouts_settings.h"
LayoutsSettings::LayoutsSettings(const QString &settingPath, QObject *parent) LayoutsSettings::LayoutsSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "layouts.ini", parent) : SettingsManager(settingPath + "layouts.ini", "layouts", QString(), parent)
{ {
} }

View file

@ -1,26 +1,26 @@
#include "message_settings.h" #include "message_settings.h"
MessageSettings::MessageSettings(const QString &settingPath, QObject *parent) MessageSettings::MessageSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "messages.ini", parent) : SettingsManager(settingPath + "messages.ini", "messages", QString(), parent)
{ {
} }
QString MessageSettings::getMessageAt(int index) QString MessageSettings::getMessageAt(int index)
{ {
return getValue(QString("msg%1").arg(index), "messages").toString(); return getValue(QString("msg%1").arg(index)).toString();
} }
int MessageSettings::getCount() int MessageSettings::getCount()
{ {
return getValue("count", "messages").toInt(); return getValue("count").toInt();
} }
void MessageSettings::setCount(int count) void MessageSettings::setCount(int count)
{ {
setValue(count, "count", "messages"); setValue(count, "count");
} }
void MessageSettings::setMessageAt(int index, QString message) void MessageSettings::setMessageAt(int index, QString message)
{ {
setValue(message, QString("msg%1").arg(index), "messages"); setValue(message, QString("msg%1").arg(index));
} }

View file

@ -3,22 +3,22 @@
#define MAX_RECENT_DECK_COUNT 10 #define MAX_RECENT_DECK_COUNT 10
RecentsSettings::RecentsSettings(const QString &settingPath, QObject *parent) RecentsSettings::RecentsSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "recents.ini", parent) : SettingsManager(settingPath + "recents.ini", "deckbuilder", QString(), parent)
{ {
} }
QStringList RecentsSettings::getRecentlyOpenedDeckPaths() QStringList RecentsSettings::getRecentlyOpenedDeckPaths()
{ {
return getValue("deckpaths", "deckbuilder").toStringList(); return getValue("deckpaths").toStringList();
} }
void RecentsSettings::clearRecentlyOpenedDeckPaths() void RecentsSettings::clearRecentlyOpenedDeckPaths()
{ {
deleteValue("deckpaths", "deckbuilder"); deleteValue("deckpaths");
emit recentlyOpenedDeckPathsChanged(); emit recentlyOpenedDeckPathsChanged();
} }
void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath) void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
{ {
auto deckPaths = getValue("deckpaths", "deckbuilder").toStringList(); auto deckPaths = getValue("deckpaths").toStringList();
deckPaths.removeAll(deckPath); deckPaths.removeAll(deckPath);
deckPaths.prepend(deckPath); deckPaths.prepend(deckPath);
@ -27,7 +27,7 @@ void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
deckPaths.removeLast(); deckPaths.removeLast();
} }
setValue(deckPaths, "deckpaths", "deckbuilder"); setValue(deckPaths, "deckpaths");
emit recentlyOpenedDeckPathsChanged(); emit recentlyOpenedDeckPathsChanged();
} }

View file

@ -4,34 +4,34 @@
#include <utility> #include <utility>
ServersSettings::ServersSettings(const QString &settingPath, QObject *parent) ServersSettings::ServersSettings(const QString &settingPath, QObject *parent)
: SettingsManager(settingPath + "servers.ini", parent) : SettingsManager(settingPath + "servers.ini", "server", QString(), parent)
{ {
} }
void ServersSettings::setPreviousHostLogin(int previous) void ServersSettings::setPreviousHostLogin(int previous)
{ {
setValue(previous, "previoushostlogin", "server"); setValue(previous, "previoushostlogin");
} }
int ServersSettings::getPreviousHostLogin() int ServersSettings::getPreviousHostLogin()
{ {
QVariant previous = getValue("previoushostlogin", "server"); QVariant previous = getValue("previoushostlogin");
return previous == QVariant() ? 1 : previous.toInt(); return previous == QVariant() ? 1 : previous.toInt();
} }
void ServersSettings::setPreviousHostList(QStringList list) void ServersSettings::setPreviousHostList(QStringList list)
{ {
setValue(list, "previoushosts", "server"); setValue(list, "previoushosts");
} }
QStringList ServersSettings::getPreviousHostList() QStringList ServersSettings::getPreviousHostList()
{ {
return getValue("previoushosts", "server").toStringList(); return getValue("previoushosts").toStringList();
} }
void ServersSettings::setPrevioushostName(const QString &name) void ServersSettings::setPrevioushostName(const QString &name)
{ {
setValue(name, "previoushostName", "server"); setValue(name, "previoushostName");
} }
QString ServersSettings::getSaveName(QString defaultname) QString ServersSettings::getSaveName(QString defaultname)
@ -50,7 +50,7 @@ QString ServersSettings::getSite(QString defaultSite)
QString ServersSettings::getPrevioushostName() QString ServersSettings::getPrevioushostName()
{ {
QVariant value = getValue("previoushostName", "server"); QVariant value = getValue("previoushostName");
return value == QVariant() ? "Rooster Ranges" : value.toString(); return value == QVariant() ? "Rooster Ranges" : value.toString();
} }
@ -107,56 +107,56 @@ bool ServersSettings::getSavePassword()
void ServersSettings::setAutoConnect(int autoconnect) void ServersSettings::setAutoConnect(int autoconnect)
{ {
setValue(autoconnect, "auto_connect", "server"); setValue(autoconnect, "auto_connect");
} }
int ServersSettings::getAutoConnect() int ServersSettings::getAutoConnect()
{ {
QVariant autoconnect = getValue("auto_connect", "server"); QVariant autoconnect = getValue("auto_connect");
return autoconnect == QVariant() ? 0 : autoconnect.toInt(); return autoconnect == QVariant() ? 0 : autoconnect.toInt();
} }
void ServersSettings::setFPHostName(QString hostname) void ServersSettings::setFPHostName(QString hostname)
{ {
setValue(hostname, "fphostname", "server"); setValue(hostname, "fphostname");
} }
QString ServersSettings::getFPHostname(QString defaultHost) QString ServersSettings::getFPHostname(QString defaultHost)
{ {
QVariant hostname = getValue("fphostname", "server"); QVariant hostname = getValue("fphostname");
return hostname == QVariant() ? std::move(defaultHost) : hostname.toString(); return hostname == QVariant() ? std::move(defaultHost) : hostname.toString();
} }
void ServersSettings::setFPPort(QString port) void ServersSettings::setFPPort(QString port)
{ {
setValue(port, "fpport", "server"); setValue(port, "fpport");
} }
QString ServersSettings::getFPPort(QString defaultPort) QString ServersSettings::getFPPort(QString defaultPort)
{ {
QVariant port = getValue("fpport", "server"); QVariant port = getValue("fpport");
return port == QVariant() ? std::move(defaultPort) : port.toString(); return port == QVariant() ? std::move(defaultPort) : port.toString();
} }
void ServersSettings::setFPPlayerName(QString playerName) void ServersSettings::setFPPlayerName(QString playerName)
{ {
setValue(playerName, "fpplayername", "server"); setValue(playerName, "fpplayername");
} }
QString ServersSettings::getFPPlayerName(QString defaultName) QString ServersSettings::getFPPlayerName(QString defaultName)
{ {
QVariant name = getValue("fpplayername", "server"); QVariant name = getValue("fpplayername");
return name == QVariant() ? std::move(defaultName) : name.toString(); return name == QVariant() ? std::move(defaultName) : name.toString();
} }
void ServersSettings::setClearDebugLogStatus(bool abIsChecked) void ServersSettings::setClearDebugLogStatus(bool abIsChecked)
{ {
setValue(abIsChecked, "save_debug_log", "server"); setValue(abIsChecked, "save_debug_log");
} }
bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue) bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue)
{ {
QVariant cbFlushLog = getValue("save_debug_log", "server"); QVariant cbFlushLog = getValue("save_debug_log");
return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool(); return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool();
} }

View file

@ -1,10 +1,35 @@
#include "settings_manager.h" #include "settings_manager.h"
SettingsManager::SettingsManager(const QString &settingPath, QObject *parent) SettingsManager::SettingsManager(const QString &settingPath,
: QObject(parent), settings(settingPath, QSettings::IniFormat) const QString &_defaultGroup,
const QString &_defaultSubGroup,
QObject *parent)
: QObject(parent), settings(settingPath, QSettings::IniFormat), defaultGroup(_defaultGroup),
defaultSubGroup(_defaultSubGroup)
{ {
} }
void SettingsManager::setValue(const QVariant &value, const QString &name)
{
if (!defaultGroup.isEmpty()) {
settings.beginGroup(defaultGroup);
}
if (!defaultSubGroup.isEmpty()) {
settings.beginGroup(defaultSubGroup);
}
settings.setValue(name, value);
if (!defaultSubGroup.isEmpty()) {
settings.endGroup();
}
if (!defaultGroup.isEmpty()) {
settings.endGroup();
}
}
void SettingsManager::setValue(const QVariant &value, void SettingsManager::setValue(const QVariant &value,
const QString &name, const QString &name,
const QString &group, const QString &group,
@ -29,6 +54,27 @@ void SettingsManager::setValue(const QVariant &value,
} }
} }
void SettingsManager::deleteValue(const QString &name)
{
if (!defaultGroup.isEmpty()) {
settings.beginGroup(defaultGroup);
}
if (!defaultSubGroup.isEmpty()) {
settings.beginGroup(defaultSubGroup);
}
settings.remove(name);
if (!defaultSubGroup.isEmpty()) {
settings.endGroup();
}
if (!defaultGroup.isEmpty()) {
settings.endGroup();
}
}
void SettingsManager::deleteValue(const QString &name, const QString &group, const QString &subGroup) void SettingsManager::deleteValue(const QString &name, const QString &group, const QString &subGroup)
{ {
if (!group.isEmpty()) { if (!group.isEmpty()) {
@ -50,6 +96,29 @@ void SettingsManager::deleteValue(const QString &name, const QString &group, con
} }
} }
QVariant SettingsManager::getValue(const QString &name)
{
if (!defaultGroup.isEmpty()) {
settings.beginGroup(defaultGroup);
}
if (!defaultSubGroup.isEmpty()) {
settings.beginGroup(defaultSubGroup);
}
QVariant value = settings.value(name);
if (!defaultSubGroup.isEmpty()) {
settings.endGroup();
}
if (!defaultGroup.isEmpty()) {
settings.endGroup();
}
return value;
}
QVariant SettingsManager::getValue(const QString &name, const QString &group, const QString &subGroup) QVariant SettingsManager::getValue(const QString &name, const QString &group, const QString &subGroup)
{ {
if (!group.isEmpty()) { if (!group.isEmpty()) {

View file

@ -16,14 +16,23 @@ class SettingsManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SettingsManager(const QString &settingPath, QObject *parent = nullptr); explicit SettingsManager(const QString &settingPath,
QVariant getValue(const QString &name, const QString &group = "", const QString &subGroup = ""); const QString &defaultGroup = QString(),
const QString &defaultSubGroup = QString(),
QObject *parent = nullptr);
QVariant getValue(const QString &name);
QVariant getValue(const QString &name, const QString &group, const QString &subGroup = QString());
void sync(); void sync();
protected: protected:
QSettings settings; QSettings settings;
void setValue(const QVariant &value, const QString &name, const QString &group = "", const QString &subGroup = ""); QString defaultGroup;
void deleteValue(const QString &name, const QString &group = "", const QString &subGroup = ""); QString defaultSubGroup;
void setValue(const QVariant &value, const QString &name);
void
setValue(const QVariant &value, const QString &name, const QString &group, const QString &subGroup = QString());
void deleteValue(const QString &name);
void deleteValue(const QString &name, const QString &group, const QString &subGroup = QString());
}; };
#endif // SETTINGSMANAGER_H #endif // SETTINGSMANAGER_H