X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=cd46c063bdc8a84d78d1e42e1c616c2fc8a3b270;hp=18790f54e4bd750be12f02fad722f23cb323672f;hb=HEAD;hpb=009fc9ae42ecccd3802f549b39c19a2ba895959d diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 18790f54..cd46c063 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -59,6 +60,7 @@ using std::back_inserter; using std::copy; using std::list; using std::make_pair; +using std::make_shared; using std::map; using std::max; using std::min; @@ -90,6 +92,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)), @@ -107,10 +110,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view sample_rate_("Hz", this), updating_sample_rate_(false), updating_sample_count_(false), - sample_count_supported_(false) + sample_count_supported_(false), #ifdef ENABLE_DECODE - , add_decoder_button_(new QToolButton()) + add_decoder_button_(new QToolButton()), #endif + add_math_signal_button_(new QToolButton()) { setObjectName(QString::fromUtf8("MainBar")); @@ -126,7 +130,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view action_open_->setText(tr("&Open...")); action_open_->setIcon(QIcon::fromTheme("document-open", QIcon(":/icons/document-open.png"))); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + action_open_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_O)); +#else action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); +#endif connect(action_open_, SIGNAL(triggered(bool)), this, SLOT(on_actionOpen_triggered())); @@ -134,17 +142,31 @@ 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"))); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + action_save_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S)); +#else + action_save_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); +#endif + 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())); action_save_selection_as_->setText(tr("Save Selected &Range As...")); action_save_selection_as_->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/icons/document-save-as.png"))); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_R)); +#else action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); +#endif connect(action_save_selection_as_, SIGNAL(triggered(bool)), this, SLOT(on_actionSaveSelectionAs_triggered())); @@ -201,6 +223,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 +237,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 @@ -232,6 +255,16 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view this, SLOT(on_add_decoder_clicked())); #endif + // Setup the math signal button + add_math_signal_button_->setIcon(QIcon(":/icons/add-math-signal.svg")); + add_math_signal_button_->setPopupMode(QToolButton::InstantPopup); + add_math_signal_button_->setToolTip(tr("Add math signal")); + add_math_signal_button_->setShortcut(QKeySequence(Qt::Key_M)); + + connect(add_math_signal_button_, SIGNAL(clicked()), + this, SLOT(on_add_math_signal_clicked())); + + connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -298,6 +331,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_; @@ -522,7 +560,7 @@ void MainBar::update_device_config_widgets() sample_count_supported_ = true; // Add notification of reconfigure events - disconnect(this, SLOT(on_config_changed())); + // Note: No need to disconnect the previous signal as that QObject instance is destroyed connect(&opts->binding(), SIGNAL(config_changed()), this, SLOT(on_config_changed())); @@ -595,7 +633,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 file_name) { using pv::dialogs::StoreProgress; @@ -654,8 +692,8 @@ 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); + if (file_name.isEmpty()) + file_name = QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter); if (file_name.isEmpty()) return; @@ -675,8 +713,13 @@ 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) { + if (format == session_.device_manager().context()->output_formats()["srzip"]) { + session_.set_save_path(QFileInfo(file_name).absolutePath()); + session_.set_name(QFileInfo(file_name).fileName()); + } else + session_.set_save_path(""); + } StoreProgress *dlg = new StoreProgress(file_name, format, options, sample_range, session_, this); @@ -798,6 +841,19 @@ void MainBar::on_actionOpen_triggered() } } +void MainBar::on_actionSave_triggered() +{ + // A path is only set if we loaded/saved an srzip file before + if (session_.save_path().isEmpty()) { + on_actionSaveAs_triggered(); + return; + } + + QFileInfo fi = QFileInfo(QDir(session_.save_path()), session_.name()); + export_file(session_.device_manager().context()->output_formats()["srzip"], false, + fi.absoluteFilePath()); +} + void MainBar::on_actionSaveAs_triggered() { export_file(session_.device_manager().context()->output_formats()["srzip"]); @@ -862,6 +918,12 @@ void MainBar::on_add_decoder_clicked() show_decoder_selector(&session_); } +void MainBar::on_add_math_signal_clicked() +{ + shared_ptr signal = make_shared(session_); + session_.add_generated_signal(signal); +} + void MainBar::add_toolbar_widgets() { addWidget(new_view_button_); @@ -881,6 +943,7 @@ void MainBar::add_toolbar_widgets() addSeparator(); addWidget(add_decoder_button_); #endif + addWidget(add_math_signal_button_); } bool MainBar::eventFilter(QObject *watched, QEvent *event)