From: Soeren Apel Date: Sun, 2 Aug 2020 15:49:39 +0000 (+0200) Subject: SignalBase: Don't check for signal types, check based on data X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4b018bf1eeed0f7b80120d41d7881673a2f29e61;p=pulseview.git SignalBase: Don't check for signal types, check based on data --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index e1091f11..f49d95eb 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -225,13 +225,10 @@ void SignalBase::set_data(shared_ptr data) disconnect(data.get(), SIGNAL(samples_added(shared_ptr, uint64_t, uint64_t)), this, SLOT(on_samples_added(shared_ptr, uint64_t, uint64_t))); - if (channel_type_ == AnalogChannel) { - shared_ptr analog = analog_data(); - assert(analog); - + shared_ptr analog = analog_data(); + if (analog) disconnect(analog.get(), SIGNAL(min_max_changed(float, float)), this, SLOT(on_min_max_changed(float, float))); - } } data_ = data; @@ -242,13 +239,10 @@ void SignalBase::set_data(shared_ptr data) connect(data.get(), SIGNAL(samples_added(SharedPtrToSegment, uint64_t, uint64_t)), this, SLOT(on_samples_added(SharedPtrToSegment, uint64_t, uint64_t))); - if (channel_type_ == AnalogChannel) { - shared_ptr analog = analog_data(); - assert(analog); - + shared_ptr analog = analog_data(); + if (analog) connect(analog.get(), SIGNAL(min_max_changed(float, float)), this, SLOT(on_min_max_changed(float, float))); - } } } @@ -263,20 +257,12 @@ void SignalBase::clear_sample_data() shared_ptr SignalBase::analog_data() const { - shared_ptr result = nullptr; - - if (channel_type_ == AnalogChannel) - result = dynamic_pointer_cast(data_); - - return result; + return dynamic_pointer_cast(data_); } shared_ptr SignalBase::logic_data() const { - shared_ptr result = nullptr; - - if (channel_type_ == LogicChannel) - result = dynamic_pointer_cast(data_); + shared_ptr result = dynamic_pointer_cast(data_); if (((conversion_type_ == A2LConversionByThreshold) || (conversion_type_ == A2LConversionBySchmittTrigger))) @@ -289,25 +275,25 @@ bool SignalBase::segment_is_complete(uint32_t segment_id) const { bool result = true; - if (channel_type_ == AnalogChannel) + shared_ptr adata = analog_data(); + if (adata) { - shared_ptr data = dynamic_pointer_cast(data_); - auto segments = data->analog_segments(); + auto segments = adata->analog_segments(); try { result = segments.at(segment_id)->is_complete(); } catch (out_of_range&) { // Do nothing } - } - - if (channel_type_ == LogicChannel) - { - shared_ptr data = dynamic_pointer_cast(data_); - auto segments = data->logic_segments(); - try { - result = segments.at(segment_id)->is_complete(); - } catch (out_of_range&) { - // Do nothing + } else { + shared_ptr ldata = logic_data(); + if (ldata) { + shared_ptr data = dynamic_pointer_cast(data_); + auto segments = data->logic_segments(); + try { + result = segments.at(segment_id)->is_complete(); + } catch (out_of_range&) { + // Do nothing + } } } @@ -318,21 +304,16 @@ bool SignalBase::has_samples() const { bool result = false; - if (channel_type_ == AnalogChannel) + shared_ptr adata = analog_data(); + if (adata) { - shared_ptr data = dynamic_pointer_cast(data_); - if (data) { - auto segments = data->analog_segments(); - if ((segments.size() > 0) && (segments.front()->get_sample_count() > 0)) - result = true; - } - } - - if (channel_type_ == LogicChannel) - { - shared_ptr data = dynamic_pointer_cast(data_); - if (data) { - auto segments = data->logic_segments(); + auto segments = adata->analog_segments(); + if ((segments.size() > 0) && (segments.front()->get_sample_count() > 0)) + result = true; + } else { + shared_ptr ldata = logic_data(); + if (ldata) { + auto segments = ldata->logic_segments(); if ((segments.size() > 0) && (segments.front()->get_sample_count() > 0)) result = true; } @@ -343,18 +324,13 @@ bool SignalBase::has_samples() const double SignalBase::get_samplerate() const { - if (channel_type_ == AnalogChannel) - { - shared_ptr data = dynamic_pointer_cast(data_); - if (data) - return data->get_samplerate(); - } - - if (channel_type_ == LogicChannel) - { - shared_ptr data = dynamic_pointer_cast(data_); - if (data) - return data->get_samplerate(); + shared_ptr adata = analog_data(); + if (adata) + return adata->get_samplerate(); + else { + shared_ptr ldata = logic_data(); + if (ldata) + return ldata->get_samplerate(); } // Default samplerate is 1 Hz @@ -580,8 +556,7 @@ void SignalBase::restore_settings(QSettings &settings) bool SignalBase::conversion_is_a2l() const { - return ((channel_type_ == AnalogChannel) && - ((conversion_type_ == A2LConversionByThreshold) || + return (((conversion_type_ == A2LConversionByThreshold) || (conversion_type_ == A2LConversionBySchmittTrigger))); } diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index f646a40d..7d7a795e 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -334,7 +334,6 @@ public: #endif virtual void save_settings(QSettings &settings) const; - virtual void restore_settings(QSettings &settings); void start_conversion(bool delayed_start=false);