diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-07-06 15:49:56 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-07-06 15:49:56 +0200 |
commit | 86c58f729706933e84b2f50771d4e4fb3345a449 (patch) | |
tree | 58631e15f4f45fbc0119f84cfa6aa24f783048cf /opentrack-compat | |
parent | 917fe201f2a6d810c8a05dc52881d67b7ba42664 (diff) |
Revert "compat/options: export template instances to lessen code bloat"
This reverts commit 1e26e00e9ae0c519355e3a6fe5ad098d1f6a9622.
Broke osx.
Diffstat (limited to 'opentrack-compat')
-rw-r--r-- | opentrack-compat/options-specialize.hpp | 21 | ||||
-rw-r--r-- | opentrack-compat/options.cpp | 118 | ||||
-rw-r--r-- | opentrack-compat/options.hpp | 125 |
3 files changed, 118 insertions, 146 deletions
diff --git a/opentrack-compat/options-specialize.hpp b/opentrack-compat/options-specialize.hpp deleted file mode 100644 index 735836d9..00000000 --- a/opentrack-compat/options-specialize.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#ifndef OPENTRACK_OPTIONS_EXTERN_TEMPLATES -# define OPENTRACK_OPTIONS_EXTERN_TEMPLATES -# error "define OPENTRACK_OPTIONS_EXTERN_TEMPLATES before including" -#endif - -#include "export.hpp" - -namespace options { - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<int, QComboBox>(value<int>& v, QComboBox* cb); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<QString, QComboBox>(value<QString>& v, QComboBox* cb); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<bool, QCheckBox>(value<bool>& v, QCheckBox* cb); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<double, QDoubleSpinBox>(value<double>& v, QDoubleSpinBox* dsb); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<int, QSpinBox>(value<int>& v, QSpinBox* sb); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<int, QSlider>(value<int>& v, QSlider* sl); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<QString, QLineEdit>(value<QString>& v, QLineEdit* le); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<QString, QLabel>(value<QString>& v, QLabel* lb); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<int, QTabWidget>(value<int>& v, QTabWidget* t); - OPENTRACK_OPTIONS_EXTERN_TEMPLATES template OPENTRACK_COMPAT_EXPORT void tie_setting<slider_value, QSlider>(value<slider_value>& v, QSlider* w); -} diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp index f12a209c..7b2eaa2f 100644 --- a/opentrack-compat/options.cpp +++ b/opentrack-compat/options.cpp @@ -1,6 +1,5 @@ -#define OPENTRACK_OPTIONS_EXTERN_TEMPLATES /* nothing */ - #include "options.hpp" + #include <cmath> namespace options @@ -241,118 +240,5 @@ OPENTRACK_COMPAT_EXPORT opt_singleton& singleton() } // end options::detail -template<> -void tie_setting(value<int>& v, QComboBox* cb) -{ - cb->setCurrentIndex(v); - v = cb->currentIndex(); - base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int)), v.DIRECT_CONNTYPE); -} - -template<> -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.DIRECT_CONNTYPE); -} - -template<> -void tie_setting(value<bool>& v, QCheckBox* cb) -{ - cb->setChecked(v); - base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool)), v.DIRECT_CONNTYPE); -} - -template<> -void tie_setting(value<double>& v, QDoubleSpinBox* dsb) -{ - dsb->setValue(v); - base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double)), v.DIRECT_CONNTYPE); -} - -template<> -void tie_setting(value<int>& v, QSpinBox* sb) -{ - sb->setValue(v); - base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.DIRECT_CONNTYPE); -} - -template<> -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.DIRECT_CONNTYPE); -} - -template<> -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.DIRECT_CONNTYPE); -} - -template<> -void tie_setting(value<QString>& v, QLabel* lb) -{ - lb->setText(v); - base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.DIRECT_CONNTYPE); -} - -template<> -void tie_setting(value<int>& v, QTabWidget* t) -{ - t->setCurrentIndex(v); - base_value::connect(t, SIGNAL(currentChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); - base_value::connect(&v, SIGNAL(valueChanged(int)), t, SLOT(setCurrentIndex(int)), v.DIRECT_CONNTYPE); -} - -template<> -void tie_setting(value<slider_value>& v, QSlider* w) -{ - // we can't get these at runtime since signals cross threads - const int q_min = w->minimum(); - const int q_max = w->maximum(); - const int q_diff = q_max - q_min; - - slider_value sv(v); - - const double sv_max = sv.max(); - const double sv_min = sv.min(); - const double sv_c = sv_max - sv_min; - - w->setValue(int((sv.cur() - sv_min) / sv_c * q_diff + q_min)); - v = slider_value(q_diff <= 0 ? 0 : (w->value() - q_min) * sv_c / (double)q_diff + sv_min, sv_min, sv_max); - - base_value::connect(w, - &QSlider::valueChanged, - &v, - [=, &v](int pos) -> void - { - if (q_diff <= 0 || pos <= 0) - v = slider_value(sv_min, sv_min, sv_max); - else - v = slider_value((pos - q_min) * sv_c / (double)q_diff + sv_min, sv_min, sv_max); - }, - v.DIRECT_CONNTYPE); - base_value::connect(&v, - static_cast<void(base_value::*)(double)>(&base_value::valueChanged), - w, - [=](double value) -> void - { - w->setValue(int(value * q_diff) + q_min); - }, - v.DIRECT_CONNTYPE); -} - -} // ns options +} // end options -#include "options-specialize.hpp" diff --git a/opentrack-compat/options.hpp b/opentrack-compat/options.hpp index aa290c74..53249746 100644 --- a/opentrack-compat/options.hpp +++ b/opentrack-compat/options.hpp @@ -282,9 +282,10 @@ namespace options { }; template<typename t, typename q> - void tie_setting(value<t>&, q*); + inline void tie_setting(value<t>&, q*); template<typename t> + inline typename std::enable_if<std::is_enum<t>::value>::type tie_setting(value<t>& v, QComboBox* cb) { @@ -361,11 +362,117 @@ namespace options { fn2(v, cb, enum_cases), v.DIRECT_CONNTYPE); } -} // ns options - -#ifndef QT_MOC_RUN -# ifndef OPENTRACK_OPTIONS_EXTERN_TEMPLATES -# define OPENTRACK_OPTIONS_EXTERN_TEMPLATES extern -# include "options-specialize.hpp" -# endif -#endif + + template<> + inline void tie_setting(value<int>& v, QComboBox* cb) + { + cb->setCurrentIndex(v); + v = cb->currentIndex(); + base_value::connect(cb, SIGNAL(currentIndexChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), cb, SLOT(setCurrentIndex(int)), v.DIRECT_CONNTYPE); + } + + template<> + inline 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.DIRECT_CONNTYPE); + } + + template<> + inline void tie_setting(value<bool>& v, QCheckBox* cb) + { + cb->setChecked(v); + base_value::connect(cb, SIGNAL(toggled(bool)), &v, SLOT(setValue(bool)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(bool)), cb, SLOT(setChecked(bool)), v.DIRECT_CONNTYPE); + } + + template<> + inline void tie_setting(value<double>& v, QDoubleSpinBox* dsb) + { + dsb->setValue(v); + base_value::connect(dsb, SIGNAL(valueChanged(double)), &v, SLOT(setValue(double)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(double)), dsb, SLOT(setValue(double)), v.DIRECT_CONNTYPE); + } + + template<> + inline void tie_setting(value<int>& v, QSpinBox* sb) + { + sb->setValue(v); + base_value::connect(sb, SIGNAL(valueChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), sb, SLOT(setValue(int)), v.DIRECT_CONNTYPE); + } + + template<> + inline 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.DIRECT_CONNTYPE); + } + + template<> + inline 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.DIRECT_CONNTYPE); + } + + template<> + inline void tie_setting(value<QString>& v, QLabel* lb) + { + lb->setText(v); + base_value::connect(&v, SIGNAL(valueChanged(QString)), lb, SLOT(setText(QString)), v.DIRECT_CONNTYPE); + } + + template<> + inline void tie_setting(value<int>& v, QTabWidget* t) + { + t->setCurrentIndex(v); + base_value::connect(t, SIGNAL(currentChanged(int)), &v, SLOT(setValue(int)), v.DIRECT_CONNTYPE); + base_value::connect(&v, SIGNAL(valueChanged(int)), t, SLOT(setCurrentIndex(int)), v.DIRECT_CONNTYPE); + } + + template<> + inline void tie_setting(value<slider_value>& v, QSlider* w) + { + // we can't get these at runtime since signals cross threads + const int q_min = w->minimum(); + const int q_max = w->maximum(); + const int q_diff = q_max - q_min; + + slider_value sv(v); + + const double sv_max = sv.max(); + const double sv_min = sv.min(); + const double sv_c = sv_max - sv_min; + + w->setValue(int((sv.cur() - sv_min) / sv_c * q_diff + q_min)); + v = slider_value(q_diff <= 0 ? 0 : (w->value() - q_min) * sv_c / (double)q_diff + sv_min, sv_min, sv_max); + + base_value::connect(w, + &QSlider::valueChanged, + &v, + [=, &v](int pos) -> void + { + if (q_diff <= 0 || pos <= 0) + v = slider_value(sv_min, sv_min, sv_max); + else + v = slider_value((pos - q_min) * sv_c / (double)q_diff + sv_min, sv_min, sv_max); + }, + v.DIRECT_CONNTYPE); + base_value::connect(&v, + static_cast<void(base_value::*)(double)>(&base_value::valueChanged), + w, + [=](double value) -> void + { + w->setValue(int(value * q_diff) + q_min); + }, + v.DIRECT_CONNTYPE); + } +} + |