X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Ftoolbars%2Fmainbar.cpp;h=8c0b06391db310f8e1dad603cf38ad7de6c81864;hb=24fa726ff2bbd151264336e764a748b8f4d40968;hp=b404b3da45b32666f335fbee88d773c657b0b855;hpb=e13e7879200700579516c0ba09bfd0253b8a2297;p=pulseview.git diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index b404b3d..8c0b063 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -110,9 +110,13 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : // Save button QToolButton *const save_button = new QToolButton(this); + vector open_actions; + open_actions.push_back(main_window.action_save_as()); + open_actions.push_back(main_window.action_save_selection_as()); + widgets::ExportMenu *export_menu = new widgets::ExportMenu(this, session.device_manager().context(), - main_window.action_save_as()); + open_actions); connect(export_menu, SIGNAL(format_selected(std::shared_ptr)), &main_window_, @@ -135,13 +139,21 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : add_decoder_button->setMenu(main_window_.menu_decoder_add()); #endif - // Setup the menu + // Setup the burger menu QMenu *const menu = new QMenu(this); + QMenu *const menu_view = new QMenu; + menu_view->setTitle(tr("&View")); + menu_view->addAction(main_window.action_view_sticky_scrolling()); + menu_view->addSeparator(); + menu_view->addAction(main_window.action_view_coloured_bg()); + QMenu *const menu_help = new QMenu; menu_help->setTitle(tr("&Help")); menu_help->addAction(main_window.action_about()); + menu->addAction(menu_view->menuAction()); + menu->addSeparator(); menu->addAction(menu_help->menuAction()); menu->addSeparator(); menu->addAction(main_window.action_quit()); @@ -226,6 +238,14 @@ void MainBar::set_capture_state(pv::Session::capture_state 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); + configure_button_.setEnabled(ui_enabled); + channels_button_.setEnabled(ui_enabled); + sample_count_.setEnabled(ui_enabled); + sample_rate_.setEnabled(ui_enabled); } void MainBar::update_sample_rate_selector() @@ -251,30 +271,16 @@ void MainBar::update_sample_rate_selector() const shared_ptr sr_dev = device->device(); - try { - keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); - } catch (Error) {} - - const auto iter = keys.find(ConfigKey::SAMPLERATE); - if (iter != keys.end() && - (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { - try { - gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE); - } catch(const sigrok::Error &e) { - // Failed to enunmerate samplerate - (void)e; - } - } - - if (!gvar_dict.gobj()) { + if (sr_dev->config_check(ConfigKey::SAMPLERATE, Capability::LIST)) { + gvar_dict = sr_dev->config_list(ConfigKey::SAMPLERATE); + } else { sample_rate_.show_none(); updating_sample_rate_ = false; return; } if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), - "samplerate-steps", G_VARIANT_TYPE("at")))) - { + "samplerate-steps", G_VARIANT_TYPE("at")))) { elements = (const uint64_t *)g_variant_get_fixed_array( gvar_list, &num_elements, sizeof(uint64_t)); @@ -291,18 +297,15 @@ void MainBar::update_sample_rate_selector() if (step == 1) sample_rate_.show_125_list(min, max); - else - { + else { // When the step is not 1, we cam't make a 1-2-5-10 // list of sample rates, because we may not be able to // make round numbers. Therefore in this case, show a // spin box. sample_rate_.show_min_max_step(min, max, step); } - } - else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), - "samplerates", G_VARIANT_TYPE("at")))) - { + } else if ((gvar_list = g_variant_lookup_value(gvar_dict.gobj(), + "samplerates", G_VARIANT_TYPE("at")))) { elements = (const uint64_t *)g_variant_get_fixed_array( gvar_list, &num_elements, sizeof(uint64_t)); sample_rate_.show_list(elements, num_elements); @@ -352,8 +355,7 @@ void MainBar::update_sample_count_selector() assert(!updating_sample_count_); updating_sample_count_ = true; - if (!sample_count_supported_) - { + if (!sample_count_supported_) { sample_count_.show_none(); updating_sample_count_ = false; return; @@ -366,20 +368,11 @@ void MainBar::update_sample_count_selector() if (sample_count == 0) sample_count = DefaultSampleCount; - const auto keys = sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS); - const auto iter = keys.find(ConfigKey::LIMIT_SAMPLES); - if (iter != keys.end() && - (*iter).second.find(sigrok::LIST) != (*iter).second.end()) { - try { - auto gvar = - sr_dev->config_list(ConfigKey::LIMIT_SAMPLES); - if (gvar.gobj()) - g_variant_get(gvar.gobj(), "(tt)", - &min_sample_count, &max_sample_count); - } catch(const sigrok::Error &e) { - // Failed to query sample limit - (void)e; - } + if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::LIST)) { + auto gvar = sr_dev->config_list(ConfigKey::LIMIT_SAMPLES); + if (gvar.gobj()) + g_variant_get(gvar.gobj(), "(tt)", + &min_sample_count, &max_sample_count); } min_sample_count = min(max(min_sample_count, MinSampleCount), @@ -388,14 +381,14 @@ void MainBar::update_sample_count_selector() sample_count_.show_125_list( min_sample_count, max_sample_count); - try { + if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::GET)) { auto gvar = sr_dev->config_get(ConfigKey::LIMIT_SAMPLES); sample_count = g_variant_get_uint64(gvar.gobj()); if (sample_count == 0) sample_count = DefaultSampleCount; sample_count = min(max(sample_count, MinSampleCount), max_sample_count); - } catch (Error error) {} + } sample_count_.set_value(sample_count); @@ -436,29 +429,14 @@ void MainBar::update_device_config_widgets() // Update supported options. sample_count_supported_ = false; - try { - for (auto entry : sr_dev->config_keys(ConfigKey::DEVICE_OPTIONS)) - { - auto key = entry.first; - auto capabilities = entry.second; - switch (key->id()) { - case SR_CONF_LIMIT_SAMPLES: - if (capabilities.count(Capability::SET)) - sample_count_supported_ = true; - break; - case SR_CONF_LIMIT_FRAMES: - if (capabilities.count(Capability::SET)) - { - sr_dev->config_set(ConfigKey::LIMIT_FRAMES, - Glib::Variant::create(1)); - on_config_changed(); - } - break; - default: - break; - } - } - } catch (Error error) {} + if (sr_dev->config_check(ConfigKey::LIMIT_SAMPLES, Capability::SET)) + sample_count_supported_ = true; + + if (sr_dev->config_check(ConfigKey::LIMIT_FRAMES, Capability::SET)) { + sr_dev->config_set(ConfigKey::LIMIT_FRAMES, + Glib::Variant::create(1)); + on_config_changed(); + } // Add notification of reconfigure events disconnect(this, SLOT(on_config_changed())); @@ -482,8 +460,7 @@ void MainBar::commit_sample_count() const shared_ptr sr_dev = device->device(); sample_count = sample_count_.value(); - if (sample_count_supported_) - { + if (sample_count_supported_) { try { sr_dev->config_set(ConfigKey::LIMIT_SAMPLES, Glib::Variant::create(sample_count)); @@ -568,12 +545,14 @@ void MainBar::on_config_changed() bool MainBar::eventFilter(QObject *watched, QEvent *event) { - if ((watched == &sample_count_ || watched == &sample_rate_) && - (event->type() == QEvent::ToolTip)) { - double sec = (double)sample_count_.value() / sample_rate_.value(); + if (sample_count_supported_ && (watched == &sample_count_ || + watched == &sample_rate_) && + (event->type() == QEvent::ToolTip)) { + auto sec = pv::util::Timestamp(sample_count_.value()) / sample_rate_.value(); QHelpEvent *help_event = static_cast(event); - QString str = tr("Total sampling time: %1").arg(pv::util::format_second(sec)); + QString str = tr("Total sampling time: %1").arg( + pv::util::format_time_si(sec, pv::util::SIPrefix::unspecified, 0, "s", false)); QToolTip::showText(help_event->globalPos(), str); return true;