From: Soeren Apel Date: Wed, 19 Feb 2020 21:46:13 +0000 (+0100) Subject: Session: Use ordered container to preserve DecodeTrace order X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=56c4de9ada023505b16b6d188fb77d9fb10e52e1;p=pulseview.git Session: Use ordered container to preserve DecodeTrace order Without this, PDs appear in random order when a session setup is restored. --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 3420fa1c..8d606d43 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -786,7 +786,7 @@ void DecodeSignal::restore_settings(QSettings &settings) // Restore channel mapping unsigned int channels = settings.value("channels").toInt(); - const unordered_set< shared_ptr > signalbases = + const vector< shared_ptr > signalbases = session_.signalbases(); for (unsigned int channel_id = 0; channel_id < channels; channel_id++) { diff --git a/pv/session.cpp b/pv/session.cpp index 6e517363..dc08afb2 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -791,8 +791,9 @@ void Session::register_view(shared_ptr view) void Session::deregister_view(shared_ptr view) { - - std::remove_if(views_.begin(), views_.end(), [&](shared_ptr v) { return v == view; }); + views_.erase(std::remove_if(views_.begin(), views_.end(), + [&](shared_ptr v) { return v == view; }), + views_.end()); if (views_.empty()) { main_view_.reset(); @@ -852,7 +853,7 @@ vector Session::get_triggers(uint32_t segment_id) const return result; } -const unordered_set< shared_ptr > Session::signalbases() const +const vector< shared_ptr > Session::signalbases() const { return signalbases_; } @@ -877,7 +878,7 @@ shared_ptr Session::add_decode_signal() // Create the decode signal signal = make_shared(*this); - signalbases_.insert(signal); + signalbases_.push_back(signal); // Add the decode signal to all views for (shared_ptr& view : views_) @@ -894,7 +895,9 @@ shared_ptr Session::add_decode_signal() void Session::remove_decode_signal(shared_ptr signal) { - signalbases_.erase(signal); + signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(), + [&](shared_ptr s) { return s == signal; }), + signalbases_.end()); for (shared_ptr& view : views_) view->remove_decode_signal(signal); @@ -1009,7 +1012,7 @@ void Session::update_signals() if (!signalbase) { signalbase = make_shared(channel, data::SignalBase::LogicChannel); - signalbases_.insert(signalbase); + signalbases_.push_back(signalbase); all_signal_data_.insert(logic_data_); signalbase->set_data(logic_data_); @@ -1026,7 +1029,7 @@ void Session::update_signals() if (!signalbase) { signalbase = make_shared(channel, data::SignalBase::AnalogChannel); - signalbases_.insert(signalbase); + signalbases_.push_back(signalbase); shared_ptr data(new data::Analog()); all_signal_data_.insert(data); diff --git a/pv/session.hpp b/pv/session.hpp index 8af833cd..095c4dd0 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -199,7 +199,7 @@ public: bool has_view(shared_ptr view); - const unordered_set< shared_ptr > signalbases() const; + const vector< shared_ptr > signalbases() const; bool all_segments_complete(uint32_t segment_id) const; @@ -287,7 +287,7 @@ private: mutable mutex sampling_mutex_; //!< Protects access to capture_state_. capture_state capture_state_; - unordered_set< shared_ptr > signalbases_; + vector< shared_ptr > signalbases_; unordered_set< shared_ptr > all_signal_data_; /// trigger_list_ contains pairs of values. diff --git a/pv/storesession.cpp b/pv/storesession.cpp index f024a36c..809dba3e 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -93,7 +93,7 @@ const QString& StoreSession::error() const bool StoreSession::start() { - const unordered_set< shared_ptr > sigs(session_.signalbases()); + const vector< shared_ptr > sigs(session_.signalbases()); shared_ptr any_segment; shared_ptr lsegment; diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index 839b4df9..f2b28be0 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include