]> sigrok.org Git - pulseview.git/commitdiff
Provide a settings checkbox for showing zero at the trigger
authorCenkron <redacted>
Wed, 10 Jan 2018 02:28:11 +0000 (20:28 -0600)
committerSoeren Apel <redacted>
Wed, 7 Feb 2018 18:41:51 +0000 (19:41 +0100)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/views/trace/ruler.cpp
pv/views/trace/ruler.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp

index 1730e7ba2ebb78c8625c97073662fc68d0ed3398..17f68a655c54dd71b86a76e715b88798ddafd41f 100644 (file)
@@ -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;
index 72c96125de580d77042cb853db0bc1d0a62e526a..d548f52f1a68a7a80187682052491a2f68479fbc 100644 (file)
@@ -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);
index eabe4d3c185498a5c19fd71ecb7eef8a420b33f1..c9a757c9ebb238b3b8a7d1ff4cc4d6487fb56fa6 100644 (file)
@@ -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";
index 9cf2978b68369751c76c9e53dc9ec0d6586ded04..c6b4cfc5891e617a4d44985f240268bf2a2fa1a0 100644 (file)
@@ -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;
index 0526bb2ceb21646f8e49bb9c4e1c64dbb1b67f6c..fe08cb06ceaa56cd874b77ec35a836c89cdfd323 100644 (file)
@@ -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)
index e9432bd6d4208fe66489a9d1ad9963947e88467e..0c614c6c8bad27360b4cca6ada99dbe91320d709 100644 (file)
@@ -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.
index 156b3eef30276515ebbb59880cffbf3e9a37ccf1..292933e7eefa70abb5753a0a3e66f9614292415a 100644 (file)
@@ -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> 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<TriggerMarker>(*this, location));
 }
 
index e80198d329062f8175b04e9e28dbf4c1be543c75..28c94e5285d1dfc6cc21c06daa618138f3723bc8 100644 (file)
@@ -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_;
index 65cf6842aeee0699686f59990379c48d9a2499c2..8311f122faa54e253b62bc11aca652d196b7c1ec 100644 (file)
@@ -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;
index c8f72ab7a3caf9e6005379bd253e779974c5b73a..0a7605db153f822693aff9ae6c709265d86cd887 100644 (file)
@@ -110,6 +110,7 @@ protected:
 
        const bool is_main_view_;
 
+       util::Timestamp ruler_shift_;
        util::TimeUnit time_unit_;
 
        unordered_set< shared_ptr<data::SignalBase> > signalbases_;