mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 07:40:30 -08:00
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:
@@ -5,7 +5,7 @@
|
||||
#include <QtMath>
|
||||
|
||||
CardCounterSettings::CardCounterSettings(const QString &settingsPath, QObject *parent)
|
||||
: SettingsManager(settingsPath + "global.ini", parent)
|
||||
: SettingsManager(settingsPath + "global.ini", "cards", "counters", parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "mocks.h"
|
||||
|
||||
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 */)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "card_database_settings.h"
|
||||
|
||||
CardDatabaseSettings::CardDatabaseSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "cardDatabase.ini", parent)
|
||||
: SettingsManager(settingPath + "cardDatabase.ini", QString(), QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "card_override_settings.h"
|
||||
|
||||
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)
|
||||
{
|
||||
setValue(cardRef.providerId, cardRef.name, "cards");
|
||||
setValue(cardRef.providerId, cardRef.name);
|
||||
}
|
||||
|
||||
void CardOverrideSettings::deleteCardPreferenceOverride(const QString &cardName)
|
||||
{
|
||||
deleteValue(cardName, "cards");
|
||||
deleteValue(cardName);
|
||||
}
|
||||
|
||||
QString CardOverrideSettings::getCardPreferenceOverride(const QString &cardName)
|
||||
{
|
||||
return getValue(cardName, "cards").toString();
|
||||
return getValue(cardName).toString();
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <QtCore/QFile>
|
||||
|
||||
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
|
||||
if (!QFile(settingPath + "debug.ini").exists()) {
|
||||
@@ -13,7 +13,7 @@ DebugSettings::DebugSettings(const QString &settingPath, QObject *parent)
|
||||
|
||||
bool DebugSettings::getShowCardId()
|
||||
{
|
||||
return getValue("showCardId", "debug").toBool();
|
||||
return getValue("showCardId").toBool();
|
||||
}
|
||||
|
||||
bool DebugSettings::getLocalGameOnStartup()
|
||||
|
||||
@@ -9,21 +9,21 @@ const QStringList DownloadSettings::DEFAULT_DOWNLOAD_URLS = {
|
||||
"https://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card"};
|
||||
|
||||
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)
|
||||
{
|
||||
setValue(QVariant::fromValue(downloadURLs), "urls", "downloads");
|
||||
setValue(QVariant::fromValue(downloadURLs), "urls");
|
||||
}
|
||||
|
||||
QStringList DownloadSettings::getAllURLs()
|
||||
{
|
||||
return getValue("urls", "downloads").toStringList();
|
||||
return getValue("urls").toStringList();
|
||||
}
|
||||
|
||||
void DownloadSettings::resetToDefaultURLs()
|
||||
{
|
||||
setValue(QVariant::fromValue(DEFAULT_DOWNLOAD_URLS), "urls", "downloads");
|
||||
setValue(QVariant::fromValue(DEFAULT_DOWNLOAD_URLS), "urls");
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QTime>
|
||||
|
||||
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)
|
||||
{
|
||||
setValue(hide, "hide_buddies_only_games", "filter_games");
|
||||
setValue(hide, "hide_buddies_only_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideBuddiesOnlyGames()
|
||||
{
|
||||
QVariant previous = getValue("hide_buddies_only_games", "filter_games");
|
||||
QVariant previous = getValue("hide_buddies_only_games");
|
||||
return previous == QVariant() || previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideFullGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_full_games", "filter_games");
|
||||
setValue(hide, "hide_full_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideFullGames()
|
||||
{
|
||||
QVariant previous = getValue("hide_full_games", "filter_games");
|
||||
QVariant previous = getValue("hide_full_games");
|
||||
return !(previous == QVariant()) && previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideGamesThatStarted(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_games_that_started", "filter_games");
|
||||
setValue(hide, "hide_games_that_started");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideGamesThatStarted()
|
||||
{
|
||||
QVariant previous = getValue("hide_games_that_started", "filter_games");
|
||||
QVariant previous = getValue("hide_games_that_started");
|
||||
return !(previous == QVariant()) && previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHidePasswordProtectedGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_password_protected_games", "filter_games");
|
||||
setValue(hide, "hide_password_protected_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHidePasswordProtectedGames()
|
||||
{
|
||||
QVariant previous = getValue("hide_password_protected_games", "filter_games");
|
||||
QVariant previous = getValue("hide_password_protected_games");
|
||||
return previous == QVariant() || previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideIgnoredUserGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_ignored_user_games", "filter_games");
|
||||
setValue(hide, "hide_ignored_user_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideIgnoredUserGames()
|
||||
{
|
||||
QVariant previous = getValue("hide_ignored_user_games", "filter_games");
|
||||
QVariant previous = getValue("hide_ignored_user_games");
|
||||
return !(previous == QVariant()) && previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideNotBuddyCreatedGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_not_buddy_created_games", "filter_games");
|
||||
setValue(hide, "hide_not_buddy_created_games");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setHideOpenDecklistGames(bool hide)
|
||||
{
|
||||
setValue(hide, "hide_open_decklist_games", "filter_games");
|
||||
setValue(hide, "hide_open_decklist_games");
|
||||
}
|
||||
|
||||
bool GameFiltersSettings::isHideOpenDecklistGames()
|
||||
{
|
||||
QVariant previous = getValue("hide_open_decklist_games", "filter_games");
|
||||
QVariant previous = getValue("hide_open_decklist_games");
|
||||
return !(previous == QVariant()) && previous.toBool();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setGameNameFilter(QString gameName)
|
||||
{
|
||||
setValue(gameName, "game_name_filter", "filter_games");
|
||||
setValue(gameName, "game_name_filter");
|
||||
}
|
||||
|
||||
QString GameFiltersSettings::getGameNameFilter()
|
||||
{
|
||||
return getValue("game_name_filter", "filter_games").toString();
|
||||
return getValue("game_name_filter").toString();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setCreatorNameFilter(QString creatorName)
|
||||
{
|
||||
setValue(creatorName, "creator_name_filter", "filter_games");
|
||||
setValue(creatorName, "creator_name_filter");
|
||||
}
|
||||
|
||||
QString GameFiltersSettings::getCreatorNameFilter()
|
||||
{
|
||||
return getValue("creator_name_filter", "filter_games").toString();
|
||||
return getValue("creator_name_filter").toString();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMinPlayers(int min)
|
||||
{
|
||||
setValue(min, "min_players", "filter_games");
|
||||
setValue(min, "min_players");
|
||||
}
|
||||
|
||||
int GameFiltersSettings::getMinPlayers()
|
||||
{
|
||||
QVariant previous = getValue("min_players", "filter_games");
|
||||
QVariant previous = getValue("min_players");
|
||||
return previous == QVariant() ? 1 : previous.toInt();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMaxPlayers(int max)
|
||||
{
|
||||
setValue(max, "max_players", "filter_games");
|
||||
setValue(max, "max_players");
|
||||
}
|
||||
|
||||
int GameFiltersSettings::getMaxPlayers()
|
||||
{
|
||||
QVariant previous = getValue("max_players", "filter_games");
|
||||
QVariant previous = getValue("max_players");
|
||||
return previous == QVariant() ? 99 : previous.toInt();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setMaxGameAge(const QTime &maxGameAge)
|
||||
{
|
||||
setValue(maxGameAge, "max_game_age_time", "filter_games");
|
||||
setValue(maxGameAge, "max_game_age_time");
|
||||
}
|
||||
|
||||
QTime GameFiltersSettings::getMaxGameAge()
|
||||
{
|
||||
QVariant previous = getValue("max_game_age_time", "filter_games");
|
||||
QVariant previous = getValue("max_game_age_time");
|
||||
return previous.toTime();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
setValue(enabled, gametypeHASHED, "filter_games");
|
||||
setValue(enabled, gametypeHASHED);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
void GameFiltersSettings::setShowSpectatorPasswordProtected(bool show)
|
||||
{
|
||||
setValue(show, "show_spectator_password_protected", "filter_games");
|
||||
setValue(show, "show_spectator_password_protected");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "layouts_settings.h"
|
||||
|
||||
LayoutsSettings::LayoutsSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "layouts.ini", parent)
|
||||
: SettingsManager(settingPath + "layouts.ini", "layouts", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
#include "message_settings.h"
|
||||
|
||||
MessageSettings::MessageSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "messages.ini", parent)
|
||||
: SettingsManager(settingPath + "messages.ini", "messages", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return getValue("count", "messages").toInt();
|
||||
return getValue("count").toInt();
|
||||
}
|
||||
|
||||
void MessageSettings::setCount(int count)
|
||||
{
|
||||
setValue(count, "count", "messages");
|
||||
setValue(count, "count");
|
||||
}
|
||||
|
||||
void MessageSettings::setMessageAt(int index, QString message)
|
||||
{
|
||||
setValue(message, QString("msg%1").arg(index), "messages");
|
||||
setValue(message, QString("msg%1").arg(index));
|
||||
}
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
#define MAX_RECENT_DECK_COUNT 10
|
||||
|
||||
RecentsSettings::RecentsSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "recents.ini", parent)
|
||||
: SettingsManager(settingPath + "recents.ini", "deckbuilder", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
QStringList RecentsSettings::getRecentlyOpenedDeckPaths()
|
||||
{
|
||||
return getValue("deckpaths", "deckbuilder").toStringList();
|
||||
return getValue("deckpaths").toStringList();
|
||||
}
|
||||
void RecentsSettings::clearRecentlyOpenedDeckPaths()
|
||||
{
|
||||
deleteValue("deckpaths", "deckbuilder");
|
||||
deleteValue("deckpaths");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
|
||||
{
|
||||
auto deckPaths = getValue("deckpaths", "deckbuilder").toStringList();
|
||||
auto deckPaths = getValue("deckpaths").toStringList();
|
||||
deckPaths.removeAll(deckPath);
|
||||
|
||||
deckPaths.prepend(deckPath);
|
||||
@@ -27,7 +27,7 @@ void RecentsSettings::updateRecentlyOpenedDeckPaths(const QString &deckPath)
|
||||
deckPaths.removeLast();
|
||||
}
|
||||
|
||||
setValue(deckPaths, "deckpaths", "deckbuilder");
|
||||
setValue(deckPaths, "deckpaths");
|
||||
emit recentlyOpenedDeckPathsChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,34 +4,34 @@
|
||||
#include <utility>
|
||||
|
||||
ServersSettings::ServersSettings(const QString &settingPath, QObject *parent)
|
||||
: SettingsManager(settingPath + "servers.ini", parent)
|
||||
: SettingsManager(settingPath + "servers.ini", "server", QString(), parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ServersSettings::setPreviousHostLogin(int previous)
|
||||
{
|
||||
setValue(previous, "previoushostlogin", "server");
|
||||
setValue(previous, "previoushostlogin");
|
||||
}
|
||||
|
||||
int ServersSettings::getPreviousHostLogin()
|
||||
{
|
||||
QVariant previous = getValue("previoushostlogin", "server");
|
||||
QVariant previous = getValue("previoushostlogin");
|
||||
return previous == QVariant() ? 1 : previous.toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setPreviousHostList(QStringList list)
|
||||
{
|
||||
setValue(list, "previoushosts", "server");
|
||||
setValue(list, "previoushosts");
|
||||
}
|
||||
|
||||
QStringList ServersSettings::getPreviousHostList()
|
||||
{
|
||||
return getValue("previoushosts", "server").toStringList();
|
||||
return getValue("previoushosts").toStringList();
|
||||
}
|
||||
|
||||
void ServersSettings::setPrevioushostName(const QString &name)
|
||||
{
|
||||
setValue(name, "previoushostName", "server");
|
||||
setValue(name, "previoushostName");
|
||||
}
|
||||
|
||||
QString ServersSettings::getSaveName(QString defaultname)
|
||||
@@ -50,7 +50,7 @@ QString ServersSettings::getSite(QString defaultSite)
|
||||
|
||||
QString ServersSettings::getPrevioushostName()
|
||||
{
|
||||
QVariant value = getValue("previoushostName", "server");
|
||||
QVariant value = getValue("previoushostName");
|
||||
return value == QVariant() ? "Rooster Ranges" : value.toString();
|
||||
}
|
||||
|
||||
@@ -107,56 +107,56 @@ bool ServersSettings::getSavePassword()
|
||||
|
||||
void ServersSettings::setAutoConnect(int autoconnect)
|
||||
{
|
||||
setValue(autoconnect, "auto_connect", "server");
|
||||
setValue(autoconnect, "auto_connect");
|
||||
}
|
||||
|
||||
int ServersSettings::getAutoConnect()
|
||||
{
|
||||
QVariant autoconnect = getValue("auto_connect", "server");
|
||||
QVariant autoconnect = getValue("auto_connect");
|
||||
return autoconnect == QVariant() ? 0 : autoconnect.toInt();
|
||||
}
|
||||
|
||||
void ServersSettings::setFPHostName(QString hostname)
|
||||
{
|
||||
setValue(hostname, "fphostname", "server");
|
||||
setValue(hostname, "fphostname");
|
||||
}
|
||||
|
||||
QString ServersSettings::getFPHostname(QString defaultHost)
|
||||
{
|
||||
QVariant hostname = getValue("fphostname", "server");
|
||||
QVariant hostname = getValue("fphostname");
|
||||
return hostname == QVariant() ? std::move(defaultHost) : hostname.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setFPPort(QString port)
|
||||
{
|
||||
setValue(port, "fpport", "server");
|
||||
setValue(port, "fpport");
|
||||
}
|
||||
|
||||
QString ServersSettings::getFPPort(QString defaultPort)
|
||||
{
|
||||
QVariant port = getValue("fpport", "server");
|
||||
QVariant port = getValue("fpport");
|
||||
return port == QVariant() ? std::move(defaultPort) : port.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setFPPlayerName(QString playerName)
|
||||
{
|
||||
setValue(playerName, "fpplayername", "server");
|
||||
setValue(playerName, "fpplayername");
|
||||
}
|
||||
|
||||
QString ServersSettings::getFPPlayerName(QString defaultName)
|
||||
{
|
||||
QVariant name = getValue("fpplayername", "server");
|
||||
QVariant name = getValue("fpplayername");
|
||||
return name == QVariant() ? std::move(defaultName) : name.toString();
|
||||
}
|
||||
|
||||
void ServersSettings::setClearDebugLogStatus(bool abIsChecked)
|
||||
{
|
||||
setValue(abIsChecked, "save_debug_log", "server");
|
||||
setValue(abIsChecked, "save_debug_log");
|
||||
}
|
||||
|
||||
bool ServersSettings::getClearDebugLogStatus(bool abDefaultValue)
|
||||
{
|
||||
QVariant cbFlushLog = getValue("save_debug_log", "server");
|
||||
QVariant cbFlushLog = getValue("save_debug_log");
|
||||
return cbFlushLog == QVariant() ? abDefaultValue : cbFlushLog.toBool();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,35 @@
|
||||
#include "settings_manager.h"
|
||||
|
||||
SettingsManager::SettingsManager(const QString &settingPath, QObject *parent)
|
||||
: QObject(parent), settings(settingPath, QSettings::IniFormat)
|
||||
SettingsManager::SettingsManager(const QString &settingPath,
|
||||
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,
|
||||
const QString &name,
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (!group.isEmpty()) {
|
||||
|
||||
@@ -16,14 +16,23 @@ class SettingsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingsManager(const QString &settingPath, QObject *parent = nullptr);
|
||||
QVariant getValue(const QString &name, const QString &group = "", const QString &subGroup = "");
|
||||
explicit SettingsManager(const QString &settingPath,
|
||||
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();
|
||||
|
||||
protected:
|
||||
QSettings settings;
|
||||
void setValue(const QVariant &value, const QString &name, const QString &group = "", const QString &subGroup = "");
|
||||
void deleteValue(const QString &name, const QString &group = "", const QString &subGroup = "");
|
||||
QString defaultGroup;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user