]> sigrok.org Git - pulseview.git/commitdiff
Trace View: Move ruler time conversion from View to Ruler
authorSoeren Apel <redacted>
Wed, 26 Jun 2019 20:20:25 +0000 (22:20 +0200)
committerUwe Hermann <redacted>
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 c218440e31eae87f04f482c448a7a0b150216f4a..0fcb6faf44dd9048b9ea842fdc57d7734b28a3f9 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 401fc3da28e86e81d2c1ba3858bd1d4cb866a0e3..5fa1be2fc4326e2eb5728c6a27035023315ace54 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 5035bfc83bffc9962f8a7d06d782c1fae5dcd232..bfab766619d135c7d251a2863c7e9078c102ee81 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 c58aa08dbc5926d08f10455af50b1efccf4b36b6..ec4c97d78937fb8d76ec42e8e69fa670897ce3f7 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 8e2a2b329daa7bfae8ffbe96f507b550de88fa92..4b95a806a490cf492ad33cb6e2b537b5f8744165 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 06b2cf2fb6275f2cd51f55e8b5a43007ff0d757c..8f59b02927cd62c218d1d84c2603e124c326a69e 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.