From: Soeren Apel Date: Sun, 28 Aug 2016 20:03:50 +0000 (+0200) Subject: Session: Save/restore channel info and top-level decoder X-Git-Tag: pulseview-0.4.0~259 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aecae05c598b1fe914253b980aa6ad43b85f562b;p=pulseview.git Session: Save/restore channel info and top-level decoder --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index bc208982..45d805a8 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -278,6 +278,7 @@ void MainWindow::save_ui_settings() } settings.beginGroup("Session" + QString::number(id++)); + settings.remove(""); // Remove all keys in this group session->save_settings(settings); settings.endGroup(); } diff --git a/pv/session.cpp b/pv/session.cpp index da9da126..34ed26b8 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -165,6 +165,7 @@ void Session::save_settings(QSettings &settings) const { map dev_info; list key_list; + int stacks = 0; if (device_) { settings.beginGroup("Device"); @@ -184,8 +185,31 @@ void Session::save_settings(QSettings &settings) const settings.remove(QString::fromUtf8(key.c_str())); } - // TODO Save channel settings and decoders + // Save channels and decoders + for (shared_ptr base : signalbases_) { +#ifdef ENABLE_DECODE + if (base->is_decode_signal()) { + shared_ptr decoder_stack = + base->decoder_stack(); + std::shared_ptr top_decoder = + decoder_stack->stack().front(); + + settings.beginGroup("decoder_stack" + QString::number(stacks++)); + settings.setValue("id", top_decoder->decoder()->id); + settings.setValue("name", top_decoder->decoder()->name); + settings.endGroup(); + } else +#endif + { + settings.beginGroup(base->internal_name()); + settings.setValue("name", base->name()); + settings.setValue("enabled", base->enabled()); + settings.setValue("colour", base->colour()); + settings.endGroup(); + } + } + settings.setValue("decoder_stacks", stacks); settings.endGroup(); } } @@ -220,7 +244,28 @@ void Session::restore_settings(QSettings &settings) if (device) { set_device(device); - // TODO Restore channel settings and decoders + // Restore channels + for (shared_ptr base : signalbases_) { + settings.beginGroup(base->internal_name()); + base->set_name(settings.value("name").toString()); + base->set_enabled(settings.value("enabled").toBool()); + base->set_colour(settings.value("colour").value()); + settings.endGroup(); + } + + // Restore decoders +#ifdef ENABLE_DECODE + int stacks = settings.value("decoder_stacks").toInt(); + + for (int i = 0; i < stacks; i++) { + settings.beginGroup("decoder_stack" + QString::number(i++)); + + QString id = settings.value("id").toString(); + add_decoder(srd_decoder_get_by_id(id.toStdString().c_str())); + + settings.endGroup(); + } +#endif } settings.endGroup(); @@ -437,6 +482,7 @@ bool Session::add_decoder(srd_decoder *const dec) shared_ptr(new data::SignalBase(nullptr)); signalbase->set_decoder_stack(decoder_stack); + signalbases_.insert(signalbase); for (std::shared_ptr view : views_) view->add_decode_trace(signalbase); diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index ffe4f67d..8dd329e0 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -149,6 +149,11 @@ void Signal::delete_pressed() void Signal::on_name_changed(const QString &text) { + // On startup, this event is fired when a session restores signal + // names. However, the name widget hasn't yet been created. + if (!name_widget_) + return; + if (text != name_widget_->currentText()) name_widget_->setEditText(text);