]> sigrok.org Git - pulseview.git/commitdiff
Add segment display mode UI controls and some related changes
authorSoeren Apel <redacted>
Sun, 7 Jan 2018 20:09:55 +0000 (21:09 +0100)
committerUwe Hermann <redacted>
Tue, 9 Jan 2018 23:40:44 +0000 (00:40 +0100)
pv/session.cpp
pv/session.hpp
pv/views/trace/standardbar.cpp
pv/views/trace/standardbar.hpp
pv/views/trace/trace.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 11a867ab6f410f9e702124c4b82dac6b3e0ce6ef..c18575ad415559a8e66fa0fae7a6b65774a53c59 100644 (file)
@@ -694,6 +694,17 @@ const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
        return signalbases_;
 }
 
+bool Session::all_segments_complete(uint32_t segment_id) const
+{
+       bool all_complete = true;
+
+       for (shared_ptr<data::SignalBase> base : signalbases_)
+               if (!base->segment_is_complete(segment_id))
+                       all_complete = false;
+
+       return all_complete;
+}
+
 #ifdef ENABLE_DECODE
 shared_ptr<data::DecodeSignal> Session::add_decode_signal()
 {
index 6bdfaa24ffe861c27b8919571115c0de67bb6ae7..ead2f82df47955773e53a562f91c18a3e75f94d6 100644 (file)
@@ -173,6 +173,8 @@ public:
 
        const unordered_set< shared_ptr<data::SignalBase> > signalbases() const;
 
+       bool all_segments_complete(uint32_t segment_id) const;
+
 #ifdef ENABLE_DECODE
        shared_ptr<data::DecodeSignal> add_decode_signal();
 
index 9d4d0e4add5fca735778b0d9fd2bbf2feeeada4a..382e9f31a347ec05de5ad468c5276110edd8142a 100644 (file)
@@ -43,6 +43,10 @@ StandardBar::StandardBar(Session &session, QWidget *parent,
        action_view_zoom_fit_(new QAction(this)),
        action_view_zoom_one_to_one_(new QAction(this)),
        action_view_show_cursors_(new QAction(this)),
+       segment_display_mode_selector_(new QToolButton(this)),
+       action_sdm_last_(new QAction(this)),
+       action_sdm_last_complete_(new QAction(this)),
+       action_sdm_single_(new QAction(this)),
        segment_selector_(new QSpinBox(this))
 {
        setObjectName(QString::fromUtf8("StandardBar"));
@@ -85,8 +89,30 @@ StandardBar::StandardBar(Session &session, QWidget *parent,
                this, SLOT(on_actionViewShowCursors_triggered()));
        action_view_show_cursors_->setText(tr("Show &Cursors"));
 
+       action_sdm_last_->setIcon(QIcon(":/icons/view-displaymode-last_segment.svg"));
+       action_sdm_last_->setText(tr("Display last segment only"));
+       connect(action_sdm_last_, SIGNAL(triggered(bool)),
+               this, SLOT(on_actionSDMLast_triggered()));
+
+       action_sdm_last_complete_->setIcon(QIcon(":/icons/view-displaymode-last_complete_segment.svg"));
+       action_sdm_last_complete_->setText(tr("Display last complete segment only"));
+       connect(action_sdm_last_complete_, SIGNAL(triggered(bool)),
+               this, SLOT(on_actionSDMLastComplete_triggered()));
+
+       action_sdm_single_->setIcon(QIcon(":/icons/view-displaymode-single_segment.svg"));
+       action_sdm_single_->setText(tr("Display a single segment"));
+       connect(action_view_show_cursors_, SIGNAL(triggered(bool)),
+               this, SLOT(on_actionSDMSingle_triggered()));
+
+       segment_display_mode_selector_->addAction(action_sdm_last_);
+       segment_display_mode_selector_->addAction(action_sdm_last_complete_);
+       segment_display_mode_selector_->addAction(action_sdm_single_);
+       segment_display_mode_selector_->setPopupMode(QToolButton::InstantPopup);
+       segment_display_mode_selector_->hide();
+
        segment_selector_->setMinimum(1);
        segment_selector_->hide();
+
        connect(&session_, SIGNAL(new_segment(int)),
                this, SLOT(on_new_segment(int)));
 
@@ -101,8 +127,8 @@ StandardBar::StandardBar(Session &session, QWidget *parent,
        connect(this, SIGNAL(segment_selected(int)),
                view_, SLOT(on_segment_changed(int)));
 
-       connect(view_, SIGNAL(segment_display_mode_changed(bool)),
-               this, SLOT(on_segment_display_mode_changed(bool)));
+       connect(view_, SIGNAL(segment_display_mode_changed(int, bool)),
+               this, SLOT(on_segment_display_mode_changed(int, bool)));
 
        connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)),
                this, SLOT(on_always_zoom_to_fit_changed(bool)));
@@ -126,6 +152,7 @@ void StandardBar::add_toolbar_widgets()
        addSeparator();
        addAction(action_view_show_cursors_);
        multi_segment_actions_.push_back(addSeparator());
+       multi_segment_actions_.push_back(addWidget(segment_display_mode_selector_));
        multi_segment_actions_.push_back(addWidget(segment_selector_));
        addSeparator();
 
@@ -138,7 +165,8 @@ void StandardBar::show_multi_segment_ui(const bool state)
        for (QAction* action : multi_segment_actions_)
                action->setVisible(state);
 
-       on_segment_display_mode_changed(view_->segment_is_selectable());
+       on_segment_display_mode_changed(view_->segment_display_mode(),
+               view_->segment_is_selectable());
 }
 
 QAction* StandardBar::action_view_zoom_in() const
