+ QAction *action;
+
+ action = _trigger_none;
+ if (type) {
+ switch (type->id()) {
+ case SR_TRIGGER_ZERO:
+ action = _trigger_low;
+ break;
+ case SR_TRIGGER_ONE:
+ action = _trigger_high;
+ break;
+ case SR_TRIGGER_RISING:
+ action = _trigger_rising;
+ break;
+ case SR_TRIGGER_FALLING:
+ action = _trigger_falling;
+ break;
+ case SR_TRIGGER_EDGE:
+ action = _trigger_change;
+ break;
+ default:
+ assert(0);
+ }
+ }
+
+ 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();