aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration/qt_specialization.cpp
blob: a97ed2b986c82af99eca38cc5d34ff3a45f6fe57 (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
#include "configuration.h"

template <>
[[nodiscard]] std::optional<QString> Configuration::value(const char *path) const
{
    const auto result = value<std::string>(path);
    return result ? std::make_optional(QString::fromStdString(result.value())) : std::nullopt;
}

template <>
[[nodiscard]] std::optional<QStringList> Configuration::value(const char *path) const
{
    const auto result = value<std::string>(path);
    return result ? std::make_optional(QString::fromStdString(result.value()).split(';')) : std::nullopt;
}

template <>
QAction &Configuration::shortcut(QAction &action, const char *name) const
{
    if(const auto result = value<QString>(name)) {
        const QString old_tooltip = action.toolTip();
        const auto &result_value = result.value();

        action.setShortcut(QKeySequence::fromString(result_value));
        action.setToolTip(QString("%1 (%2)").arg(old_tooltip, result_value));
    }
    return action;
}

template <>
QKeySequence &Configuration::shortcut(QKeySequence &sequence, const char *name) const
{
    if(const auto result = value<QString>(name)) {
        const auto &result_value = result.value();

        sequence = QKeySequence::fromString(result_value);
    }
    return sequence;
}