]> sigrok.org Git - pulseview.git/commitdiff
Add "new session" and "new view" toolbar buttons
authorSoeren Apel <redacted>
Thu, 1 Sep 2016 19:11:18 +0000 (21:11 +0200)
committerSoeren Apel <redacted>
Thu, 1 Sep 2016 19:11:18 +0000 (21:11 +0200)
Those are temporary and will eventually replaced by
a proper UI.

icons/document-new.png [new file with mode: 0644]
icons/window-new.png [new file with mode: 0644]
pv/mainwindow.cpp
pv/mainwindow.hpp
pv/toolbars/mainbar.cpp
pv/toolbars/mainbar.hpp

diff --git a/icons/document-new.png b/icons/document-new.png
new file mode 100644 (file)
index 0000000..e3808a1
Binary files /dev/null and b/icons/document-new.png differ
diff --git a/icons/window-new.png b/icons/window-new.png
new file mode 100644 (file)
index 0000000..314f997
Binary files /dev/null and b/icons/window-new.png differ
index a99ba35298c39080930e764adcb699e0feb6d707..dab9c7866fab2b61ac85438dfe336bb05a96a9cd 100644 (file)
@@ -200,6 +200,11 @@ shared_ptr<pv::view::View> MainWindow::add_view(const QString &title,
                                main_bar = make_shared<MainBar>(session, *this);
                                dock_main->addToolBar(main_bar.get());
                                session.set_main_bar(main_bar);
+
+                               connect(main_bar.get(), SIGNAL(new_session()),
+                                       this, SLOT(on_new_session()));
+                               connect(main_bar.get(), SIGNAL(new_view(Session*)),
+                                       this, SLOT(on_new_view(Session*)));
                        }
                        main_bar->action_view_show_cursors()->setChecked(v->cursors_shown());
 
@@ -348,6 +353,19 @@ void MainWindow::on_add_view(const QString &title, view::ViewType type,
                        add_view(title, type, *s);
 }
 
+void MainWindow::on_new_session()
+{
+       add_session();
+}
+
+void MainWindow::on_new_view(Session *session)
+{
+       // We get a pointer and need a reference
+       for (std::shared_ptr<Session> s : sessions_)
+               if (s.get() == session)
+                       add_view(session->name(), pv::view::TraceView, *s);
+}
+
 void MainWindow::on_actionViewStickyScrolling_triggered()
 {
        shared_ptr<pv::view::View> view = get_active_view();
index 87e8755b8f8a6264e19f4c9b863dbb735a26e384..2bd8dadbf815d8ebdc594c9a3afb92208319a3ad 100644 (file)
@@ -94,6 +94,9 @@ private Q_SLOTS:
        void on_add_view(const QString &title, view::ViewType type,
                Session *session);
 
+       void on_new_session();
+       void on_new_view(Session *session);
+
        void on_actionViewStickyScrolling_triggered();
 
        void on_actionViewColouredBg_triggered();
index 0adb6c9250c3bd17ca45c4e8da4d28466a97a7c1..a0f190f7eea64d9eb1c38d3956139c8113f9d7fc 100644 (file)
@@ -89,6 +89,8 @@ const char *MainBar::SettingSaveDirectory = "MainWindow/SaveDirectory";
 
 MainBar::MainBar(Session &session, MainWindow &main_window) :
        QToolBar("Sampling Bar", &main_window),
+       action_new_session_(new QAction(this)),
+       action_new_view_(new QAction(this)),
        action_open_(new QAction(this)),
        action_save_as_(new QAction(this)),
        action_save_selection_as_(new QAction(this)),
@@ -127,6 +129,18 @@ MainBar::MainBar(Session &session, MainWindow &main_window) :
        setContextMenuPolicy(Qt::PreventContextMenu);
 
        // Actions
+       action_new_session_->setText(tr("New &Session"));
+       action_new_session_->setIcon(QIcon::fromTheme("document-new",
+               QIcon(":/icons/document-new.png")));
+       connect(action_new_session_, SIGNAL(triggered(bool)),
+               this, SLOT(on_actionNewSession_triggered()));
+
+       action_new_view_->setText(tr("New &View"));
+       action_new_view_->setIcon(QIcon::fromTheme("window-new",
+               QIcon(":/icons/window-new.png")));
+       connect(action_new_view_, SIGNAL(triggered(bool)),
+               this, SLOT(on_actionNewView_triggered()));
+
        action_open_->setText(tr("&Open..."));
        action_open_->setIcon(QIcon::fromTheme("document-open",
                QIcon(":/icons/document-open.png")));
@@ -255,6 +269,9 @@ MainBar::MainBar(Session &session, MainWindow &main_window) :
 #endif
 
        // Setup the toolbar
+       addAction(action_new_session_);
+       addAction(action_new_view_);
+       addSeparator();
        addWidget(open_button);
        addWidget(save_button);
        addSeparator();
@@ -944,6 +961,16 @@ void MainBar::on_config_changed()
        commit_sample_rate();   
 }
 
+void MainBar::on_actionNewSession_triggered()
+{
+       new_session();
+}
+
+void MainBar::on_actionNewView_triggered()
+{
+       new_view(&session_);
+}
+
 void MainBar::on_actionOpen_triggered()
 {
        QSettings settings;
index ed38dfaae8c0728a27c0a9e5b417b65278a3655a..d39cb5e412b09a0ba02e4d6a25097b9d4698419e 100644 (file)
@@ -93,6 +93,8 @@ public:
        void load_init_file(const std::string &file_name,
                const std::string &format);
 
+       QAction* action_new_session() const;
+       QAction* action_new_view() const;
        QAction* action_open() const;
        QAction* action_save_as() const;
        QAction* action_save_selection_as() const;
@@ -125,6 +127,8 @@ private:
 
        void session_error(const QString text, const QString info_text);
 
+       QAction *const action_new_session_;
+       QAction *const action_new_view_;
        QAction *const action_open_;
        QAction *const action_save_as_;
        QAction *const action_save_selection_as_;
@@ -154,6 +158,9 @@ private Q_SLOTS:
 
        void on_config_changed();
 
+       void on_actionNewSession_triggered();
+       void on_actionNewView_triggered();
+
        void on_actionOpen_triggered();
        void on_actionSaveAs_triggered();
        void on_actionSaveSelectionAs_triggered();
@@ -175,6 +182,10 @@ private Q_SLOTS:
 protected:
        bool eventFilter(QObject *watched, QEvent *event);
 
+Q_SIGNALS:
+       void new_session();
+       void new_view(Session *session);
+
 private:
        Session &session_;