From a2f96263f56e019f811a7fc2eba3129ede1d9a5f Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Sun, 6 May 2018 20:09:42 +0200 Subject: [PATCH] Fix #1149 by handling "d" and "(dd)" types separately --- pv/prop/enum.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pv/prop/enum.cpp b/pv/prop/enum.cpp index a6a53764..1f542b74 100644 --- a/pv/prop/enum.cpp +++ b/pv/prop/enum.cpp @@ -18,11 +18,14 @@ */ #include +#include +#include #include #include "enum.hpp" +using std::abs; using std::pair; using std::vector; @@ -75,8 +78,29 @@ void Enum::update_widget() for (unsigned int i = 0; i < values_.size(); i++) { const pair &v = values_[i]; - if (v.first.equal(variant)) - selector_->setCurrentIndex(i); + + // g_variant_equal() doesn't handle floating point properly + if (v.first.is_of_type(Glib::VariantType("d"))) { + gdouble a, b; + g_variant_get(variant.gobj(), "d", &a); + g_variant_get((GVariant*)(v.first.gobj()), "d", &b); + if (abs(a - b) <= 2 * DBL_EPSILON) + selector_->setCurrentIndex(i); + } else { + // Check for "(dd)" type and handle it if it's found + if (v.first.is_of_type(Glib::VariantType("(dd)"))) { + gdouble a1, a2, b1, b2; + g_variant_get(variant.gobj(), "(dd)", &a1, &a2); + g_variant_get((GVariant*)(v.first.gobj()), "(dd)", &b1, &b2); + if ((abs(a1 - b1) <= 2 * DBL_EPSILON) && \ + (abs(a2 - b2) <= 2 * DBL_EPSILON)) + selector_->setCurrentIndex(i); + + } else + // Handle all other types + if (v.first.equal(variant)) + selector_->setCurrentIndex(i); + } } } -- 2.30.2