From c4942d72935cacc150815f2f5221c71fc3f05bc1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 29 Apr 2017 16:18:21 +0200 Subject: options/tie: allow for binding with a format string --- options/options.hpp | 2 +- options/tie.cpp | 2 +- options/tie.hpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/options/options.hpp b/options/options.hpp index c1eed97c..0528b0d9 100644 --- a/options/options.hpp +++ b/options/options.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2016 Stanislaw Halik +/* Copyright (c) 2013-2017 Stanislaw Halik * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above diff --git a/options/tie.cpp b/options/tie.cpp index ce0e5a35..934871a9 100644 --- a/options/tie.cpp +++ b/options/tie.cpp @@ -103,7 +103,7 @@ OTR_OPTIONS_EXPORT void tie_setting(value& v, QLineEdit* le) OTR_OPTIONS_EXPORT void tie_setting(value& v, QLabel* lb) { lb->setText(v); - base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.SAFE_CONNTYPE); } OTR_OPTIONS_EXPORT void tie_setting(value& v, QTabWidget* t) diff --git a/options/tie.hpp b/options/tie.hpp index 93004e0f..a3b5a19f 100644 --- a/options/tie.hpp +++ b/options/tie.hpp @@ -47,6 +47,17 @@ tie_setting(value& v, QComboBox* cb) v.SAFE_CONNTYPE); } +template +void tie_setting(value& v, QLabel* lb, const QString& format, const xs&... args) +{ + auto closure = [=](const t& x) { lb->setText(format.arg(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