From ffc00fdd5946593ad2a587078fd4ee9ba0a507ec Mon Sep 17 00:00:00 2001 From: Cenkron Date: Tue, 9 Jan 2018 20:28:11 -0600 Subject: [PATCH] Provide a settings checkbox for showing zero at the trigger --- pv/dialogs/settings.cpp | 10 +++++++ pv/dialogs/settings.hpp | 1 + pv/globalsettings.cpp | 1 + pv/globalsettings.hpp | 1 + pv/views/trace/ruler.cpp | 4 +-- pv/views/trace/ruler.hpp | 2 +- pv/views/trace/view.cpp | 56 +++++++++++++++++++++++++++++++++------- pv/views/trace/view.hpp | 16 +++++++++--- pv/views/viewbase.cpp | 1 + pv/views/viewbase.hpp | 1 + 10 files changed, 77 insertions(+), 16 deletions(-) diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 1730e7ba..17f68a65 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -160,6 +160,10 @@ QWidget *Settings::get_view_settings_form(QWidget *parent) const SLOT(on_view_zoomToFitAfterAcq_changed(int))); trace_view_layout->addRow(tr("Perform a zoom-to-&fit when acquisition stops"), cb); + cb = create_checkbox(GlobalSettings::Key_View_TriggerIsZeroTime, + SLOT(on_view_triggerIsZero_changed(int))); + trace_view_layout->addRow(tr("Show time zero at the trigger"), cb); + cb = create_checkbox(GlobalSettings::Key_View_StickyScrolling, SLOT(on_view_stickyScrolling_changed(int))); trace_view_layout->addRow(tr("Always keep &newest samples at the right edge during capture"), cb); @@ -424,6 +428,12 @@ void Settings::on_view_zoomToFitAfterAcq_changed(int state) settings.setValue(GlobalSettings::Key_View_ZoomToFitAfterAcq, state ? true : false); } +void Settings::on_view_triggerIsZero_changed(int state) +{ + GlobalSettings settings; + settings.setValue(GlobalSettings::Key_View_TriggerIsZeroTime, state ? true : false); +} + void Settings::on_view_colouredBG_changed(int state) { GlobalSettings settings; diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index 72c96125..d548f52f 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -52,6 +52,7 @@ private Q_SLOTS: void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous); void on_view_zoomToFitDuringAcq_changed(int state); void on_view_zoomToFitAfterAcq_changed(int state); + void on_view_triggerIsZero_changed(int state); void on_view_colouredBG_changed(int state); void on_view_stickyScrolling_changed(int state); void on_view_showSamplingPoints_changed(int state); diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index eabe4d3c..c9a757c9 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -32,6 +32,7 @@ namespace pv { const QString GlobalSettings::Key_View_ZoomToFitDuringAcq = "View_ZoomToFitDuringAcq"; const QString GlobalSettings::Key_View_ZoomToFitAfterAcq = "View_ZoomToFitAfterAcq"; +const QString GlobalSettings::Key_View_TriggerIsZeroTime = "View_TriggerIsZeroTime"; const QString GlobalSettings::Key_View_ColouredBG = "View_ColouredBG"; const QString GlobalSettings::Key_View_StickyScrolling = "View_StickyScrolling"; const QString GlobalSettings::Key_View_ShowSamplingPoints = "View_ShowSamplingPoints"; diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index 9cf2978b..c6b4cfc5 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -42,6 +42,7 @@ class GlobalSettings : public QSettings public: static const QString Key_View_ZoomToFitDuringAcq; static const QString Key_View_ZoomToFitAfterAcq; + static const QString Key_View_TriggerIsZeroTime; static const QString Key_View_ColouredBG; static const QString Key_View_StickyScrolling; static const QString Key_View_ShowSamplingPoints; diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 0526bb2c..fe08cb06 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -140,7 +140,7 @@ void Ruler::paintEvent(QPaintEvent*) tick_position_cache_ = calculate_tick_positions( view_.tick_period(), - view_.offset(), + view_.ruler_offset(), view_.scale(), width(), ffunc); @@ -228,7 +228,7 @@ Ruler::TickPositions Ruler::calculate_tick_positions( void Ruler::mouseDoubleClickEvent(QMouseEvent *event) { - view_.add_flag(view_.offset() + ((double)event->x() + 0.5) * view_.scale()); + view_.add_flag(view_.ruler_offset() + ((double)event->x() + 0.5) * view_.scale()); } void Ruler::draw_hover_mark(QPainter &p, int text_height) diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index e9432bd6..0c614c6c 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -157,7 +157,7 @@ private: * Calculates the major and minor tick positions. * * @param major_period The period between the major ticks. - * @param offset The time at the left border of the ruler. + * @param offset The virtual time at the left border of the ruler. * @param scale The scale in seconds per pixel. * @param width the Width of the ruler. * @param format_function A function used to format the major tick times. diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 156b3eef..292933e7 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -129,6 +129,7 @@ View::View(Session &session, bool is_main_view, QWidget *parent) : segment_selectable_(false), scale_(1e-3), offset_(0), + ruler_offset_(0), updating_scroll_(false), settings_restored_(false), header_was_shrunk_(false), @@ -326,10 +327,18 @@ void View::save_settings(QSettings &settings) const settings.setValue("splitter_state", splitter_->saveState()); settings.setValue("segment_display_mode", segment_display_mode_); - stringstream ss; - boost::archive::text_oarchive oa(ss); - oa << boost::serialization::make_nvp("offset", offset_); - settings.setValue("offset", QString::fromStdString(ss.str())); + { + stringstream ss; + boost::archive::text_oarchive oa(ss); + oa << boost::serialization::make_nvp("ruler_shift", ruler_shift_); + settings.setValue("ruler_shift", QString::fromStdString(ss.str())); + } + { + stringstream ss; + boost::archive::text_oarchive oa(ss); + oa << boost::serialization::make_nvp("offset", offset_); + settings.setValue("offset", QString::fromStdString(ss.str())); + } for (shared_ptr signal : signals_) { settings.beginGroup(signal->base()->internal_name()); @@ -346,6 +355,17 @@ void View::restore_settings(QSettings &settings) if (settings.contains("scale")) set_scale(settings.value("scale").toDouble()); + if (settings.contains("ruler_shift")) { + util::Timestamp shift; + stringstream ss; + ss << settings.value("ruler_shift").toString().toStdString(); + + boost::archive::text_iarchive ia(ss); + ia >> boost::serialization::make_nvp("ruler_shift", shift); + + ruler_shift_ = shift; + } + if (settings.contains("offset")) { util::Timestamp offset; stringstream ss; @@ -354,6 +374,7 @@ void View::restore_settings(QSettings &settings) boost::archive::text_iarchive ia(ss); ia >> boost::serialization::make_nvp("offset", offset); + // This also updates ruler_offset_ set_offset(offset); } @@ -411,19 +432,27 @@ void View::set_scale(double scale) } } -const Timestamp& View::offset() const -{ - return offset_; -} - void View::set_offset(const pv::util::Timestamp& offset) { if (offset_ != offset) { offset_ = offset; + ruler_offset_ = offset_ + ruler_shift_; offset_changed(); } } +// Returns the internal version of the time offset +const Timestamp& View::offset() const +{ + return offset_; +} + +// Returns the ruler version of the time offset +const Timestamp& View::ruler_offset() const +{ + return ruler_offset_; +} + int View::owner_visual_v_offset() const { return -scrollarea_->verticalScrollBar()->sliderPosition(); @@ -794,6 +823,15 @@ void View::restack_all_trace_tree_items() void View::trigger_event(util::Timestamp location) { + // Set up ruler_shift if the Key_View_TriggerIsZeroTime option is set. + GlobalSettings settings; + bool trigger_is_zero_time = settings.value(GlobalSettings::Key_View_TriggerIsZeroTime).toBool(); + + ruler_shift_ = (trigger_is_zero_time) ? (-location) : (0); + // Force an immediate update of both offsets + offset_ -= 0.001; + set_offset(offset_ + 0.001); + trigger_markers_.push_back(make_shared(*this, location)); } diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index e80198d3..28c94e52 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -151,11 +151,17 @@ public: double scale() const; /** - * Returns the time offset of the left edge of the view in - * seconds. + * Returns the internal view version of the time offset of the left edge + * of the view in seconds. */ const pv::util::Timestamp& offset() const; + /** + * Returns the ruler version of the time offset of the left edge + * of the view in seconds. + */ + const pv::util::Timestamp& ruler_offset() const; + /** * Returns the vertical scroll offset. */ @@ -397,7 +403,7 @@ private Q_SLOTS: void process_sticky_events(); /** - * Sets the 'offset_' member and emits the 'offset_changed' + * Sets the 'offset_' and ruler_offset_ members and emits the 'offset_changed' * signal if needed. */ void set_offset(const pv::util::Timestamp& offset); @@ -458,8 +464,10 @@ private: /// The view time scale in seconds per pixel. double scale_; - /// The view time offset in seconds. + /// The internal view version of the time offset in seconds. pv::util::Timestamp offset_; + /// The ruler version of the time offset in seconds. + pv::util::Timestamp ruler_offset_; bool updating_scroll_; bool settings_restored_; diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index 65cf6842..8311f122 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -38,6 +38,7 @@ const int ViewBase::MaxViewAutoUpdateRate = 25; // No more than 25 Hz ViewBase::ViewBase(Session &session, bool is_main_view, QWidget *parent) : session_(session), is_main_view_(is_main_view), + ruler_shift_(0), current_segment_(0) { (void)parent; diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index c8f72ab7..0a7605db 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -110,6 +110,7 @@ protected: const bool is_main_view_; + util::Timestamp ruler_shift_; util::TimeUnit time_unit_; unordered_set< shared_ptr > signalbases_; -- 2.30.2