]> sigrok.org Git - pulseview.git/blobdiff - pv/mainwindow.cpp
MainWindow: Make on_run_stop_clicked() public
[pulseview.git] / pv / mainwindow.cpp
index 7d350625a4ddd3e9528dac8403ed75385b881420..6749b5f0343517a6c0afb467f8907f7878dcd38f 100644 (file)
@@ -52,7 +52,8 @@
 
 #ifdef ENABLE_DECODE
 #include "subwindows/decoder_selector/subwindow.hpp"
-#include "views/decoder_output/view.hpp"
+#include "views/decoder_binary/view.hpp"
+#include "views/tabular_decoder/view.hpp"
 #endif
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
@@ -162,8 +163,10 @@ shared_ptr<views::ViewBase> MainWindow::add_view(views::ViewType type,
                // This view will be the main view if there's no main bar yet
                v = make_shared<views::trace::View>(session, (main_bar ? false : true), dock_main);
 #ifdef ENABLE_DECODE
-       if (type == views::ViewTypeDecoderOutput)
-               v = make_shared<views::decoder_output::View>(session, false, dock_main);
+       if (type == views::ViewTypeDecoderBinary)
+               v = make_shared<views::decoder_binary::View>(session, false, dock_main);
+       if (type == views::ViewTypeTabularDecoder)
+               v = make_shared<views::tabular_decoder::View>(session, false, dock_main);
 #endif
 
        if (!v)
@@ -330,8 +333,8 @@ shared_ptr<Session> MainWindow::add_session()
 
        shared_ptr<Session> session = make_shared<Session>(device_manager_, name);
 
-       connect(session.get(), SIGNAL(add_view(views::ViewType, Session*)),
-               this, SLOT(on_add_view(views::ViewType, Session*)));
+       connect(session.get(), SIGNAL(add_view(ViewType, Session*)),
+               this, SLOT(on_add_view(ViewType, Session*)));
        connect(session.get(), SIGNAL(name_changed()),
                this, SLOT(on_session_name_changed()));
        connect(session.get(), SIGNAL(device_changed()),
@@ -569,10 +572,16 @@ void MainWindow::setup_ui()
 
 void MainWindow::update_acq_button(Session *session)
 {
-       int state = session->get_capture_state();
+       int state;
+       QString run_caption;
 
-       const QString run_caption =
-               session->using_file_device() ? tr("Reload") : tr("Run");
+       if (session) {
+               state = session->get_capture_state();
+               run_caption = session->using_file_device() ? tr("Reload") : tr("Run");
+       } else {
+               state = Session::Stopped;
+               run_caption = tr("Run");
+       }
 
        const QIcon *icons[] = {&icon_grey_, &icon_red_, &icon_green_};
        run_stop_button_->setIcon(*icons[state]);
@@ -650,6 +659,25 @@ bool MainWindow::restoreState(const QByteArray &state, int version)
        return false;
 }
 
+void MainWindow::on_run_stop_clicked()
+{
+       shared_ptr<Session> session = last_focused_session_;
+
+       if (!session)
+               return;
+
+       switch (session->get_capture_state()) {
+       case Session::Stopped:
+               session->start_capture([&](QString message) {
+                       show_session_error("Capture failed", message); });
+               break;
+       case Session::AwaitingTrigger:
+       case Session::Running:
+               session->stop_capture();
+               break;
+       }
+}
+
 void MainWindow::on_add_view(views::ViewType type, Session *session)
 {
        // We get a pointer and need a reference
@@ -700,25 +728,6 @@ void MainWindow::on_new_session_clicked()
        add_session();
 }
 
-void MainWindow::on_run_stop_clicked()
-{
-       shared_ptr<Session> session = last_focused_session_;
-
-       if (!session)
-               return;
-
-       switch (session->get_capture_state()) {
-       case Session::Stopped:
-               session->start_capture([&](QString message) {
-                       show_session_error("Capture failed", message); });
-               break;
-       case Session::AwaitingTrigger:
-       case Session::Running:
-               session->stop_capture();
-               break;
-       }
-}
-
 void MainWindow::on_settings_clicked()
 {
        dialogs::Settings dlg(device_manager_);
@@ -847,6 +856,9 @@ void MainWindow::on_tab_close_requested(int index)
                tr("This session contains unsaved data. Close it anyway?"),
                QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
                remove_session(session);
+
+       if (sessions_.empty())
+               update_acq_button(nullptr);
 }
 
 void MainWindow::on_show_decoder_selector(Session *session)
@@ -869,6 +881,8 @@ void MainWindow::on_show_decoder_selector(Session *session)
        for (shared_ptr<Session>& s : sessions_)
                if (s.get() == session)
                        add_subwindow(subwindows::SubWindowTypeDecoderSelector, *s);
+#else
+       (void)session;
 #endif
 }