X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=b35e14661373d88325eb4a28c1d73a580d587e4f;hp=666c28d3049f7bd6b8a9ff7ccc35dc902b69814b;hb=b0773a8aa01735d7220284ab7a3e8b5d02b48e9e;hpb=96dbf014dad1309d4ade9c14a8b46733e2f531c8 diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 666c28d3..b35e1466 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,11 +92,13 @@ 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)), action_save_setup_(new QAction(this)), action_connect_(new QAction(this)), + new_view_button_(new QToolButton()), open_button_(new QToolButton()), save_button_(new QToolButton()), device_selector_(parent, session.device_manager(), action_connect_), @@ -106,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")); @@ -133,10 +138,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())); @@ -167,6 +178,20 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view connect(action_connect_, SIGNAL(triggered(bool)), this, SLOT(on_actionConnect_triggered())); + // New view button + QMenu *menu_new_view = new QMenu(); + connect(menu_new_view, SIGNAL(triggered(QAction*)), + this, SLOT(on_actionNewView_triggered(QAction*))); + + for (int i = 0; i < views::ViewTypeCount; i++) { + QAction *const action = menu_new_view->addAction(tr(views::ViewTypeNames[i])); + action->setData(QVariant::fromValue(i)); + } + + new_view_button_->setMenu(menu_new_view); + new_view_button_->setDefaultAction(action_new_view_); + new_view_button_->setPopupMode(QToolButton::MenuButtonPopup); + // Open button vector open_actions; open_actions.push_back(action_open_); @@ -186,6 +211,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); @@ -199,7 +225,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 @@ -211,11 +237,22 @@ MainBar::MainBar(Session &session, QWidget *parent, pv::views::trace::View *view add_decoder_button_->setIcon(QIcon(":/icons/add-decoder.svg")); add_decoder_button_->setPopupMode(QToolButton::InstantPopup); add_decoder_button_->setToolTip(tr("Add protocol decoder")); + add_decoder_button_->setShortcut(QKeySequence(Qt::Key_D)); connect(add_decoder_button_, SIGNAL(clicked()), 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()), @@ -282,6 +319,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_; @@ -579,7 +621,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; @@ -638,8 +680,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; @@ -659,8 +701,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); @@ -754,9 +801,13 @@ void MainBar::on_config_changed() commit_sample_rate(); } -void MainBar::on_actionNewView_triggered() +void MainBar::on_actionNewView_triggered(QAction* action) { - new_view(&session_); + if (action) + new_view(&session_, action->data().toInt()); + else + // When the icon of the button is clicked, we create a trace view + new_view(&session_, views::ViewTypeTrace); } void MainBar::on_actionOpen_triggered() @@ -778,6 +829,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"]); @@ -842,9 +906,15 @@ 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() { - addAction(action_new_view_); + addWidget(new_view_button_); addSeparator(); addWidget(open_button_); addWidget(save_button_); @@ -861,6 +931,7 @@ void MainBar::add_toolbar_widgets() addSeparator(); addWidget(add_decoder_button_); #endif + addWidget(add_math_signal_button_); } bool MainBar::eventFilter(QObject *watched, QEvent *event)