chore: reformat

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu
2023-08-02 18:35:35 +02:00
parent ce2ca13815
commit 1d468ac35a
594 changed files with 16040 additions and 16536 deletions

View File

@ -36,17 +36,16 @@
#pragma once
#include <QIODevice>
#include <QString>
#include <QVariant>
#include <QIODevice>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonDocument>
// Sectionless INI parser (for instance config files)
class INIFile : public QMap<QString, QVariant>
{
public:
class INIFile : public QMap<QString, QVariant> {
public:
explicit INIFile();
bool loadFile(QString fileName);

View File

@ -19,8 +19,7 @@
#include <QDebug>
#include <QFile>
INISettingsObject::INISettingsObject(QStringList paths, QObject *parent)
: SettingsObject(parent)
INISettingsObject::INISettingsObject(QStringList paths, QObject* parent) : SettingsObject(parent)
{
auto first_path = paths.constFirst();
for (auto path : paths) {
@ -39,14 +38,13 @@ INISettingsObject::INISettingsObject(QStringList paths, QObject *parent)
m_ini.loadFile(first_path);
}
INISettingsObject::INISettingsObject(QString path, QObject* parent)
: SettingsObject(parent)
INISettingsObject::INISettingsObject(QString path, QObject* parent) : SettingsObject(parent)
{
m_filePath = path;
m_ini.loadFile(path);
}
void INISettingsObject::setFilePath(const QString &filePath)
void INISettingsObject::setFilePath(const QString& filePath)
{
m_filePath = filePath;
}
@ -64,28 +62,24 @@ void INISettingsObject::suspendSave()
void INISettingsObject::resumeSave()
{
m_suspendSave = false;
if(m_doSave)
{
if (m_doSave) {
m_ini.saveFile(m_filePath);
}
}
void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
void INISettingsObject::changeSetting(const Setting& setting, QVariant value)
{
if (contains(setting.id()))
{
if (contains(setting.id())) {
// valid value -> set the main config, remove all the sysnonyms
if (value.isValid())
{
if (value.isValid()) {
auto list = setting.configKeys();
m_ini.set(list.takeFirst(), value);
for(auto iter: list)
for (auto iter : list)
m_ini.remove(iter);
}
// invalid -> remove all (just like resetSetting)
else
{
for(auto iter: setting.configKeys())
else {
for (auto iter : setting.configKeys())
m_ini.remove(iter);
}
doSave();
@ -94,35 +88,29 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
void INISettingsObject::doSave()
{
if(m_suspendSave)
{
if (m_suspendSave) {
m_doSave = true;
}
else
{
} else {
m_ini.saveFile(m_filePath);
}
}
void INISettingsObject::resetSetting(const Setting &setting)
void INISettingsObject::resetSetting(const Setting& setting)
{
// if we have the setting, remove all the synonyms. ALL OF THEM
if (contains(setting.id()))
{
for(auto iter: setting.configKeys())
if (contains(setting.id())) {
for (auto iter : setting.configKeys())
m_ini.remove(iter);
doSave();
}
}
QVariant INISettingsObject::retrieveValue(const Setting &setting)
QVariant INISettingsObject::retrieveValue(const Setting& setting)
{
// if we have the setting, return value of the first matching synonym
if (contains(setting.id()))
{
for(auto iter: setting.configKeys())
{
if(m_ini.contains(iter))
if (contains(setting.id())) {
for (auto iter : setting.configKeys()) {
if (m_ini.contains(iter))
return m_ini[iter];
}
}

View File

@ -24,44 +24,40 @@
/*!
* \brief A settings object that stores its settings in an INIFile.
*/
class INISettingsObject : public SettingsObject
{
class INISettingsObject : public SettingsObject {
Q_OBJECT
public:
public:
/** 'paths' is a list of INI files to try, in order, for fallback support. */
explicit INISettingsObject(QStringList paths, QObject* parent = nullptr);
explicit INISettingsObject(QString path, QObject* parent = nullptr);
explicit INISettingsObject(QString path, QObject* parent = nullptr);
/*!
* \brief Gets the path to the INI file.
* \return The path to the INI file.
*/
virtual QString filePath() const
{
return m_filePath;
}
virtual QString filePath() const { return m_filePath; }
/*!
* \brief Sets the path to the INI file and reloads it.
* \param filePath The INI file's new path.
*/
virtual void setFilePath(const QString &filePath);
virtual void setFilePath(const QString& filePath);
bool reload() override;
void suspendSave() override;
void resumeSave() override;
protected slots:
virtual void changeSetting(const Setting &setting, QVariant value) override;
virtual void resetSetting(const Setting &setting) override;
protected slots:
virtual void changeSetting(const Setting& setting, QVariant value) override;
virtual void resetSetting(const Setting& setting) override;
protected:
virtual QVariant retrieveValue(const Setting &setting) override;
protected:
virtual QVariant retrieveValue(const Setting& setting) override;
void doSave();
protected:
protected:
INIFile m_ini;
QString m_filePath;
};

View File

@ -15,8 +15,7 @@
#include "OverrideSetting.h"
OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other, std::shared_ptr<Setting> gate)
: Setting(other->configKeys(), QVariant())
OverrideSetting::OverrideSetting(std::shared_ptr<Setting> other, std::shared_ptr<Setting> gate) : Setting(other->configKeys(), QVariant())
{
Q_ASSERT(other);
Q_ASSERT(gate);
@ -36,8 +35,7 @@ QVariant OverrideSetting::defValue() const
QVariant OverrideSetting::get() const
{
if(isOverriding())
{
if (isOverriding()) {
return Setting::get();
}
return m_other->get();

View File

@ -26,21 +26,20 @@
* The other setting can be (and usually is) a part of a different SettingsObject
* than this one.
*/
class OverrideSetting : public Setting
{
class OverrideSetting : public Setting {
Q_OBJECT
public:
public:
explicit OverrideSetting(std::shared_ptr<Setting> overriden, std::shared_ptr<Setting> gate);
virtual QVariant defValue() const;
virtual QVariant get() const;
virtual void set (QVariant value);
virtual void set(QVariant value);
virtual void reset();
private:
private:
bool isOverriding() const;
protected:
protected:
std::shared_ptr<Setting> m_other;
std::shared_ptr<Setting> m_gate;
};

View File

@ -25,8 +25,7 @@ PassthroughSetting::PassthroughSetting(std::shared_ptr<Setting> other, std::shar
bool PassthroughSetting::isOverriding() const
{
if(!m_gate)
{
if (!m_gate) {
return false;
}
return m_gate->get().toBool();
@ -34,8 +33,7 @@ bool PassthroughSetting::isOverriding() const
QVariant PassthroughSetting::defValue() const
{
if(isOverriding())
{
if (isOverriding()) {
return m_other->get();
}
return m_other->defValue();
@ -43,8 +41,7 @@ QVariant PassthroughSetting::defValue() const
QVariant PassthroughSetting::get() const
{
if(isOverriding())
{
if (isOverriding()) {
return Setting::get();
}
return m_other->get();
@ -52,8 +49,7 @@ QVariant PassthroughSetting::get() const
void PassthroughSetting::reset()
{
if(isOverriding())
{
if (isOverriding()) {
Setting::reset();
}
m_other->reset();
@ -61,8 +57,7 @@ void PassthroughSetting::reset()
void PassthroughSetting::set(QVariant value)
{
if(isOverriding())
{
if (isOverriding()) {
Setting::set(value);
}
m_other->set(value);

View File

@ -25,21 +25,20 @@
* If 'gate' evaluates to true, the override stores and returns data
* If 'gate' evaluates to false, the original does,
*/
class PassthroughSetting : public Setting
{
class PassthroughSetting : public Setting {
Q_OBJECT
public:
public:
explicit PassthroughSetting(std::shared_ptr<Setting> overriden, std::shared_ptr<Setting> gate);
virtual QVariant defValue() const;
virtual QVariant get() const;
virtual void set (QVariant value);
virtual void set(QVariant value);
virtual void reset();
private:
private:
bool isOverriding() const;
protected:
protected:
std::shared_ptr<Setting> m_other;
std::shared_ptr<Setting> m_gate;
};

View File

@ -16,20 +16,14 @@
#include "Setting.h"
#include "settings/SettingsObject.h"
Setting::Setting(QStringList synonyms, QVariant defVal)
: QObject(), m_synonyms(synonyms), m_defVal(defVal)
{
}
Setting::Setting(QStringList synonyms, QVariant defVal) : QObject(), m_synonyms(synonyms), m_defVal(defVal) {}
QVariant Setting::get() const
{
SettingsObject *sbase = m_storage;
if (!sbase)
{
SettingsObject* sbase = m_storage;
if (!sbase) {
return defValue();
}
else
{
} else {
QVariant test = sbase->retrieveValue(*this);
if (!test.isValid())
return defValue();

View File

@ -16,8 +16,8 @@
#pragma once
#include <QObject>
#include <QVariant>
#include <QStringList>
#include <QVariant>
#include <memory>
class SettingsObject;
@ -25,10 +25,9 @@ class SettingsObject;
/*!
*
*/
class Setting : public QObject
{
class Setting : public QObject {
Q_OBJECT
public:
public:
/**
* Construct a Setting
*
@ -47,10 +46,7 @@ public:
* undefined behavior.
* \return The ID of the setting.
*/
virtual QString id() const
{
return m_synonyms.first();
}
virtual QString id() const { return m_synonyms.first(); }
/*!
* \brief Gets this setting's config file key.
@ -58,10 +54,7 @@ public:
* the same as the setting's ID, but it can be different.
* \return The setting's config file key.
*/
virtual QStringList configKeys() const
{
return m_synonyms;
}
virtual QStringList configKeys() const { return m_synonyms; }
/*!
* \brief Gets this setting's value as a QVariant.
@ -78,22 +71,21 @@ public:
*/
virtual QVariant defValue() const;
signals:
signals:
/*!
* \brief Signal emitted when this Setting object's value changes.
* \param setting A reference to the Setting that changed.
* \param value This Setting object's new value.
*/
void SettingChanged(const Setting &setting, QVariant value);
void SettingChanged(const Setting& setting, QVariant value);
/*!
* \brief Signal emitted when this Setting object's value resets to default.
* \param setting A reference to the Setting that changed.
*/
void settingReset(const Setting &setting);
void settingReset(const Setting& setting);
public
slots:
public slots:
/*!
* \brief Changes the setting's value.
* This is done by emitting the SettingChanged() signal which will then be
@ -109,10 +101,9 @@ slots:
*/
virtual void reset();
protected:
protected:
friend class SettingsObject;
SettingsObject * m_storage;
SettingsObject* m_storage;
QStringList m_synonyms;
QVariant m_defVal;
};

View File

@ -14,30 +14,25 @@
*/
#include "settings/SettingsObject.h"
#include "settings/Setting.h"
#include "settings/OverrideSetting.h"
#include "PassthroughSetting.h"
#include <QDebug>
#include "PassthroughSetting.h"
#include "settings/OverrideSetting.h"
#include "settings/Setting.h"
#include <QVariant>
SettingsObject::SettingsObject(QObject *parent) : QObject(parent)
{
}
SettingsObject::SettingsObject(QObject* parent) : QObject(parent) {}
SettingsObject::~SettingsObject()
{
m_settings.clear();
}
std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original,
std::shared_ptr<Setting> gate)
std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate)
{
if (contains(original->id()))
{
qCritical() << QString("Failed to register setting %1. ID already exists.")
.arg(original->id());
return nullptr; // Fail
if (contains(original->id())) {
qCritical() << QString("Failed to register setting %1. ID already exists.").arg(original->id());
return nullptr; // Fail
}
auto override = std::make_shared<OverrideSetting>(original, gate);
override->m_storage = this;
@ -46,14 +41,11 @@ std::shared_ptr<Setting> SettingsObject::registerOverride(std::shared_ptr<Settin
return override;
}
std::shared_ptr<Setting> SettingsObject::registerPassthrough(std::shared_ptr<Setting> original,
std::shared_ptr<Setting> gate)
std::shared_ptr<Setting> SettingsObject::registerPassthrough(std::shared_ptr<Setting> original, std::shared_ptr<Setting> gate)
{
if (contains(original->id()))
{
qCritical() << QString("Failed to register setting %1. ID already exists.")
.arg(original->id());
return nullptr; // Fail
if (contains(original->id())) {
qCritical() << QString("Failed to register setting %1. ID already exists.").arg(original->id());
return nullptr; // Fail
}
auto passthrough = std::make_shared<PassthroughSetting>(original, gate);
passthrough->m_storage = this;
@ -66,11 +58,9 @@ std::shared_ptr<Setting> SettingsObject::registerSetting(QStringList synonyms, Q
{
if (synonyms.empty())
return nullptr;
if (contains(synonyms.first()))
{
qCritical() << QString("Failed to register setting %1. ID already exists.")
.arg(synonyms.first());
return nullptr; // Fail
if (contains(synonyms.first())) {
qCritical() << QString("Failed to register setting %1. ID already exists.").arg(synonyms.first());
return nullptr; // Fail
}
auto setting = std::make_shared<Setting>(synonyms, defVal);
setting->m_storage = this;
@ -79,7 +69,7 @@ std::shared_ptr<Setting> SettingsObject::registerSetting(QStringList synonyms, Q
return setting;
}
std::shared_ptr<Setting> SettingsObject::getSetting(const QString &id) const
std::shared_ptr<Setting> SettingsObject::getSetting(const QString& id) const
{
// Make sure there is a setting with the given ID.
if (!m_settings.contains(id))
@ -88,54 +78,49 @@ std::shared_ptr<Setting> SettingsObject::getSetting(const QString &id) const
return m_settings[id];
}
QVariant SettingsObject::get(const QString &id) const
QVariant SettingsObject::get(const QString& id) const
{
auto setting = getSetting(id);
return (setting ? setting->get() : QVariant());
}
bool SettingsObject::set(const QString &id, QVariant value)
bool SettingsObject::set(const QString& id, QVariant value)
{
auto setting = getSetting(id);
if (!setting)
{
if (!setting) {
qCritical() << QString("Error changing setting %1. Setting doesn't exist.").arg(id);
return false;
}
else
{
} else {
setting->set(value);
return true;
}
}
void SettingsObject::reset(const QString &id) const
void SettingsObject::reset(const QString& id) const
{
auto setting = getSetting(id);
if (setting)
setting->reset();
}
bool SettingsObject::contains(const QString &id)
bool SettingsObject::contains(const QString& id)
{
return m_settings.contains(id);
}
bool SettingsObject::reload()
{
for (auto setting : m_settings.values())
{
for (auto setting : m_settings.values()) {
setting->set(setting->get());
}
return true;
}
void SettingsObject::connectSignals(const Setting &setting)
void SettingsObject::connectSignals(const Setting& setting)
{
connect(&setting, &Setting::SettingChanged, this, &SettingsObject::changeSetting);
connect(&setting, SIGNAL(SettingChanged(const Setting &, QVariant)), this,
SIGNAL(SettingChanged(const Setting &, QVariant)));
connect(&setting, SIGNAL(SettingChanged(const Setting&, QVariant)), this, SIGNAL(SettingChanged(const Setting&, QVariant)));
connect(&setting, &Setting::settingReset, this, &SettingsObject::resetSetting);
connect(&setting, SIGNAL(settingReset(Setting)), this, SIGNAL(settingReset(const Setting &)));
connect(&setting, SIGNAL(settingReset(Setting)), this, SIGNAL(settingReset(const Setting&)));
}

View File

@ -15,12 +15,12 @@
#pragma once
#include <QObject>
#include <QJsonArray>
#include <QJsonDocument>
#include <QMap>
#include <QObject>
#include <QStringList>
#include <QVariant>
#include <QJsonDocument>
#include <QJsonArray>
#include <memory>
class Setting;
@ -41,27 +41,20 @@ typedef std::weak_ptr<SettingsObject> SettingsObjectWeakPtr;
*
* \sa Setting
*/
class SettingsObject : public QObject
{
class SettingsObject : public QObject {
Q_OBJECT
public:
class Lock
{
public:
Lock(SettingsObjectPtr locked)
:m_locked(locked)
{
m_locked->suspendSave();
}
~Lock()
{
m_locked->resumeSave();
}
private:
public:
class Lock {
public:
Lock(SettingsObjectPtr locked) : m_locked(locked) { m_locked->suspendSave(); }
~Lock() { m_locked->resumeSave(); }
private:
SettingsObjectPtr m_locked;
};
public:
explicit SettingsObject(QObject *parent = 0);
public:
explicit SettingsObject(QObject* parent = 0);
virtual ~SettingsObject();
/*!
* Registers an override setting for the given original setting in this settings object
@ -90,8 +83,7 @@ public:
* the one that is being registered.
* \return A valid Setting shared pointer if successful.
*/
std::shared_ptr<Setting> registerSetting(QStringList synonyms,
QVariant defVal = QVariant());
std::shared_ptr<Setting> registerSetting(QStringList synonyms, QVariant defVal = QVariant());
/*!
* Registers the given setting with this SettingsObject and connects the necessary signals.
@ -100,10 +92,7 @@ public:
* the one that is being registered.
* \return A valid Setting shared pointer if successful.
*/
std::shared_ptr<Setting> registerSetting(QString id, QVariant defVal = QVariant())
{
return registerSetting(QStringList(id), defVal);
}
std::shared_ptr<Setting> registerSetting(QString id, QVariant defVal = QVariant()) { return registerSetting(QStringList(id), defVal); }
/*!
* \brief Gets the setting with the given ID.
@ -112,7 +101,7 @@ public:
* Returns null if there is no setting with the given ID.
* \sa operator []()
*/
std::shared_ptr<Setting> getSetting(const QString &id) const;
std::shared_ptr<Setting> getSetting(const QString& id) const;
/*!
* \brief Gets the value of the setting with the given ID.
@ -120,7 +109,7 @@ public:
* \return The setting's value as a QVariant.
* If no setting with the given ID exists, returns an invalid QVariant.
*/
QVariant get(const QString &id) const;
QVariant get(const QString& id) const;
/*!
* \brief Sets the value of the setting with the given ID.
@ -129,20 +118,20 @@ public:
* \param value The new value of the setting.
* \return True if successful, false if it failed.
*/
bool set(const QString &id, QVariant value);
bool set(const QString& id, QVariant value);
/*!
* \brief Reverts the setting with the given ID to default.
* \param id The ID of the setting to reset.
*/
void reset(const QString &id) const;
void reset(const QString& id) const;
/*!
* \brief Checks if this SettingsObject contains a setting with the given ID.
* \param id The ID to check for.
* \return True if the SettingsObject has a setting with the given ID.
*/
bool contains(const QString &id);
bool contains(const QString& id);
/*!
* \brief Reloads the settings and emit signals for changed settings
@ -152,7 +141,7 @@ public:
virtual void suspendSave() = 0;
virtual void resumeSave() = 0;
signals:
signals:
/*!
* \brief Signal emitted when one of this SettingsObject object's settings changes.
* This is usually just connected directly to each Setting object's
@ -160,7 +149,7 @@ signals:
* \param setting A reference to the Setting object that changed.
* \param value The Setting object's new value.
*/
void SettingChanged(const Setting &setting, QVariant value);
void SettingChanged(const Setting& setting, QVariant value);
/*!
* \brief Signal emitted when one of this SettingsObject object's settings resets.
@ -168,10 +157,9 @@ signals:
* settingReset() signals.
* \param setting A reference to the Setting object that changed.
*/
void settingReset(const Setting &setting);
void settingReset(const Setting& setting);
protected
slots:
protected slots:
/*!
* \brief Changes a setting.
* This slot is usually connected to each Setting object's
@ -180,7 +168,7 @@ slots:
* \param setting A reference to the Setting object that changed.
* \param value The setting's new value.
*/
virtual void changeSetting(const Setting &setting, QVariant value) = 0;
virtual void changeSetting(const Setting& setting, QVariant value) = 0;
/*!
* \brief Resets a setting.
@ -189,27 +177,28 @@ slots:
* to update the setting's value in the config file.
* \param setting A reference to the Setting object that changed.
*/
virtual void resetSetting(const Setting &setting) = 0;
virtual void resetSetting(const Setting& setting) = 0;
protected:
protected:
/*!
* \brief Connects the necessary signals to the given Setting.
* \param setting The setting to connect.
*/
void connectSignals(const Setting &setting);
void connectSignals(const Setting& setting);
/*!
* \brief Function used by Setting objects to get their values from the SettingsObject.
* \param setting The
* \return
*/
virtual QVariant retrieveValue(const Setting &setting) = 0;
virtual QVariant retrieveValue(const Setting& setting) = 0;
friend class Setting;
private:
private:
QMap<QString, std::shared_ptr<Setting>> m_settings;
protected:
protected:
bool m_suspendSave = false;
bool m_doSave = false;
};