X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=cd46c063bdc8a84d78d1e42e1c616c2fc8a3b270;hp=a2a20fb62a93aafe4956d0a6b52b4742099e7dfc;hb=HEAD;hpb=2cd6be62cb3dbbc60f4af3a888b232b7d0437532 diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index a2a20fb6..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; @@ -108,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")); @@ -127,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())); @@ -138,7 +145,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view 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())); @@ -151,7 +162,11 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view 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())); @@ -240,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()), @@ -535,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())); @@ -608,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, QString path) +void MainBar::export_file(shared_ptr format, bool selection_only, QString file_name) { using pv::dialogs::StoreProgress; @@ -667,9 +692,8 @@ void MainBar::export_file(shared_ptr format, bool selection_only, tr("All Files")); // Show the file dialog - const QString file_name = path.isEmpty() ? - QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter) : - path; + if (file_name.isEmpty()) + file_name = QFileDialog::getSaveFileName(this, tr("Save File"), dir, filter); if (file_name.isEmpty()) return; @@ -689,9 +713,13 @@ void MainBar::export_file(shared_ptr format, bool selection_only, options = dlg.options(); } - if (!selection_only && - format == session_.device_manager().context()->output_formats()["srzip"]) - session_.set_path(file_name); + 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); @@ -815,7 +843,15 @@ void MainBar::on_actionOpen_triggered() void MainBar::on_actionSave_triggered() { - export_file(session_.device_manager().context()->output_formats()["srzip"], false, session_.path()); + // 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() @@ -882,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_); @@ -901,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)