13 #ifndef CONFIGURATION_H
14 #define CONFIGURATION_H
18 #include <QDomDocument>
21 #include <QStringList>
43 QString m_fileName {kDefaultFilename};
48 QDomNode FindNode(
const QString &setting,
bool create);
49 QDomNode FindNode(QStringList &path, QDomNode &
current,
bool create);
51 QString GetValue(
const QString &setting);
55 static constexpr
auto kDefaultFilename =
"config.xml";
59 : m_fileName(std::move(fileName))
69 bool GetValue(
const QString &setting,
const bool defaultValue)
71 QString value = GetValue(setting);
72 return (!value.isNull()) ? QVariant(value).toBool() : defaultValue;
74 int GetValue(
const QString &setting,
const int defaultValue)
76 QString value = GetValue(setting);
77 return (!value.isNull()) ? QVariant(value).toInt() : defaultValue;
79 QString
GetValue(
const QString &setting,
const QString &defaultValue)
81 QString value = GetValue(setting);
82 return (!value.isNull()) ? value : defaultValue;
87 QString
GetValue(
const QString &setting,
const char* defaultValue)
89 QString value = GetValue(setting);
90 return (!value.isNull()) ? value : QString(defaultValue);
93 void SetValue(
const QString &setting,
bool value)
95 SetValue(setting, QVariant(value).
toString());
97 void SetValue(
const QString &setting,
int value)
99 SetValue(setting, QVariant(value).
toString());
105 void SetValue(
const QString &setting,
const char* value)
107 SetValue(setting, QString(value));
109 void SetValue(
const QString &setting,
const QString &value);
110 void ClearValue(
const QString &setting);
112 template <
typename T>
113 typename std::enable_if_t<std::chrono::__is_duration<T>::value, T>
116 return T(GetValue(setting,
static_cast<int>(defaultValue.count())));
119 template <
typename T>
120 typename std::enable_if_t<std::chrono::__is_duration<T>::value>
123 SetValue(setting,
static_cast<int>(value.count()));
127 #endif // CONFIGURATION_H