]> sigrok.org Git - pulseview.git/commitdiff
Initial working context bar
authorJoel Holdsworth <redacted>
Sun, 19 May 2013 09:37:52 +0000 (10:37 +0100)
committerJoel Holdsworth <redacted>
Sun, 19 May 2013 11:24:53 +0000 (12:24 +0100)
pv/mainwindow.cpp
pv/mainwindow.h
pv/toolbars/contextbar.cpp
pv/toolbars/contextbar.h

index 6b3398f22d9a40c7bb8266b24a37e29972fe3bef..e70ca9891c565ca81891ef30e2f1b2246aa661d8 100644 (file)
 #include <glib.h>
 #include <libsigrok/libsigrok.h>
 
 #include <glib.h>
 #include <libsigrok/libsigrok.h>
 
+using namespace boost;
 using namespace std;
 
 namespace pv {
 
 using namespace std;
 
 namespace pv {
 
+namespace view {
+class SelectableItem;
+}
+
 MainWindow::MainWindow(DeviceManager &device_manager,
        const char *open_file_name,
        QWidget *parent) :
 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);
        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
        _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);
 }
 
        _sampling_bar->set_sampling(state != SigSession::Stopped);
 }
 
+void MainWindow::view_selection_changed()
+{
+       assert(_context_bar);
+
+       const list<weak_ptr<pv::view::SelectableItem> > items(
+               _view->selected_items());
+       _context_bar->set_selected_items(items);
+}
+
 } // namespace pv
 } // namespace pv
index 51577bdb742d9a53303ed260bfc77075e17a8aa8..001c28b037033d5394088b94455b046198799e2f 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <list>
 
 
 #include <list>
 
+#include <boost/weak_ptr.hpp>
+
 #include <QMainWindow>
 
 #include "sigsession.h"
 #include <QMainWindow>
 
 #include "sigsession.h"
@@ -97,6 +99,8 @@ private slots:
 
        void capture_state_changed(int state);
 
 
        void capture_state_changed(int state);
 
+       void view_selection_changed();
+
 private:
        DeviceManager &_device_manager;
 
 private:
        DeviceManager &_device_manager;
 
index 8e92676a5137c897557e968d67424b72b3df60a7..a538d64ac4caed2f68a44298b8cb6f4220b93a1e 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <stdio.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/foreach.hpp>
+
 #include "contextbar.h"
 
 #include "contextbar.h"
 
+#include <pv/view/selectableitem.h>
+
+using namespace boost;
 using namespace std;
 
 namespace pv {
 using namespace std;
 
 namespace pv {
@@ -30,5 +38,27 @@ ContextBar::ContextBar(QWidget *parent) :
 {
 }
 
 {
 }
 
+void ContextBar::set_selected_items(const list<
+       weak_ptr<pv::view::SelectableItem> > &items)
+{
+       clear();
+
+       if (items.empty())
+               return;
+
+       if (shared_ptr<pv::view::SelectableItem> item =
+               items.front().lock()) {
+
+               assert(item);
+
+               const list<QAction*> actions(
+                       item->get_context_bar_actions());
+               BOOST_FOREACH(QAction *action, actions) {
+                       assert(action);
+                       addAction(action);
+               }
+       }
+}
+
 } // namespace toolbars
 } // namespace pv
 } // namespace toolbars
 } // namespace pv
index 02ff37e15aebb84c723a6e4ce8007a23725f5232..6d8e7f3f9bd591fa7d0d579be399b290918d8105 100644 (file)
 #ifndef PULSEVIEW_PV_TOOLBARS_CONTEXTBAR_H
 #define PULSEVIEW_PV_TOOLBARS_CONTEXTBAR_H
 
 #ifndef PULSEVIEW_PV_TOOLBARS_CONTEXTBAR_H
 #define PULSEVIEW_PV_TOOLBARS_CONTEXTBAR_H
 
+#include <boost/weak_ptr.hpp>
+
 #include <QToolBar>
 
 #include <QToolBar>
 
+#include <pv/view/selectableitem.h>
+
 namespace pv {
 namespace toolbars {
 
 namespace pv {
 namespace toolbars {
 
@@ -32,6 +36,10 @@ class ContextBar : public QToolBar
 
 public:
        ContextBar(QWidget *parent);
 
 public:
        ContextBar(QWidget *parent);
+
+public:
+       void set_selected_items(const std::list<
+               boost::weak_ptr<pv::view::SelectableItem> > &items);
 };
 
 } // namespace toolbars
 };
 
 } // namespace toolbars