]> sigrok.org Git - pulseview.git/commitdiff
Fix #1448 by using different captions for the Run button
authorSoeren Apel <redacted>
Fri, 10 Jan 2020 22:01:18 +0000 (23:01 +0100)
committerUwe Hermann <redacted>
Sun, 12 Jan 2020 15:46:45 +0000 (16:46 +0100)
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/session.cpp
pv/session.hpp

index 799f10d4b7c3bb7d3f8ccabd70e319df988ec990..c5387beb0a21b0ed943324b926cb093b77b48a3f 100644 (file)
@@ -332,6 +332,8 @@ shared_ptr<Session> 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<Session*>(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<Session*>(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)
index 06eba40ac212760373defba5fbdac8b7c46b9037..bf23acfb1fabe76795d9b558b64d8c2bccd5b23c 100644 (file)
@@ -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);
index 51a1aee715853ed305d331bb7f04ab158f26a00c..6397416be03dd194735c3f26a4e1b0610dd9abdb 100644 (file)
@@ -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<devices::SessionFile> sessionfile_device =
+               dynamic_pointer_cast<devices::SessionFile>(device_);
+
+       shared_ptr<devices::InputFile> inputfile_device =
+               dynamic_pointer_cast<devices::InputFile>(device_);
+
+       return (sessionfile_device || inputfile_device);
+}
+
 /**
  * Convert generic options to data types that are specific to InputFormat.
  *
index 8d85996ec6ec05e9656ffa6519e9c86ee2f1d656..f4d150dbe0031133afbd2497db3c4947a047c01b 100644 (file)
@@ -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);