]> sigrok.org Git - pulseview.git/commitdiff
Make new views take over the main view's signal settings
authorSoeren Apel <redacted>
Sat, 21 Dec 2019 21:38:48 +0000 (22:38 +0100)
committerSoeren Apel <redacted>
Sat, 21 Dec 2019 21:38:48 +0000 (22:38 +0100)
pv/session.cpp
pv/views/trace/analogsignal.cpp
pv/views/trace/analogsignal.hpp
pv/views/trace/logicsignal.cpp
pv/views/trace/logicsignal.hpp
pv/views/trace/signal.cpp
pv/views/trace/signal.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp

index 0e071fbcdd9882d96ac7c4714ed3e969cf6e24b6..51a1aee715853ed305d331bb7f04ab158f26a00c 100644 (file)
@@ -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<sigrok::Context> Session::sr_context;
@@ -889,18 +893,17 @@ void Session::update_signals()
                        qobject_cast<views::trace::View*>(viewbase.get());
 
                if (trace_view) {
-                       unordered_set< shared_ptr<views::trace::Signal> >
-                               prev_sigs(trace_view->signals());
+                       unordered_set< shared_ptr<Signal> > prev_sigs(trace_view->signals());
                        trace_view->clear_signals();
 
                        for (auto channel : sr_dev->channels()) {
                                shared_ptr<data::SignalBase> signalbase;
-                               shared_ptr<views::trace::Signal> signal;
+                               shared_ptr<Signal> signal;
 
                                // Find the channel in the old signals
                                const auto iter = find_if(
                                        prev_sigs.cbegin(), prev_sigs.cend(),
-                                       [&](const shared_ptr<views::trace::Signal> &s) {
+                                       [&](const shared_ptr<Signal> &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> 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<views::trace::Signal>(
-                                                       new views::trace::LogicSignal(*this,
-                                                               device_, signalbase));
-                                               trace_view->add_signal(signal);
+                                               signal = shared_ptr<Signal>(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<views::trace::Signal>(
-                                                       new views::trace::AnalogSignal(
-                                                               *this, signalbase));
-                                               trace_view->add_signal(signal);
+                                               signal = shared_ptr<Signal>(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<pv::views::trace::View> main_tv =
+                                                       dynamic_pointer_cast<pv::views::trace::View>(main_view_);
+                                               shared_ptr<Signal> main_signal =
+                                                       main_tv->get_signal_by_signalbase(signalbase);
+                                               signal->restore_settings(main_signal->save_settings());
+                                       }
+
+                                       trace_view->add_signal(signal);
                                }
                        }
                }
index faa80a11bc94243bd277755770cc5e00c9e0b482..39ca26f7ad64437da3ca3f163982c0dafe2fa8f2 100644 (file)
@@ -105,13 +105,13 @@ AnalogSignal::AnalogSignal(
        pv::Session &session,
        shared_ptr<data::SignalBase> base) :
        Signal(session, base),
+       value_at_hover_pos_(std::numeric_limits<float>::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<float>::quiet_NaN())
+       autoranging_(true)
 {
        axis_pen_ = AxisPen;
 
@@ -143,38 +143,48 @@ shared_ptr<pv::data::SignalData> AnalogSignal::data() const
        return base_->analog_data();
 }
 
-void AnalogSignal::save_settings(QSettings &settings) const
+std::map<QString, QVariant> 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<QString, QVariant> 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<QString, QVariant> 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
index 0c14b66acd6a0e42ade65556efcf2b5dae2724e7..c588eb88bf26e33abb7e7a8ac0fc53e7dc30af47 100644 (file)
@@ -77,9 +77,8 @@ public:
 
        shared_ptr<pv::data::SignalData> data() const;
 
-       virtual void save_settings(QSettings &settings) const;
-
-       virtual void restore_settings(QSettings &settings);
+       virtual std::map<QString, QVariant> save_settings() const;
+       virtual void restore_settings(std::map<QString, QVariant> 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<float> 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
index f9ab16f102cdf5328613d81957a5d4563602d07e..a3fd7a0bbdcf9dc18c3561673497414c65a3b1b5 100644 (file)
@@ -146,16 +146,21 @@ shared_ptr<pv::data::Logic> LogicSignal::logic_data() const
        return base_->logic_data();
 }
 
-void LogicSignal::save_settings(QSettings &settings) const
+std::map<QString, QVariant> LogicSignal::save_settings() const
 {
-       settings.setValue("trace_height", signal_height_);
+       std::map<QString, QVariant> result;
+
+       result["trace_height"] = signal_height_;
+
+       return result;
 }
 
-void LogicSignal::restore_settings(QSettings &settings)
+void LogicSignal::restore_settings(std::map<QString, QVariant> 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
index b170e2c08d76da930f5b6d482fad9ad1ce4cb6d4..b769ec55914cfea4af1d6a685e3a53a96528fe96 100644 (file)
@@ -81,8 +81,8 @@ public:
 
        shared_ptr<pv::data::Logic> logic_data() const;
 
-       virtual void save_settings(QSettings &settings) const;
-       virtual void restore_settings(QSettings &settings);
+       virtual std::map<QString, QVariant> save_settings() const;
+       virtual void restore_settings(std::map<QString, QVariant> settings);
 
        /**
         * Computes the vertical extents of the contents of this row item.
index 0c0cde05e18aa4d9d9f5cab9b748743b7fbffc7c..b770dee3acadd0d5a45cf38a323850aeed7bb665 100644 (file)
@@ -90,14 +90,34 @@ shared_ptr<data::SignalBase> Signal::base() const
 
 void Signal::save_settings(QSettings &settings) const
 {
-       (void)settings;
+       std::map<QString, QVariant> settings_map = save_settings();
+
+       for (auto& entry : settings_map)
+               settings.setValue(entry.first, entry.second);
+}
+
+std::map<QString, QVariant> Signal::save_settings() const
+{
+       return std::map<QString, QVariant>();
 }
 
 void Signal::restore_settings(QSettings &settings)
+{
+       std::map<QString, QVariant> 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<QString, QVariant> settings)
 {
        (void)settings;
 }
 
+
 void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp)
 {
        if (base_->enabled())
index 1b9f254330a79fd150f6f73165f5cb910a76b5be..c9f38dd96107657d7e16fd6fb05b71a16488dfa2 100644 (file)
@@ -23,6 +23,8 @@
 #include <memory>
 
 #include <QComboBox>
+#include <QString>
+#include <QVariant>
 #include <QWidgetAction>
 
 #include <cstdint>
@@ -87,8 +89,10 @@ public:
        shared_ptr<data::SignalBase> base() const;
 
        virtual void save_settings(QSettings &settings) const;
+       virtual std::map<QString, QVariant> save_settings() const;
 
        virtual void restore_settings(QSettings &settings);
+       virtual void restore_settings(std::map<QString, QVariant> settings);
 
        void paint_back(QPainter &p, ViewItemPaintParams &pp);
 
index 9b8e76c5696cc6559bd450fbee614bbb5f2c04dc..d2e9006075d698f1af96b9ba8a77aa27df02d96f 100644 (file)
@@ -303,6 +303,19 @@ unordered_set< shared_ptr<Signal> > View::signals() const
        return signals_;
 }
 
+shared_ptr<Signal> View::get_signal_by_signalbase(shared_ptr<data::SignalBase> base) const
+{
+       shared_ptr<Signal> ret_val;
+
+       for (const shared_ptr<Signal> s : signals_)
+               if (s->base() == base) {
+                       ret_val = s;
+                       break;
+               }
+
+       return ret_val;
+}
+
 void View::clear_signals()
 {
        ViewBase::clear_signals();
index 0ba23bb6cb4d8af09e48b3637a4a38b9b6e4ff85..fdd401764811570042bd42c4e9a19d13ce69e1c9 100644 (file)
@@ -120,6 +120,8 @@ public:
         */
        unordered_set< shared_ptr<Signal> > signals() const;
 
+       shared_ptr<Signal> get_signal_by_signalbase(shared_ptr<data::SignalBase> base) const;
+
        virtual void clear_signals();
 
        void add_signal(const shared_ptr<Signal> 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();
 
index da455ed30ca4f8db3e4651baf5748df6ce1d8863..ecdefdcde294a68f188336f8b47180155057ab9e 100644 (file)
@@ -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;
index af885751f170a17ea75a617a11276aa32c681568..9621f35117bd47a702eb9e397afa7e8a54fc9d7c 100644 (file)
@@ -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