@@ -195,6 +223,21 @@ void StandardBar::on_actionViewShowCursors_triggered()
        view_->show_cursors(show);
 }
 
+void StandardBar::on_actionSDMLast_triggered()
+{
+       view_->set_segment_display_mode(Trace::ShowLastSegmentOnly);
+}
+
+void StandardBar::on_actionSDMLastComplete_triggered()
+{
+       view_->set_segment_display_mode(Trace::ShowLastCompleteSegmentOnly);
+}
+
+void StandardBar::on_actionSDMSingle_triggered()
+{
+       view_->set_segment_display_mode(Trace::ShowSingleSegmentOnly);
+}
+
 void StandardBar::on_always_zoom_to_fit_changed(bool state)
 {
        action_view_zoom_fit_->setChecked(state);
@@ -211,28 +254,58 @@ void StandardBar::on_new_segment(int new_segment_id)
 
 void StandardBar::on_segment_changed(int segment_id)
 {
+       // We need to adjust the value by 1 because internally, segments
+       // start at 0 while they start with 1 for the spinbox
+       const uint32_t ui_segment_id = segment_id + 1;
+
        // This is called when the current segment was changed
        // by other parts of the UI, e.g. the view itself
 
-       // We need to adjust the value by 1 because internally, segments
-       // start at 0 while they start with 1 for the spinbox
-       segment_selector_->setValue(segment_id + 1);
+       // Make sure our value isn't limited by a too low maximum
+       // Note: this can happen if on_segment_changed() is called before
+       // on_new_segment()
+       if ((uint32_t)segment_selector_->maximum() < ui_segment_id)
+               segment_selector_->setMaximum(ui_segment_id);
 
-       segment_selected(segment_id);
+       segment_selector_->setValue(ui_segment_id);
 }
 
 void StandardBar::on_segment_selected(int ui_segment_id)
 {
-       // This is called when the user selected a segment using the spin box
-
        // We need to adjust the value by 1 because internally, segments
        // start at 0 while they start with 1 for the spinbox
-       segment_selected(ui_segment_id - 1);
+       const uint32_t segment_id = ui_segment_id - 1;
+
+       // This is called when the user selected a segment using the spin box
+       // or when the value of the spinbox was assigned a new value. Since we
+       // only care about the former, we filter out the latter:
+       if (segment_id == view_->current_segment())
+               return;
+
+       // No matter which segment display mode we were in, we now show a single segment
+       if (view_->segment_display_mode() != Trace::ShowSingleSegmentOnly)
+               on_actionSDMSingle_triggered();
+
+       segment_selected(segment_id);
 }
 
-void StandardBar::on_segment_display_mode_changed(bool segment_selectable)
+void StandardBar::on_segment_display_mode_changed(int mode, bool segment_selectable)
 {
        segment_selector_->setReadOnly(!segment_selectable);
+
+       switch ((Trace::SegmentDisplayMode)mode) {
+       case Trace::ShowLastSegmentOnly:
+               segment_display_mode_selector_->setDefaultAction(action_sdm_last_);
+               break;
+       case Trace::ShowLastCompleteSegmentOnly:
+               segment_display_mode_selector_->setDefaultAction(action_sdm_last_complete_);
+               break;
+       case Trace::ShowSingleSegmentOnly:
+               segment_display_mode_selector_->setDefaultAction(action_sdm_single_);
+               break;
+       default:
+               break;
+       }
 }
 
 } // namespace trace
