From: Soeren Apel Date: Fri, 10 Jan 2020 22:01:18 +0000 (+0100) Subject: Fix #1448 by using different captions for the Run button X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=31d1aca6b7ab1b890b5ec7c05862e87986d5e6fd Fix #1448 by using different captions for the Run button --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 799f10d4..c5387beb 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -332,6 +332,8 @@ shared_ptr MainWindow::add_session() this, SLOT(on_add_view(views::ViewType, Session*))); connect(session.get(), SIGNAL(name_changed()), this, SLOT(on_session_name_changed())); + connect(session.get(), SIGNAL(device_changed()), + this, SLOT(on_session_device_changed())); session_state_mapper_.setMapping(session.get(), session.get()); connect(session.get(), SIGNAL(capture_state_changed(int)), &session_state_mapper_, SLOT(map())); @@ -566,6 +568,19 @@ void MainWindow::setup_ui() this, SLOT(on_focus_changed())); } +void MainWindow::update_acq_button(Session *session) +{ + int state = session->get_capture_state(); + + const QString run_caption = + session->using_file_device() ? tr("Reload") : tr("Run"); + + const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_}; + run_stop_button_->setIcon(*icons[state]); + run_stop_button_->setText((state == pv::Session::Stopped) ? + run_caption : tr("Stop")); +} + void MainWindow::save_ui_settings() { QSettings settings; @@ -739,6 +754,19 @@ void MainWindow::on_session_name_changed() setWindowTitle(session->name() + " - " + WindowTitle); } +void MainWindow::on_session_device_changed() +{ + Session *session = qobject_cast(QObject::sender()); + assert(session); + + // Ignore if caller is not the currently focused session + // unless there is only one session + if ((sessions_.size() > 1) && (session != last_focused_session_.get())) + return; + + update_acq_button(session); +} + void MainWindow::on_capture_state_changed(QObject *obj) { Session *caller = qobject_cast(obj); @@ -748,12 +776,7 @@ void MainWindow::on_capture_state_changed(QObject *obj) if ((sessions_.size() > 1) && (caller != last_focused_session_.get())) return; - int state = caller->get_capture_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")); + update_acq_button(caller); } void MainWindow::on_new_view(Session *session, int view_type) diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 06eba40a..bf23acfb 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -100,6 +100,7 @@ public: private: void setup_ui(); + void update_acq_button(Session *session); void save_ui_settings(); void restore_ui_settings(); @@ -123,6 +124,7 @@ private Q_SLOTS: void on_settings_clicked(); void on_session_name_changed(); + void on_session_device_changed(); void on_capture_state_changed(QObject *obj); void on_new_view(Session *session, int view_type); diff --git a/pv/session.cpp b/pv/session.cpp index 51a1aee7..6397416b 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -485,6 +485,17 @@ void Session::set_default_device() set_device((iter == devices.end()) ? devices.front() : *iter); } +bool Session::using_file_device() const +{ + shared_ptr sessionfile_device = + dynamic_pointer_cast(device_); + + shared_ptr inputfile_device = + dynamic_pointer_cast(device_); + + return (sessionfile_device || inputfile_device); +} + /** * Convert generic options to data types that are specific to InputFormat. * diff --git a/pv/session.hpp b/pv/session.hpp index 8d85996e..f4d150db 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -172,6 +172,8 @@ public: void set_default_device(); + bool using_file_device() const; + void load_init_file(const string &file_name, const string &format, const string &setup_file_name);