Auto-load session setups if they exist and auto-save them if desired
authorSoeren Apel <soeren@apelpie.net>
Sun, 24 Feb 2019 14:20:24 +0000 (15:20 +0100)
committerSoeren Apel <soeren@apelpie.net>
Sat, 2 Mar 2019 13:42:50 +0000 (14:42 +0100)
pv/dialogs/settings.cpp
pv/dialogs/settings.hpp
pv/globalsettings.cpp
pv/globalsettings.hpp
pv/session.cpp
pv/storesession.cpp

index 780a666..1cd7d23 100644 (file)
@@ -204,6 +204,7 @@ QPlainTextEdit *Settings::create_log_view() const
 QWidget *Settings::get_general_settings_form(QWidget *parent) const
 {
        GlobalSettings settings;
+       QCheckBox *cb;
 
        QWidget *form = new QWidget(parent);
        QVBoxLayout *form_layout = new QVBoxLayout(form);
@@ -249,6 +250,10 @@ QWidget *Settings::get_general_settings_form(QWidget *parent) const
        description_2->setAlignment(Qt::AlignRight);
        general_layout->addRow(description_2);
 
+       cb = create_checkbox(GlobalSettings::Key_General_SaveWithSetup,
+               SLOT(on_general_save_with_setup_changed(int)));
+       general_layout->addRow(tr("Save session &setup along with .sr file"), cb);
+
        return form;
 }
 
@@ -612,6 +617,12 @@ void Settings::on_general_style_changed(int state)
        settings.apply_theme();
 }
 
+void Settings::on_general_save_with_setup_changed(int state)
+{
+       GlobalSettings settings;
+       settings.setValue(GlobalSettings::Key_General_SaveWithSetup, state ? true : false);
+}
+
 void Settings::on_view_zoomToFitDuringAcq_changed(int state)
 {
        GlobalSettings settings;
index 43988fe..e2ee568 100644 (file)
@@ -60,6 +60,7 @@ private Q_SLOTS:
        void on_page_changed(QListWidgetItem *current, QListWidgetItem *previous);
        void on_general_theme_changed_changed(int state);
        void on_general_style_changed(int state);
+       void on_general_save_with_setup_changed(int state);
        void on_view_zoomToFitDuringAcq_changed(int state);
        void on_view_zoomToFitAfterAcq_changed(int state);
        void on_view_triggerIsZero_changed(int state);
index 34dbc83..19ce0cd 100644 (file)
@@ -44,6 +44,7 @@ const vector< pair<QString, QString> > Themes {
 
 const QString GlobalSettings::Key_General_Theme = "General_Theme";
 const QString GlobalSettings::Key_General_Style = "General_Style";
+const QString GlobalSettings::Key_General_SaveWithSetup = "General_SaveWithSetup";
 const QString GlobalSettings::Key_View_ZoomToFitDuringAcq = "View_ZoomToFitDuringAcq";
 const QString GlobalSettings::Key_View_ZoomToFitAfterAcq = "View_ZoomToFitAfterAcq";
 const QString GlobalSettings::Key_View_TriggerIsZeroTime = "View_TriggerIsZeroTime";
@@ -94,6 +95,10 @@ void GlobalSettings::set_defaults_where_needed()
        if (!contains(Key_General_Style))
                setValue(Key_General_Style, "");
 
+       // Save setup with .sr files by default
+       if (!contains(Key_General_SaveWithSetup))
+               setValue(Key_General_SaveWithSetup, true);
+
        // Enable zoom-to-fit after acquisition by default
        if (!contains(Key_View_ZoomToFitAfterAcq))
                setValue(Key_View_ZoomToFitAfterAcq, true);
index e890a80..a65a723 100644 (file)
@@ -53,6 +53,7 @@ class GlobalSettings : public QSettings
 public:
        static const QString Key_General_Theme;
        static const QString Key_General_Style;
+       static const QString Key_General_SaveWithSetup;
        static const QString Key_View_ZoomToFitDuringAcq;
        static const QString Key_View_ZoomToFitAfterAcq;
        static const QString Key_View_TriggerIsZeroTime;
index 99bd748..d3b2d6a 100644 (file)
@@ -582,6 +582,15 @@ void Session::load_file(QString file_name,
                return;
        }
 
+       // Auto-load the setup if one exists
+       QString setup_file_name = file_name;
+       setup_file_name.truncate(setup_file_name.lastIndexOf('.'));
+       setup_file_name.append(".pvs");
+       if (QFileInfo::exists(setup_file_name) && QFileInfo(setup_file_name).isReadable()) {
+               QSettings settings_storage(setup_file_name, QSettings::IniFormat);
+               restore_setup(settings_storage);
+       }
+
        main_bar_->update_device_list();
 
        start_capture([&, errorMessage](QString infoMessage) {
index ee1a3a0..42b13c4 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "storesession.hpp"
 
+#include <QSettings>
+
 #include <pv/data/analog.hpp>
 #include <pv/data/analogsegment.hpp>
 #include <pv/data/logic.hpp>
@@ -28,6 +30,7 @@
 #include <pv/data/signalbase.hpp>
 #include <pv/devicemanager.hpp>
 #include <pv/devices/device.hpp>
+#include <pv/globalsettings.hpp>
 #include <pv/session.hpp>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
@@ -189,6 +192,20 @@ bool StoreSession::start()
 
        thread_ = std::thread(&StoreSession::store_proc, this,
                achannel_list, asegment_list, lsegment);
+
+       // Save session setup if we're saving to srzip and the user wants it
+       GlobalSettings settings;
+       bool save_with_setup = settings.value(GlobalSettings::Key_General_SaveWithSetup).toBool();
+
+       if ((output_format_->name() == "srzip") && (save_with_setup)) {
+               QString setup_file_name = QString::fromStdString(file_name_);
+               setup_file_name.truncate(setup_file_name.lastIndexOf('.'));
+               setup_file_name.append(".pvs");
+
+               QSettings settings_storage(setup_file_name, QSettings::IniFormat);
+               session_.save_setup(settings_storage);
+       }
+
        return true;
 }