+void LogicSignal::init_trigger_actions(QWidget *parent)
+{
+ _trigger_none = new QAction(QIcon(":/icons/trigger-none.svg"),
+ tr("No trigger"), parent);
+ _trigger_none->setCheckable(true);
+ connect(_trigger_none, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ _trigger_rising = new QAction(QIcon(":/icons/trigger-rising.svg"),
+ tr("Trigger on rising edge"), parent);
+ _trigger_rising->setCheckable(true);
+ connect(_trigger_rising, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ _trigger_high = new QAction(QIcon(":/icons/trigger-high.svg"),
+ tr("Trigger on high level"), parent);
+ _trigger_high->setCheckable(true);
+ connect(_trigger_high, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ _trigger_falling = new QAction(QIcon(":/icons/trigger-falling.svg"),
+ tr("Trigger on falling edge"), parent);
+ _trigger_falling->setCheckable(true);
+ connect(_trigger_falling, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ _trigger_low = new QAction(QIcon(":/icons/trigger-low.svg"),
+ tr("Trigger on low level"), parent);
+ _trigger_low->setCheckable(true);
+ connect(_trigger_low, SIGNAL(triggered()), this, SLOT(on_trigger()));
+
+ _trigger_change = new QAction(QIcon(":/icons/trigger-change.svg"),
+ tr("Trigger on rising or falling edge"), parent);
+ _trigger_change->setCheckable(true);
+ connect(_trigger_change, SIGNAL(triggered()), this, SLOT(on_trigger()));
+}
+
+QAction* LogicSignal::match_action(const TriggerMatchType *type)
+{
+ 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();
+}
+