]> sigrok.org Git - pulseview.git/commitdiff
Session: Use ordered container to preserve DecodeTrace order
authorSoeren Apel <redacted>
Wed, 19 Feb 2020 21:46:13 +0000 (22:46 +0100)
committerSoeren Apel <redacted>
Wed, 19 Feb 2020 21:46:13 +0000 (22:46 +0100)
Without this, PDs appear in random order when a session setup is restored.

pv/data/decodesignal.cpp
pv/session.cpp
pv/session.hpp
pv/storesession.cpp
pv/views/trace/decodetrace.hpp

index 3420fa1c7efbed0c899de170fc4d191118c7ebdf..8d606d43dd9b87c9b4ce5b9c7eda5426d4a4f61a 100644 (file)
@@ -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<data::SignalBase> > signalbases =
+       const vector< shared_ptr<data::SignalBase> > signalbases =
                session_.signalbases();
 
        for (unsigned int channel_id = 0; channel_id < channels; channel_id++) {
index 6e517363cb99be05636108f80677736daa3e2e76..dc08afb245f8fc5e5ea54d3da40e745b0322d4a5 100644 (file)
@@ -791,8 +791,9 @@ void Session::register_view(shared_ptr<views::ViewBase> view)
 
 void Session::deregister_view(shared_ptr<views::ViewBase> view)
 {
-
-       std::remove_if(views_.begin(), views_.end(), [&](shared_ptr<views::ViewBase> v) { return v == view; });
+       views_.erase(std::remove_if(views_.begin(), views_.end(),
+               [&](shared_ptr<views::ViewBase> v) { return v == view; }),
+               views_.end());
 
        if (views_.empty()) {
                main_view_.reset();
@@ -852,7 +853,7 @@ vector<util::Timestamp> Session::get_triggers(uint32_t segment_id) const
        return result;
 }
 
-const unordered_set< shared_ptr<data::SignalBase> > Session::signalbases() const
+const vector< shared_ptr<data::SignalBase> > Session::signalbases() const
 {
        return signalbases_;
 }
@@ -877,7 +878,7 @@ shared_ptr<data::DecodeSignal> Session::add_decode_signal()
                // Create the decode signal
                signal = make_shared<data::DecodeSignal>(*this);
 
-               signalbases_.insert(signal);
+               signalbases_.push_back(signal);
 
                // Add the decode signal to all views
                for (shared_ptr<views::ViewBase>& view : views_)
@@ -894,7 +895,9 @@ shared_ptr<data::DecodeSignal> Session::add_decode_signal()
 
 void Session::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
 {
-       signalbases_.erase(signal);
+       signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(),
+               [&](shared_ptr<data::SignalBase> s) { return s == signal; }),
+               signalbases_.end());
 
        for (shared_ptr<views::ViewBase>& view : views_)
                view->remove_decode_signal(signal);
@@ -1009,7 +1012,7 @@ void Session::update_signals()
                                                if (!signalbase) {
                                                        signalbase = make_shared<data::SignalBase>(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<data::SignalBase>(channel,
                                                                data::SignalBase::AnalogChannel);
-                                                       signalbases_.insert(signalbase);
+                                                       signalbases_.push_back(signalbase);
 
                                                        shared_ptr<data::Analog> data(new data::Analog());
                                                        all_signal_data_.insert(data);
index 8af833cd6d84f8acf224480af84040f8296ac5af..095c4dd0217dd51f490c3d4d99bbc3d952b773b9 100644 (file)
@@ -199,7 +199,7 @@ public:
 
        bool has_view(shared_ptr<views::ViewBase> view);
 
-       const unordered_set< shared_ptr<data::SignalBase> > signalbases() const;
+       const vector< shared_ptr<data::SignalBase> > 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<data::SignalBase> > signalbases_;
+       vector< shared_ptr<data::SignalBase> > signalbases_;
        unordered_set< shared_ptr<data::SignalData> > all_signal_data_;
 
        /// trigger_list_ contains pairs of <segment_id, timestamp> values.
index f024a36cb8a8c49792eb5d8bd14d424429f42d2c..809dba3e6694e37da736e6799e2deaa946e69d18 100644 (file)
@@ -93,7 +93,7 @@ const QString& StoreSession::error() const
 
 bool StoreSession::start()
 {
-       const unordered_set< shared_ptr<data::SignalBase> > sigs(session_.signalbases());
+       const vector< shared_ptr<data::SignalBase> > sigs(session_.signalbases());
 
        shared_ptr<data::Segment> any_segment;
        shared_ptr<data::LogicSegment> lsegment;
index 839b4df9f6863eb406f0a48de88d6925cf279dfe..f2b28be04dd04772254095c156713d2e4bf52a71 100644 (file)
@@ -29,6 +29,7 @@
 #include <vector>
 
 #include <QColor>
+#include <QComboBox>
 #include <QCheckBox>
 #include <QElapsedTimer>
 #include <QPolygon>