#pragma once #include "slider.hpp" #include "export.hpp" #include #include #include namespace options::detail { template using cv_qualified = std::conditional_t>, std::remove_cvref_t, std::add_lvalue_reference_t>>>; template struct default_value_traits { using value_type = t; using stored_type = u; static inline value_type value_with_default(cv_qualified val, cv_qualified) { return val; } static inline value_type value_from_storage(cv_qualified x) { return static_cast(x); } static inline stored_type storage_from_value(cv_qualified val) { return static_cast(val); } static inline value_type value_from_qvariant(const QVariant& x) { return value_from_storage(storage_from_qvariant(x)); } static inline QVariant qvariant_from_value(cv_qualified val) { return qvariant_from_storage(storage_from_value(val)); } static constexpr inline value_type pass_value(cv_qualified x) { if constexpr(std::is_same_v) return x; else return value_from_storage(storage_from_value(x)); } static inline stored_type storage_from_qvariant(const QVariant& x) { // XXX TODO return x.value(); } static inline QVariant qvariant_from_storage(cv_qualified val) { // XXX TODO return QVariant::fromValue(val); } static inline bool is_equal(cv_qualified x, cv_qualified y) { return x == y; } }; template struct value_traits : default_value_traits {}; template<> inline bool default_value_traits::is_equal(double x, double y) { return std::fabs(x - y) < 1e-6; } template<> struct value_traits : default_value_traits {}; template<> inline bool default_value_traits::is_equal(float x, float y) { return std::fabs(x - y) < 1e-6f; } template<> inline slider_value default_value_traits::value_with_default(cv_qualified val, cv_qualified def) { return { val.cur(), def.min(), def.max() }; } template<> inline bool default_value_traits::is_equal(cv_qualified x, cv_qualified y) { return value_traits::is_equal(x.cur(), y.cur()); } // Qt uses int a lot in slots so use it for all enums template struct value_traits>> : default_value_traits {}; } // ns options::detail