aboutsummaryrefslogtreecommitdiff
path: root/lib/settings
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-01-07 23:28:42 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-01-07 23:28:42 +0100
commitb984992fc92b6dd607732d6dad1c533b36f1ba3a (patch)
tree984c5ede072c2ebb10ad32acb5d5928162feb97f /lib/settings
parentSearching through BookmarkModel elements (diff)
downloadsmolbote-b984992fc92b6dd607732d6dad1c533b36f1ba3a.tar.xz
Added .clang-format
Diffstat (limited to 'lib/settings')
-rw-r--r--lib/settings/configuration.cpp54
-rw-r--r--lib/settings/configuration.h35
-rw-r--r--lib/settings/settingsdialog.cpp14
-rw-r--r--lib/settings/settingsdialog.h3
4 files changed, 54 insertions, 52 deletions
diff --git a/lib/settings/configuration.cpp b/lib/settings/configuration.cpp
index 1fa1fbf..06ee0bd 100644
--- a/lib/settings/configuration.cpp
+++ b/lib/settings/configuration.cpp
@@ -38,19 +38,19 @@ bool Configuration::readUserConfiguration(const std::string &path)
m_userCfgPath = path;
try {
m_userCfg->readFile(path.c_str());
- } catch (FileIOException) {
+ } catch(FileIOException) {
return false;
- } catch (ParseException) {
+ } catch(ParseException) {
return false;
}
- return true;
+ return true;
}
bool Configuration::parse(const std::string &contents)
{
try {
m_userCfg->readString(contents);
- } catch (ParseException) {
+ } catch(ParseException) {
return false;
}
return true;
@@ -61,7 +61,7 @@ bool Configuration::writeUserConfiguration(const std::string &path)
m_userCfgPath = path;
try {
m_userCfg->writeFile(m_userCfgPath.c_str());
- } catch (FileIOException) {
+ } catch(FileIOException) {
return false;
}
return true;
@@ -71,7 +71,7 @@ bool Configuration::writeIfNeeded()
{
try {
m_userCfg->writeFile(m_userCfgPath.c_str());
- } catch (FileIOException) {
+ } catch(FileIOException) {
return false;
}
return true;
@@ -81,13 +81,13 @@ bool Configuration::parseDefaultConfiguration(const std::string &contents)
{
try {
m_defaultCfg->readString(contents);
- } catch (ParseException) {
+ } catch(ParseException) {
return false;
}
return true;
}
-std::vector<std::string> Configuration::childrenSettings(const char* name)
+std::vector<std::string> Configuration::childrenSettings(const char *name)
{
std::vector<std::string> groupNames;
const Setting &root = m_userCfg->lookup(name);
@@ -101,7 +101,7 @@ std::vector<std::string> Configuration::childrenSettings(const char* name)
return groupNames;
}
-std::vector<std::string> Configuration::childrenGroups(const char* name)
+std::vector<std::string> Configuration::childrenGroups(const char *name)
{
std::vector<std::string> groupNames;
const Setting &root = m_userCfg->lookup(name);
@@ -118,7 +118,7 @@ void Configuration::resetValue(const char *path)
{
if(m_userCfg->exists(path)) {
Setting &v = m_userCfg->lookup(path);
- switch (v.getType()) {
+ switch(v.getType()) {
case Setting::TypeNone:
break;
case Setting::TypeInt:
@@ -146,8 +146,8 @@ void Configuration::resetValue(const char *path)
}
}
-template<typename T>
-std::optional<T> Configuration::value(const char* path) const
+template <typename T>
+std::optional<T> Configuration::value(const char *path) const
{
// if setting doesn't exist, give back a nullopt
if(!m_userCfg->exists(path)) {
@@ -160,7 +160,7 @@ std::optional<T> Configuration::value(const char* path) const
// cast depending on type
// type checks are done during compile time
- switch (setting.getType()) {
+ switch(setting.getType()) {
case Setting::TypeNone:
r = std::nullopt;
break;
@@ -201,7 +201,7 @@ std::optional<T> Configuration::value(const char* path) const
case Setting::TypeString:
// const char*, std::string
if constexpr(std::is_same<T, std::string>::value) {
- r = std::optional<std::string>(static_cast<const char*>(setting));
+ r = std::optional<std::string>(static_cast<const char *>(setting));
} else {
r = std::nullopt;
}
@@ -235,22 +235,22 @@ std::optional<T> Configuration::value(const char* path) const
}
// tell the compiler to export these functions, otherwise you get linking errors
-template std::optional<int> Configuration::value<int>(const char* path) const;
-template std::optional<unsigned int> Configuration::value<unsigned int>(const char* path) const;
-template std::optional<long> Configuration::value<long>(const char* path) const;
-template std::optional<unsigned long> Configuration::value<unsigned long>(const char* path) const;
+template std::optional<int> Configuration::value<int>(const char *path) const;
+template std::optional<unsigned int> Configuration::value<unsigned int>(const char *path) const;
+template std::optional<long> Configuration::value<long>(const char *path) const;
+template std::optional<unsigned long> Configuration::value<unsigned long>(const char *path) const;
-template std::optional<long long> Configuration::value<long long>(const char* path) const;
-template std::optional<unsigned long long> Configuration::value<unsigned long long>(const char* path) const;
+template std::optional<long long> Configuration::value<long long>(const char *path) const;
+template std::optional<unsigned long long> Configuration::value<unsigned long long>(const char *path) const;
-template std::optional<float> Configuration::value<float>(const char* path) const;
-template std::optional<double> Configuration::value<double>(const char* path) const;
+template std::optional<float> Configuration::value<float>(const char *path) const;
+template std::optional<double> Configuration::value<double>(const char *path) const;
-template std::optional<bool> Configuration::value<bool>(const char* path) const;
+template std::optional<bool> Configuration::value<bool>(const char *path) const;
-template std::optional<std::string> Configuration::value<std::string>(const char* path) const;
+template std::optional<std::string> Configuration::value<std::string>(const char *path) const;
-template<typename T>
+template <typename T>
bool Configuration::setValue(std::string path, const T &val)
{
if(m_userCfg->exists(path)) {
@@ -259,7 +259,7 @@ bool Configuration::setValue(std::string path, const T &val)
if constexpr(std::is_unsigned_v<T> && !std::is_same_v<T, bool>) {
setting = static_cast<typename std::make_signed_t<T>>(val);
} else if constexpr(std::is_same_v<T, std::string>) {
- switch (setting.getType()) {
+ switch(setting.getType()) {
case Setting::TypeNone:
break;
@@ -279,7 +279,7 @@ bool Configuration::setValue(std::string path, const T &val)
case Setting::TypeBoolean:
if(static_cast<std::string>(val) == "true") {
setting = true;
- } else if (static_cast<std::string>(val) == "false") {
+ } else if(static_cast<std::string>(val) == "false") {
setting = false;
}
break;
diff --git a/lib/settings/configuration.h b/lib/settings/configuration.h
index b258cb3..4fc614e 100644
--- a/lib/settings/configuration.h
+++ b/lib/settings/configuration.h
@@ -10,10 +10,11 @@
#define CONFIGURATION_H
#include <optional>
-#include <vector>
#include <string>
+#include <vector>
-namespace libconfig {
+namespace libconfig
+{
class Config;
class Setting;
}
@@ -34,12 +35,12 @@ public:
std::vector<std::string> childrenSettings(const char *name = "");
std::vector<std::string> childrenGroups(const char *name = "");
- void resetValue(const char* path);
+ void resetValue(const char *path);
- template<typename T>
- std::optional<T> value(const char* path) const;
+ template <typename T>
+ std::optional<T> value(const char *path) const;
- template<typename T>
+ template <typename T>
bool setValue(std::string path, const T &val);
private:
@@ -49,26 +50,26 @@ private:
};
// replace ~ with home
-std::string& patchHome(std::string &path, const std::string &home);
+std::string &patchHome(std::string &path, const std::string &home);
// instantiate functions
// this needs to be done because the implementation is in the cpp file
// Settings::value<>
-extern template std::optional<int> Configuration::value<int>(const char* path) const;
-extern template std::optional<unsigned int> Configuration::value<unsigned int>(const char* path) const;
-extern template std::optional<long> Configuration::value<long>(const char* path) const;
-extern template std::optional<unsigned long> Configuration::value<unsigned long>(const char* path) const;
+extern template std::optional<int> Configuration::value<int>(const char *path) const;
+extern template std::optional<unsigned int> Configuration::value<unsigned int>(const char *path) const;
+extern template std::optional<long> Configuration::value<long>(const char *path) const;
+extern template std::optional<unsigned long> Configuration::value<unsigned long>(const char *path) const;
-extern template std::optional<long long> Configuration::value<long long>(const char* path) const;
-extern template std::optional<unsigned long long> Configuration::value<unsigned long long>(const char* path) const;
+extern template std::optional<long long> Configuration::value<long long>(const char *path) const;
+extern template std::optional<unsigned long long> Configuration::value<unsigned long long>(const char *path) const;
-extern template std::optional<float> Configuration::value<float>(const char* path) const;
-extern template std::optional<double> Configuration::value<double>(const char* path) const;
+extern template std::optional<float> Configuration::value<float>(const char *path) const;
+extern template std::optional<double> Configuration::value<double>(const char *path) const;
-extern template std::optional<bool> Configuration::value<bool>(const char* path) const;
+extern template std::optional<bool> Configuration::value<bool>(const char *path) const;
-extern template std::optional<std::string> Configuration::value<std::string>(const char* path) const;
+extern template std::optional<std::string> Configuration::value<std::string>(const char *path) const;
// Settings::setValue<>
extern template bool Configuration::setValue<int>(std::string path, const int &val);
diff --git a/lib/settings/settingsdialog.cpp b/lib/settings/settingsdialog.cpp
index 478e372..97b5f44 100644
--- a/lib/settings/settingsdialog.cpp
+++ b/lib/settings/settingsdialog.cpp
@@ -7,19 +7,19 @@
*/
#include "settingsdialog.h"
-#include "ui_settingsdialog.h"
#include "configuration.h"
-#include <QScrollArea>
+#include "ui_settingsdialog.h"
#include <QFormLayout>
+#include <QGroupBox>
#include <QLineEdit>
+#include <QScrollArea>
#include <QToolButton>
-#include <QGroupBox>
inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget);
-SettingsDialog::SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::SettingsDialog)
+SettingsDialog::SettingsDialog(std::shared_ptr<Configuration> &settings, QWidget *parent)
+ : QDialog(parent)
+ , ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
@@ -67,7 +67,7 @@ QWidget *widgetForGroup(std::shared_ptr<Configuration> &settings, const std::str
return widget;
}
-inline QHBoxLayout *createEntry(Configuration* config, const std::string &path, QWidget *widget)
+inline QHBoxLayout *createEntry(Configuration *config, const std::string &path, QWidget *widget)
{
QLineEdit *lineEdit = new QLineEdit(widget);
lineEdit->setText(QString::fromStdString(config->value<std::string>(path.c_str()).value()));
diff --git a/lib/settings/settingsdialog.h b/lib/settings/settingsdialog.h
index 74dd964..f77b822 100644
--- a/lib/settings/settingsdialog.h
+++ b/lib/settings/settingsdialog.h
@@ -12,7 +12,8 @@
#include <QDialog>
#include <memory>
-namespace Ui {
+namespace Ui
+{
class SettingsDialog;
}