From: Valentin Ochs Date: Sat, 13 Jun 2020 17:23:49 +0000 (+0200) Subject: Add a new action to save to the last .sr file, and use it for control-S saving X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2cd6be62cb3dbbc60f4af3a888b232b7d0437532;p=pulseview.git Add a new action to save to the last .sr file, and use it for control-S saving --- diff --git a/pv/session.cpp b/pv/session.cpp index ea3fe07b..840773d1 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -176,6 +176,17 @@ void Session::set_name(QString name) name_changed(); } +QString Session::path() const +{ + return path_; +} + +void Session::set_path(QString path) +{ + path_ = path; + set_name(QFileInfo(path).fileName()); +} + const vector< shared_ptr > Session::views() const { return views_; @@ -444,6 +455,8 @@ void Session::restore_settings(QSettings &settings) settings.endGroup(); } + + QString path; if ((device_type == "sessionfile") || (device_type == "inputfile")) { if (device_type == "sessionfile") { settings.beginGroup("device"); @@ -451,6 +464,7 @@ void Session::restore_settings(QSettings &settings) settings.endGroup(); if (QFileInfo(filename).isReadable()) { + path = filename; device = make_shared(device_manager_.context(), filename.toStdString()); } @@ -472,6 +486,9 @@ void Session::restore_settings(QSettings &settings) set_name(QString::fromStdString( dynamic_pointer_cast(device)->display_name(device_manager_))); + + if (!path.isEmpty()) + set_path(path); } } @@ -709,7 +726,7 @@ void Session::load_file(QString file_name, QString setup_file_name, start_capture([&, errorMessage](QString infoMessage) { MainWindow::show_session_error(errorMessage, infoMessage); }); - set_name(QFileInfo(file_name).fileName()); + set_path(file_name); } Session::capture_state Session::get_capture_state() const diff --git a/pv/session.hpp b/pv/session.hpp index cfc69d4a..871dcba8 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -141,6 +141,9 @@ public: QString name() const; void set_name(QString name); + QString path() const; + void set_path(QString path); + const vector< shared_ptr > views() const; shared_ptr main_view() const; @@ -270,7 +273,7 @@ private: DeviceManager &device_manager_; shared_ptr device_; - QString default_name_, name_; + QString default_name_, name_, path_; vector< shared_ptr > views_; shared_ptr main_view_; diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 18790f54..a2a20fb6 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -90,6 +90,7 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view StandardBar(session, parent, view, false), action_new_view_(new QAction(this)), action_open_(new QAction(this)), + action_save_(new QAction(this)), action_save_as_(new QAction(this)), action_save_selection_as_(new QAction(this)), action_restore_setup_(new QAction(this)), @@ -134,10 +135,16 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view connect(action_restore_setup_, SIGNAL(triggered(bool)), this, SLOT(on_actionRestoreSetup_triggered())); - action_save_as_->setText(tr("&Save As...")); + action_save_->setText(tr("&Save...")); + action_save_->setIcon(QIcon::fromTheme("document-save-as", + QIcon(":/icons/document-save-as.png"))); + action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); + connect(action_save_, SIGNAL(triggered(bool)), + this, SLOT(on_actionSave_triggered())); + + action_save_as_->setText(tr("Save &As...")); action_save_as_->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png"))); - action_save_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); connect(action_save_as_, SIGNAL(triggered(bool)), this, SLOT(on_actionSaveAs_triggered())); @@ -201,6 +208,7 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view // Save button vector save_actions; + save_actions.push_back(action_save_); save_actions.push_back(action_save_as_); save_actions.push_back(action_save_selection_as_); QAction* separator_s = new QAction(this); @@ -214,7 +222,7 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view this, SLOT(export_file(shared_ptr))); save_button_->setMenu(export_menu); - save_button_->setDefaultAction(action_save_as_); + save_button_->setDefaultAction(action_save_); save_button_->setPopupMode(QToolButton::MenuButtonPopup); // Device selector menu @@ -298,6 +306,11 @@ QAction* MainBar::action_open() const return action_open_; } +QAction* MainBar::action_save() const +{ + return action_save_; +} + QAction* MainBar::action_save_as() const { return action_save_as_; @@ -595,7 +608,7 @@ void MainBar::show_session_error(const QString text, const QString info_text) msg.exec(); } -void MainBar::export_file(shared_ptr format, bool selection_only) +void MainBar::export_file(shared_ptr format, bool selection_only, QString path) { using pv::dialogs::StoreProgress; @@ -654,8 +667,9 @@ void MainBar::export_file(shared_ptr format, bool selection_only) tr("All Files")); // Show the file dialog - const QString file_name = QFileDialog::getSaveFileName( - this, tr("Save File"), dir, filter); + const QString file_name = path.isEmpty() ? + QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter) : + path; if (file_name.isEmpty()) return; @@ -675,8 +689,9 @@ void MainBar::export_file(shared_ptr format, bool selection_only) options = dlg.options(); } - if (!selection_only) - session_.set_name(QFileInfo(file_name).fileName()); + if (!selection_only && + format == session_.device_manager().context()->output_formats()["srzip"]) + session_.set_path(file_name); StoreProgress *dlg = new StoreProgress(file_name, format, options, sample_range, session_, this); @@ -798,6 +813,11 @@ void MainBar::on_actionOpen_triggered() } } +void MainBar::on_actionSave_triggered() +{ + export_file(session_.device_manager().context()->output_formats()["srzip"], false, session_.path()); +} + void MainBar::on_actionSaveAs_triggered() { export_file(session_.device_manager().context()->output_formats()["srzip"]); diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index 04c344c5..fca6acab 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -96,6 +96,7 @@ public: QAction* action_new_view() const; QAction* action_open() const; + QAction* action_save() const; QAction* action_save_as() const; QAction* action_save_selection_as() const; QAction* action_restore_setup() const; @@ -120,7 +121,8 @@ private Q_SLOTS: void show_session_error(const QString text, const QString info_text); void export_file(shared_ptr format, - bool selection_only = false); + bool selection_only = false, + QString path = QString{}); void import_file(shared_ptr format); void on_device_selected(); @@ -134,6 +136,7 @@ private Q_SLOTS: void on_actionNewView_triggered(QAction* action = nullptr); void on_actionOpen_triggered(); + void on_actionSave_triggered(); void on_actionSaveAs_triggered(); void on_actionSaveSelectionAs_triggered(); @@ -156,6 +159,7 @@ Q_SIGNALS: private: QAction *const action_new_view_; QAction *const action_open_; + QAction *const action_save_; QAction *const action_save_as_; QAction *const action_save_selection_as_; QAction *const action_restore_setup_;