From: Soeren Apel Date: Tue, 27 Jun 2017 06:33:08 +0000 (+0200) Subject: Fix #832 by saving/restoring the decoder stack without settings X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c8e60bdf0f33b3005e695a6b256b559dbc7b8576;p=pulseview.git Fix #832 by saving/restoring the decoder stack without settings --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index be2ed161..4a9c139b 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -77,7 +77,7 @@ const vector< shared_ptr >& 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(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 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(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() diff --git a/pv/data/decodesignal.hpp b/pv/data/decodesignal.hpp index 86b19318..d859ea0c 100644 --- a/pv/data/decodesignal.hpp +++ b/pv/data/decodesignal.hpp @@ -87,7 +87,7 @@ public: bool is_decode_signal() const; const vector< shared_ptr >& 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); diff --git a/pv/session.cpp b/pv/session.cpp index 4edba0f7..732f4a8c 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -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 signal = add_decode_signal(); + signal->restore_settings(settings); settings.endGroup(); } #endif