+ }
+
+ return action;
+}
+
+const TriggerMatchType *LogicSignal::action_match(QAction *action)
+{
+ if (action == trigger_low_)
+ return TriggerMatchType::ZERO;
+ else if (action == trigger_high_)
+ return TriggerMatchType::ONE;
+ else if (action == trigger_rising_)
+ return TriggerMatchType::RISING;
+ else if (action == trigger_falling_)
+ return TriggerMatchType::FALLING;
+ else if (action == trigger_change_)
+ return TriggerMatchType::EDGE;
+ else
+ return nullptr;
+}
+
+void LogicSignal::populate_popup_form(QWidget *parent, QFormLayout *form)
+{
+ Glib::VariantContainerBase gvar;
+ vector<int32_t> trig_types;
+
+ Signal::populate_popup_form(parent, form);
+
+ try {
+ gvar = device_->config_list(ConfigKey::TRIGGER_MATCH);
+ } catch (Error e) {
+ return;
+ }
+
+ trigger_bar_ = new QToolBar(parent);
+ init_trigger_actions(trigger_bar_);
+ trigger_bar_->addAction(trigger_none_);
+ trigger_none_->setChecked(!trigger_match_);
+ trig_types =
+ Glib::VariantBase::cast_dynamic<Glib::Variant<vector<int32_t>>>(
+ gvar).get();
+ for (auto type_id : trig_types) {
+ auto type = TriggerMatchType::get(type_id);
+ trigger_bar_->addAction(match_action(type));
+ match_action(type)->setChecked(trigger_match_ == type);
+ }
+ form->addRow(tr("Trigger"), trigger_bar_);
+
+}
+
+void LogicSignal::modify_trigger()
+{
+ auto trigger = session_.session()->trigger();
+ auto new_trigger = session_.device_manager().context()->create_trigger("pulseview");
+
+ if (trigger) {
+ for (auto stage : trigger->stages()) {
+ const auto &matches = stage->matches();
+ if (std::none_of(begin(matches), end(matches),
+ [&](shared_ptr<TriggerMatch> match) {
+ return match->channel() != channel_; }))
+ continue;
+
+ auto new_stage = new_trigger->add_stage();
+ for (auto match : stage->matches()) {
+ if (match->channel() == channel_)
+ continue;
+ new_stage->add_match(match->channel(), match->type());
+ }
+ }
+ }
+
+ if (trigger_match_)
+ new_trigger->add_stage()->add_match(channel_, trigger_match_);
+
+ session_.session()->set_trigger(
+ new_trigger->stages().empty() ? nullptr : new_trigger);
+}
+
+void LogicSignal::on_trigger()
+{
+ QAction *action;
+
+ match_action(trigger_match_)->setChecked(false);
+
+ action = (QAction *)sender();
+ action->setChecked(true);
+ trigger_match_ = action_match(action);
+
+ modify_trigger();