Fix #1412 by only showing suitable PDs, not all of them
authorSoeren Apel <soeren@apelpie.net>
Wed, 6 Nov 2019 19:43:56 +0000 (20:43 +0100)
committerSoeren Apel <soeren@apelpie.net>
Wed, 6 Nov 2019 20:11:00 +0000 (21:11 +0100)
pv/views/trace/decodetrace.cpp
pv/views/trace/decodetrace.hpp
pv/widgets/decodermenu.cpp
pv/widgets/decodermenu.hpp

index 65a2bf6c6a72f3e773b837e1941565bd7378012a..8ff00cd296ecb005a99dcbcc69219ee5023c67de 100644 (file)
@@ -263,6 +263,31 @@ void DecodeTrace::paint_fore(QPainter &p, ViewItemPaintParams &pp)
                paint_hover_marker(p);
 }
 
+void DecodeTrace::update_stack_button()
+{
+       const vector< shared_ptr<data::decode::Decoder> > &stack = decode_signal_->decoder_stack();
+
+       // Only show decoders in the menu that can be stacked onto the last one in the stack
+       if (!stack.empty()) {
+               const srd_decoder* d = stack.back()->decoder();
+
+               if (d->outputs) {
+                       pv::widgets::DecoderMenu *const decoder_menu =
+                               new pv::widgets::DecoderMenu(stack_button_, (const char*)(d->outputs->data));
+                       connect(decoder_menu, SIGNAL(decoder_selected(srd_decoder*)),
+                               this, SLOT(on_stack_decoder(srd_decoder*)));
+
+                       stack_button_->setMenu(decoder_menu);
+                       stack_button_->show();
+                       return;
+               }
+       }
+
+       // No decoders available for stacking
+       stack_button_->setMenu(nullptr);
+       stack_button_->hide();
+}
+
 void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
        using pv::data::decode::Decoder;
@@ -297,18 +322,12 @@ void DecodeTrace::populate_popup_form(QWidget *parent, QFormLayout *form)
        }
 
        // Add stacking button
-       pv::widgets::DecoderMenu *const decoder_menu =
-               new pv::widgets::DecoderMenu(parent);
-       connect(decoder_menu, SIGNAL(decoder_selected(srd_decoder*)),
-               this, SLOT(on_stack_decoder(srd_decoder*)));
-
-       QPushButton *const stack_button =
-               new QPushButton(tr("Stack Decoder"), parent);
-       stack_button->setMenu(decoder_menu);
-       stack_button->setToolTip(tr("Stack a higher-level decoder on top of this one"));
+       stack_button_ = new QPushButton(tr("Stack Decoder"), parent);
+       stack_button_->setToolTip(tr("Stack a higher-level decoder on top of this one"));
+       update_stack_button();
 
        QHBoxLayout *stack_button_box = new QHBoxLayout;
-       stack_button_box->addWidget(stack_button, 0, Qt::AlignRight);
+       stack_button_box->addWidget(stack_button_, 0, Qt::AlignRight);
        form->addRow(stack_button_box);
 }
 
index 3d25c3e4d7410f10853204ba21116dc363610c40..6779712e689c681113f5f00d8fb369fa49eb4ac0 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <QColor>
 #include <QComboBox>
+#include <QPushButton>
 #include <QSignalMapper>
 #include <QTimer>
 
@@ -168,6 +169,8 @@ private:
 
        const QString get_annotation_at_point(const QPoint &point);
 
+       void update_stack_button();
+
        void create_decoder_form(int index,
                shared_ptr<pv::data::decode::Decoder> &dec,
                QWidget *parent, QFormLayout *form);
@@ -224,6 +227,7 @@ private:
        pair<uint64_t, uint64_t> selected_sample_range_;
 
        vector<pv::widgets::DecoderGroupBox*> decoder_forms_;
+       QPushButton* stack_button_;
 
        map<data::decode::Row, int> row_title_widths_;
        int row_height_, max_visible_rows_;
index 28b54babdfb9aad3c0e67e2a732b22ac79cbe918..9fcc0cf077c5e7a00b6a0e7ccadc0cb3e7590383 100644 (file)
@@ -26,7 +26,7 @@
 namespace pv {
 namespace widgets {
 
-DecoderMenu::DecoderMenu(QWidget *parent, bool first_level_decoder) :
+DecoderMenu::DecoderMenu(QWidget *parent, const char* input, bool first_level_decoder) :
        QMenu(parent),
        mapper_(this)
 {
@@ -37,14 +37,25 @@ DecoderMenu::DecoderMenu(QWidget *parent, bool first_level_decoder) :
                assert(d);
 
                const bool have_channels = (d->channels || d->opt_channels) != 0;
-               if (first_level_decoder == have_channels) {
-                       QAction *const action =
-                               addAction(QString::fromUtf8(d->name));
-                       action->setData(qVariantFromValue(l->data));
-                       mapper_.setMapping(action, action);
-                       connect(action, SIGNAL(triggered()),
-                               &mapper_, SLOT(map()));
+               if (first_level_decoder != have_channels)
+                       continue;
+
+               if (!first_level_decoder) {
+                       // Dismiss all non-stacked decoders unless we're looking for first-level decoders
+                       if (!d->inputs)
+                               continue;
+
+                       // TODO For now we ignore that d->inputs is actually a list
+                       if (strncmp((char*)(d->inputs->data), input, 1024) != 0)
+                               continue;
                }
+
+               QAction *const action =
+                       addAction(QString::fromUtf8(d->name));
+               action->setData(qVariantFromValue(l->data));
+               mapper_.setMapping(action, action);
+               connect(action, SIGNAL(triggered()),
+                       &mapper_, SLOT(map()));
        }
        g_slist_free(li);
 
index 2fe7cd2b28e9e1c68f0ab093e456a44f80ed2c11..6ef4d2c6bdffcde8827a550069b5b34484b8c788 100644 (file)
@@ -33,7 +33,7 @@ class DecoderMenu : public QMenu
        Q_OBJECT;
 
 public:
-       DecoderMenu(QWidget *parent, bool first_level_decoder = false);
+       DecoderMenu(QWidget *parent, const char* input, bool first_level_decoder = false);
 
 private:
        static int decoder_name_cmp(const void *a, const void *b);