summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-13 15:05:05 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-13 15:09:26 +0200
commit9a0822c445e56580fb3034224191ec825ea0274a (patch)
tree9fce6a93bb72a0db6b60015b58272abe0fba68ba
parent887dd41c5d67c30bd1e9631920d8fc1c3dd1a3f0 (diff)
options/tie: change "tie" overloads
Adjust usages. There are ODR issues with MSVC and it doesn't support C++17 "static inline constexpr" _variables_. Otherwise, "signal_fun" could be a variable and not a function. The usages in accela/ewma2 dialog are more verbose now but the original API was silly.
-rw-r--r--compat/util.hpp6
-rw-r--r--filter-accela/ftnoir_filter_accela_dialog.cpp24
-rw-r--r--filter-ewma2/ftnoir_filter_ewma2_dialog.cpp9
-rw-r--r--gui/main-window.cpp6
-rw-r--r--gui/mapping-window.cpp4
-rw-r--r--options/base-value.hpp14
-rw-r--r--options/tie.cpp16
-rw-r--r--options/tie.hpp27
-rw-r--r--tracker-pt/ftnoir_tracker_pt_dialog.cpp17
9 files changed, 69 insertions, 54 deletions
diff --git a/compat/util.hpp b/compat/util.hpp
index c0d3e3fd..41c8def9 100644
--- a/compat/util.hpp
+++ b/compat/util.hpp
@@ -8,6 +8,7 @@
#include "macros.hpp"
#include "value-templates.hpp"
+#include <type_traits>
#include <memory>
#include <cmath>
#include <utility>
@@ -80,3 +81,8 @@ inline auto clamp(const t& val, const u& min, const w& max)
using tp = decltype(val + min + max);
return ::util_detail::clamp<std::decay_t<tp>, tp>::clamp_(val, min, max);
}
+
+template<typename t>
+using cv_qualified = std::conditional_t<is_fundamental_v<std::decay_t<t>>, std::decay_t<t>, const t&>;
+
+
diff --git a/filter-accela/ftnoir_filter_accela_dialog.cpp b/filter-accela/ftnoir_filter_accela_dialog.cpp
index 519e6e0d..c504188a 100644
--- a/filter-accela/ftnoir_filter_accela_dialog.cpp
+++ b/filter-accela/ftnoir_filter_accela_dialog.cpp
@@ -27,18 +27,18 @@ dialog_accela::dialog_accela()
tie_setting(s.pos_deadzone, ui.trans_dz_slider);
tie_setting(s.rot_nonlinearity, ui.rot_nl_slider);
- tie_setting(s.rot_sensitivity, ui.rot_gain, tr("%1°"), 0, 'g', 4);
- tie_setting(s.pos_sensitivity, ui.trans_gain, tr("%1mm"));
- tie_setting(s.ewma, ui.ewma_label, tr("%1ms"));
- tie_setting(s.rot_deadzone, ui.rot_dz, tr("%1°"), 0, 'g', 4);
- tie_setting(s.pos_deadzone, ui.trans_dz, tr("%1mm"));
- tie_setting(s.rot_nonlinearity, ui.rot_nl,
- tr("<html><head/><body>"
- "<p>x<span style='vertical-align:super;'>"
- "%1"
- "</span></p>"
- "</body></html>")
- );
+ tie_setting(s.rot_sensitivity, ui.rot_gain, [](const slider_value& s) { return tr("%1°").arg(s, 0, 'g', 4); });
+ tie_setting(s.pos_sensitivity, ui.trans_gain, [](const slider_value& s) { return tr("%1mm").arg(s, 0, 'g', 4); });
+ tie_setting(s.ewma, ui.ewma_label, [](const slider_value& s) { return tr("%1ms").arg(s); });
+ tie_setting(s.rot_deadzone, ui.rot_dz, [](const slider_value& s) { return tr("%1°").arg(s, 0, 'g', 4); });
+ tie_setting(s.pos_deadzone, ui.trans_dz, [](const slider_value& s) { return tr("%1mm").arg(s); });
+ tie_setting(s.rot_nonlinearity, ui.rot_nl, [](const slider_value& s) {
+ return tr("<html><head/><body>"
+ "<p>x<span style='vertical-align:super;'>"
+ "%1"
+ "</span></p>"
+ "</body></html>").arg(s);
+ });
//#define SPLINE_ROT_DEBUG
//#define SPLINE_TRANS_DEBUG
diff --git a/filter-ewma2/ftnoir_filter_ewma2_dialog.cpp b/filter-ewma2/ftnoir_filter_ewma2_dialog.cpp
index 55e9782e..da572ce4 100644
--- a/filter-ewma2/ftnoir_filter_ewma2_dialog.cpp
+++ b/filter-ewma2/ftnoir_filter_ewma2_dialog.cpp
@@ -20,16 +20,13 @@ dialog_ewma::dialog_ewma()
tie_setting(s.kSmoothingScaleCurve, ui.powCurve);
tie_setting(s.kSmoothingScaleCurve, ui.curve_label,
- [](auto& x) { return x * 100; },
- "%1%", 0, 'f', 2);
+ [](auto& x) { return QStringLiteral("%1%").arg(x * 100, 0, 'f', 2); });
tie_setting(s.kMinSmoothing, ui.min_label,
- [](auto& x) { return x * 100; },
- "%1%", 0, 'f', 2);
+ [](auto& x) { return QStringLiteral("%1%").arg(x * 100, 0, 'f', 2);});
tie_setting(s.kMaxSmoothing, ui.max_label,
- [](auto& x) { return x * 100; },
- "%1%", 0, 'f', 2);
+ [](auto& x) { return QStringLiteral("%1%").arg(x * 100, 0, 'f', 2);});
connect(ui.minSmooth, &QSlider::valueChanged, this,
[&](int v) -> void { if (ui.maxSmooth->value() < v) ui.maxSmooth->setValue(v); });
diff --git a/gui/main-window.cpp b/gui/main-window.cpp
index 51e22861..6a7be89f 100644
--- a/gui/main-window.cpp
+++ b/gui/main-window.cpp
@@ -115,17 +115,17 @@ MainWindow::MainWindow() :
// dylibs
{
connect(&m.tracker_dll,
- static_cast<void(base_value::*)(const QString&) const>(&base_value::valueChanged),
+ base_value::signal_fun<QString>(),
this,
[&](const QString&) { if (pTrackerDialog) pTrackerDialog = nullptr; save_modules(); });
connect(&m.protocol_dll,
- static_cast<void(base_value::*)(const QString&) const>(&base_value::valueChanged),
+ base_value::signal_fun<QString>(),
this,
[&](const QString&) { if (pProtocolDialog) pProtocolDialog = nullptr; save_modules(); });
connect(&m.filter_dll,
- static_cast<void(base_value::*)(const QString&) const>(&base_value::valueChanged),
+ base_value::signal_fun<QString>(),
this,
[&](const QString&) { if (pFilterDialog) pFilterDialog = nullptr; save_modules(); });
}
diff --git a/gui/mapping-window.cpp b/gui/mapping-window.cpp
index 0d2c9fbb..127929fe 100644
--- a/gui/mapping-window.cpp
+++ b/gui/mapping-window.cpp
@@ -109,14 +109,14 @@ void MapWidget::load()
if (altp)
{
connect(&axis.opts.altp,
- static_cast<void(base_value::*)(bool) const>(&base_value::valueChanged),
+ base_value::signal_fun<bool>(),
this,
[&](bool f) -> void {qfc.setEnabled(f); qfc.force_redraw();});
qfc.setEnabled(axis.opts.altp);
qfc.force_redraw();
}
- connect(&axis.opts.clamp, static_cast<void(base_value::*)(int) const>(&base_value::valueChanged),
+ connect(&axis.opts.clamp, base_value::signal_fun<int>(),
&qfc, [i, &conf, &qfc](int value) {
conf.set_max_input(value);
qfc.reload_spline();
diff --git a/options/base-value.hpp b/options/base-value.hpp
index 4f90e3fc..5106908d 100644
--- a/options/base-value.hpp
+++ b/options/base-value.hpp
@@ -22,13 +22,25 @@ namespace options {
class OTR_OPTIONS_EXPORT base_value : public QObject
{
Q_OBJECT
+
friend class detail::connector;
using comparator = bool(*)(const QVariant& val1, const QVariant& val2);
+ template<typename t>
+ using signal_sig = void(base_value::*)(cv_qualified<t>) const;
public:
QString name() const { return self_name; }
base_value(bundle b, const QString& name, comparator cmp, std::type_index type_idx);
~base_value() override;
+
+ // MSVC has ODR problems in 15.4
+ // no C++17 "constexpr inline" for data declarations in MSVC
+ template<typename t>
+ constexpr static auto signal_fun()
+ {
+ return static_cast<signal_sig<t>>(&base_value::valueChanged);
+ }
+
signals:
OPENTRACK_DEFINE_SIGNAL(double);
OPENTRACK_DEFINE_SIGNAL(float);
@@ -80,6 +92,8 @@ public slots:
virtual void reload() = 0;
virtual void bundle_value_changed() const = 0;
virtual void set_to_default() = 0;
+
+ friend void ::options::detail::set_base_value_to_default(base_value* val);
};
} //ns options
diff --git a/options/tie.cpp b/options/tie.cpp
index 3cb32319..162a0f56 100644
--- a/options/tie.cpp
+++ b/options/tie.cpp
@@ -22,8 +22,8 @@ OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QComboBox* cb)
{
cb->setCurrentText(v);
v = cb->currentText();
- base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(QString)), v.DIRECT_CONNTYPE);
- base_value::connect(&v, SIGNAL(valueChanged(QString)), cb, SLOT(setCurrentText(QString)), v.SAFE_CONNTYPE);
+ base_value::connect(cb, SIGNAL(currentTextChanged(QString)), &v, SLOT(setValue(const QString&)), v.DIRECT_CONNTYPE);
+ base_value::connect(&v, SIGNAL(valueChanged(const QString&)), cb, SLOT(setCurrentText(const QString&)), v.SAFE_CONNTYPE);
}
OTR_OPTIONS_EXPORT void tie_setting(value<QVariant>& v, QComboBox* cb)
@@ -55,7 +55,7 @@ OTR_OPTIONS_EXPORT void tie_setting(value<QVariant>& v, QComboBox* cb)
&v, [cb, &v](int idx) {
v = cb->itemData(idx);
}, v.DIRECT_CONNTYPE);
- base_value::connect(&v, static_cast<void(base_value::*)(const QVariant&) const>(&base_value::valueChanged),
+ base_value::connect(&v, base_value::signal_fun<QVariant>(),
cb,
[cb, set_idx](const QVariant& var) {
run_in_thread_sync(cb, [&]() {
@@ -91,21 +91,21 @@ OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QSlider* sl)
{
sl->setValue(v);
v = sl->value();
- base_value::connect(sl, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE);
- base_value::connect(&v, SIGNAL(valueChanged(int)), sl, SLOT(setValue(int)), v.SAFE_CONNTYPE);
+ base_value::connect(sl, &QSlider::valueChanged, &v, base_value::signal_fun<int>(), v.DIRECT_CONNTYPE);
+ base_value::connect(&v, base_value::signal_fun<int>(), sl, &QSlider::setValue, v.SAFE_CONNTYPE);
}
OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QLineEdit* le)
{
le->setText(v);
base_value::connect(le, SIGNAL(textChanged(QString)), &v, SLOT(setValue(QString)), v.DIRECT_CONNTYPE);
- base_value::connect(&v, SIGNAL(valueChanged(QString)),le, SLOT(setText(QString)), v.SAFE_CONNTYPE);
+ base_value::connect(&v, base_value::signal_fun<QString>(), le, &QLineEdit::setText, v.SAFE_CONNTYPE);
}
OTR_OPTIONS_EXPORT void tie_setting(value<QString>& v, QLabel* lb)
{
lb->setText(v);
- base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.SAFE_CONNTYPE);
+ base_value::connect(&v, base_value::signal_fun<QString>(), lb, &QLabel::setText, v.SAFE_CONNTYPE);
}
OTR_OPTIONS_EXPORT void tie_setting(value<int>& v, QTabWidget* t)
@@ -141,7 +141,7 @@ OTR_OPTIONS_EXPORT void tie_setting(value<slider_value>& v, QSlider* w)
v.DIRECT_CONNTYPE);
base_value::connect(&v,
- static_cast<void(base_value::*)(const slider_value&) const>(&base_value::valueChanged),
+ base_value::signal_fun<slider_value>(),
w,
[=, &v](double) {
run_in_thread_sync(w, [=, &v]()
diff --git a/options/tie.hpp b/options/tie.hpp
index 92e98680..0a4ace74 100644
--- a/options/tie.hpp
+++ b/options/tie.hpp
@@ -52,36 +52,17 @@ tie_setting(value<t>& v, QComboBox* cb)
v.SAFE_CONNTYPE);
}
-template<typename t, typename... xs>
-void tie_setting(value<t>& v, QLabel* lb, const QString& format, const xs&... args)
+template<typename t, typename F>
+void tie_setting(value<t>& v, QLabel* lb, F&& fun)
{
- auto closure = [=](const t& x) { lb->setText(format.arg(x, args...)); };
+ auto closure = [=](cv_qualified<t> x) { lb->setText(fun(x)); };
closure(v());
- base_value::connect(&v, static_cast<void(base_value::*)(const t&) const>(&base_value::valueChanged),
+ base_value::connect(&v, base_value::signal_fun<t>(),
lb, closure,
v.SAFE_CONNTYPE);
}
-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, 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);
-}
-
-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)
-{
- tie_setting(v, lb, fun, QStringLiteral("%1"));
-}
-
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);
diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp
index 6b31ac8a..a4b8c668 100644
--- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp
+++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp
@@ -93,6 +93,23 @@ TrackerDialog_PT::TrackerDialog_PT()
ui.blob_color->setItemData(k, int(color_types[k]));
tie_setting(s.blob_color, ui.blob_color);
+
+ tie_setting(s.threshold, ui.threshold_value_display, [this](int x) {
+ if (!s.auto_threshold)
+ return tr("Brightness %1/255").arg(x);
+ else
+ {
+ CamInfo info;
+ int w = 640, h = 480;
+
+ if (tracker && tracker->get_cam_info(&info) && info.res_x * info.res_y != 0)
+ w = info.res_x, h = info.res_y;
+
+ double value = PointExtractor::threshold_radius_value(w, h, x);
+
+ return tr("LED radius %1 pixels").arg(value, 0, 'f', 2);
+ }
+ });
}
void TrackerDialog_PT::startstop_trans_calib(bool start)