From: Joel Holdsworth Date: Sun, 12 Apr 2015 15:03:55 +0000 (+0100) Subject: MainBar: Support having no selected device X-Git-Tag: pulseview-0.3.0~196 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9dd888899b1318787ffae6db62f4948b9aee2b84;p=pulseview.git MainBar: Support having no selected device --- diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 5518e98b..4bb39fac 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -73,6 +73,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : configure_button_(this), configure_button_action_(nullptr), channels_button_(this), + channels_button_action_(nullptr), sample_count_(" samples", this), sample_rate_("Hz", this), updating_sample_rate_(false), @@ -82,6 +83,7 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : icon_green_(":/icons/status-green.svg"), icon_grey_(":/icons/status-grey.svg"), run_stop_button_(this), + run_stop_button_action_(nullptr), menu_button_(this) { setObjectName(QString::fromUtf8("MainBar")); @@ -182,10 +184,10 @@ MainBar::MainBar(Session &session, MainWindow &main_window) : addWidget(&device_selector_); configure_button_action_ = addWidget(&configure_button_); - addWidget(&channels_button_); + channels_button_action_ = addWidget(&channels_button_); addWidget(&sample_count_); addWidget(&sample_rate_); - addWidget(&run_stop_button_); + run_stop_button_action_ = addWidget(&run_stop_button_); #ifdef ENABLE_DECODE addSeparator(); addWidget(add_decoder_button); @@ -211,7 +213,6 @@ void MainBar::update_device_list() if (std::find(devs.begin(), devs.end(), selected_device) == devs.end()) devs.push_back(selected_device); - assert(selected_device); device_selector_.set_device_list(devs, selected_device); update_device_config_widgets(); @@ -235,8 +236,10 @@ void MainBar::update_sample_rate_selector() gsize num_elements; map< const ConfigKey*, std::set > keys; - if (updating_sample_rate_) + if (updating_sample_rate_) { + sample_rate_.show_none(); return; + } const shared_ptr device = device_selector_.selected_device(); @@ -405,8 +408,16 @@ void MainBar::update_device_config_widgets() const shared_ptr device = device_selector_.selected_device(); - if (!device) + + // 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(); + sample_rate_.show_none(); return; + } const shared_ptr sr_dev = device->device(); if (!sr_dev) diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index 8e299dc9..6e2a7068 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -98,6 +98,7 @@ private: QAction *configure_button_action_; pv::widgets::PopupToolButton channels_button_; + QAction *channels_button_action_; pv::widgets::SweepTimingWidget sample_count_; pv::widgets::SweepTimingWidget sample_rate_; @@ -110,6 +111,7 @@ private: QIcon icon_green_; QIcon icon_grey_; QToolButton run_stop_button_; + QAction *run_stop_button_action_; QToolButton menu_button_; };