From: Soeren Apel Date: Sun, 24 Feb 2019 14:20:24 +0000 (+0100) Subject: Auto-load session setups if they exist and auto-save them if desired X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8962d7b3b640b5f07f26a4b4ebee839c4880b69d;p=pulseview.git Auto-load session setups if they exist and auto-save them if desired --- diff --git a/pv/dialogs/settings.cpp b/pv/dialogs/settings.cpp index 780a6665..1cd7d23c 100644 --- a/pv/dialogs/settings.cpp +++ b/pv/dialogs/settings.cpp @@ -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; diff --git a/pv/dialogs/settings.hpp b/pv/dialogs/settings.hpp index 43988fec..e2ee568b 100644 --- a/pv/dialogs/settings.hpp +++ b/pv/dialogs/settings.hpp @@ -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); diff --git a/pv/globalsettings.cpp b/pv/globalsettings.cpp index 34dbc832..19ce0cd7 100644 --- a/pv/globalsettings.cpp +++ b/pv/globalsettings.cpp @@ -44,6 +44,7 @@ const vector< pair > 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); diff --git a/pv/globalsettings.hpp b/pv/globalsettings.hpp index e890a800..a65a723c 100644 --- a/pv/globalsettings.hpp +++ b/pv/globalsettings.hpp @@ -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; diff --git a/pv/session.cpp b/pv/session.cpp index 99bd7482..d3b2d6ac 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -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) { diff --git a/pv/storesession.cpp b/pv/storesession.cpp index ee1a3a03..42b13c46 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -21,6 +21,8 @@ #include "storesession.hpp" +#include + #include #include #include @@ -28,6 +30,7 @@ #include #include #include +#include #include #include @@ -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; }