From: Soeren Apel Date: Tue, 25 Jul 2017 14:09:08 +0000 (+0200) Subject: Use getter for the conversion type instead of a local copy X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=06b6ce26694bdde31c7d5b703c4dda36f4a25938;p=pulseview.git Use getter for the conversion type instead of a local copy Don't ask me why I used a local copy in the first place, even I can't figure it out :) --- diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index b43e5bb0..0e887b4c 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -174,6 +174,11 @@ shared_ptr SignalBase::logic_data() const return result; } +SignalBase::ConversionType SignalBase::get_conversion_type() const +{ + return conversion_type_; +} + void SignalBase::set_conversion_type(ConversionType t) { if (conversion_type_ != NoConversion) { diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 635db660..a2d23244 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -157,6 +157,11 @@ public: */ shared_ptr logic_data() const; + /** + * Queries the kind of conversion performed on this channel. + */ + ConversionType get_conversion_type() const; + /** * Changes the kind of conversion performed on this channel. */ @@ -209,7 +214,7 @@ protected: ChannelType channel_type_; shared_ptr data_; shared_ptr converted_data_; - int conversion_type_; + ConversionType conversion_type_; std::thread conversion_thread_; atomic conversion_interrupt_; diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index e26b203a..c346fd5b 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -92,7 +92,6 @@ AnalogSignal::AnalogSignal( pos_vdivs_(1), neg_vdivs_(1), resolution_(0), - conversion_type_(data::SignalBase::NoConversion), display_type_(DisplayBoth), autoranging_(true) { @@ -119,7 +118,6 @@ void AnalogSignal::save_settings(QSettings &settings) const settings.setValue("pos_vdivs", pos_vdivs_); settings.setValue("neg_vdivs", neg_vdivs_); settings.setValue("scale_index", scale_index_); - settings.setValue("conversion_type", conversion_type_); settings.setValue("display_type", display_type_); settings.setValue("autoranging", autoranging_); settings.setValue("div_height", div_height_); @@ -138,11 +136,6 @@ void AnalogSignal::restore_settings(QSettings &settings) update_scale(); } - if (settings.contains("conversion_type")) { - conversion_type_ = (data::SignalBase::ConversionType)(settings.value("conversion_type").toInt()); - update_conversion_type(); - } - if (settings.contains("display_type")) display_type_ = (DisplayType)(settings.value("display_type").toInt()); @@ -243,8 +236,11 @@ void AnalogSignal::paint_mid(QPainter &p, ViewItemPaintParams &pp) } if ((display_type_ == DisplayConverted) || (display_type_ == DisplayBoth)) { - if (((conversion_type_ == data::SignalBase::A2LConversionByTreshold) || - (conversion_type_ == data::SignalBase::A2LConversionBySchmittTrigger))) { + const data::SignalBase::ConversionType conv_type = + base_->get_conversion_type(); + + if (((conv_type == data::SignalBase::A2LConversionByTreshold) || + (conv_type == data::SignalBase::A2LConversionBySchmittTrigger))) { paint_logic_mid(p, pp); } @@ -594,14 +590,6 @@ void AnalogSignal::update_scale() scale_ = div_height_ / resolution_; } -void AnalogSignal::update_conversion_type() -{ - base_->set_conversion_type(conversion_type_); - - if (owner_) - owner_->row_item_appearance_changed(false, true); -} - void AnalogSignal::perform_autoranging(bool keep_divs, bool force_update) { const deque< shared_ptr > &segments = @@ -740,7 +728,7 @@ void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form) conversion_cb_->addItem("to logic via threshold", data::SignalBase::A2LConversionByTreshold); conversion_cb_->addItem("to logic via schmitt-trigger", data::SignalBase::A2LConversionBySchmittTrigger); - cur_idx = conversion_cb_->findData(QVariant(conversion_type_)); + cur_idx = conversion_cb_->findData(QVariant(base_->get_conversion_type())); conversion_cb_->setCurrentIndex(cur_idx); layout->addRow(tr("Conversion"), conversion_cb_); @@ -870,13 +858,17 @@ void AnalogSignal::on_autoranging_changed(int state) void AnalogSignal::on_conversion_changed(int index) { - data::SignalBase::ConversionType old_conv_type = conversion_type_; + data::SignalBase::ConversionType old_conv_type = + base_->get_conversion_type(); - conversion_type_ = (data::SignalBase::ConversionType)(conversion_cb_->itemData(index).toInt()); + data::SignalBase::ConversionType conv_type = + (data::SignalBase::ConversionType)(conversion_cb_->itemData(index).toInt()); - if (conversion_type_ != old_conv_type) { - base_->set_conversion_type(conversion_type_); - update_conversion_type(); + if (conv_type != old_conv_type) { + base_->set_conversion_type(conv_type); + + if (owner_) + owner_->row_item_appearance_changed(false, true); } } diff --git a/pv/views/trace/analogsignal.hpp b/pv/views/trace/analogsignal.hpp index a67c4ff3..07b66711 100644 --- a/pv/views/trace/analogsignal.hpp +++ b/pv/views/trace/analogsignal.hpp @@ -144,8 +144,6 @@ private: void update_scale(); - void update_conversion_type(); - void perform_autoranging(bool keep_divs, bool force_update); protected: @@ -178,7 +176,6 @@ private: int pos_vdivs_, neg_vdivs_; // divs per positive/negative side float resolution_; // e.g. 10 for 10 V/div - data::SignalBase::ConversionType conversion_type_; DisplayType display_type_; bool autoranging_; };