From: Soeren Apel Date: Tue, 5 May 2020 18:27:00 +0000 (+0200) Subject: Continue reworking the channel/signal handling X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f9a0fd83226d97af7458d8c9dac0b88c83a54d29;p=pulseview.git Continue reworking the channel/signal handling --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index ff7a2764..28157794 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -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 dec = *iter; - decoder_removed(iter->get()); + decoder_removed(dec.get()); // Delete the element stack_.erase(iter); diff --git a/pv/session.cpp b/pv/session.cpp index f5338378..85b6c0b4 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -115,6 +115,7 @@ namespace pv { shared_ptr 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 signal) void Session::remove_generated_signal(shared_ptr signal) { + if (shutting_down_) + return; + signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(), [&](shared_ptr s) { return s == signal; }), signalbases_.end()); @@ -916,6 +922,9 @@ shared_ptr Session::add_decode_signal() void Session::remove_decode_signal(shared_ptr signal) { + if (shutting_down_) + return; + signalbases_.erase(std::remove_if(signalbases_.begin(), signalbases_.end(), [&](shared_ptr s) { return s == signal; }), signalbases_.end()); diff --git a/pv/session.hpp b/pv/session.hpp index 7c7d0dde..56fbc3a4 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -262,6 +262,8 @@ public Q_SLOTS: #endif private: + bool shutting_down_; + DeviceManager &device_manager_; shared_ptr device_; QString default_name_, name_; diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 46bae5d8..a470715b 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -389,6 +389,11 @@ void View::add_signalbase(const shared_ptr signalbase) void View::remove_signalbase(const shared_ptr signalbase) { ViewBase::remove_signalbase(signalbase); + + shared_ptr 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 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) +{ + 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 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 > 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 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 diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 0adab674..1d630158 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -134,6 +134,8 @@ public: virtual void remove_decode_signal(shared_ptr signal); #endif + void remove_trace(shared_ptr trace); + shared_ptr get_signal_under_mouse_cursor() const; /**