Show ruler timestamps in cursors and popups
authorjaseg <git@jaseg.net>
Sun, 9 Jun 2019 11:07:55 +0000 (20:07 +0900)
committerSoeren Apel <soeren@apelpie.net>
Thu, 4 Jul 2019 21:17:27 +0000 (23:17 +0200)
Prior to this absolute timestamps would be shown, even with the zero
point set somewhere else.

pv/views/trace/cursor.cpp
pv/views/trace/timemarker.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 7a375c7aad49410450c5f41f0d6d8c949e6bcd38..c218440e31eae87f04f482c448a7a0b150216f4a 100644 (file)
@@ -59,7 +59,8 @@ QString Cursor::get_text() const
        const pv::util::Timestamp& diff = abs(time_ - other->time_);
 
        return Ruler::format_time_with_distance(
-               diff, time_, view_.tick_prefix(), view_.time_unit(), view_.tick_precision());
+               diff, view_.absolute_to_ruler_time(time_),
+        view_.tick_prefix(), view_.time_unit(), view_.tick_precision());
 }
 
 QRectF Cursor::label_rect(const QRectF &rect) const
index 266007a57053c220f59a87fe80eb630438a413c0..c58aa08dbc5926d08f10455af50b1efccf4b36b6 100644 (file)
@@ -65,7 +65,7 @@ void TimeMarker::set_time(const pv::util::Timestamp& time)
 
        if (value_widget_) {
                updating_value_widget_ = true;
-               value_widget_->setValue(time);
+               value_widget_->setValue(view_.absolute_to_ruler_time(time));
                updating_value_widget_ = false;
        }
 
@@ -179,7 +179,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
        popup->setLayout(form);
 
        value_widget_ = new pv::widgets::TimestampSpinBox(parent);
-       value_widget_->setValue(time_);
+       value_widget_->setValue(view_.absolute_to_ruler_time(time_));
 
        connect(value_widget_, SIGNAL(valueChanged(const pv::util::Timestamp&)),
                this, SLOT(on_value_changed(const pv::util::Timestamp&)));
@@ -192,7 +192,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(value);
+               set_time(view_.ruler_to_absolute_time(value));
 }
 
 } // namespace trace
index 7f77635d235791192bb05ed5db79f680dfc5ae6d..8e2a2b329daa7bfae8ffbe96f507b550de88fa92 100644 (file)
@@ -456,6 +456,16 @@ 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) {
index c6a7c55743caf64e9496e4c4fc0d054940cc4ab8..06b2cf2fb6275f2cd51f55e8b5a43007ff0d757c 100644 (file)
@@ -177,6 +177,9 @@ 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;
+
        /**
         * Returns the vertical scroll offset.
         */