From: Soeren Apel Date: Wed, 6 Nov 2019 19:43:56 +0000 (+0100) Subject: Fix #1412 by only showing suitable PDs, not all of them X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cf0a3c9c7a8763eeb4427e4fb6fe2c921ae38f09;p=pulseview.git Fix #1412 by only showing suitable PDs, not all of them --- diff --git a/pv/views/trace/decodetrace.cpp b/pv/views/trace/decodetrace.cpp index 65a2bf6c..8ff00cd2 100644 --- a/pv/views/trace/decodetrace.cpp +++ b/pv/views/trace/decodetrace.cpp @@ -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 > &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); } diff --git a/pv/views/trace/decodetrace.hpp b/pv/views/trace/decodetrace.hpp index 3d25c3e4..6779712e 100644 --- a/pv/views/trace/decodetrace.hpp +++ b/pv/views/trace/decodetrace.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -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 &dec, QWidget *parent, QFormLayout *form); @@ -224,6 +227,7 @@ private: pair selected_sample_range_; vector decoder_forms_; + QPushButton* stack_button_; map row_title_widths_; int row_height_, max_visible_rows_; diff --git a/pv/widgets/decodermenu.cpp b/pv/widgets/decodermenu.cpp index 28b54bab..9fcc0cf0 100644 --- a/pv/widgets/decodermenu.cpp +++ b/pv/widgets/decodermenu.cpp @@ -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); diff --git a/pv/widgets/decodermenu.hpp b/pv/widgets/decodermenu.hpp index 2fe7cd2b..6ef4d2c6 100644 --- a/pv/widgets/decodermenu.hpp +++ b/pv/widgets/decodermenu.hpp @@ -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);