summaryrefslogtreecommitdiffhomepage
path: root/options/tie.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-05-06 13:26:02 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-05-10 11:19:22 +0200
commit33580cee78020e8389834ea271556320f33521e4 (patch)
treebf53b4b956f1bf462826493ff3b0ba66d54f8f0f /options/tie.hpp
parentdd83dc780bd1232444b6051aff5698f63cd4d741 (diff)
options/tie: allow for custom-formatting the ini value
Diffstat (limited to 'options/tie.hpp')
-rw-r--r--options/tie.hpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/options/tie.hpp b/options/tie.hpp
index a3b5a19f..94fe5d49 100644
--- a/options/tie.hpp
+++ b/options/tie.hpp
@@ -58,6 +58,23 @@ void tie_setting(value<t>& v, QLabel* lb, const QString& format, const xs&... ar
v.SAFE_CONNTYPE);
}
+// Clang 3.9 has a bug
+// error: missing default argument on parameter 'args'
+
+// cf. http://stackoverflow.com/questions/29098835/can-parameter-pack-function-arguments-be-defaulted
+
+template<typename t, typename F, typename... xs>
+decltype((void)((std::declval<F>())(std::declval<const t&>())))
+tie_setting(value<t>& v, QLabel* lb, F&& fun, const QString& fmt = QStringLiteral("%1"), const xs&... args)
+{
+ auto closure = [=](const t& x) { lb->setText(fmt.arg(fun(x), args...)); };
+
+ closure(v());
+ base_value::connect(&v, static_cast<void(base_value::*)(const t&) const>(&base_value::valueChanged),
+ lb, closure,
+ v.SAFE_CONNTYPE);
+}
+
OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QComboBox* cb);
OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QComboBox* cb);
OTR_OPTIONS_EXPORT void tie_setting(value<QVariant>& v, QComboBox* cb);