]> sigrok.org Git - pulseview.git/commitdiff
Fix #832 by saving/restoring the decoder stack without settings
authorSoeren Apel <redacted>
Tue, 27 Jun 2017 06:33:08 +0000 (08:33 +0200)
committerUwe Hermann <redacted>
Wed, 5 Jul 2017 22:37:08 +0000 (00:37 +0200)
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/session.cpp

index be2ed1616d1bdbed47c4eeb604028ca654f1bfc7..4a9c139bb039a90627960d35c6a24a4f64ae7b3f 100644 (file)
@@ -77,7 +77,7 @@ const vector< shared_ptr<Decoder> >& DecodeSignal::decoder_stack() const
        return stack_;
 }
 
-void DecodeSignal::stack_decoder(srd_decoder *decoder)
+void DecodeSignal::stack_decoder(const srd_decoder *decoder)
 {
        assert(decoder);
        stack_.push_back(make_shared<decode::Decoder>(decoder));
@@ -413,14 +413,51 @@ void DecodeSignal::save_settings(QSettings &settings) const
 {
        SignalBase::save_settings(settings);
 
-       // TODO Save decoder stack, channel mapping and decoder options
+       settings.setValue("decoders", (int)(stack_.size()));
+
+       int decoder_idx = 0;
+       for (shared_ptr<decode::Decoder> decoder : stack_) {
+               settings.beginGroup("decoder" + QString::number(decoder_idx++));
+
+               settings.setValue("id", decoder->decoder()->id);
+
+               settings.endGroup();
+       }
+
+       // TODO Save channel mapping and decoder options
 }
 
 void DecodeSignal::restore_settings(QSettings &settings)
 {
        SignalBase::restore_settings(settings);
 
-       // TODO Restore decoder stack, channel mapping and decoder options
+       GSList *dec_list = g_slist_copy((GSList*)srd_decoder_list());
+
+       int decoders = settings.value("decoders").toInt();
+
+       for (int decoder_idx = 0; decoder_idx < decoders; decoder_idx++) {
+               settings.beginGroup("decoder" + QString::number(decoder_idx));
+
+               QString id = settings.value("id").toString();
+
+               for (GSList *entry = dec_list; entry; entry = entry->next) {
+                       const srd_decoder *dec = (srd_decoder*)entry->data;
+                       if (!dec)
+                               continue;
+
+                       if (QString::fromUtf8(dec->id) == id) {
+                               stack_.push_back(make_shared<decode::Decoder>(dec));
+
+                               // Include the newly created decode channels in the channel lists
+                               update_channel_list();
+                               break;
+                       }
+               }
+
+               settings.endGroup();
+       }
+
+       // TODO Restore channel mapping and decoder options
 }
 
 void DecodeSignal::update_channel_list()
index 86b1931834e29211b83d427814315071144f494e..d859ea0cdb665a9979d26685f639dbebca578333 100644 (file)
@@ -87,7 +87,7 @@ public:
        bool is_decode_signal() const;
        const vector< shared_ptr<data::decode::Decoder> >& decoder_stack() const;
 
-       void stack_decoder(srd_decoder *decoder);
+       void stack_decoder(const srd_decoder *decoder);
        void remove_decoder(int index);
        bool toggle_decoder_visibility(int index);
 
index 4edba0f7a2de9c5f428e9f07fe38d7532e69ad1e..732f4a8cbf55b69c7befe816cba3921f23fb80ec 100644 (file)
@@ -317,8 +317,8 @@ void Session::restore_settings(QSettings &settings)
 
                for (int i = 0; i < decode_signals; i++) {
                        settings.beginGroup("decode_signal" + QString::number(i++));
-                       // TODO Split up add_decoder() into add_decode_signal() and add_decoder(),
-                       // then call add_decode_signal() and signal->restore_settings() here
+                       shared_ptr<data::DecodeSignal> signal = add_decode_signal();
+                       signal->restore_settings(settings);
                        settings.endGroup();
                }
 #endif