Trace View: Move ruler time conversion from View to Ruler
authorSoeren Apel <soeren@apelpie.net>
Wed, 26 Jun 2019 20:20:25 +0000 (22:20 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Fri, 5 Jul 2019 20:49:08 +0000 (22:49 +0200)
pv/views/trace/cursor.cpp
pv/views/trace/ruler.cpp
pv/views/trace/ruler.hpp
pv/views/trace/timemarker.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index c218440..0fcb6fa 100644 (file)
@@ -59,7 +59,7 @@ QString Cursor::get_text() const
        const pv::util::Timestamp& diff = abs(time_ - other->time_);
 
        return Ruler::format_time_with_distance(
-               diff, view_.absolute_to_ruler_time(time_),
+               diff, view_.ruler()->get_ruler_time_from_absolute_time(time_),
         view_.tick_prefix(), view_.time_unit(), view_.tick_precision());
 }
 
index 401fc3d..5fa1be2 100644 (file)
@@ -129,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);
index 5035bfc..bfab766 100644 (file)
@@ -120,6 +120,9 @@ public:
        pv::util::Timestamp get_absolute_time_from_x_pos(uint32_t x) const;
        pv::util::Timestamp get_ruler_time_from_x_pos(uint32_t x) const;
 
+       pv::util::Timestamp get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const;
+       pv::util::Timestamp get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const;
+
 protected:
        virtual void contextMenuEvent(QContextMenuEvent *event) override;
        void resizeEvent(QResizeEvent*) override;
index c58aa08..ec4c97d 100644 (file)
@@ -25,6 +25,7 @@
 #include "timemarker.hpp"
 
 #include "pv/widgets/timestampspinbox.hpp"
+#include "ruler.hpp"
 #include "view.hpp"
 
 #include <QApplication>
@@ -65,7 +66,7 @@ void TimeMarker::set_time(const pv::util::Timestamp& time)
 
        if (value_widget_) {
                updating_value_widget_ = true;
-               value_widget_->setValue(view_.absolute_to_ruler_time(time));
+               value_widget_->setValue(view_.ruler()->get_ruler_time_from_absolute_time(time));
                updating_value_widget_ = false;
        }
 
@@ -179,7 +180,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
        popup->setLayout(form);
 
        value_widget_ = new pv::widgets::TimestampSpinBox(parent);
-       value_widget_->setValue(view_.absolute_to_ruler_time(time_));
+       value_widget_->setValue(view_.ruler()->get_ruler_time_from_absolute_time(time_));
 
        connect(value_widget_, SIGNAL(valueChanged(const pv::util::Timestamp&)),
                this, SLOT(on_value_changed(const pv::util::Timestamp&)));
@@ -192,7 +193,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
 void TimeMarker::on_value_changed(const pv::util::Timestamp& value)
 {
        if (!updating_value_widget_)
-               set_time(view_.ruler_to_absolute_time(value));
+               set_time(view_.ruler()->get_absolute_time_from_ruler_time(value));
 }
 
 } // namespace trace
index 8e2a2b3..4b95a80 100644 (file)
@@ -456,16 +456,6 @@ void View::set_scale(double scale)
        }
 }
 
-pv::util::Timestamp View::absolute_to_ruler_time(const pv::util::Timestamp& abs_time) const
-{
-    return abs_time + zero_offset_;
-}
-
-pv::util::Timestamp View::ruler_to_absolute_time(const pv::util::Timestamp& ruler_time) const
-{
-    return ruler_time - zero_offset_;
-}
-
 void View::set_offset(const pv::util::Timestamp& offset, bool force_update)
 {
        if ((offset_ != offset) || force_update) {
@@ -503,6 +493,11 @@ void View::reset_zero_position()
        ruler_->update();
 }
 
+pv::util::Timestamp View::zero_offset() const
+{
+       return zero_offset_;
+}
+
 int View::owner_visual_v_offset() const
 {
        return -scrollarea_->verticalScrollBar()->sliderPosition();
index 06b2cf2..8f59b02 100644 (file)
@@ -177,8 +177,7 @@ public:
 
        void reset_zero_position();
 
-    pv::util::Timestamp absolute_to_ruler_time(const pv::util::Timestamp& abs_time) const;
-    pv::util::Timestamp ruler_to_absolute_time(const pv::util::Timestamp& ruler_time) const;
+       pv::util::Timestamp zero_offset() const;
 
        /**
         * Returns the vertical scroll offset.