X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fmainwindow.cpp;h=65071330da07e1d24c5955448ad44efe3f929383;hp=195c460a1de90f3aea20b3fb4af9745a6a34103b;hb=b926e4eeef6db657601ebd4bbededdf9d329cdd6;hpb=d2fc6be9af3ba409032da6dcabc4630c657bb56c diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 195c460a..65071330 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -110,12 +110,15 @@ MainWindow::MainWindow(DeviceManager &device_manager, action_view_zoom_fit_(new QAction(this)), action_view_zoom_one_to_one_(new QAction(this)), action_view_sticky_scrolling_(new QAction(this)), + action_view_coloured_bg_(new QAction(this)), action_view_show_cursors_(new QAction(this)), action_about_(new QAction(this)) #ifdef ENABLE_DECODE , menu_decoders_add_(new pv::widgets::DecoderMenu(this, true)) #endif { + qRegisterMetaType("util::Timestamp"); + setup_ui(); restore_ui_settings(); if (open_file_name.empty()) @@ -134,6 +137,11 @@ QAction* MainWindow::action_save_as() const return action_save_as_; } +QAction* MainWindow::action_save_selection_as() const +{ + return action_save_selection_as_; +} + QAction* MainWindow::action_connect() const { return action_connect_; @@ -169,6 +177,11 @@ QAction* MainWindow::action_view_sticky_scrolling() const return action_view_sticky_scrolling_; } +QAction* MainWindow::action_view_coloured_bg() const +{ + return action_view_coloured_bg_; +} + QAction* MainWindow::action_view_show_cursors() const { return action_view_show_cursors_; @@ -188,12 +201,11 @@ QMenu* MainWindow::menu_decoder_add() const void MainWindow::run_stop() { - switch(session_.get_capture_state()) { + 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(); @@ -208,7 +220,7 @@ void MainWindow::select_device(shared_ptr device) session_.set_device(device); else session_.set_default_device(); - } catch(const QString &e) { + } catch (const QString &e) { QMessageBox msg(this); msg.setText(e); msg.setInformativeText(tr("Failed to Select Device")); @@ -218,7 +230,8 @@ void MainWindow::select_device(shared_ptr device) } } -void MainWindow::export_file(shared_ptr format) +void MainWindow::export_file(shared_ptr format, + bool selection_only) { using pv::dialogs::StoreProgress; @@ -228,6 +241,30 @@ void MainWindow::export_file(shared_ptr format) QSettings settings; const QString dir = settings.value(SettingSaveDirectory).toString(); + std::pair sample_range; + + // Selection only? Verify that the cursors are active and fetch their values + if (selection_only) { + if (!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).")); + return; + } + + const double samplerate = session_.get_samplerate(); + + const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); + const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); + + const uint64_t start_sample = start_time.convert_to() * samplerate; + const uint64_t end_sample = end_time.convert_to() * samplerate; + + sample_range = std::make_pair(start_sample, end_sample); + } else { + sample_range = std::make_pair(0, 0); + } + // Construct the filter const vector exts = format->extensions(); QString filter = tr("%1 files ").arg( @@ -262,8 +299,6 @@ void MainWindow::export_file(shared_ptr format) options = dlg.options(); } - const std::pair sample_range = std::make_pair(0, 0); - StoreProgress *dlg = new StoreProgress(file_name, format, options, sample_range, session_, this); dlg->run(); @@ -430,7 +465,7 @@ void MainWindow::setup_ui() QString::fromUtf8("actionViewZoomOneToOne")); menu_view->addAction(action_view_zoom_one_to_one_); - menu_file->addSeparator(); + menu_view->addSeparator(); action_view_sticky_scrolling_->setCheckable(true); action_view_sticky_scrolling_->setChecked(true); @@ -444,6 +479,18 @@ void MainWindow::setup_ui() menu_view->addSeparator(); + action_view_coloured_bg_->setCheckable(true); + action_view_coloured_bg_->setChecked(true); + action_view_coloured_bg_->setShortcut(QKeySequence(Qt::Key_B)); + action_view_coloured_bg_->setObjectName( + QString::fromUtf8("actionViewColouredBg")); + action_view_coloured_bg_->setText(tr("Use &coloured backgrounds")); + menu_view->addAction(action_view_coloured_bg_); + + view_->enable_coloured_bg(action_view_coloured_bg_->isChecked()); + + menu_view->addSeparator(); + action_view_show_cursors_->setCheckable(true); action_view_show_cursors_->setChecked(view_->cursors_shown()); action_view_show_cursors_->setIcon(QIcon::fromTheme("show-cursors", @@ -504,20 +551,25 @@ void MainWindow::setup_ui() SLOT(capture_state_changed(int))); connect(&session_, SIGNAL(device_selected()), this, SLOT(device_selected())); + connect(&session_, SIGNAL(trigger_event(util::Timestamp)), view_, + SLOT(trigger_event(util::Timestamp))); // Setup view_ events connect(view_, SIGNAL(sticky_scrolling_changed(bool)), this, SLOT(sticky_scrolling_changed(bool))); connect(view_, SIGNAL(always_zoom_to_fit_changed(bool)), this, SLOT(always_zoom_to_fit_changed(bool))); + } -void MainWindow::select_init_device() { +void MainWindow::select_init_device() +{ QSettings settings; map dev_info; list key_list; + shared_ptr device; - // Re-select last used device if possible. + // Re-select last used device if possible but only if it's not demo settings.beginGroup("Device"); key_list.push_back("vendor"); key_list.push_back("model"); @@ -535,8 +587,24 @@ void MainWindow::select_init_device() { dev_info.insert(std::make_pair(key, value)); } - const shared_ptr device = - device_manager_.find_device_from_info(dev_info); + if (dev_info.count("model") > 0) + if (dev_info.at("model").find("Demo device") == std::string::npos) + device = device_manager_.find_device_from_info(dev_info); + + // When we can't find a device similar to the one we used last + // time and there is at least one device aside from demo, use it + if (!device) { + for (shared_ptr dev : device_manager_.devices()) { + dev_info = device_manager_.get_device_info(dev); + + if (dev_info.count("model") > 0) + if (dev_info.at("model").find("Demo device") == std::string::npos) { + device = dev; + break; + } + } + } + select_device(device); update_device_list(); @@ -544,7 +612,8 @@ void MainWindow::select_init_device() { } void MainWindow::load_init_file(const std::string &file_name, - const std::string &format) { + const std::string &format) +{ shared_ptr input_format; if (!format.empty()) { @@ -589,7 +658,6 @@ void MainWindow::save_ui_settings() session_.device()); for (string key : key_list) { - if (dev_info.count(key)) settings.setValue(QString::fromUtf8(key.c_str()), QString::fromUtf8(dev_info.at(key).c_str())); @@ -648,7 +716,7 @@ void MainWindow::load_file(QString file_name, new devices::SessionFile( device_manager_.context(), file_name.toStdString()))); - } catch(Error e) { + } catch (Error e) { show_session_error(tr("Failed to load ") + file_name, e.what()); session_.set_default_device(); update_device_list(); @@ -661,87 +729,6 @@ void MainWindow::load_file(QString file_name, session_error(errorMessage, infoMessage); }); } -void MainWindow::save_selection_to_file() -{ - // Stop any currently running capture session - session_.stop_capture(); - - // Get sample rate - double samplerate = 0.0; - - for (const shared_ptr d : session_.get_data()) { - assert(d); - const vector< shared_ptr > segments = - d->segments(); - for (const shared_ptr &s : segments) - samplerate = std::max(samplerate, s->samplerate()); - } - - if (samplerate == 0.0) - samplerate = 1; - - // Verify that the cursors are active and fetch their values - if (!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).")); - return; - } - - const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); - const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); - - const uint64_t start_sample = start_time.convert_to() * samplerate; - const uint64_t end_sample = end_time.convert_to() * samplerate; - - const std::pair sample_range = - std::make_pair(start_sample, end_sample); - - // Ask for output file name - QSettings settings; - const QString dir = settings.value(SettingSaveDirectory).toString(); - - shared_ptr format = - device_manager_.context()->output_formats()["srzip"]; - - const vector exts = format->extensions(); - QString filter = tr("%1 files ").arg( - QString::fromStdString(format->description())); - - if (exts.empty()) - filter += "(*.*)"; - else - filter += QString("(*.%1);;%2 (*.*)").arg( - QString::fromStdString(join(exts, ", *."))).arg( - tr("All Files")); - - const QString file_name = QFileDialog::getSaveFileName( - this, tr("Save File"), dir, filter); - - if (file_name.isEmpty()) - return; - - const QString abs_path = QFileInfo(file_name).absolutePath(); - settings.setValue(SettingSaveDirectory, abs_path); - - // Show the options dialog - map options; - if (!format->options().empty()) { - dialogs::InputOutputOptions dlg( - tr("Export %1").arg(QString::fromStdString( - format->description())), - format->options(), this); - if (!dlg.exec()) - return; - options = dlg.options(); - } - - // Save - pv::dialogs::StoreProgress *dlg = new pv::dialogs::StoreProgress(file_name, - format, options, sample_range, session_, this); - dlg->run(); -} - void MainWindow::closeEvent(QCloseEvent *event) { save_ui_settings(); @@ -794,7 +781,7 @@ void MainWindow::on_actionSaveAs_triggered() void MainWindow::on_actionSaveSelectionAs_triggered() { - save_selection_to_file(); + export_file(device_manager_.context()->output_formats()["srzip"], true); } void MainWindow::on_actionConnect_triggered() @@ -842,6 +829,11 @@ void MainWindow::on_actionViewStickyScrolling_triggered() view_->enable_sticky_scrolling(action_view_sticky_scrolling_->isChecked()); } +void MainWindow::on_actionViewColouredBg_triggered() +{ + view_->enable_coloured_bg(action_view_coloured_bg_->isChecked()); +} + void MainWindow::on_actionViewShowCursors_triggered() { assert(view_);