浏览代码

Makes ctkRangeWidget sensitive to its decimal number

when it comes to comparing 2 numbers. Because spinboxes truncate the
numbers based on their decimals, numbers can be different for small orders.
Julien Finet 14 年之前
父节点
当前提交
352ac124a5
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      Libs/Widgets/ctkRangeWidget.cpp

+ 6 - 3
Libs/Widgets/ctkRangeWidget.cpp

@@ -26,6 +26,9 @@
 #include "ctkRangeWidget.h"
 #include "ui_ctkRangeWidget.h"
 
+// STD includes
+#include <cmath>
+
 //-----------------------------------------------------------------------------
 class ctkRangeWidgetPrivate: public Ui_ctkRangeWidget
 {
@@ -39,7 +42,7 @@ public:
   void updateSpinBoxWidth();
   int synchronizedSpinBoxWidth()const;
   void synchronizeSiblingSpinBox(int newWidth);
-  static bool equal(double v1, double v2);
+  bool equal(double v1, double v2)const;
   void relayout();
 
   bool          Tracking;
@@ -52,9 +55,9 @@ public:
 };
 
 // --------------------------------------------------------------------------
-bool ctkRangeWidgetPrivate::equal(double v1, double v2)
+bool ctkRangeWidgetPrivate::equal(double v1, double v2)const
 {
-  return qAbs(v1 - v2) < 0.0001;
+  return qAbs(v1 - v2) < pow(10., -this->MinimumSpinBox->decimals());
 }
 
 // --------------------------------------------------------------------------