X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=b670b75a6c41a2da6a117e4e7a55a205414f46a6;hb=fd22c71c1a9cc470b53c71c0ee131a4b2d645f80;hp=1875d3c415a34fab1cb8d2c0e65c5e486c16e7cd;hpb=91f8fe8c30131fb438dbdb1b58d69ede7ba9247b;p=pulseview.git diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 1875d3c..b670b75 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -64,7 +64,6 @@ using std::list; using std::map; using std::max; using std::min; -using std::pair; using std::shared_ptr; using std::string; using std::vector; @@ -89,6 +88,7 @@ const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory"; MainBar::MainBar(Session &session, MainWindow &main_window) : QToolBar("Sampling Bar", &main_window), + action_new_view_(new QAction(this)), action_open_(new QAction(this)), action_save_as_(new QAction(this)), action_save_selection_as_(new QAction(this)), @@ -109,13 +109,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : sample_rate_("Hz", this), updating_sample_rate_(false), updating_sample_count_(false), - sample_count_supported_(false), - icon_red_(":/icons/status-red.svg"), - icon_green_(":/icons/status-green.svg"), - icon_grey_(":/icons/status-grey.svg"), - run_stop_button_(this), - run_stop_button_action_(nullptr), - menu_button_(this) + sample_count_supported_(false) #ifdef ENABLE_DECODE , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true)) #endif @@ -127,23 +121,32 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : setContextMenuPolicy(Qt::PreventContextMenu); // Actions + action_new_view_->setText(tr("New &View")); + action_new_view_->setIcon(QIcon::fromTheme("window-new", + QIcon(":/icons/window-new.png"))); + connect(action_new_view_, SIGNAL(triggered(bool)), + this, SLOT(on_actionNewView_triggered())); + action_open_->setText(tr("&Open...")); action_open_->setIcon(QIcon::fromTheme("document-open", QIcon(":/icons/document-open.png"))); action_open_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); - action_open_->setObjectName(QString::fromUtf8("actionOpen")); + connect(action_open_, SIGNAL(triggered(bool)), + this, SLOT(on_actionOpen_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)); - action_save_as_->setObjectName(QString::fromUtf8("actionSaveAs")); + 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"))); action_save_selection_as_->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); - action_save_selection_as_->setObjectName(QString::fromUtf8("actionSaveSelectionAs")); + connect(action_save_selection_as_, SIGNAL(triggered(bool)), + this, SLOT(on_actionSaveSelectionAs_triggered())); widgets::ExportMenu *menu_file_export = new widgets::ExportMenu(this, session.device_manager().context()); @@ -160,44 +163,45 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : this, SLOT(import_file(std::shared_ptr))); action_connect_->setText(tr("&Connect to Device...")); - action_connect_->setObjectName(QString::fromUtf8("actionConnect")); + connect(action_connect_, SIGNAL(triggered(bool)), + this, SLOT(on_actionConnect_triggered())); action_view_zoom_in_->setText(tr("Zoom &In")); action_view_zoom_in_->setIcon(QIcon::fromTheme("zoom-in", QIcon(":/icons/zoom-in.png"))); // simply using Qt::Key_Plus shows no + in the menu action_view_zoom_in_->setShortcut(QKeySequence::ZoomIn); - action_view_zoom_in_->setObjectName( - QString::fromUtf8("actionViewZoomIn")); + connect(action_view_zoom_in_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomIn_triggered())); action_view_zoom_out_->setText(tr("Zoom &Out")); action_view_zoom_out_->setIcon(QIcon::fromTheme("zoom-out", QIcon(":/icons/zoom-out.png"))); action_view_zoom_out_->setShortcut(QKeySequence::ZoomOut); - action_view_zoom_out_->setObjectName( - QString::fromUtf8("actionViewZoomOut")); + connect(action_view_zoom_out_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomOut_triggered())); action_view_zoom_fit_->setCheckable(true); action_view_zoom_fit_->setText(tr("Zoom to &Fit")); action_view_zoom_fit_->setIcon(QIcon::fromTheme("zoom-fit", QIcon(":/icons/zoom-fit.png"))); action_view_zoom_fit_->setShortcut(QKeySequence(Qt::Key_F)); - action_view_zoom_fit_->setObjectName( - QString::fromUtf8("actionViewZoomFit")); + connect(action_view_zoom_fit_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomFit_triggered())); action_view_zoom_one_to_one_->setText(tr("Zoom to O&ne-to-One")); action_view_zoom_one_to_one_->setIcon(QIcon::fromTheme("zoom-original", QIcon(":/icons/zoom-original.png"))); action_view_zoom_one_to_one_->setShortcut(QKeySequence(Qt::Key_O)); - action_view_zoom_one_to_one_->setObjectName( - QString::fromUtf8("actionViewZoomOneToOne")); + connect(action_view_zoom_one_to_one_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewZoomOneToOne_triggered())); action_view_show_cursors_->setCheckable(true); action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors", QIcon(":/icons/show-cursors.svg"))); action_view_show_cursors_->setShortcut(QKeySequence(Qt::Key_C)); - action_view_show_cursors_->setObjectName( - QString::fromUtf8("actionViewShowCursors")); + connect(action_view_show_cursors_, SIGNAL(triggered(bool)), + this, SLOT(on_actionViewShowCursors_triggered())); action_view_show_cursors_->setText(tr("Show &Cursors")); // Open button @@ -207,7 +211,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : session.device_manager().context(), action_open_); connect(import_menu, SIGNAL(format_selected(std::shared_ptr)), - &main_window, + this, SLOT(import_file(std::shared_ptr))); open_button->setMenu(import_menu); @@ -226,7 +230,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : open_actions); connect(export_menu, SIGNAL(format_selected(std::shared_ptr)), - &main_window, + this, SLOT(export_file(std::shared_ptr))); save_button->setMenu(export_menu); @@ -236,8 +240,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : // Device selector menu connect(&device_selector_, SIGNAL(device_selected()), this, SLOT(on_device_selected())); - connect(&session, SIGNAL(device_changed()), - this, SLOT(on_device_changed())); // Setup the decoder button #ifdef ENABLE_DECODE @@ -253,6 +255,8 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : #endif // Setup the toolbar + addAction(action_new_view_); + addSeparator(); addWidget(open_button); addWidget(save_button); addSeparator(); @@ -264,8 +268,6 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : addAction(action_view_show_cursors_); addSeparator(); - connect(&run_stop_button_, SIGNAL(clicked()), - this, SLOT(on_run_stop())); connect(&sample_count_, SIGNAL(value_changed()), this, SLOT(on_sample_count_changed())); connect(&sample_rate_, SIGNAL(value_changed()), @@ -281,33 +283,24 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : channels_button_.setIcon(QIcon::fromTheme("channels", QIcon(":/icons/channels.svg"))); - run_stop_button_.setToolButtonStyle(Qt::ToolButtonTextBesideIcon); - addWidget(&device_selector_); configure_button_action_ = addWidget(&configure_button_); channels_button_action_ = addWidget(&channels_button_); addWidget(&sample_count_); addWidget(&sample_rate_); - run_stop_button_action_ = addWidget(&run_stop_button_); #ifdef ENABLE_DECODE addSeparator(); addWidget(add_decoder_button); #endif - QWidget *const spacer = new QWidget(); - spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - addWidget(spacer); - - addWidget(&menu_button_); - sample_count_.installEventFilter(this); sample_rate_.installEventFilter(this); // Setup session_ events - connect(&session_, SIGNAL(capture_state_changed(int)), this, - SLOT(capture_state_changed(int))); - connect(&session_, SIGNAL(device_selected()), this, - SLOT(device_selected())); + connect(&session_, SIGNAL(capture_state_changed(int)), + this, SLOT(capture_state_changed(int))); + connect(&session, SIGNAL(device_changed()), + this, SLOT(on_device_changed())); update_device_list(); } @@ -335,12 +328,6 @@ void MainBar::update_device_list() void MainBar::set_capture_state(pv::Session::capture_state state) { - const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_}; - run_stop_button_.setIcon(*icons[state]); - run_stop_button_.setText((state == pv::Session::Stopped) ? - tr("Run") : tr("Stop")); - run_stop_button_.setShortcut(QKeySequence(Qt::Key_Space)); - bool ui_enabled = (state == pv::Session::Stopped) ? true : false; device_selector_.setEnabled(ui_enabled); @@ -355,47 +342,6 @@ void MainBar::reset_device_selector() device_selector_.reset(); } -void MainBar::select_device(shared_ptr device) -{ - try { - if (device) - session_.set_device(device); - else - session_.set_default_device(); - } catch (const QString &e) { - QMessageBox msg(this); - msg.setText(e); - msg.setInformativeText(tr("Failed to Select Device")); - msg.setStandardButtons(QMessageBox::Ok); - msg.setIcon(QMessageBox::Warning); - msg.exec(); - } -} - -void MainBar::load_init_file(const std::string &file_name, - const std::string &format) -{ - shared_ptr input_format; - - DeviceManager& device_manager = session_.device_manager(); - - if (!format.empty()) { - const map > formats = - device_manager.context()->input_formats(); - const auto iter = find_if(formats.begin(), formats.end(), - [&](const pair > f) { - return f.first == format; }); - if (iter == formats.end()) { - cerr << "Unexpected input format: " << format << endl; - return; - } - - input_format = (*iter).second; - } - - load_file(QString::fromStdString(file_name), input_format); -} - QAction* MainBar::action_open() const { return action_open_; @@ -441,56 +387,6 @@ QAction* MainBar::action_view_show_cursors() const return action_view_show_cursors_; } -void MainBar::run_stop() -{ - switch (session_.get_capture_state()) { - case Session::Stopped: - session_.start_capture([&](QString message) { - session_error("Capture failed", message); }); - break; - case Session::AwaitingTrigger: - case Session::Running: - session_.stop_capture(); - break; - } -} - -void MainBar::load_file(QString file_name, - std::shared_ptr format, - const std::map &options) -{ - DeviceManager& device_manager = session_.device_manager(); - - const QString errorMessage( - QString("Failed to load file %1").arg(file_name)); - - try { - if (format) - session_.set_device(shared_ptr( - new devices::InputFile( - device_manager.context(), - file_name.toStdString(), - format, options))); - else - session_.set_device(shared_ptr( - new devices::SessionFile( - device_manager.context(), - file_name.toStdString()))); - } catch (Error e) { - show_session_error(tr("Failed to load ") + file_name, e.what()); - session_.set_default_device(); - update_device_list(); - return; - } - - session_.set_name(QFileInfo(file_name).fileName()); - - update_device_list(); - - session_.start_capture([&, errorMessage](QString infoMessage) { - session_error(errorMessage, infoMessage); }); -} - void MainBar::update_sample_rate_selector() { Glib::VariantContainerBase gvar_dict; @@ -647,7 +543,6 @@ void MainBar::update_device_config_widgets() // Hide the widgets if no device is selected channels_button_action_->setVisible(!!device); - run_stop_button_action_->setVisible(!!device); if (!device) { configure_button_action_->setVisible(false); sample_count_.show_none(); @@ -797,7 +692,10 @@ void MainBar::export_file(shared_ptr format, // Selection only? Verify that the cursors are active and fetch their values if (selection_only) { - if (!session_.main_view()->cursors()->enabled()) { + views::TraceView::View *trace_view = + qobject_cast(session_.main_view().get()); + + if (!trace_view->cursors()->enabled()) { show_session_error(tr("Missing Cursors"), tr("You need to set the " \ "cursors before you can save the data enclosed by them " \ "to a session file (e.g. using ALT-V - Show Cursors).")); @@ -806,8 +704,8 @@ void MainBar::export_file(shared_ptr format, const double samplerate = session_.get_samplerate(); - const pv::util::Timestamp& start_time = session_.main_view()->cursors()->first()->time(); - const pv::util::Timestamp& end_time = session_.main_view()->cursors()->second()->time(); + const pv::util::Timestamp& start_time = trace_view->cursors()->first()->time(); + const pv::util::Timestamp& end_time = trace_view->cursors()->second()->time(); const uint64_t start_sample = std::max((double)0, start_time.convert_to() * samplerate); @@ -852,7 +750,8 @@ void MainBar::export_file(shared_ptr format, options = dlg.options(); } - session_.set_name(QFileInfo(file_name).fileName()); + if (!selection_only) + session_.set_name(QFileInfo(file_name).fileName()); StoreProgress *dlg = new StoreProgress(file_name, format, options, sample_range, session_, this); @@ -894,7 +793,7 @@ void MainBar::import_file(shared_ptr format) options = dlg.options(); } - load_file(file_name, format, options); + session_.load_file(file_name, format, options); const QString abs_path = QFileInfo(file_name).absolutePath(); settings.setValue(SettingOpenDirectory, abs_path); @@ -908,7 +807,7 @@ void MainBar::on_device_selected() return; } - select_device(device); + session_.select_device(device); } void MainBar::on_device_changed() @@ -929,17 +828,15 @@ void MainBar::on_sample_rate_changed() commit_sample_rate(); } -void MainBar::on_run_stop() +void MainBar::on_config_changed() { commit_sample_count(); commit_sample_rate(); - run_stop(); } -void MainBar::on_config_changed() +void MainBar::on_actionNewView_triggered() { - commit_sample_count(); - commit_sample_rate(); + new_view(&session_); } void MainBar::on_actionOpen_triggered() @@ -954,7 +851,7 @@ void MainBar::on_actionOpen_triggered() "All Files (*.*)")); if (!file_name.isEmpty()) { - load_file(file_name); + session_.load_file(file_name); const QString abs_path = QFileInfo(file_name).absolutePath(); settings.setValue(SettingOpenDirectory, abs_path); @@ -981,38 +878,58 @@ void MainBar::on_actionConnect_triggered() // If the user selected a device, select it in the device list. Select the // current device otherwise. if (dlg.exec()) - select_device(dlg.get_selected_device()); + session_.select_device(dlg.get_selected_device()); update_device_list(); } void MainBar::on_actionViewZoomIn_triggered() { - session_.main_view()->zoom(1); + views::TraceView::View *trace_view = + qobject_cast(session_.main_view().get()); + + trace_view->zoom(1); } void MainBar::on_actionViewZoomOut_triggered() { - session_.main_view()->zoom(-1); + views::TraceView::View *trace_view = + qobject_cast(session_.main_view().get()); + + trace_view->zoom(-1); } void MainBar::on_actionViewZoomFit_triggered() { - session_.main_view()->zoom_fit(action_view_zoom_fit_->isChecked()); + views::TraceView::View *trace_view = + qobject_cast(session_.main_view().get()); + + trace_view->zoom_fit(action_view_zoom_fit_->isChecked()); } void MainBar::on_actionViewZoomOneToOne_triggered() { - session_.main_view()->zoom_one_to_one(); + views::TraceView::View *trace_view = + qobject_cast(session_.main_view().get()); + + trace_view->zoom_one_to_one(); } void MainBar::on_actionViewShowCursors_triggered() { - const bool show = !session_.main_view()->cursors_shown(); + views::TraceView::View *trace_view = + qobject_cast(session_.main_view().get()); + + const bool show = !trace_view->cursors_shown(); if (show) - session_.main_view()->centre_cursors(); + trace_view->centre_cursors(); - session_.main_view()->show_cursors(show); + trace_view->show_cursors(show); +} + +void MainBar::on_always_zoom_to_fit_changed(bool state) +{ + action_view_zoom_fit_->setChecked(state); } bool MainBar::eventFilter(QObject *watched, QEvent *event)