From b1264f5650d4bd6cb801585ed5d1dc61226a21db Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 19 May 2013 10:37:52 +0100 Subject: [PATCH] Initial working context bar --- pv/mainwindow.cpp | 17 +++++++++++++++++ pv/mainwindow.h | 4 ++++ pv/toolbars/contextbar.cpp | 30 ++++++++++++++++++++++++++++++ pv/toolbars/contextbar.h | 8 ++++++++ 4 files changed, 59 insertions(+) diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 6b3398f2..e70ca989 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -53,10 +53,15 @@ #include #include +using namespace boost; using namespace std; namespace pv { +namespace view { +class SelectableItem; +} + MainWindow::MainWindow(DeviceManager &device_manager, const char *open_file_name, QWidget *parent) : @@ -93,6 +98,9 @@ void MainWindow::setup_ui() setCentralWidget(_central_widget); _view = new pv::view::View(_session, this); + connect(_view, SIGNAL(selection_changed()), this, + SLOT(view_selection_changed())); + _vertical_layout->addWidget(_view); // Setup the menu bar @@ -358,4 +366,13 @@ void MainWindow::capture_state_changed(int state) _sampling_bar->set_sampling(state != SigSession::Stopped); } +void MainWindow::view_selection_changed() +{ + assert(_context_bar); + + const list > items( + _view->selected_items()); + _context_bar->set_selected_items(items); +} + } // namespace pv diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 51577bdb..001c28b0 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -23,6 +23,8 @@ #include +#include + #include #include "sigsession.h" @@ -97,6 +99,8 @@ private slots: void capture_state_changed(int state); + void view_selection_changed(); + private: DeviceManager &_device_manager; diff --git a/pv/toolbars/contextbar.cpp b/pv/toolbars/contextbar.cpp index 8e92676a..a538d64a 100644 --- a/pv/toolbars/contextbar.cpp +++ b/pv/toolbars/contextbar.cpp @@ -18,8 +18,16 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + +#include +#include + #include "contextbar.h" +#include + +using namespace boost; using namespace std; namespace pv { @@ -30,5 +38,27 @@ ContextBar::ContextBar(QWidget *parent) : { } +void ContextBar::set_selected_items(const list< + weak_ptr > &items) +{ + clear(); + + if (items.empty()) + return; + + if (shared_ptr item = + items.front().lock()) { + + assert(item); + + const list actions( + item->get_context_bar_actions()); + BOOST_FOREACH(QAction *action, actions) { + assert(action); + addAction(action); + } + } +} + } // namespace toolbars } // namespace pv diff --git a/pv/toolbars/contextbar.h b/pv/toolbars/contextbar.h index 02ff37e1..6d8e7f3f 100644 --- a/pv/toolbars/contextbar.h +++ b/pv/toolbars/contextbar.h @@ -21,8 +21,12 @@ #ifndef PULSEVIEW_PV_TOOLBARS_CONTEXTBAR_H #define PULSEVIEW_PV_TOOLBARS_CONTEXTBAR_H +#include + #include +#include + namespace pv { namespace toolbars { @@ -32,6 +36,10 @@ class ContextBar : public QToolBar public: ContextBar(QWidget *parent); + +public: + void set_selected_items(const std::list< + boost::weak_ptr > &items); }; } // namespace toolbars -- 2.30.2