From: Soeren Apel Date: Sun, 10 Sep 2017 19:26:59 +0000 (+0200) Subject: Add segment selector UI + helpers X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7f9654641c096b303fc30b710335e235b9738ce9;p=pulseview.git Add segment selector UI + helpers --- diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 51e7f495..c8bafc0f 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -51,6 +51,11 @@ vector< shared_ptr > Analog::segments() const segments_.begin(), segments_.end()); } +int Analog::get_segment_count() const +{ + return segments_.size(); +} + void Analog::clear() { segments_.clear(); diff --git a/pv/data/analog.hpp b/pv/data/analog.hpp index 633c6fba..b53e7f04 100644 --- a/pv/data/analog.hpp +++ b/pv/data/analog.hpp @@ -49,6 +49,8 @@ public: vector< shared_ptr > segments() const; + int get_segment_count() const; + void clear(); uint64_t max_sample_count() const; diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index ac47c29d..084e8efd 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -57,6 +57,11 @@ vector< shared_ptr > Logic::segments() const return vector< shared_ptr >(segments_.begin(), segments_.end()); } +int Logic::get_segment_count() const +{ + return segments_.size(); +} + void Logic::clear() { segments_.clear(); diff --git a/pv/data/logic.hpp b/pv/data/logic.hpp index 1ca5d3ed..a371d22b 100644 --- a/pv/data/logic.hpp +++ b/pv/data/logic.hpp @@ -50,6 +50,8 @@ public: vector< shared_ptr > segments() const; + int get_segment_count() const; + void clear(); uint64_t max_sample_count() const; diff --git a/pv/data/signaldata.hpp b/pv/data/signaldata.hpp index a90204f0..adede1c2 100644 --- a/pv/data/signaldata.hpp +++ b/pv/data/signaldata.hpp @@ -45,6 +45,8 @@ public: public: virtual vector< shared_ptr > segments() const = 0; + virtual int get_segment_count() const = 0; + virtual void clear() = 0; virtual uint64_t max_sample_count() const = 0; diff --git a/pv/session.cpp b/pv/session.cpp index ad4c17e2..a44ceb99 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -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 : all_signal_data_) + if (data->get_segment_count() < min_val) + min_val = data->get_segment_count(); + + return min_val; +} + const unordered_set< shared_ptr > Session::signalbases() const { return signalbases_; diff --git a/pv/session.hpp b/pv/session.hpp index 9d42a4d9..dcb4ad1d 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -163,6 +163,8 @@ public: double get_samplerate() const; + int get_segment_count() const; + void register_view(shared_ptr view); void deregister_view(shared_ptr view); diff --git a/pv/views/trace/standardbar.cpp b/pv/views/trace/standardbar.cpp index bc2c3ba8..fa04c8e2 100644 --- a/pv/views/trace/standardbar.cpp +++ b/pv/views/trace/standardbar.cpp @@ -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 diff --git a/pv/views/trace/standardbar.hpp b/pv/views/trace/standardbar.hpp index 09c7907f..94a6d81b 100644 --- a/pv/views/trace/standardbar.hpp +++ b/pv/views/trace/standardbar.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -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 multi_segment_actions_; }; } // namespace trace