]> sigrok.org Git - pulseview.git/commitdiff
Continue reworking the channel/signal handling
authorSoeren Apel <redacted>
Tue, 5 May 2020 18:27:00 +0000 (20:27 +0200)
committerSoeren Apel <redacted>
Mon, 11 May 2020 19:24:22 +0000 (21:24 +0200)
pv/data/decodesignal.cpp
pv/session.cpp
pv/session.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index ff7a27640fb597c4aed12863da5d6bf0ff9f2dd7..28157794208c6fbf4a7b65be20b76773bb21b189 100644 (file)
@@ -108,11 +108,12 @@ void DecodeSignal::remove_decoder(int index)
        assert(index < (int)stack_.size());
 
        // Find the decoder in the stack
-       auto iter = stack_.begin();
-       for (int i = 0; i < index; i++, iter++)
-               assert(iter != stack_.end());
+       auto iter = stack_.begin() + index;
+       assert(iter != stack_.end());
+
+       shared_ptr<Decoder> dec = *iter;
 
-       decoder_removed(iter->get());
+       decoder_removed(dec.get());
 
        // Delete the element
        stack_.erase(iter);
index f53383789f3ff669adb21af9bd7b0bb997c43cd6..85b6c0b4968795666cb422e2919afb892eb58fe8 100644 (file)
@@ -115,6 +115,7 @@ namespace pv {
 shared_ptr<sigrok::Context> Session::sr_context;
 
 Session::Session(DeviceManager &device_manager, QString name) :
+       shutting_down_(false),
        device_manager_(device_manager),
        default_name_(name),
        name_(name),
@@ -126,6 +127,8 @@ Session::Session(DeviceManager &device_manager, QString name) :
 
 Session::~Session()
 {
+       shutting_down_ = true;
+
        // Stop and join to the thread
        stop_capture();
 }
@@ -869,6 +872,9 @@ void Session::add_generated_signal(shared_ptr<data::SignalBase> signal)
 
 void Session::remove_generated_signal(shared_ptr<data::SignalBase> signal)
 {
+       if (shutting_down_)
+               return;
+
        signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(),
                [&](shared_ptr<data::SignalBase> s) { return s == signal; }),
                signalbases_.end());
@@ -916,6 +922,9 @@ shared_ptr<data::DecodeSignal> Session::add_decode_signal()
 
 void Session::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
 {
+       if (shutting_down_)
+               return;
+
        signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(),
                [&](shared_ptr<data::SignalBase> s) { return s == signal; }),
                signalbases_.end());
index 7c7d0dde3ab13bfb8a961c55b09fa11e79f0ebb8..56fbc3a4ee38427af414a3efe5afad3fc324e0d2 100644 (file)
@@ -262,6 +262,8 @@ public Q_SLOTS:
 #endif
 
 private:
+       bool shutting_down_;
+
        DeviceManager &device_manager_;
        shared_ptr<devices::Device> device_;
        QString default_name_, name_;
index 46bae5d8b27755287fe17a187ded3ea31e79cb59..a470715b48595d94ec89eff74a3f12ddd34a3a52 100644 (file)
@@ -389,6 +389,11 @@ void View::add_signalbase(const shared_ptr<data::SignalBase> signalbase)
 void View::remove_signalbase(const shared_ptr<data::SignalBase> signalbase)
 {
        ViewBase::remove_signalbase(signalbase);
+
+       shared_ptr<Signal> signal = get_signal_by_signalbase(signalbase);
+
+       if (signal)
+               remove_trace(signal);
 }
 
 #ifdef ENABLE_DECODE
@@ -418,14 +423,34 @@ void View::remove_decode_signal(shared_ptr<data::DecodeSignal> signal)
        for (auto i = decode_traces_.begin(); i != decode_traces_.end(); i++)
                if ((*i)->base() == signal) {
                        decode_traces_.erase(i);
-                       signals_changed();
-                       return;
+                       break;
                }
 
        ViewBase::remove_decode_signal(signal);
 }
 #endif
 
+void View::remove_trace(shared_ptr<Trace> trace)
+{
+       TraceTreeItemOwner *const owner = trace->owner();
+       assert(owner);
+       owner->remove_child_item(trace);
+
+       for (auto i = signals_.begin(); i != signals_.end(); i++)
+               if ((*i) == trace) {
+                       signals_.erase(i);
+                       break;
+               }
+
+       if (!header_was_shrunk_)
+               resize_header_to_fit();
+
+       update_layout();
+
+       header_->update();
+       viewport_->update();
+}
+
 shared_ptr<Signal> View::get_signal_under_mouse_cursor() const
 {
        return signal_under_mouse_cursor_;
@@ -1773,7 +1798,6 @@ void View::signals_changed()
 #ifdef ENABLE_DECODE
        traces.insert(decode_traces_.begin(), decode_traces_.end());
 #endif
-
        set< shared_ptr<Trace> > add_traces;
        set_difference(traces.begin(), traces.end(),
                prev_traces.begin(), prev_traces.end(),
@@ -1887,6 +1911,10 @@ void View::signals_changed()
        // Add and position the pending top levels items
        int offset = v_extents().second;
        for (shared_ptr<TraceTreeItem> item : new_top_level_items) {
+               // items may already have gained an owner when they were added to a group above
+               if (item->owner())
+                       continue;
+
                add_child_item(item);
 
                // Position the item after the last item or at the top if there is none
index 0adab674b10cfdeaa513bce11d7b6d871aa8ee1a..1d630158401e2592c4754bfd7a8e11c787f246fe 100644 (file)
@@ -134,6 +134,8 @@ public:
        virtual void remove_decode_signal(shared_ptr<data::DecodeSignal> signal);
 #endif
 
+       void remove_trace(shared_ptr<Trace> trace);
+
        shared_ptr<Signal> get_signal_under_mouse_cursor() const;
 
        /**