]> sigrok.org Git - pulseview.git/commitdiff
SignalBase: Don't assume all channel settings are restorable
authorSoeren Apel <redacted>
Wed, 11 Apr 2018 21:03:19 +0000 (23:03 +0200)
committerSoeren Apel <redacted>
Sun, 15 Apr 2018 06:19:59 +0000 (08:19 +0200)
pv/data/signalbase.cpp

index eb2996d04105d605dc5472a182ab42a496352c89..791094036ddcb23511329a9922c67f1774fa0268 100644 (file)
@@ -444,18 +444,30 @@ void SignalBase::save_settings(QSettings &settings) const
 
 void SignalBase::restore_settings(QSettings &settings)
 {
-       set_name(settings.value("name").toString());
-       set_enabled(settings.value("enabled").toBool());
-       set_color(settings.value("color").value<QColor>());
-       set_conversion_type((ConversionType)settings.value("conversion_type").toInt());
+       if (settings.contains("name"))
+               set_name(settings.value("name").toString());
 
-       int conv_options = settings.value("conv_options").toInt();
+       if (settings.contains("enabled"))
+               set_enabled(settings.value("enabled").toBool());
+
+       if (settings.contains("color"))
+               set_color(settings.value("color").value<QColor>());
+
+       if (settings.contains("conversion_type"))
+               set_conversion_type((ConversionType)settings.value("conversion_type").toInt());
+
+       int conv_options = 0;
+       if (settings.contains("conv_options"))
+               conv_options = settings.value("conv_options").toInt();
 
        if (conv_options)
                for (int i = 0; i < conv_options; i++) {
-                       QString key = settings.value(QString("conv_option%1_key").arg(i)).toString();
-                       QVariant value = settings.value(QString("conv_option%1_value").arg(i));
-                       conversion_options_[key] = value;
+                       const QString key_id = QString("conv_option%1_key").arg(i);
+                       const QString value_id = QString("conv_option%1_value").arg(i);
+
+                       if (settings.contains(key_id) && settings.contains(value_id))
+                               conversion_options_[settings.value(key_id).toString()] =
+                                       settings.value(value_id);
                }
 }