From 33580cee78020e8389834ea271556320f33521e4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 6 May 2017 13:26:02 +0200 Subject: options/tie: allow for custom-formatting the ini value --- options/tie.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'options/tie.hpp') 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& 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 +decltype((void)((std::declval())(std::declval()))) +tie_setting(value& 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(&base_value::valueChanged), + lb, closure, + v.SAFE_CONNTYPE); +} + OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); OTR_OPTIONS_EXPORT void tie_setting(value& v, QComboBox* cb); -- cgit v1.2.3