blob: c58a498b02e5c7bee71618af8143f21dbbd3ca7d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "configuration.h"
#include <stdexcept>
template <>
callable_when(unconsumed) [[nodiscard]] std::optional<QString> Configuration::value(const char *path) const
{
const auto v = value<std::string>(path);
if(!v)
return std::nullopt;
else
return QString::fromStdString(v.value());
}
template <>
callable_when(unconsumed) [[nodiscard]] std::optional<QStringList> Configuration::value(const char *path) const
{
const auto v = value<std::string>(path);
if(!v)
return std::nullopt;
else
return QString::fromStdString(v.value()).split(';');
}
template <>
callable_when(unconsumed) QAction &Configuration::shortcut(QAction &action, const char *name) const
{
if(const auto shortcut = value<QString>(name)) {
const QString old_tooltip = action.toolTip();
action.setShortcut(QKeySequence::fromString(shortcut.value()));
action.setToolTip(QString("%1 (%2)").arg(old_tooltip, shortcut.value()));
}
return action;
}
template <>
callable_when(unconsumed) QKeySequence &Configuration::shortcut(QKeySequence &sequence, const char *name) const
{
if(const auto shortcut = value<QString>(name)) {
sequence = QKeySequence::fromString(shortcut.value());
}
return sequence;
}
|