return data_saved_;
}
+void Session::save_setup(QSettings &settings) const
+{
+ int decode_signals = 0, views = 0;
+
+ // Save channels and decoders
+ for (const shared_ptr<data::SignalBase>& base : signalbases_) {
+#ifdef ENABLE_DECODE
+ if (base->is_decode_signal()) {
+ settings.beginGroup("decode_signal" + QString::number(decode_signals++));
+ base->save_settings(settings);
+ settings.endGroup();
+ } else
+#endif
+ {
+ settings.beginGroup(base->internal_name());
+ base->save_settings(settings);
+ settings.endGroup();
+ }
+ }
+
+ settings.setValue("decode_signals", decode_signals);
+
+ // Save view states and their signal settings
+ // Note: main_view must be saved as view0
+ settings.beginGroup("view" + QString::number(views++));
+ main_view_->save_settings(settings);
+ settings.endGroup();
+
+ for (const shared_ptr<views::ViewBase>& view : views_) {
+ if (view != main_view_) {
+ settings.beginGroup("view" + QString::number(views++));
+ view->save_settings(settings);
+ settings.endGroup();
+ }
+ }
+
+ settings.setValue("views", views);
+}
+
void Session::save_settings(QSettings &settings) const
{
map<string, string> dev_info;
list<string> key_list;
- int decode_signals = 0, views = 0;
if (device_) {
shared_ptr<devices::HardwareDevice> hw_device =
settings.endGroup();
}
- // Save channels and decoders
- for (const shared_ptr<data::SignalBase>& base : signalbases_) {
+ save_setup(settings);
+ }
+}
+
+void Session::restore_setup(QSettings &settings)
+{
+ // Restore channels
+ for (shared_ptr<data::SignalBase> base : signalbases_) {
+ settings.beginGroup(base->internal_name());
+ base->restore_settings(settings);
+ settings.endGroup();
+ }
+
+ // Restore decoders
#ifdef ENABLE_DECODE
- if (base->is_decode_signal()) {
- settings.beginGroup("decode_signal" + QString::number(decode_signals++));
- base->save_settings(settings);
- settings.endGroup();
- } else
+ int decode_signals = settings.value("decode_signals").toInt();
+
+ for (int i = 0; i < decode_signals; i++) {
+ settings.beginGroup("decode_signal" + QString::number(i));
+ shared_ptr<data::DecodeSignal> signal = add_decode_signal();
+ signal->restore_settings(settings);
+ settings.endGroup();
+ }
#endif
- {
- settings.beginGroup(base->internal_name());
- base->save_settings(settings);
- settings.endGroup();
- }
- }
- settings.setValue("decode_signals", decode_signals);
+ // Restore views
+ int views = settings.value("views").toInt();
- // Save view states and their signal settings
- // Note: main_view must be saved as view0
- settings.beginGroup("view" + QString::number(views++));
- main_view_->save_settings(settings);
- settings.endGroup();
+ for (int i = 0; i < views; i++) {
+ settings.beginGroup("view" + QString::number(i));
- for (const shared_ptr<views::ViewBase>& view : views_) {
- if (view != main_view_) {
- settings.beginGroup("view" + QString::number(views++));
- view->save_settings(settings);
- settings.endGroup();
- }
- }
+ if (i > 0) {
+ views::ViewType type = (views::ViewType)settings.value("type").toInt();
+ add_view(name_, type, this);
+ views_.back()->restore_settings(settings);
+ } else
+ main_view_->restore_settings(settings);
- settings.setValue("views", views);
+ settings.endGroup();
}
}
}
}
- if (device) {
- // Restore channels
- for (shared_ptr<data::SignalBase> base : signalbases_) {
- settings.beginGroup(base->internal_name());
- base->restore_settings(settings);
- settings.endGroup();
- }
-
- // Restore decoders
-#ifdef ENABLE_DECODE
- int decode_signals = settings.value("decode_signals").toInt();
-
- for (int i = 0; i < decode_signals; i++) {
- settings.beginGroup("decode_signal" + QString::number(i));
- shared_ptr<data::DecodeSignal> signal = add_decode_signal();
- signal->restore_settings(settings);
- settings.endGroup();
- }
-#endif
-
- // Restore views
- int views = settings.value("views").toInt();
-
- for (int i = 0; i < views; i++) {
- settings.beginGroup("view" + QString::number(i));
-
- if (i > 0) {
- views::ViewType type = (views::ViewType)settings.value("type").toInt();
- add_view(name_, type, this);
- views_.back()->restore_settings(settings);
- } else
- main_view_->restore_settings(settings);
-
- settings.endGroup();
- }
- }
+ if (device)
+ restore_setup(settings);
}
void Session::select_device(shared_ptr<devices::Device> device)
*/
bool data_saved() const;
+ void save_setup(QSettings &settings) const;
+
void save_settings(QSettings &settings) const;
+ void restore_setup(QSettings &settings);
+
void restore_settings(QSettings &settings);
/**
action_open_(new QAction(this)),
action_save_as_(new QAction(this)),
action_save_selection_as_(new QAction(this)),
+ action_restore_setup_(new QAction(this)),
+ action_save_setup_(new QAction(this)),
action_connect_(new QAction(this)),
open_button_(new QToolButton()),
save_button_(new QToolButton()),
connect(action_open_, SIGNAL(triggered(bool)),
this, SLOT(on_actionOpen_triggered()));
+ action_restore_setup_->setText(tr("Restore Session Setu&p..."));
+ connect(action_restore_setup_, SIGNAL(triggered(bool)),
+ this, SLOT(on_actionRestoreSetup_triggered()));
+
action_save_as_->setText(tr("&Save As..."));
action_save_as_->setIcon(QIcon::fromTheme("document-save-as",
QIcon(":/icons/document-save-as.png")));
connect(action_save_selection_as_, SIGNAL(triggered(bool)),
this, SLOT(on_actionSaveSelectionAs_triggered()));
+ action_save_setup_->setText(tr("Save Session Setu&p..."));
+ connect(action_save_setup_, SIGNAL(triggered(bool)),
+ this, SLOT(on_actionSaveSetup_triggered()));
+
widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this,
session.device_manager().context());
menu_file_export->setTitle(tr("&Export"));
this, SLOT(on_actionConnect_triggered()));
// Open button
+ vector<QAction*> open_actions;
+ open_actions.push_back(action_open_);
+ QAction* separator_o = new QAction(this);
+ separator_o->setSeparator(true);
+ open_actions.push_back(separator_o);
+ open_actions.push_back(action_restore_setup_);
+
widgets::ImportMenu *import_menu = new widgets::ImportMenu(this,
- session.device_manager().context(), action_open_);
+ session.device_manager().context(), open_actions);
connect(import_menu, SIGNAL(format_selected(shared_ptr<sigrok::InputFormat>)),
this, SLOT(import_file(shared_ptr<sigrok::InputFormat>)));
open_button_->setPopupMode(QToolButton::MenuButtonPopup);
// Save button
- vector<QAction*> open_actions;
- open_actions.push_back(action_save_as_);
- open_actions.push_back(action_save_selection_as_);
+ vector<QAction*> save_actions;
+ save_actions.push_back(action_save_as_);
+ save_actions.push_back(action_save_selection_as_);
+ QAction* separator_s = new QAction(this);
+ separator_s->setSeparator(true);
+ save_actions.push_back(separator_s);
+ save_actions.push_back(action_save_setup_);
widgets::ExportMenu *export_menu = new widgets::ExportMenu(this,
- session.device_manager().context(), open_actions);
+ session.device_manager().context(), save_actions);
connect(export_menu, SIGNAL(format_selected(shared_ptr<sigrok::OutputFormat>)),
this, SLOT(export_file(shared_ptr<sigrok::OutputFormat>)));
export_file(session_.device_manager().context()->output_formats()["srzip"], true);
}
+void MainBar::on_actionSaveSetup_triggered()
+{
+ QSettings settings;
+ const QString dir = settings.value(SettingSaveDirectory).toString();
+
+ const QString file_name = QFileDialog::getSaveFileName(
+ this, tr("Save File"), dir, tr(
+ "PulseView Session Setups (*.pvs);;"
+ "All Files (*)"));
+
+ if (file_name.isEmpty())
+ return;
+
+ QSettings settings_storage(file_name, QSettings::IniFormat);
+ session_.save_setup(settings_storage);
+}
+
+void MainBar::on_actionRestoreSetup_triggered()
+{
+ QSettings settings;
+ const QString dir = settings.value(SettingSaveDirectory).toString();
+
+ const QString file_name = QFileDialog::getOpenFileName(
+ this, tr("Open File"), dir, tr(
+ "PulseView Session Setups (*.pvs);;"
+ "All Files (*)"));
+
+ if (file_name.isEmpty())
+ return;
+
+ QSettings settings_storage(file_name, QSettings::IniFormat);
+ session_.restore_setup(settings_storage);
+}
+
void MainBar::on_actionConnect_triggered()
{
// Stop any currently running capture session
QAction* action_open() const;
QAction* action_save_as() const;
QAction* action_save_selection_as() const;
+ QAction* action_restore_setup() const;
+ QAction* action_save_setup() const;
QAction* action_connect() const;
private:
QAction *const action_open_;
QAction *const action_save_as_;
QAction *const action_save_selection_as_;
+ QAction *const action_restore_setup_;
+ QAction *const action_save_setup_;
QAction *const action_connect_;
private Q_SLOTS:
void on_actionSaveAs_triggered();
void on_actionSaveSelectionAs_triggered();
+ void on_actionSaveSetup_triggered();
+ void on_actionRestoreSetup_triggered();
+
void on_actionConnect_triggered();
protected:
using std::pair;
using std::string;
using std::shared_ptr;
+using std::vector;
using sigrok::Context;
using sigrok::InputFormat;
namespace widgets {
ImportMenu::ImportMenu(QWidget *parent, shared_ptr<Context> context,
- QAction *open_action) :
+ vector<QAction *>open_actions) :
QMenu(parent),
context_(context),
mapper_(this)
{
assert(context);
- if (open_action) {
- addAction(open_action);
- setDefaultAction(open_action);
+ if (!open_actions.empty()) {
+ bool first_action = true;
+ for (auto open_action : open_actions) {
+ addAction(open_action);
+
+ if (first_action) {
+ first_action = false;
+ setDefaultAction(open_action);
+ }
+ }
addSeparator();
}
#include <QSignalMapper>
using std::shared_ptr;
+using std::vector;
namespace sigrok {
class Context;
public:
ImportMenu(QWidget *parent, shared_ptr<sigrok::Context> context,
- QAction *open_action = nullptr);
+ vector<QAction *>open_actions = vector<QAction *>());
private Q_SLOTS:
void on_action(QObject *action);