index a6e8606e132831044de132780cfecdd677167e8c..060a7ef55a3ee90285eb2beb757a50fba12b39d9 100644 (file)
 #include <QAction>
 #include <QSpinBox>
 #include <QToolBar>
+#include <QToolButton>
 #include <QWidget>
 
 #include <pv/session.hpp>
 
+#include "trace.hpp"
+
 namespace pv {
 
 class MainWindow;
@@ -73,6 +76,11 @@ protected:
        QAction *const action_view_zoom_one_to_one_;
        QAction *const action_view_show_cursors_;
 
+       QToolButton *segment_display_mode_selector_;
+       QAction *const action_sdm_last_;
+       QAction *const action_sdm_last_complete_;
+       QAction *const action_sdm_single_;
+
        QSpinBox *segment_selector_;
 
 Q_SIGNALS:
@@ -89,12 +97,16 @@ protected Q_SLOTS:
 
        void on_actionViewShowCursors_triggered();
 
+       void on_actionSDMLast_triggered();
+       void on_actionSDMLastComplete_triggered();
+       void on_actionSDMSingle_triggered();
+
        void on_always_zoom_to_fit_changed(bool state);
 
        void on_new_segment(int new_segment_id);
        void on_segment_changed(int segment_id);
        void on_segment_selected(int ui_segment_id);
-       void on_segment_display_mode_changed(bool segment_selectable);
+       void on_segment_display_mode_changed(int mode, bool segment_selectable);
 
 private:
        vector<QAction*> multi_segment_actions_;
index 777ea5001198a3cb355540006a43bfbc2f222e82..134f11024f3a8de618dd64354280b5817b9c69fa 100644 (file)
@@ -70,9 +70,11 @@ public:
         * Note: Consider these locations when updating the list:
         * *
         * @ref View::set_segment_display_mode
+        * @ref View::on_segment_changed
         * @ref AnalogSignal::get_analog_segment_to_paint
         * @ref AnalogSignal::get_logic_segment_to_paint
         * @ref LogicSignal::get_logic_segment_to_paint
+        * @ref StandardBar
         */
        enum SegmentDisplayMode {
                ShowLastSegmentOnly = 1,
index 58056e5c9a82279285a4357de17d91b9b0bf5329..156b3eef30276515ebbb59880cffbf3e9a37ccf1 100644 (file)
@@ -324,6 +324,7 @@ void View::save_settings(QSettings &settings) const
                scrollarea_->verticalScrollBar()->sliderPosition());
 
        settings.setValue("splitter_state", splitter_->saveState());
+       settings.setValue("segment_display_mode", segment_display_mode_);
 
        stringstream ss;
        boost::archive::text_oarchive oa(ss);
@@ -359,6 +360,10 @@ void View::restore_settings(QSettings &settings)
        if (settings.contains("splitter_state"))
                splitter_->restoreState(settings.value("splitter_state").toByteArray());
 
+       if (settings.contains("segment_display_mode"))
+               set_segment_display_mode(
+                       (Trace::SegmentDisplayMode)(settings.value("segment_display_mode").toInt()));
+
        for (shared_ptr<Signal> signal : signals_) {
                settings.beginGroup(signal->base()->internal_name());
                signal->restore_settings(settings);
@@ -436,6 +441,11 @@ unsigned int View::depth() const
        return 0;
 }
 
+uint32_t View::current_segment() const
+{
+       return current_segment_;
+}
+
 pv::util::SIPrefix View::tick_prefix() const
 {
        return tick_prefix_;
@@ -498,6 +508,8 @@ void View::set_current_segment(uint32_t segment_id)
                dt->set_current_segment(current_segment_);
 
        viewport_->update();
+
+       segment_changed(segment_id);
 }
 
 bool View::segment_is_selectable() const
@@ -505,19 +517,55 @@ bool View::segment_is_selectable() const
        return segment_selectable_;
 }
 
