X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fviews%2Ftrace%2Fruler.cpp;h=5fa1be2fc4326e2eb5728c6a27035023315ace54;hp=98f55ddb06fb72ebac091263abb65c062e87bfc5;hb=4468ee4246cd5e47845494e8b3b22a17d434ed5b;hpb=ef85cfa4599d3741e7007921e39a44490e97cfaf diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 98f55ddb..5fa1be2f 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -88,8 +88,7 @@ QString Ruler::format_time_with_distance( pv::util::SIPrefix prefix, pv::util::TimeUnit unit, unsigned precision, - bool sign, - bool show_unit) + bool sign) { const unsigned limit = 60; @@ -98,7 +97,12 @@ QString Ruler::format_time_with_distance( // If we have to use samples then we have no alternative formats if (unit == pv::util::TimeUnit::Samples) - return pv::util::format_time_si_adjusted(t, prefix, precision, show_unit ? "sa" : NULL, sign); + return pv::util::format_time_si_adjusted(t, prefix, precision, "sa", sign); + + QString unit_string; + if (unit == pv::util::TimeUnit::Time) + unit_string = "s"; + // Note: In case of pv::util::TimeUnit::None, unit_string remains empty // View zoomed way out -> low precision (0), big distance (>=60s) // -> DD:HH:MM @@ -110,7 +114,7 @@ QString Ruler::format_time_with_distance( // View zoomed way in -> high precision (>3), low step size (<1s) // -> HH:MM:SS.mmm... or xxxx (si unit) if less than limit seconds if (abs(t) < limit) - return pv::util::format_time_si_adjusted(t, prefix, precision, show_unit ? "s" : NULL, sign); + return pv::util::format_time_si_adjusted(t, prefix, precision, unit_string, sign); else return pv::util::format_time_minutes(t, precision, sign); } @@ -125,6 +129,16 @@ pv::util::Timestamp Ruler::get_ruler_time_from_x_pos(uint32_t x) const return view_.ruler_offset() + ((double)x + 0.5) * view_.scale(); } +pv::util::Timestamp Ruler::get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const +{ + return abs_time + view_.zero_offset(); +} + +pv::util::Timestamp Ruler::get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const +{ + return ruler_time - view_.zero_offset(); +} + void Ruler::contextMenuEvent(QContextMenuEvent *event) { MarginWidget::contextMenuEvent(event);