]> sigrok.org Git - pulseview.git/blobdiff - pv/view/cursor.cpp
View: Determine time unit and use it in other classes
[pulseview.git] / pv / view / cursor.cpp
index 0ea6f5ab7b0c5e3edbc21b64600bc06e2f1346dd..2f2bc482f22cc567c408723cd6eb8eedd651df32 100644 (file)
 
 #include <cassert>
 #include <cstdio>
+#include <limits>
 
+using std::abs;
 using std::shared_ptr;
+using std::numeric_limits;
 
 namespace pv {
 namespace view {
@@ -52,7 +55,8 @@ bool Cursor::enabled() const
 
 QString Cursor::get_text() const
 {
-       return pv::util::format_time(time_, view_.tick_prefix(), 2);
+       return util::format_time(time_, view_.tick_prefix(),
+               view_.time_unit(), 2);
 }
 
 QRectF Cursor::label_rect(const QRectF &rect) const
@@ -72,7 +76,10 @@ QRectF Cursor::label_rect(const QRectF &rect) const
                TimeMarker::ArrowSize - 0.5f;
        const float height = label_size.height();
 
-       if (time_ > other->time())
+       const double other_time = other->time();
+       if (time_ > other_time ||
+               (abs(time_ - other_time) < numeric_limits<double>::epsilon() &&
+               this > other.get()))
                return QRectF(x, top, label_size.width(), height);
        else
                return QRectF(x - label_size.width(), top,