+Trace::SegmentDisplayMode View::segment_display_mode() const
+{
+       return segment_display_mode_;
+}
+
 void View::set_segment_display_mode(Trace::SegmentDisplayMode mode)
 {
+       segment_display_mode_ = mode;
+
        for (shared_ptr<Signal> signal : signals_)
                signal->set_segment_display_mode(mode);
 
-       viewport_->update();
+       uint32_t last_segment = session_.get_segment_count() - 1;
+
+       switch (mode) {
+       case Trace::ShowLastSegmentOnly:
+               if (current_segment_ != last_segment)
+                       set_current_segment(last_segment);
+               break;
+
+       case Trace::ShowLastCompleteSegmentOnly:
+               // Do nothing if we only have one segment so far
+               if (last_segment > 0) {
+                       // If the last segment isn't complete, the previous one must be
+                       uint32_t segment_id =
+                               (session_.all_segments_complete(last_segment)) ?
+                               last_segment : last_segment - 1;
+
+                       if (current_segment_ != segment_id)
+                               set_current_segment(segment_id);
+               }
+               break;
+
+       case Trace::ShowSingleSegmentOnly:
+       case Trace::ShowAllSegments:
+       case Trace::ShowAccumulatedIntensity:
+       default:
+               // Current segment remains as-is
+               break;
+       }
 
        segment_selectable_ = true;
 
-       if (mode == Trace::ShowLastSegmentOnly)
+       if ((mode == Trace::ShowAllSegments) || (mode == Trace::ShowAccumulatedIntensity))
                segment_selectable_ = false;
 
-       segment_display_mode_changed(segment_selectable_);
+       viewport_->update();
+
+       segment_display_mode_changed((int)mode, segment_selectable_);
 }
 
 void View::zoom(double steps)
@@ -1433,13 +1481,11 @@ void View::capture_state_updated(int state)
 void View::on_new_segment(int new_segment_id)
 {
        on_segment_changed(new_segment_id);
-       segment_changed(new_segment_id);
 }
 
 void View::on_segment_completed(int segment_id)
 {
        on_segment_changed(segment_id);
-       segment_changed(segment_id);
 }
 
 void View::on_segment_changed(int segment)
@@ -1451,17 +1497,9 @@ void View::on_segment_changed(int segment)
                break;
 
        case Trace::ShowLastCompleteSegmentOnly:
-               {
-                       // Only update if all segments are complete
-                       bool all_complete = true;
-
-                       for (shared_ptr<Signal> signal : signals_)
-                               if (!signal->base()->segment_is_complete(segment))
-                                       all_complete = false;
-
-                       if (all_complete)
-                               set_current_segment(segment);
-               }
+               // Only update if all segments are complete
+               if (session_.all_segments_complete(segment))
+                       set_current_segment(segment);
                break;
 
        case Trace::ShowAllSegments:
index 679e587bf3036e705820604eb2f23df99d89205f..e80198d329062f8175b04e9e28dbf4c1be543c75 100644 (file)
@@ -191,12 +191,18 @@ public:
         */
        unsigned int depth() const;
 
+       /**
+        * Returns the currently displayed segment, starting at 0.
+        */
+       uint32_t current_segment() const;
+
        /**
         * Returns whether the currently shown segment can be influenced
         * (selected) or not.
         */
        bool segment_is_selectable() const;
 
+       Trace::SegmentDisplayMode segment_display_mode() const;
        void set_segment_display_mode(Trace::SegmentDisplayMode mode);
 
        void zoom(double steps);
@@ -308,7 +314,8 @@ Q_SIGNALS:
        void segment_changed(int segment_id);
 
        /// Emitted when the multi-segment display mode changed
-       void segment_display_mode_changed(bool segment_selectable);
+       /// @param mode is a value of Trace::SegmentDisplayMode
+       void segment_display_mode_changed(int mode, bool segment_selectable);
 
 public Q_SLOTS:
        void trigger_event(util::Timestamp location);