From: Soeren Apel Date: Sat, 21 Dec 2019 21:38:48 +0000 (+0100) Subject: Make new views take over the main view's signal settings X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0a952555b9d153f42912e47f35fac5dd4643fca9;p=pulseview.git Make new views take over the main view's signal settings --- diff --git a/pv/session.cpp b/pv/session.cpp index 0e071fbc..51a1aee7 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -105,6 +105,10 @@ using Gst::ElementFactory; using Gst::Pipeline; #endif +using pv::views::trace::Signal; +using pv::views::trace::AnalogSignal; +using pv::views::trace::LogicSignal; + namespace pv { shared_ptr Session::sr_context; @@ -889,18 +893,17 @@ void Session::update_signals() qobject_cast(viewbase.get()); if (trace_view) { - unordered_set< shared_ptr > - prev_sigs(trace_view->signals()); + unordered_set< shared_ptr > prev_sigs(trace_view->signals()); trace_view->clear_signals(); for (auto channel : sr_dev->channels()) { shared_ptr signalbase; - shared_ptr signal; + shared_ptr signal; // Find the channel in the old signals const auto iter = find_if( prev_sigs.cbegin(), prev_sigs.cend(), - [&](const shared_ptr &s) { + [&](const shared_ptr &s) { return s->base()->channel() == channel; }); if (iter != prev_sigs.end()) { @@ -914,6 +917,8 @@ void Session::update_signals() if (b->channel() == channel) signalbase = b; + shared_ptr signal; + switch(channel->type()->id()) { case SR_CHANNEL_LOGIC: if (!signalbase) { @@ -928,10 +933,7 @@ void Session::update_signals() signalbase.get(), SLOT(on_capture_state_changed(int))); } - signal = shared_ptr( - new views::trace::LogicSignal(*this, - device_, signalbase)); - trace_view->add_signal(signal); + signal = shared_ptr(new LogicSignal(*this, device_, signalbase)); break; case SR_CHANNEL_ANALOG: @@ -949,10 +951,7 @@ void Session::update_signals() signalbase.get(), SLOT(on_capture_state_changed(int))); } - signal = shared_ptr( - new views::trace::AnalogSignal( - *this, signalbase)); - trace_view->add_signal(signal); + signal = shared_ptr(new AnalogSignal(*this, signalbase)); break; } @@ -960,6 +959,17 @@ void Session::update_signals() assert(false); break; } + + // New views take their signal settings from the main view + if (!viewbase->is_main_view()) { + shared_ptr main_tv = + dynamic_pointer_cast(main_view_); + shared_ptr main_signal = + main_tv->get_signal_by_signalbase(signalbase); + signal->restore_settings(main_signal->save_settings()); + } + + trace_view->add_signal(signal); } } } diff --git a/pv/views/trace/analogsignal.cpp b/pv/views/trace/analogsignal.cpp index faa80a11..39ca26f7 100644 --- a/pv/views/trace/analogsignal.cpp +++ b/pv/views/trace/analogsignal.cpp @@ -105,13 +105,13 @@ AnalogSignal::AnalogSignal( pv::Session &session, shared_ptr base) : Signal(session, base), + value_at_hover_pos_(std::numeric_limits::quiet_NaN()), scale_index_(4), // 20 per div pos_vdivs_(1), neg_vdivs_(1), resolution_(0), display_type_(DisplayBoth), - autoranging_(true), - value_at_hover_pos_(std::numeric_limits::quiet_NaN()) + autoranging_(true) { axis_pen_ = AxisPen; @@ -143,38 +143,48 @@ shared_ptr AnalogSignal::data() const return base_->analog_data(); } -void AnalogSignal::save_settings(QSettings &settings) const +std::map AnalogSignal::save_settings() const { - settings.setValue("pos_vdivs", pos_vdivs_); - settings.setValue("neg_vdivs", neg_vdivs_); - settings.setValue("scale_index", scale_index_); - settings.setValue("display_type", display_type_); - settings.setValue("autoranging", autoranging_); - settings.setValue("div_height", div_height_); + std::map result; + + result["pos_vdivs"] = pos_vdivs_; + result["neg_vdivs"] = neg_vdivs_; + result["scale_index"] = scale_index_; + result["display_type"] = display_type_; + result["autoranging"] = pos_vdivs_; + result["div_height"] = div_height_; + + return result; } -void AnalogSignal::restore_settings(QSettings &settings) +void AnalogSignal::restore_settings(std::map settings) { - if (settings.contains("pos_vdivs")) - pos_vdivs_ = settings.value("pos_vdivs").toInt(); + auto entry = settings.find("pos_vdivs"); + if (entry != settings.end()) + pos_vdivs_ = settings["pos_vdivs"].toInt(); - if (settings.contains("neg_vdivs")) - neg_vdivs_ = settings.value("neg_vdivs").toInt(); + entry = settings.find("neg_vdivs"); + if (entry != settings.end()) + neg_vdivs_ = settings["neg_vdivs"].toInt(); - if (settings.contains("scale_index")) { - scale_index_ = settings.value("scale_index").toInt(); + entry = settings.find("scale_index"); + if (entry != settings.end()) { + scale_index_ = settings["scale_index"].toInt(); update_scale(); } - if (settings.contains("display_type")) - display_type_ = (DisplayType)(settings.value("display_type").toInt()); + entry = settings.find("display_type"); + if (entry != settings.end()) + display_type_ = (DisplayType)(settings["display_type"].toInt()); - if (settings.contains("autoranging")) - autoranging_ = settings.value("autoranging").toBool(); + entry = settings.find("autoranging"); + if (entry != settings.end()) + autoranging_ = settings["autoranging"].toBool(); - if (settings.contains("div_height")) { + entry = settings.find("div_height"); + if (entry != settings.end()) { const int old_height = div_height_; - div_height_ = settings.value("div_height").toInt(); + div_height_ = settings["div_height"].toInt(); if ((div_height_ != old_height) && owner_) { // Call order is important, otherwise the lazy event handler won't work diff --git a/pv/views/trace/analogsignal.hpp b/pv/views/trace/analogsignal.hpp index 0c14b66a..c588eb88 100644 --- a/pv/views/trace/analogsignal.hpp +++ b/pv/views/trace/analogsignal.hpp @@ -77,9 +77,8 @@ public: shared_ptr data() const; - virtual void save_settings(QSettings &settings) const; - - virtual void restore_settings(QSettings &settings); + virtual std::map save_settings() const; + virtual void restore_settings(std::map settings); /** * Computes the vertical extents of the contents of this row item. @@ -185,19 +184,10 @@ private: double signal_min_, signal_max_; // Min/max values of this signal's analog data - float scale_; - int scale_index_; - - int div_height_; - int pos_vdivs_, neg_vdivs_; // divs per positive/negative side - float resolution_; // e.g. 10 for 10 V/div - bool show_analog_minor_grid_; QColor high_fill_color_; bool show_sampling_points_, fill_high_areas_; - DisplayType display_type_; - bool autoranging_; int conversion_threshold_disp_mode_; vector value_at_pixel_pos_; @@ -205,6 +195,18 @@ private: float prev_value_at_pixel_; // Only used during lookup table update float min_value_at_pixel_, max_value_at_pixel_; // Only used during lookup table update int current_pixel_pos_; // Only used during lookup table update + + // --------------------------------------------------------------------------- + // Note: Make sure to update .. when adding a trace-configurable variable here + float scale_; + int scale_index_; + + int div_height_; + int pos_vdivs_, neg_vdivs_; // divs per positive/negative side + float resolution_; // e.g. 10 for 10 V/div + + DisplayType display_type_; + bool autoranging_; }; } // namespace trace diff --git a/pv/views/trace/logicsignal.cpp b/pv/views/trace/logicsignal.cpp index f9ab16f1..a3fd7a0b 100644 --- a/pv/views/trace/logicsignal.cpp +++ b/pv/views/trace/logicsignal.cpp @@ -146,16 +146,21 @@ shared_ptr LogicSignal::logic_data() const return base_->logic_data(); } -void LogicSignal::save_settings(QSettings &settings) const +std::map LogicSignal::save_settings() const { - settings.setValue("trace_height", signal_height_); + std::map result; + + result["trace_height"] = signal_height_; + + return result; } -void LogicSignal::restore_settings(QSettings &settings) +void LogicSignal::restore_settings(std::map settings) { - if (settings.contains("trace_height")) { + auto entry = settings.find("trace_height"); + if (entry != settings.end()) { const int old_height = signal_height_; - signal_height_ = settings.value("trace_height").toInt(); + signal_height_ = settings["trace_height"].toInt(); if ((signal_height_ != old_height) && owner_) { // Call order is important, otherwise the lazy event handler won't work diff --git a/pv/views/trace/logicsignal.hpp b/pv/views/trace/logicsignal.hpp index b170e2c0..b769ec55 100644 --- a/pv/views/trace/logicsignal.hpp +++ b/pv/views/trace/logicsignal.hpp @@ -81,8 +81,8 @@ public: shared_ptr logic_data() const; - virtual void save_settings(QSettings &settings) const; - virtual void restore_settings(QSettings &settings); + virtual std::map save_settings() const; + virtual void restore_settings(std::map settings); /** * Computes the vertical extents of the contents of this row item. diff --git a/pv/views/trace/signal.cpp b/pv/views/trace/signal.cpp index 0c0cde05..b770dee3 100644 --- a/pv/views/trace/signal.cpp +++ b/pv/views/trace/signal.cpp @@ -90,14 +90,34 @@ shared_ptr Signal::base() const void Signal::save_settings(QSettings &settings) const { - (void)settings; + std::map settings_map = save_settings(); + + for (auto& entry : settings_map) + settings.setValue(entry.first, entry.second); +} + +std::map Signal::save_settings() const +{ + return std::map(); } void Signal::restore_settings(QSettings &settings) +{ + std::map settings_map; + + QStringList keys = settings.allKeys(); + for (int i = 0; i < keys.size(); i++) + settings_map[keys.at(i)] = settings.value(keys.at(i)); + + restore_settings(settings_map); +} + +void Signal::restore_settings(std::map settings) { (void)settings; } + void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp) { if (base_->enabled()) diff --git a/pv/views/trace/signal.hpp b/pv/views/trace/signal.hpp index 1b9f2543..c9f38dd9 100644 --- a/pv/views/trace/signal.hpp +++ b/pv/views/trace/signal.hpp @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include @@ -87,8 +89,10 @@ public: shared_ptr base() const; virtual void save_settings(QSettings &settings) const; + virtual std::map save_settings() const; virtual void restore_settings(QSettings &settings); + virtual void restore_settings(std::map settings); void paint_back(QPainter &p, ViewItemPaintParams &pp); diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 9b8e76c5..d2e90060 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -303,6 +303,19 @@ unordered_set< shared_ptr > View::signals() const return signals_; } +shared_ptr View::get_signal_by_signalbase(shared_ptr base) const +{ + shared_ptr ret_val; + + for (const shared_ptr s : signals_) + if (s->base() == base) { + ret_val = s; + break; + } + + return ret_val; +} + void View::clear_signals() { ViewBase::clear_signals(); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 0ba23bb6..fdd40176 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -120,6 +120,8 @@ public: */ unordered_set< shared_ptr > signals() const; + shared_ptr get_signal_by_signalbase(shared_ptr base) const; + virtual void clear_signals(); void add_signal(const shared_ptr signal); @@ -425,7 +427,6 @@ public: void extents_changed(bool horz, bool vert); private Q_SLOTS: - void on_signal_name_changed(); void on_splitter_moved(); diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index da455ed3..ecdefdcd 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -63,6 +63,11 @@ ViewBase::ViewBase(Session &session, bool is_main_view, QMainWindow *parent) : delayed_view_updater_.setInterval(1000 / MaxViewAutoUpdateRate); } +bool ViewBase::is_main_view() const +{ + return is_main_view_; +} + void ViewBase::reset_view_state() { current_segment_ = 0; diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index af885751..9621f351 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -73,6 +73,7 @@ public: explicit ViewBase(Session &session, bool is_main_view = false, QMainWindow *parent = nullptr); virtual ViewType get_type() const = 0; + bool is_main_view() const; /** * Resets the view to its default state after construction. It does however