+ if (!enabled())
+ return QString();
+
+ const pair<uint64_t, uint64_t> sample_range =
+ get_sample_range(point.x(), point.x() + 1);
+ const int row = get_row_at_point(point);
+ if (row < 0)
+ return QString();
+
+ vector<pv::data::decode::Annotation> annotations;
+
+ assert(decoder_stack_);
+ decoder_stack_->get_annotation_subset(annotations, visible_rows_[row],
+ sample_range.first, sample_range.second);
+
+ return (annotations.empty()) ?
+ QString() : annotations[0].annotations().front();
+}
+
+void DecodeTrace::hover_point_changed()
+{
+ assert(owner_);
+
+ const View *const view = owner_->view();
+ assert(view);
+
+ QPoint hp = view->hover_point();
+ QString ann = get_annotation_at_point(hp);
+
+ assert(view);
+
+ if (!row_height_ || ann.isEmpty()) {
+ QToolTip::hideText();
+ return;
+ }
+
+ const int hover_row = get_row_at_point(hp);
+
+ QFontMetrics m(QToolTip::font());
+ const QRect text_size = m.boundingRect(QRect(), 0, ann);
+
+ // This is OS-specific and unfortunately we can't query it, so
+ // use an approximation to at least try to minimize the error.
+ const int padding = 8;
+
+ // Make sure the tool tip doesn't overlap with the mouse cursor.
+ // If it did, the tool tip would constantly hide and re-appear.
+ // We also push it up by one row so that it appears above the
+ // decode trace, not below.
+ hp.setX(hp.x() - (text_size.width() / 2) - padding);
+
+ hp.setY(get_visual_y() - (row_height_ / 2) +
+ (hover_row * row_height_) -
+ row_height_ - text_size.height() - padding);
+
+ QToolTip::showText(view->viewport()->mapToGlobal(hp), ann);
+}
+
+void DecodeTrace::create_decoder_form(int index,
+ shared_ptr<data::decode::Decoder> &dec, QWidget *parent,
+ QFormLayout *form)
+{
+ const GSList *l;
+
+ assert(dec);
+ const srd_decoder *const decoder = dec->decoder();
+ assert(decoder);
+
+ pv::widgets::DecoderGroupBox *const group =
+ new pv::widgets::DecoderGroupBox(
+ QString::fromUtf8(decoder->name));
+ group->set_decoder_visible(dec->shown());
+
+ delete_mapper_.setMapping(group, index);
+ connect(group, SIGNAL(delete_decoder()), &delete_mapper_, SLOT(map()));
+
+ show_hide_mapper_.setMapping(group, index);
+ connect(group, SIGNAL(show_hide_decoder()),
+ &show_hide_mapper_, SLOT(map()));
+
+ QFormLayout *const decoder_form = new QFormLayout;
+ group->add_layout(decoder_form);
+
+ // Add the mandatory channels
+ for(l = decoder->channels; l; l = l->next) {
+ const struct srd_channel *const pdch =
+ (struct srd_channel *)l->data;
+ QComboBox *const combo = create_channel_selector(parent, dec, pdch);
+ connect(combo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(on_channel_selected(int)));
+ decoder_form->addRow(tr("<b>%1</b> (%2) *")
+ .arg(QString::fromUtf8(pdch->name))
+ .arg(QString::fromUtf8(pdch->desc)), combo);
+
+ const ChannelSelector s = {combo, dec, pdch};
+ channel_selectors_.push_back(s);
+ }
+
+ // Add the optional channels
+ for(l = decoder->opt_channels; l; l = l->next) {
+ const struct srd_channel *const pdch =
+ (struct srd_channel *)l->data;
+ QComboBox *const combo = create_channel_selector(parent, dec, pdch);
+ connect(combo, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(on_channel_selected(int)));
+ decoder_form->addRow(tr("<b>%1</b> (%2)")
+ .arg(QString::fromUtf8(pdch->name))
+ .arg(QString::fromUtf8(pdch->desc)), combo);
+
+ const ChannelSelector s = {combo, dec, pdch};
+ channel_selectors_.push_back(s);
+ }
+
+ // Add the options
+ shared_ptr<prop::binding::DecoderOptions> binding(
+ new prop::binding::DecoderOptions(decoder_stack_, dec));
+ binding->add_properties_to_form(decoder_form, true);
+
+ bindings_.push_back(binding);
+
+ form->addRow(group);
+ decoder_forms_.push_back(group);
+}
+
+QComboBox* DecodeTrace::create_channel_selector(
+ QWidget *parent, const shared_ptr<data::decode::Decoder> &dec,
+ const srd_channel *const pdch)
+{
+ assert(dec);
+
+ shared_lock<shared_mutex> lock(session_.signals_mutex());
+ const vector< shared_ptr<Signal> > &sigs(session_.signals());
+
+ assert(decoder_stack_);
+ const auto channel_iter = dec->channels().find(pdch);