]> sigrok.org Git - pulseview.git/commitdiff
Use ordered data types for signals and use first signal as fallback
authorSoeren Apel <redacted>
Mon, 24 Feb 2020 08:38:20 +0000 (09:38 +0100)
committerSoeren Apel <redacted>
Mon, 24 Feb 2020 08:38:20 +0000 (09:38 +0100)
...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.

pv/session.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp

index dc08afb245f8fc5e5ea54d3da40e745b0322d4a5..e42f730a4dc4d2900b6ee4e12f541f0c134ec0ee 100644 (file)
@@ -761,7 +761,7 @@ void Session::register_view(shared_ptr<views::ViewBase> view)
        update_signals();
 
        // Add all other signals
-       unordered_set< shared_ptr<data::SignalBase> > view_signalbases = view->signalbases();
+       vector< shared_ptr<data::SignalBase> > view_signalbases = view->signalbases();
 
        for (const shared_ptr<data::SignalBase>& signalbase : signalbases_) {
                const int sb_exists = count_if(
@@ -981,7 +981,7 @@ void Session::update_signals()
                        qobject_cast<views::trace::View*>(viewbase.get());
 
                if (trace_view) {
-                       unordered_set< shared_ptr<Signal> > prev_sigs(trace_view->signals());
+                       vector< shared_ptr<Signal> > prev_sigs(trace_view->signals());
                        trace_view->clear_signals();
 
                        for (auto channel : sr_dev->channels()) {
index 26282a78debed7fa569b8c7fd7ab4824288877d2..227fadfdb4197c334d084dd9a19edb37e4728181 100644 (file)
@@ -318,7 +318,7 @@ const Session& View::session() const
        return session_;
 }
 
-unordered_set< shared_ptr<Signal> > View::signals() const
+vector< shared_ptr<Signal> > View::signals() const
 {
        return signals_;
 }
@@ -345,7 +345,7 @@ void View::clear_signals()
 void View::add_signal(const shared_ptr<Signal> 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<SignalData> > View::get_visible_data() const
+vector< shared_ptr<SignalData> > View::get_visible_data() const
 {
        // Make a set of all the visible data objects
-       set< shared_ptr<SignalData> > visible_data;
+       vector< shared_ptr<SignalData> > visible_data;
        for (const shared_ptr<Signal>& 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<SignalData> > View::get_visible_data() const
 pair<Timestamp, Timestamp> View::get_time_extents() const
 {
        boost::optional<Timestamp> left_time, right_time;
-       const set< shared_ptr<SignalData> > visible_data = get_visible_data();
-       for (const shared_ptr<SignalData>& d : visible_data) {
+
+       vector< shared_ptr<SignalData> > data;
+       if (signals_.size() == 0)
+               return make_pair(0, 0);
+
+       data.push_back(signals_.front()->data());
+
+       for (const shared_ptr<SignalData>& d : data) {
                const vector< shared_ptr<Segment> > segments = d->segments();
                for (const shared_ptr<Segment>& s : segments) {
                        double samplerate = s->samplerate();
index bf8b64325feef171b3c7fb17b01dff461985284f..14217d25549de9ce45bfa7aeb733fc696866f3ff 100644 (file)
@@ -119,7 +119,7 @@ public:
        /**
         * Returns the signals contained in this view.
         */
-       unordered_set< shared_ptr<Signal> > signals() const;
+       vector< shared_ptr<Signal> > signals() const;
 
        shared_ptr<Signal> get_signal_by_signalbase(shared_ptr<data::SignalBase> base) const;
 
@@ -262,7 +262,7 @@ public:
         */
        void set_scale_offset(double scale, const pv::util::Timestamp& offset);
 
-       set< shared_ptr<pv::data::SignalData> > get_visible_data() const;
+       vector< shared_ptr<pv::data::SignalData> > get_visible_data() const;
 
        pair<pv::util::Timestamp, pv::util::Timestamp> 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<Signal> > signals_;
+       vector< shared_ptr<Signal> > signals_;
 
 #ifdef ENABLE_DECODE
        vector< shared_ptr<DecodeTrace> > decode_traces_;
index ecdefdcde294a68f188336f8b47180155057ab9e..26b4ef1f893ca882abf563b5f026a9aba55766f5 100644 (file)
@@ -88,7 +88,7 @@ void ViewBase::clear_signals()
        clear_signalbases();
 }
 
-unordered_set< shared_ptr<data::SignalBase> > ViewBase::signalbases() const
+vector< shared_ptr<data::SignalBase> > ViewBase::signalbases() const
 {
        return signalbases_;
 }
@@ -107,7 +107,7 @@ void ViewBase::clear_signalbases()
 
 void ViewBase::add_signalbase(const shared_ptr<data::SignalBase> 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<data::DecodeSignal> signal)
 {
-       decode_signals_.insert(signal);
+       decode_signals_.push_back(signal);
 }
 
 void ViewBase::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
 {
-       decode_signals_.erase(signal);
+       decode_signals_.erase(std::remove_if(
+               decode_signals_.begin(), decode_signals_.end(),
+               [&](shared_ptr<data::DecodeSignal> s) { return s == signal; }),
+               decode_signals_.end());
 }
 #endif
 
index d3111dc79cdfbc5929f260d8f0181a2238f592a9..3fff28f0cf09da7230ee9ec41809431857b05cb3 100644 (file)
@@ -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<data::SignalBase> > signalbases() const;
+       vector< shared_ptr<data::SignalBase> > signalbases() const;
 
        virtual void clear_signalbases();
 
@@ -128,9 +128,9 @@ protected:
 
        util::TimeUnit time_unit_;
 
-       unordered_set< shared_ptr<data::SignalBase> > signalbases_;
+       vector< shared_ptr<data::SignalBase> > signalbases_;
 #ifdef ENABLE_DECODE
-       unordered_set< shared_ptr<data::DecodeSignal> > decode_signals_;
+       vector< shared_ptr<data::DecodeSignal> > decode_signals_;
 #endif
 
        /// The ID of the currently displayed segment