From: Soeren Apel Date: Thu, 1 Sep 2016 19:11:18 +0000 (+0200) Subject: Add "new session" and "new view" toolbar buttons X-Git-Tag: pulseview-0.4.0~253 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=c9da51187f8db0c9822d544a0253e0e7a58945d7;p=pulseview.git Add "new session" and "new view" toolbar buttons Those are temporary and will eventually replaced by a proper UI. --- diff --git a/icons/document-new.png b/icons/document-new.png new file mode 100644 index 00000000..e3808a10 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 index 00000000..314f9979 Binary files /dev/null and b/icons/window-new.png differ diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index a99ba352..dab9c786 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -200,6 +200,11 @@ shared_ptr MainWindow::add_view(const QString &title, main_bar = make_shared(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 s : sessions_) + if (s.get() == session) + add_view(session->name(), pv::view::TraceView, *s); +} + void MainWindow::on_actionViewStickyScrolling_triggered() { shared_ptr view = get_active_view(); diff --git a/pv/mainwindow.hpp b/pv/mainwindow.hpp index 87e8755b..2bd8dadb 100644 --- a/pv/mainwindow.hpp +++ b/pv/mainwindow.hpp @@ -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(); diff --git a/pv/toolbars/mainbar.cpp b/pv/toolbars/mainbar.cpp index 0adb6c92..a0f190f7 100644 --- a/pv/toolbars/mainbar.cpp +++ b/pv/toolbars/mainbar.cpp @@ -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; diff --git a/pv/toolbars/mainbar.hpp b/pv/toolbars/mainbar.hpp index ed38dfaa..d39cb5e4 100644 --- a/pv/toolbars/mainbar.hpp +++ b/pv/toolbars/mainbar.hpp @@ -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_;