]> sigrok.org Git - pulseview.git/commitdiff
Added decoders list
authorJoel Holdsworth <redacted>
Sat, 1 Jun 2013 15:30:25 +0000 (16:30 +0100)
committerJoel Holdsworth <redacted>
Sun, 22 Sep 2013 22:15:05 +0000 (23:15 +0100)
pv/mainwindow.cpp
pv/mainwindow.h

index 5fe4ccb6cfb63cce767ef5bbb142d99216503528..02df0ad510e3fb38be0b108daf444804e1fbfcfc 100644 (file)
@@ -65,7 +65,8 @@ MainWindow::MainWindow(DeviceManager &device_manager,
        QWidget *parent) :
        QMainWindow(parent),
        _device_manager(device_manager),
-       _session(device_manager)
+       _session(device_manager),
+       _decoders_add_mapper(this)
 {
        setup_ui();
        if (open_file_name) {
@@ -173,6 +174,20 @@ void MainWindow::setup_ui()
                "MainWindow", "Show &Cursors", 0, QApplication::UnicodeUTF8));
        _menu_view->addAction(_action_view_show_cursors);
 
+       // Decoders Menu
+       _menu_decoders = new QMenu(_menu_bar);
+       _menu_decoders->setTitle(QApplication::translate(
+               "MainWindow", "&Decoders", 0, QApplication::UnicodeUTF8));
+
+       _menu_decoders_add = new QMenu(_menu_decoders);
+       _menu_decoders_add->setTitle(QApplication::translate(
+               "MainWindow", "&Add", 0, QApplication::UnicodeUTF8));
+       setup_add_decoders(_menu_decoders_add);
+
+       _menu_decoders->addMenu(_menu_decoders_add);
+       connect(&_decoders_add_mapper, SIGNAL(mapped(QObject*)),
+               this, SLOT(add_decoder(QObject*)));
+
        // Help Menu
        _menu_help = new QMenu(_menu_bar);
        _menu_help->setTitle(QApplication::translate(
@@ -186,6 +201,7 @@ void MainWindow::setup_ui()
 
        _menu_bar->addAction(_menu_file->menuAction());
        _menu_bar->addAction(_menu_view->menuAction());
+       _menu_bar->addAction(_menu_decoders->menuAction());
        _menu_bar->addAction(_menu_help->menuAction());
 
        setMenuBar(_menu_bar);
@@ -278,6 +294,27 @@ void MainWindow::show_session_error(
        msg.exec();
 }
 
+gint MainWindow::decoder_name_cmp(gconstpointer a, gconstpointer b)
+{
+       return strcmp(((const srd_decoder*)a)->name,
+               ((const srd_decoder*)b)->name);
+}
+
+void MainWindow::setup_add_decoders(QMenu *parent)
+{
+       GSList *l = g_slist_sort(g_slist_copy(
+               (GSList*)srd_decoder_list()), decoder_name_cmp);
+       while ((l = l->next)) {
+               QAction *const action = parent->addAction(QString(
+                       ((srd_decoder*)l->data)->name));
+               action->setData(qVariantFromValue(l->data));
+               _decoders_add_mapper.setMapping(action, action);
+               connect(action, SIGNAL(triggered()),
+                       &_decoders_add_mapper, SLOT(map()));
+       }
+       g_slist_free(l);
+}
+
 void MainWindow::on_actionOpen_triggered()
 {
        // Enumerate the file formats
@@ -343,6 +380,11 @@ void MainWindow::device_selected()
        _session.set_device(_sampling_bar->get_selected_device());
 }
 
+void MainWindow::add_decoder(QObject *action)
+{
+       (void)action;
+}
+
 void MainWindow::run_stop()
 {
        switch(_session.get_capture_state()) {
index 001c28b037033d5394088b94455b046198799e2f..b4b64f779de1419ac4686defedd67566c942aa5c 100644 (file)
@@ -26,6 +26,7 @@
 #include <boost/weak_ptr.hpp>
 
 #include <QMainWindow>
+#include <QSignalMapper>
 
 #include "sigsession.h"
 
@@ -73,6 +74,9 @@ private:
        void update_device_list(
                struct sr_dev_inst *selected_device = NULL);
 
+       static gint decoder_name_cmp(gconstpointer a, gconstpointer b);
+       void setup_add_decoders(QMenu *parent);
+
 private slots:
        void load_file(QString file_name);
 
@@ -95,6 +99,8 @@ private slots:
 
        void device_selected();
 
+       void add_decoder(QObject *action);
+
        void run_stop();
 
        void capture_state_changed(int state);
@@ -119,6 +125,10 @@ private:
        QAction *_action_view_zoom_out;
        QAction *_action_view_show_cursors;
 
+       QMenu *_menu_decoders;
+       QMenu *_menu_decoders_add;
+       QSignalMapper _decoders_add_mapper;
+
        QMenu *_menu_help;
        QAction *_action_about;