]> sigrok.org Git - pulseview.git/commitdiff
Session: Save/restore channel info and top-level decoder
authorSoeren Apel <redacted>
Sun, 28 Aug 2016 20:03:50 +0000 (22:03 +0200)
committerSoeren Apel <redacted>
Sun, 28 Aug 2016 20:03:50 +0000 (22:03 +0200)
pv/mainwindow.cpp
pv/session.cpp
pv/view/signal.cpp

index bc20898249afd70ee4f90972304289a2db7ab0ba..45d805a8d6f87f2c08eb649cbdf930c70dca48df 100644 (file)
@@ -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();
        }
index da9da12628690cc0b408c1cd5c9eb449bd78ceea..34ed26b8fada81a4468868e94447610f78754a03 100644 (file)
@@ -165,6 +165,7 @@ void Session::save_settings(QSettings &settings) const
 {
        map<string, string> dev_info;
        list<string> 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<data::SignalBase> base : signalbases_) {
+#ifdef ENABLE_DECODE
+                       if (base->is_decode_signal()) {
+                               shared_ptr<pv::data::DecoderStack> decoder_stack =
+                                               base->decoder_stack();
+                               std::shared_ptr<data::decode::Decoder> 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<data::SignalBase> 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<QColor>());
+                       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<data::SignalBase>(new data::SignalBase(nullptr));
 
                signalbase->set_decoder_stack(decoder_stack);
+               signalbases_.insert(signalbase);
 
                for (std::shared_ptr<pv::view::View> view : views_)
                        view->add_decode_trace(signalbase);
index ffe4f67dc9c4cf14cff9e8573b6cce69d6fe669a..8dd329e0f7fd947c08717068e58dd4999307c827 100644 (file)
@@ -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);