]> sigrok.org Git - pulseview.git/commitdiff
Auto-load session setups if they exist and auto-save them if desired
authorSoeren Apel <redacted>
Sun, 24 Feb 2019 14:20:24 +0000 (15:20 +0100)
committerSoeren Apel <redacted>
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 780a66655e91826083bad6e4932c8246f52959d0..1cd7d23c8bf83068e97a91a1e6d518feb528d34b 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 43988fec9e09b2889237dd7a97dfa86d3558be6e..e2ee568b28971f98497f6c322a09f71a2cb3532e 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 34dbc8326e8acb0f5db01d4c195764af310c73ab..19ce0cd79104cce58878f1ee194fd4ac452f1736 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 e890a800e306b302f0b5939c28d7c78bcfe537d0..a65a723c0c0e85f4704fa38bb712a8e68276c0ba 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 99bd74823904079e1d507be7178afe7b03aedc3c..d3b2d6ac81d4c0517c999b7487602c9437f25aa3 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 ee1a3a03f096cf5c55d3a0ce16ea3f3c85496669..42b13c46c24303c5fad2ad7ef6cf55ca13322a0f 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;
 }