From: Soeren Apel Date: Mon, 24 Feb 2020 08:38:20 +0000 (+0100) Subject: Use ordered data types for signals and use first signal as fallback X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=533b67b7af83c96af2692bac127b0023cca4dbe7;p=pulseview.git Use ordered data types for signals and use first signal as fallback ...for zoom-to-fit. This is only necessary when the user has hidden all traces but wants to use zoom-to-fit. Before, this would yield an invalid time range. --- diff --git a/pv/session.cpp b/pv/session.cpp index dc08afb2..e42f730a 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -761,7 +761,7 @@ void Session::register_view(shared_ptr view) update_signals(); // Add all other signals - unordered_set< shared_ptr > view_signalbases = view->signalbases(); + vector< shared_ptr > view_signalbases = view->signalbases(); for (const shared_ptr& signalbase : signalbases_) { const int sb_exists = count_if( @@ -981,7 +981,7 @@ void Session::update_signals() qobject_cast(viewbase.get()); if (trace_view) { - unordered_set< shared_ptr > prev_sigs(trace_view->signals()); + vector< shared_ptr > prev_sigs(trace_view->signals()); trace_view->clear_signals(); for (auto channel : sr_dev->channels()) { diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 26282a78..227fadfd 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -318,7 +318,7 @@ const Session& View::session() const return session_; } -unordered_set< shared_ptr > View::signals() const +vector< shared_ptr > View::signals() const { return signals_; } @@ -345,7 +345,7 @@ void View::clear_signals() void View::add_signal(const shared_ptr signal) { ViewBase::add_signalbase(signal->base()); - signals_.insert(signal); + signals_.push_back(signal); signal->set_segment_display_mode(segment_display_mode_); signal->set_current_segment(current_segment_); @@ -811,13 +811,13 @@ void View::set_scale_offset(double scale, const Timestamp& offset) viewport_->update(); } -set< shared_ptr > View::get_visible_data() const +vector< shared_ptr > View::get_visible_data() const { // Make a set of all the visible data objects - set< shared_ptr > visible_data; + vector< shared_ptr > visible_data; for (const shared_ptr& sig : signals_) if (sig->enabled()) - visible_data.insert(sig->data()); + visible_data.push_back(sig->data()); return visible_data; } @@ -825,8 +825,14 @@ set< shared_ptr > View::get_visible_data() const pair View::get_time_extents() const { boost::optional left_time, right_time; - const set< shared_ptr > visible_data = get_visible_data(); - for (const shared_ptr& d : visible_data) { + + vector< shared_ptr > data; + if (signals_.size() == 0) + return make_pair(0, 0); + + data.push_back(signals_.front()->data()); + + for (const shared_ptr& d : data) { const vector< shared_ptr > segments = d->segments(); for (const shared_ptr& s : segments) { double samplerate = s->samplerate(); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index bf8b6432..14217d25 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -119,7 +119,7 @@ public: /** * Returns the signals contained in this view. */ - unordered_set< shared_ptr > signals() const; + vector< shared_ptr > signals() const; shared_ptr get_signal_by_signalbase(shared_ptr base) const; @@ -262,7 +262,7 @@ public: */ void set_scale_offset(double scale, const pv::util::Timestamp& offset); - set< shared_ptr > get_visible_data() const; + vector< shared_ptr > get_visible_data() const; pair get_time_extents() const; @@ -511,7 +511,7 @@ private: QShortcut *grab_ruler_left_shortcut_, *grab_ruler_right_shortcut_; QShortcut *cancel_grab_shortcut_; - unordered_set< shared_ptr > signals_; + vector< shared_ptr > signals_; #ifdef ENABLE_DECODE vector< shared_ptr > decode_traces_; diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index ecdefdcd..26b4ef1f 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -88,7 +88,7 @@ void ViewBase::clear_signals() clear_signalbases(); } -unordered_set< shared_ptr > ViewBase::signalbases() const +vector< shared_ptr > ViewBase::signalbases() const { return signalbases_; } @@ -107,7 +107,7 @@ void ViewBase::clear_signalbases() void ViewBase::add_signalbase(const shared_ptr signalbase) { - signalbases_.insert(signalbase); + signalbases_.push_back(signalbase); connect(signalbase.get(), SIGNAL(samples_cleared()), this, SLOT(on_data_updated())); @@ -123,12 +123,15 @@ void ViewBase::clear_decode_signals() void ViewBase::add_decode_signal(shared_ptr signal) { - decode_signals_.insert(signal); + decode_signals_.push_back(signal); } void ViewBase::remove_decode_signal(shared_ptr signal) { - decode_signals_.erase(signal); + decode_signals_.erase(std::remove_if( + decode_signals_.begin(), decode_signals_.end(), + [&](shared_ptr s) { return s == signal; }), + decode_signals_.end()); } #endif diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index d3111dc7..3fff28f0 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -38,7 +38,7 @@ #endif using std::shared_ptr; -using std::unordered_set; +using std::vector; namespace pv { @@ -89,7 +89,7 @@ public: /** * Returns the signal bases contained in this view. */ - unordered_set< shared_ptr > signalbases() const; + vector< shared_ptr > signalbases() const; virtual void clear_signalbases(); @@ -128,9 +128,9 @@ protected: util::TimeUnit time_unit_; - unordered_set< shared_ptr > signalbases_; + vector< shared_ptr > signalbases_; #ifdef ENABLE_DECODE - unordered_set< shared_ptr > decode_signals_; + vector< shared_ptr > decode_signals_; #endif /// The ID of the currently displayed segment