]> sigrok.org Git - pulseview.git/commitdiff
Add segment selector UI + helpers
authorSoeren Apel <redacted>
Sun, 10 Sep 2017 19:26:59 +0000 (21:26 +0200)
committerSoeren Apel <redacted>
Fri, 22 Sep 2017 18:58:16 +0000 (20:58 +0200)
pv/data/analog.cpp
pv/data/analog.hpp
pv/data/logic.cpp
pv/data/logic.hpp
pv/data/signaldata.hpp
pv/session.cpp
pv/session.hpp
pv/views/trace/standardbar.cpp
pv/views/trace/standardbar.hpp

index 51e7f4953b78370af21b5b8401bf01adf682fad6..c8bafc0fab292cf0982adc8b502739232ba11a56 100644 (file)
@@ -51,6 +51,11 @@ vector< shared_ptr<Segment> > Analog::segments() const
                segments_.begin(), segments_.end());
 }
 
+int Analog::get_segment_count() const
+{
+       return segments_.size();
+}
+
 void Analog::clear()
 {
        segments_.clear();
index 633c6fba296eb24a47166772fcc11b960b218649..b53e7f04f4b8f5a85b1adb63f625d9ebbf8288fa 100644 (file)
@@ -49,6 +49,8 @@ public:
 
        vector< shared_ptr<Segment> > segments() const;
 
+       int get_segment_count() const;
+
        void clear();
 
        uint64_t max_sample_count() const;
index ac47c29d6ac12d004f44c23ccc80b6678e44e78b..084e8efd7f231fd920a0da8dfad18cfd9e4ac66e 100644 (file)
@@ -57,6 +57,11 @@ vector< shared_ptr<Segment> > Logic::segments() const
        return vector< shared_ptr<Segment> >(segments_.begin(), segments_.end());
 }
 
+int Logic::get_segment_count() const
+{
+       return segments_.size();
+}
+
 void Logic::clear()
 {
        segments_.clear();
index 1ca5d3ed3af0f407ca34cb54908d4e6dc01e40e0..a371d22bdecf1f4e6402e3223b6ac62891f324e7 100644 (file)
@@ -50,6 +50,8 @@ public:
 
        vector< shared_ptr<Segment> > segments() const;
 
+       int get_segment_count() const;
+
        void clear();
 
        uint64_t max_sample_count() const;
index a90204f06f23bd379abd78278bb6bcf0bbc41455..adede1c211c595eefb9e108d1929cad6d9b5af0b 100644 (file)
@@ -45,6 +45,8 @@ public:
 public:
        virtual vector< shared_ptr<Segment> > segments() const = 0;
 
+       virtual int get_segment_count() const = 0;
+
        virtual void clear() = 0;
 
        virtual uint64_t max_sample_count() const = 0;
index ad4c17e246f0609079e470750c9c3f979d3f20cd..a44ceb99b669aec396c97d92c19c733a6f489698 100644 (file)
@@ -677,6 +677,17 @@ double Session::get_samplerate() const
        return samplerate;
 }
 
+int Session::get_segment_count() const
+{
+       int min_val = INT_MAX;
+
+       for (shared_ptr<data::SignalData> data : all_signal_data_)
+               if (data->get_segment_count() < min_val)
+                       min_val = data->get_segment_count();
+
+       return min_val;
+}
+
 const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
 {
        return signalbases_;
index 9d42a4d98b657896a5e61e18667758052c601e8f..dcb4ad1db96cd55cc06f133838acf1ea42c187b3 100644 (file)
@@ -163,6 +163,8 @@ public:
 
        double get_samplerate() const;
 
+       int get_segment_count() const;
+
        void register_view(shared_ptr<views::ViewBase> view);
 
        void deregister_view(shared_ptr<views::ViewBase> view);
index bc2c3ba8a3cb9380710eb7462d51663a9987eca8..fa04c8e2318bf40e63f896abc8b345509e7ecbc2 100644 (file)
@@ -42,7 +42,8 @@ StandardBar::StandardBar(Session &session, QWidget *parent,
        action_view_zoom_out_(new QAction(this)),
        action_view_zoom_fit_(new QAction(this)),
        action_view_zoom_one_to_one_(new QAction(this)),
-       action_view_show_cursors_(new QAction(this))
+       action_view_show_cursors_(new QAction(this)),
+       segment_selector_(new QSpinBox(this))
 {
        setObjectName(QString::fromUtf8("StandardBar"));
 
@@ -84,6 +85,10 @@ StandardBar::StandardBar(Session &session, QWidget *parent,
                this, SLOT(on_actionViewShowCursors_triggered()));
        action_view_show_cursors_->setText(tr("Show &Cursors"));
 
+       segment_selector_->setMinimum(1);
+       connect(&session_, SIGNAL(frame_ended()),
+               this, SLOT(on_segment_added()));
+
        connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)),
                this, SLOT(on_always_zoom_to_fit_changed(bool)));
 
@@ -105,6 +110,18 @@ void StandardBar::add_toolbar_widgets()
        addAction(action_view_zoom_one_to_one_);
        addSeparator();
        addAction(action_view_show_cursors_);
+       multi_segment_actions_.push_back(addSeparator());
+       multi_segment_actions_.push_back(addWidget(segment_selector_));
+       addSeparator();
+
+       // Hide the multi-segment UI until we know that there are multiple segments
+       show_multi_segment_ui(false);
+}
+
+void StandardBar::show_multi_segment_ui(const bool state)
+{
+       for (QAction* action : multi_segment_actions_)
+               action->setVisible(state);
 }
 
 QAction* StandardBar::action_view_zoom_in() const
@@ -166,6 +183,17 @@ void StandardBar::on_always_zoom_to_fit_changed(bool state)
        action_view_zoom_fit_->setChecked(state);
 }
 
+void StandardBar::on_segment_added()
+{
+       const int segment_count = session_.get_segment_count();
+
+       if (segment_count > 1) {
+               show_multi_segment_ui(true);
+               segment_selector_->setMaximum(segment_count);
+       } else
+               show_multi_segment_ui(false);
+}
+
 } // namespace trace
 } // namespace views
 } // namespace pv
index 09c7907f3da3f4fc5fdb55bfa548267bd0fbce28..94a6d81b3e3f9f0ac47c219bd9efea0cbd82d580 100644 (file)
@@ -24,6 +24,7 @@
 #include <cstdint>
 
 #include <QAction>
+#include <QSpinBox>
 #include <QToolBar>
 #include <QWidget>
 
@@ -61,6 +62,8 @@ public:
 protected:
        virtual void add_toolbar_widgets();
 
+       virtual void show_multi_segment_ui(const bool state);
+
        Session &session_;
        trace::View *view_;
 
@@ -70,6 +73,8 @@ protected:
        QAction *const action_view_zoom_one_to_one_;
        QAction *const action_view_show_cursors_;
 
+       QSpinBox *segment_selector_;
+
 protected Q_SLOTS:
        void on_actionViewZoomIn_triggered();
 
@@ -82,6 +87,11 @@ protected Q_SLOTS:
        void on_actionViewShowCursors_triggered();
 
        void on_always_zoom_to_fit_changed(bool state);
+
+       void on_segment_added();
+
+private:
+       vector<QAction*> multi_segment_actions_;
 };
 
 } // namespace trace